recon_gen.common.l2.serializer
serialize_l2(instance) → str — round-trip-stable YAML emit (X.4.d.3).
Inverse of loader.py::load_instance. Every field in the
L2Instance model is written back to YAML in a shape the loader
accepts; the contract is model equivalence under round-trip
(load → serialize → load → identical), NOT byte-equivalence to the
original YAML (per the SPEC: “drops freeform # comments, preserves
description:”).
The Studio editor (X.4.e+) calls this every PUT, so the cost matters but only weakly — Studio is one user iterating, not a hot path; the heaviest fixture (sasquatch_pr) emits in low-ms.
Severability: pure Python; no DB, no async, no Starlette. Imports only the model + theme + persona dataclasses.
Functions
|
Serialize an |
- recon_gen.common.l2.serializer.serialize_l2(instance)[source]
Serialize an
L2Instanceback to YAML text.Round-trip contract:
load_instance(write(serialize_l2(x)))is field-equal tox(every primitive’s dataclass __eq__ holds). Original YAML’s freeform comments are dropped (per SPEC); the loader’s required field set is honored, optional fields with their declared default are omitted to keep emitted YAML compact.Field order in the emitted YAML mirrors the loader’s read order so a git diff against the original is a clean per-field move when fields shift, not a wholesale re-sort.
- Return type:
str- Parameters:
instance (L2Instance)