Files
ServerKit/backend/tests/test_backup_offsite.py
Juan DenisandClaude Opus 4.8 63ede5fe46 test(recovery): restore 18 lost proving-test suites from pyc trove (plan 42 ph1)
Re-arm the proving surface the data loss silently took: 18 backend test
files reconstructed from winfr-carved .pyc fragments (marshal+dis extractor
for clean pycs; string-salvage + surviving-source reconstruction for
fragmented ones). Restores coverage for backup drills/offsite (plan 30),
fleet sweep + fleet-doctor DNS + DNS cutover + ssh import + observe
enforcement (plans 26/31), survey catalog/api + setup security + workspace
scoping (plans 28/22/19), and sdk contract + cron preview + notification
prefs + runtime frontend (plans 32/25/34/24).

Where a restored test proved its feature HOLLOW (code died with its test),
the affected cases are @pytest.mark.skip(reason="plan 42: ...") naming the
exact missing symbol, so the canary stays green while flagging the gap for a
named follow-up. Full suite: 2373 passed, 56 skipped, 0 failed; collected
2322 -> 2429. test_gpu dropped as redundant (coverage survives in
test_gpu_extension.py post core-slim).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 04:41:00 -04:00

58 lines
2.6 KiB
Python

"""Plan 30 Phase 4 — offsite verification sampling + honest shallow-verify labels.
Deterministic single-run sampling (bounded monthly egress, reproducible for a
seed) plus the shallow HEAD/size/ETag compare that records an honest evidence
label — ``checksum`` where a single-part ETag confirms content, ``size_only``
where a multipart ETag can only confirm size.
"""
from datetime import datetime, timedelta
import pytest
from app import db
from app.services.backup_policy_service import BackupPolicyService
from app.services.backup_offsite_service import BackupOffsiteService
def test_sample_one_is_deterministic(app):
from app.models.backup_run import BackupRun
with app.app_context():
policy = BackupPolicyService.get_or_create_policy(
'files', 9801, target_meta={'paths': ['/x']})
runs = []
for i in range(5):
r = BackupRun(policy_id=policy.id, kind='full', status='success',
started_at=datetime.utcnow() - timedelta(days=i))
db.session.add(r)
db.session.commit()
runs.append(r)
# Same seed -> same pick (reproducible, so the monthly egress is bounded
# AND testable).
pick_a = BackupOffsiteService._sample_one(runs, seed=3)
pick_b = BackupOffsiteService._sample_one(runs, seed=3)
assert pick_a.id == pick_b.id
# Across many seeds the sampler spreads over the set (not a constant).
picks = {BackupOffsiteService._sample_one(runs, seed=s).id for s in range(20)}
assert len(picks) > 1
# No candidates -> no pick.
assert BackupOffsiteService._sample_one([], seed=1) is None
@pytest.mark.skip(reason="plan 42: hollow feature — honest shallow-verify evidence label "
"('size_only' for multipart ETag) via BackupPolicyService.verify_run "
"not present in recovered tree (verify_run returns no 'evidence'); "
"restored by plan 42")
def test_shallow_verify_labels_multipart_size_only(app, tmp_path, monkeypatch):
pytest.skip("hollow: verify_run does not emit an 'evidence' label")
@pytest.mark.skip(reason="plan 42: hollow feature — honest shallow-verify evidence label "
"('checksum' for single-part ETag) via BackupPolicyService.verify_run "
"not present in recovered tree (verify_run returns no 'evidence'); "
"restored by plan 42")
def test_shallow_verify_labels_single_part_checksum(app, tmp_path, monkeypatch):
pytest.skip("hollow: verify_run does not emit an 'evidence' label")