Enhance Rematch Logic and Slot Filtering in Planning Path
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s

- Introduced `filter_rematch_slot_indices` to exclude preserved slots from rematching, improving the accuracy of slot assignments.
- Added `_slot_priority_for_rematch` to prioritize existing slot assignments during rematching, enhancing the robustness of the rematch process.
- Updated `_run_roadmap_rematch_loop` to utilize the new filtering and prioritization logic, ensuring better handling of rematch scenarios.
- Enhanced tests in `test_planning_path_rematch.py` to validate the new filtering behavior and ensure correct exercise restoration when not rejected.
- Bumped version to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-06-12 12:33:00 +02:00
1 parent f3710ac0a1
commit b8f65e04c5
4 files changed
+223 -6

No files matched your search

+101
View File
@@ -214,6 +214,7 @@ def test_rematch_unfilled_leaves_placeholder_step():
slot_indices={1},
rematch_reasons={1: "stage_mismatch"},
match_slot_fn=_no_match,
rejected_by_major={1: {99}},
)
assert len(ordered) == 2
@@ -235,3 +236,103 @@ def test_prune_filled_from_roadmap_unfilled():
unfilled_steps = [{"exercise_id": None, "roadmap_major_step_index": 5}]
kept2 = _prune_filled_from_roadmap_unfilled(unfilled_steps, [(4, spec)])
assert len(kept2) == 1
def test_rematch_keeps_same_exercise_when_not_rejected():
"""Regression: slot_assignment_history blockierte gültige Wiederzuordnung → leere Slots."""
specs = _stage_specs()
ctx = ProgressionRoadmapContext(
goal_query="Mae Geri",
max_steps=3,
stage_specs=specs,
)
steps = [
{"exercise_id": 10, "title": "OK", "roadmap_major_step_index": 0},
{"exercise_id": 42, "title": "Gut", "roadmap_major_step_index": 1},
]
def _same_match(cur, *, stage_spec, slot_priority_exercise_id=None, **kwargs):
assert slot_priority_exercise_id == 42
return (
{"exercise_id": 42, "title": "Gut", "roadmap_major_step_index": stage_spec.major_step_index},
None,
)
ordered, log, unfilled = rematch_roadmap_slots(
None,
tenant=None,
body=None,
goal_query="Mae Geri",
max_steps=3,
semantic_brief=None,
path_target_profile=None,
path_intent="",
roadmap_ctx=ctx,
steps=steps,
slot_indices={1},
rematch_reasons={1: "refine_stage_spec"},
match_slot_fn=_same_match,
rejected_by_major={},
)
assert ordered[1]["exercise_id"] == 42
assert log[0]["action"] == "replaced"
assert not unfilled
def test_rematch_restores_when_match_fails_and_not_rejected():
specs = _stage_specs()
ctx = ProgressionRoadmapContext(
goal_query="Mae Geri",
max_steps=3,
stage_specs=specs,
)
steps = [
{"exercise_id": 10, "title": "OK", "roadmap_major_step_index": 0},
{"exercise_id": 42, "title": "Gut", "roadmap_major_step_index": 1},
]
def _no_match(cur, *, stage_spec, **kwargs):
return None, stage_spec
ordered, log, unfilled = rematch_roadmap_slots(
None,
tenant=None,
body=None,
goal_query="Mae Geri",
max_steps=3,
semantic_brief=None,
path_target_profile=None,
path_intent="",
roadmap_ctx=ctx,
steps=steps,
slot_indices={1},
rematch_reasons={1: "refine_stage_spec"},
match_slot_fn=_no_match,
rejected_by_major={},
)
assert ordered[1]["exercise_id"] == 42
assert log[0]["action"] == "restored"
assert not unfilled
def test_filter_rematch_skips_preserved_slots():
from planning_path_rematch import filter_rematch_slot_indices
steps = [
{
"exercise_id": 10,
"roadmap_major_step_index": 0,
"roadmap_match_source": "slot_best_match",
"slot_status": "preserved",
},
{"exercise_id": 20, "roadmap_major_step_index": 1},
]
filtered = filter_rematch_slot_indices(
steps,
{0, 1},
stripped_off_topic=[],
off_topic_steps=[],
)
assert filtered == {1}