# orphans
# date: 2026-11-12T00:01:29  commit: 276dbda

$ docker compose --env-file .env --profile fault up -d api-fault
 Container mtusi-lab5-postgres-1 Running 
 Container mtusi-lab5-postgres-1 Waiting 
 Container mtusi-lab5-postgres-1 Healthy 
 Container mtusi-lab5-api-fault-1 Starting 
 Container mtusi-lab5-api-fault-1 Started 
[exit 0]

$ C:\Users\79152\AppData\Local\Python\pythoncore-3.14-64\python.exe student-tests/orphans.py --base-url http://localhost:8080 --fault-url http://localhost:8082
  ok   - fault replica (profile fault) is ready on --fault-url
  ok   - committed attachment that must survive every cleanup
  ok   - it is processed to ready (lab5)
  baseline: {'objects': 29, 'attachments': 29, 'upload_intents': 0}
== 1. прерванная загрузка ==
  ok   - no object, no metadata, no journal row after interrupted upload ({'objects': 29, 'attachments': 29, 'upload_intents': 0})
== 2. отказ БД после PUT: немедленная компенсация ==
  ok   - upload answered 503, not 202 (got 503)
  ok   - object deleted by compensation, journal clean ({'objects': 29, 'attachments': 29, 'upload_intents': 0})
== 3. процесс убит между PUT и COMMIT ==
  ok   - client did NOT get 202 (got 502)
  ok   - orphan object + journal row left behind, no metadata ({'objects': 30, 'attachments': 29, 'upload_intents': 1})
  ok   - default grace 900 s: fresh upload is NOT touched
  ok   - dry-run reports 1 object, changes nothing
  ok   - janitor removed orphan + journal row ({'grace_seconds': 5, 'dry_run': False, 'locked': True, 'intents_expired': 1, 'intents_removed': 1, 'objects_deleted': 1, 'would_delete_objects': 0, 'orphans_found': 0, 'errors': 0, 'duration_ms': 30.5})
  ok   - second run is a no-op (idempotent)
== 4. объект без журнала (страховочный обход bucket) ==
  ok   - untracked object planted
  ok   - scan with grace 1 h ignores a fresh object
  ok   - scan dry-run finds 1
  ok   - scan deletes the untracked object ({'grace_seconds': 5, 'dry_run': False, 'locked': True, 'intents_expired': 0, 'intents_removed': 0, 'objects_deleted': 1, 'would_delete_objects': 0, 'orphans_found': 1, 'errors': 0, 'objects_scanned': 30, 'duration_ms': 126.7})
== 5. готовые вложения не тронуты ==
  ok   - committed attachment still downloads, sha256 matches
  ok   - published original + metadata, staging cleaned, no journal row ({'staging_object_exists': False, 'original_object_exists': True, 'attachment_row': True, 'attachment_status': 'ready', 'upload_intent': False})

18 passed, 0 failed
[exit 0]

$ docker compose --env-file .env --profile fault stop api-fault
 Container mtusi-lab5-api-fault-1 Stopping 
 Container mtusi-lab5-api-fault-1 Stopped 
[exit 0]
