feat(segmentation): parse the adjudication state a plan already carries

This commit is contained in:
Kjell Tore Guttormsen 2026-09-02 14:44:06 +02:00
commit 233cdc5671
2 changed files with 181 additions and 0 deletions

View file

@ -531,3 +531,101 @@ def test_an_entry_without_an_anchor_keeps_todays_offset_behaviour() -> None:
"""The anchor is a capability, not a new requirement on authored plans."""
sliced = slice_segments(SECTIONS, five_section_plan())
assert [item.span for item, _ in sliced] == list(SPANS)
# --- S5d: the adjudication state, parsed rather than discarded --------------
#
# The proposer has written `adjudicated: false` and `proposed_by` into every
# plan since the tool shipped, and the parser dropped both on the floor: a
# plan a human had ratified parsed into an object byte-identical to one nobody
# had looked at. The whole design rests on that distinction -- a proposal must
# never be replayable as an adjudication -- so it has to survive parsing
# before anything downstream can act on it.
#
# Key names are B2's, verbatim (`docs/plan/office-intake.md` § 5). One
# vocabulary from plan to frontmatter, so the profile that writes the marker
# has nothing to translate and nothing to get wrong.
def test_a_ratified_plan_and_an_unratified_one_are_distinguishable() -> None:
assert parse_segmentation_plan(plan(adjudicated=True)).adjudicated is True
assert parse_segmentation_plan(plan(adjudicated=False)).adjudicated is False
def test_an_unmarked_plan_is_not_adjudicated() -> None:
"""Absence is the safe reading: nobody ratified a plan that never said so.
The opposite default would let a plan predating the field replay as a
human judgement, which is the one thing this module exists to prevent.
"""
payload = plan()
assert "adjudicated" not in payload
assert parse_segmentation_plan(payload).adjudicated is False
def test_a_non_boolean_adjudicated_flag_is_refused() -> None:
"""`"false"` is truthy. A string here would ratify a plan by accident."""
error = parse_fails(plan(adjudicated="false"))
assert error.code == "segmentation_plan_invalid"
def test_the_proposer_identity_survives_parsing() -> None:
parsed = parse_segmentation_plan(plan(proposed_by="okf-propose-segments/1"))
assert parsed.proposed_by == "okf-propose-segments/1"
assert parse_segmentation_plan(plan()).proposed_by is None
def test_a_per_entry_verdict_round_trips_with_its_dwell_time() -> None:
"""Dwell time travels WITH the verdict, per B2.
A ratified flag carrying no per-item time is unfalsifiable, and it is the
same field that makes adjudication throughput measurable at all.
"""
verdict = {
"adjudicated_by": "ktg",
"adjudicated_at": "2026-09-02T10:00:00Z",
"adjudication_dwell_s": 41,
}
parsed = parse_segmentation_plan(plan(entries=[entry(adjudication=verdict)]))
record = parsed.entries[0].adjudication
assert record is not None
assert record.adjudicated_by == "ktg"
assert record.adjudicated_at == "2026-09-02T10:00:00Z"
assert record.adjudication_dwell_s == 41
assert parse_segmentation_plan(plan()).entries[0].adjudication is None
def test_a_verdict_missing_its_dwell_time_is_refused() -> None:
error = parse_fails(
plan(
entries=[
entry(
adjudication={
"adjudicated_by": "ktg",
"adjudicated_at": "2026-09-02T10:00:00Z",
}
)
]
)
)
assert error.code == "segmentation_plan_invalid"
assert "adjudication_dwell_s" in str(error)
def test_a_dwell_time_that_is_not_a_whole_number_of_seconds_is_refused() -> None:
"""Integer seconds, per B2. `True` is an `int` in Python and is not one."""
for bad in ("41", 41.5, True):
error = parse_fails(
plan(
entries=[
entry(
adjudication={
"adjudicated_by": "ktg",
"adjudicated_at": "2026-09-02T10:00:00Z",
"adjudication_dwell_s": bad,
}
)
]
)
)
assert error.code == "segmentation_plan_invalid"