test_serializer_key_order.py
python
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠ breaking
1 day ago
| 1 | """Unit tests for freeze-block key-order preservation (§K5.7 / K5b-r F3).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from tools.freeze_reviewer.serializer import dump_freeze_mapping, parse_freeze_mapping, round_trip_stable |
| 6 | |
| 7 | |
| 8 | def test_preserves_existing_key_relative_order() -> None: |
| 9 | data = { |
| 10 | "frozen_inputs": [{"id": "x", "path": "a"}], |
| 11 | "phase": "K", |
| 12 | "outputs": [{"id": "a", "path": "docs/a.md", "frozen": True}], |
| 13 | "custom_z": 1, |
| 14 | "custom_a": 2, |
| 15 | } |
| 16 | serialized = dump_freeze_mapping(data) |
| 17 | keys = list(parse_freeze_mapping(serialized).keys()) |
| 18 | assert keys == ["frozen_inputs", "phase", "outputs", "custom_z", "custom_a"] |
| 19 | |
| 20 | |
| 21 | def test_review_stamp_after_frozen_inputs() -> None: |
| 22 | data = { |
| 23 | "phase": "K", |
| 24 | "outputs": [{"id": "a", "path": "docs/a.md", "frozen": True}], |
| 25 | "frozen_inputs": [{"id": "x", "path": "a"}], |
| 26 | "review_stamp": {"verdict": "pass"}, |
| 27 | } |
| 28 | keys = list(parse_freeze_mapping(dump_freeze_mapping(data)).keys()) |
| 29 | assert keys == ["phase", "outputs", "frozen_inputs", "review_stamp"] |
| 30 | |
| 31 | |
| 32 | def test_review_stamp_after_outputs_when_no_frozen_inputs() -> None: |
| 33 | data = { |
| 34 | "phase": "K", |
| 35 | "outputs": [{"id": "a", "path": "docs/a.md", "frozen": True}], |
| 36 | "review_stamp": {"verdict": "pass"}, |
| 37 | "extra": True, |
| 38 | } |
| 39 | # Preserve relative order of non-stamp keys; stamp after outputs. |
| 40 | data_ordered = { |
| 41 | "phase": "K", |
| 42 | "outputs": [{"id": "a", "path": "docs/a.md", "frozen": True}], |
| 43 | "extra": True, |
| 44 | "review_stamp": {"verdict": "pass"}, |
| 45 | } |
| 46 | keys = list(parse_freeze_mapping(dump_freeze_mapping(data_ordered)).keys()) |
| 47 | assert keys.index("review_stamp") == keys.index("outputs") + 1 |
| 48 | assert keys == ["phase", "outputs", "review_stamp", "extra"] |
| 49 | |
| 50 | |
| 51 | def test_round_trip_stable_with_custom_order() -> None: |
| 52 | data = { |
| 53 | "frozen_inputs": [{"id": "x", "path": "a"}], |
| 54 | "phase": "K", |
| 55 | "outputs": [{"id": "a", "path": "docs/a.md", "frozen": True}], |
| 56 | } |
| 57 | assert round_trip_stable(data) |
File History
1 commit
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠
1 day ago