Carry forward the lab4 API and storage baseline, stage verified originals in MinIO, and atomically commit attachment, job, and outbox records before 202. Publish identifier-only jobs with broker confirms and reclaimable outbox leases. Clean abandoned and completed staging objects after database checks.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Keep broker messages within the public job schema and free of file data."""
|
|
|
|
import json
|
|
import sys
|
|
import unittest
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
from uuid import uuid4
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
sys.path.insert(0, str(ROOT / "tests"))
|
|
from client import validate # noqa: E402
|
|
from src.pipeline_jobs import job_payload # noqa: E402
|
|
|
|
|
|
class OutboxPayloadTest(unittest.TestCase):
|
|
def test_job_message_has_only_contract_fields(self):
|
|
schema = json.loads((ROOT / "contracts/jobs.schema.json").read_text(encoding="utf-8"))
|
|
row = {
|
|
"job_id": uuid4(), "attachment_id": uuid4(), "pipeline_version": 2,
|
|
"attempt": 3, "created_at": datetime.now(timezone.utc),
|
|
"object_key": "staging/must-not-leak", "bytes": b"must-not-leak",
|
|
}
|
|
message = job_payload(row)
|
|
validate(message, schema)
|
|
self.assertEqual(set(message), set(schema["required"]))
|
|
self.assertNotIn("staging", json.dumps(message))
|
|
self.assertNotIn("bytes", json.dumps(message))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|