diff --git a/src/durable_workflow/history_bundle_verify.py b/src/durable_workflow/history_bundle_verify.py index 64fa801..9cc17aa 100644 --- a/src/durable_workflow/history_bundle_verify.py +++ b/src/durable_workflow/history_bundle_verify.py @@ -545,7 +545,16 @@ def _check_payload_manifest(bundle: Mapping[str, Any], findings: list[dict[str, ) ) - if entry.get("codec") == "avro" and available: + # The same condition as the PHP and native verifiers: an available, + # unredacted Avro entry needs inline framing unless its diagnostic + # marks it as an external storage reference, which names an object + # outside the bundle. + if ( + entry.get("codec") == "avro" + and available + and not redacted + and diagnostic != "external_storage_reference" + ): if not _string_or_none(entry.get("avro_framing")): findings.append( _finding( diff --git a/tests/test_history_bundle_verify.py b/tests/test_history_bundle_verify.py index d4b75bc..30bcbb5 100644 --- a/tests/test_history_bundle_verify.py +++ b/tests/test_history_bundle_verify.py @@ -271,6 +271,88 @@ def test_writer_schema_fingerprint_mismatch_in_payload_manifest() -> None: assert report["status"] == STATUS_FAILED +def test_external_storage_reference_entries_need_no_avro_framing() -> None: + signing_key = "secret" + bundle = _base_bundle() + bundle["payload_manifest"]["entries"].append( + { + "path": "payloads.arguments.data", + "codec": "avro", + "available": True, + "redacted": False, + "encoding": "external-storage-reference", + "diagnostic": "external_storage_reference", + } + ) + bundle = _sign(bundle, signing_key, "key-1") + + report = verify_bundle(bundle, signing_key=signing_key) + + assert "payload_manifest.avro_framing_missing" not in _rule_names(report) + + +def test_external_encoding_without_matching_diagnostic_still_warns() -> None: + # PHP and native skip on the diagnostic alone, so an entry that only + # claims the external encoding is still checked. + signing_key = "secret" + bundle = _base_bundle() + bundle["payload_manifest"]["entries"].append( + { + "path": "payloads.arguments.data", + "codec": "avro", + "available": True, + "redacted": False, + "encoding": "external-storage-reference", + "diagnostic": None, + } + ) + bundle = _sign(bundle, signing_key, "key-1") + + report = verify_bundle(bundle, signing_key=signing_key) + + assert "payload_manifest.avro_framing_missing" in _rule_names(report) + + +def test_redacted_avro_entry_needs_no_framing() -> None: + signing_key = "secret" + bundle = _base_bundle() + bundle["payload_manifest"]["entries"].append( + { + "path": "payloads.output.data", + "codec": "avro", + "available": True, + "redacted": True, + "encoding": "base64-avro-single-object", + "diagnostic": None, + } + ) + bundle = _sign(bundle, signing_key, "key-1") + + report = verify_bundle(bundle, signing_key=signing_key) + + assert "payload_manifest.avro_framing_missing" not in _rule_names(report) + + +def test_inline_avro_entry_without_framing_still_warns() -> None: + signing_key = "secret" + bundle = _base_bundle() + bundle["payload_manifest"]["entries"].append( + { + "path": "payloads.output.data", + "codec": "avro", + "available": True, + "redacted": False, + "encoding": "base64-avro-single-object", + "diagnostic": None, + } + ) + bundle = _sign(bundle, signing_key, "key-1") + + report = verify_bundle(bundle, signing_key=signing_key) + + assert "payload_manifest.avro_framing_missing" in _rule_names(report) + + def test_required_evidence_sections_are_enforced() -> None: signing_key = "secret" bundle = _base_bundle()