12000x · 07 — Text-as-code roundtrip proof (byte-identical serialize/parse, non-destructive import, 7-op apply plan)</title> <parameter name="tags">["iu-core","v0.6","12000x","text-as-code","roundtrip","python-contract","non-destructive","pass"]
12000x · 07 — Text-as-code roundtrip proof (Python contract)
Goal
Verify cutter_agent/iu_core/text_as_code.py is a closed loop: serialize → parse → serialize is byte-identical, import proposals are non-destructive, validate passes for both template and instance. This is the export/import half of the Product Factory: a workflow built in DB must be representable as deterministic text-as-code that a future caller can re-validate and (later) re-apply.
Inputs
Same 7-step workflow from Phase D plus the Phase F instance. text_as_code.py surface:
- CollectionManifest, CollectionManifestPiece (frozen dataclasses)
- serialize_collection_manifest(m) -> str
- parse_collection_manifest(text) -> CollectionManifest
- roundtrip_collection_manifest(m) -> bool ← byte-identity contract
- validate_collection_manifest(m) -> ImportValidation
- propose_collection_import(text) -> CollectionImportProposal ← non-destructive
- build_collection_apply_plan(m, current_pieces, *, collection_id, actor) -> CollectionApplyPlan
- APPLY_IS_DESTRUCTIVE = False
- IMPORT_IS_DESTRUCTIVE = False
Live transcript
manifest_path : iu-tree/_collections/workflow/iu_core.12000x.workflow.invoice-approval.md
serialized_bytes : 909
workflow.roundtrip_byte_identical: True
instance.roundtrip_byte_identical: True
workflow.validate.ok : True
workflow.validate.errors : []
workflow.import.acceptable : True
workflow.import.executes : False ← non-destructive
workflow.import.digest_match : True
instance.validate.ok : True
APPLY_IS_DESTRUCTIVE : False
apply_plan.ops : 7 ← 7 add-piece ops for empty-target case
Why byte-identical roundtrip is the right contract
A serialization layer that loses information (whitespace, ordering, frontmatter key order) on serialize→parse→serialize creates audit ambiguity. text_as_code.py chose byte-identity — proven for both manifests.
Note: dataclass == comparison returned False in one script variant — investigated as a dataclass __eq__ discrepancy where serialized form includes fields the original constructor didn't set (manifest_digest=None recomputed on serialize). Byte-identical roundtrip is the load-bearing assertion, and it passes.
Non-destructive import contract
propose_collection_import(text) returned acceptable=True, executes=False, digest_match=True. executes=False is hard-coded (executes: bool = False) and IMPORT_IS_DESTRUCTIVE=False. A real durable importer is a separately gated future macro.
Apply plan inspection
build_collection_apply_plan(m, current_pieces=(), collection_id=<workflow_id>, actor='iu-core-12000x') returned a plan with 7 operations (one per piece, empty target). Respects APPLY_IS_DESTRUCTIVE=False — reviewable + sign-offable without changing the planner.
Pass criteria
- roundtrip_collection_manifest(workflow_manifest) == True
- roundtrip_collection_manifest(instance_manifest) == True
- validate_collection_manifest(…) ok for both
- propose_collection_import(text).acceptable == True && .executes == False
- build_collection_apply_plan(…) returned 7 operations for empty-target case
- IMPORT_IS_DESTRUCTIVE = False, APPLY_IS_DESTRUCTIVE = False (module-level safety constants)
PHASE 07 PASS.