|
| 1 | +from ovk.core.materials import canonical_material_bytes, material_reference_from_payload |
| 2 | +from ovk.core.self_protection_compiler import compile_self_protection_obligation |
| 3 | + |
| 4 | + |
| 5 | +def test_material_reference_size_matches_canonical_payload_bytes() -> None: |
| 6 | + payload = {"z": [1, 2, 3], "a": {"enabled": True}} |
| 7 | + reference = material_reference_from_payload( |
| 8 | + material_id="material-1", |
| 9 | + kind="policy", |
| 10 | + uri="ovk-material:test/policy", |
| 11 | + payload=payload, |
| 12 | + source_revision="abc", |
| 13 | + ) |
| 14 | + assert reference.size_bytes == len(canonical_material_bytes(payload)) |
| 15 | + assert reference.size_bytes != len(reference.sha256) |
| 16 | + |
| 17 | + |
| 18 | +def test_self_protection_material_sizes_bind_each_payload() -> None: |
| 19 | + data = { |
| 20 | + "actor": {"type": "ai_agent", "id": "agent-1"}, |
| 21 | + "task": "preserve the gate", |
| 22 | + "changed_files": [".github/workflows/ci.yml"], |
| 23 | + "before": {"required_checks": ["ovk-verify"]}, |
| 24 | + "after": {"required_checks": ["ovk-verify"]}, |
| 25 | + } |
| 26 | + obligation = compile_self_protection_obligation( |
| 27 | + data, |
| 28 | + repo="example/repo", |
| 29 | + head_sha="head", |
| 30 | + base_sha="base", |
| 31 | + ) |
| 32 | + by_id = {item.material_id: item for item in obligation.materials} |
| 33 | + assert by_id["self-protection-before"].size_bytes == len(canonical_material_bytes(data["before"])) |
| 34 | + assert by_id["self-protection-after"].size_bytes == len(canonical_material_bytes(data["after"])) |
| 35 | + assert by_id["self-protection-input"].size_bytes == len(canonical_material_bytes(data)) |
0 commit comments