Review fix: validate engine keys as child ids; every-day three-child walk
Review round 1 (Codex gpt-5.6-terra, 2 LOW): engine snapshot keys now pass _validate_child_id (True/1.0 compare equal to 1 and would be accepted then behave differently on lookup); the always-present test now walks all 28 days asserting all three children's expected verdicts instead of sampling every third day. Suite: 985 passed.
This commit is contained in:
@@ -339,6 +339,10 @@ class PresenceEngine:
|
|||||||
f"{schedules!r}"
|
f"{schedules!r}"
|
||||||
)
|
)
|
||||||
for child_id, schedule in schedules.items():
|
for child_id, schedule in schedules.items():
|
||||||
|
# Validate the KEY as a model child id too: True and 1.0
|
||||||
|
# compare equal to 1, so {True: schedule(1)} would be
|
||||||
|
# accepted and then behave differently on lookup.
|
||||||
|
_validate_child_id(child_id)
|
||||||
if not isinstance(schedule, PresenceSchedule):
|
if not isinstance(schedule, PresenceSchedule):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"schedules[{child_id!r}] must be a PresenceSchedule, "
|
f"schedules[{child_id!r}] must be a PresenceSchedule, "
|
||||||
|
|||||||
+18
-4
@@ -393,11 +393,21 @@ def _three_child_engine() -> PresenceEngine:
|
|||||||
|
|
||||||
|
|
||||||
def test_engine_child_without_schedule_is_always_present() -> None:
|
def test_engine_child_without_schedule_is_always_present() -> None:
|
||||||
|
"""Every day of the four-week span, all three children get the
|
||||||
|
expected verdict: Chloe (no schedule) always present; the two
|
||||||
|
rotation children complementary per the anchor pattern."""
|
||||||
engine = _three_child_engine()
|
engine = _three_child_engine()
|
||||||
# Chloe has no schedule: present every day, including weekends.
|
anchor = datetime.date(2026, 1, 5)
|
||||||
for offset in range(0, 28, 3):
|
for offset in range(28):
|
||||||
day = datetime.date(2026, 1, 5) + datetime.timedelta(days=offset)
|
day = anchor + datetime.timedelta(days=offset)
|
||||||
assert engine.is_present(3, day) is True, f"offset {offset}"
|
week = ((day - anchor).days // 7) % 2
|
||||||
|
assert engine.is_present(3, day) is True, f"offset {offset}: Chloe"
|
||||||
|
assert engine.is_present(1, day) is (week == 0), (
|
||||||
|
f"offset {offset}: Declan should follow week {week}"
|
||||||
|
)
|
||||||
|
assert engine.is_present(2, day) is (week == 1), (
|
||||||
|
f"offset {offset}: Jordyn should follow week {week}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_engine_alternating_children_are_complementary_for_four_weeks() -> None:
|
def test_engine_alternating_children_are_complementary_for_four_weeks() -> None:
|
||||||
@@ -449,6 +459,10 @@ def test_engine_rejects_bad_construction_and_inputs() -> None:
|
|||||||
PresenceEngine({1: "not-a-schedule"})
|
PresenceEngine({1: "not-a-schedule"})
|
||||||
with pytest.raises(ValueError, match="holds the schedule"):
|
with pytest.raises(ValueError, match="holds the schedule"):
|
||||||
PresenceEngine({2: schedule})
|
PresenceEngine({2: schedule})
|
||||||
|
with pytest.raises(ValueError, match="child_id must be an integer"):
|
||||||
|
PresenceEngine({True: schedule})
|
||||||
|
with pytest.raises(ValueError, match="child_id must be an integer"):
|
||||||
|
PresenceEngine({1.0: PresenceSchedule(1, 1, ANCHOR, {0: {0}})})
|
||||||
engine = PresenceEngine({1: schedule})
|
engine = PresenceEngine({1: schedule})
|
||||||
with pytest.raises(ValueError, match="child_id must be an integer"):
|
with pytest.raises(ValueError, match="child_id must be an integer"):
|
||||||
engine.is_present(True, ANCHOR)
|
engine.is_present(True, ANCHOR)
|
||||||
|
|||||||
Reference in New Issue
Block a user