fix(rectification): bind quality cards to the followup probe
Independent Staging Quality Gate / validate (push) Successful in 23m15s
Independent Staging Quality Gate / publish (push) Failing after 36s

Graduation no longer gets the college-experience question, and identical D24 splits only ask once.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-09-04 23:47:47 +08:00
parent 73c2a1a51e
commit 40c623edf6
9 changed files with 462 additions and 9 deletions
+161
View File
@@ -9,7 +9,10 @@ from scripts.rectification.event_probes import (
MAX_COLLECTION_PROBES,
MAX_PROBES,
MAX_PROBES_PER_DOMAIN,
MAX_QUALITY_DISTINGUISH_PROBES,
_agent_brief,
_quality_distinguish_probes,
_select_quality_distinguish_rows,
discriminating_event_probes,
event_clarification_probes,
evidence_collection_probes,
@@ -900,5 +903,163 @@ class EventProbesTest(unittest.TestCase):
self.assertEqual({int(item["year"]) for item in relocation}, {2016, 2019, 2022})
def _education_event(event_id: str, kind: str, date: str, summary: str) -> dict:
return {
"id": event_id,
"domain": "education",
"event_kind": kind,
"summary": summary,
"date": date,
"precision": "month",
}
def _d24_split_clusters() -> list[dict]:
return [
{
"representative": {"feature": {"varga_ascendants": {"D24": 1}}},
"times": ["05:00", "05:01"],
},
{
"representative": {"feature": {"varga_ascendants": {"D24": 2}}},
"times": ["05:10", "05:11"],
},
]
def _quality_rows(*events: dict) -> list[dict]:
return _quality_distinguish_probes(
list(events),
_d24_split_clusters(),
set_version="quality-dedupe-set",
holdout_ids=set(),
holdout_keys=set(),
)
class QualityDistinguishDedupeTests(unittest.TestCase):
def test_start_and_completion_emit_one_quality_probe_for_start(self) -> None:
start = _education_event(
"00000000-0000-4000-8000-000000000021",
"education_start",
"2014-09-01",
"入学",
)
completion = _education_event(
"00000000-0000-4000-8000-000000000022",
"education_completion",
"2018-06-01",
"毕业",
)
rows = _quality_rows(start, completion)
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["target_evidence_id"], start["id"])
self.assertEqual(rows[0]["year"], 2014)
self.assertNotIn(completion["id"], [item["target_evidence_id"] for item in rows])
def test_completion_alone_emits_no_quality_probe(self) -> None:
completion = _education_event(
"00000000-0000-4000-8000-000000000022",
"education_completion",
"2018-06-01",
"毕业",
)
self.assertEqual(_quality_rows(completion), [])
def test_completion_still_participates_in_ordinary_time_probes(self) -> None:
request = _request(events=[
_education_event(
"00000000-0000-4000-8000-000000000022",
"education_completion",
"2018-06-01",
"毕业",
),
{
"id": "00000000-0000-4000-8000-000000000013",
"domain": "career",
"event_kind": "career_entry",
"summary": "入职",
"date": "2018-07-01",
"precision": "month",
},
{
"id": "00000000-0000-4000-8000-000000000014",
"domain": "relationship",
"event_kind": "relationship_start",
"summary": "相识",
"date": "2021-08-01",
"precision": "month",
},
{
"id": "00000000-0000-4000-8000-000000000015",
"domain": "family",
"event_kind": "family_event",
"summary": "家里添丁",
"date": "2020-01-01",
"precision": "year",
},
])
probes = _probes(request, _multi_layer_window_built(), ["05:00", "05:06", "05:07"], "05:00")
quality = [item for item in probes if item["source"] == "known_event_quality"]
self.assertEqual(quality, [])
self.assertTrue(probes)
self.assertTrue(any(item["source"] in {"dasha_boundary", "dasha_activation"} for item in probes))
def test_same_split_keeps_earliest_eligible_education_event(self) -> None:
start = _education_event(
"00000000-0000-4000-8000-000000000021",
"education_start",
"2014-09-01",
"入学",
)
change = _education_event(
"00000000-0000-4000-8000-000000000023",
"education_change",
"2016-03-01",
"转学",
)
rows = _quality_rows(start, change)
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["target_evidence_id"], start["id"])
def test_different_quality_groups_keep_two_up_to_cap(self) -> None:
def stub(year: int, month: int, supports: list[str], conflicts: list[str], evidence_id: str) -> dict:
return {
"domain": "education",
"year": year,
"month": month,
"information_gain": 0.5,
"target_evidence_id": evidence_id,
"expected_outcomes": [
{"answer_class": "yes", "supports": supports, "conflicts": conflicts},
{"answer_class": "no", "supports": conflicts, "conflicts": supports},
],
}
same_split = _select_quality_distinguish_rows([
stub(2014, 9, ["05:00"], ["05:10"], "start"),
stub(2016, 3, ["05:00"], ["05:10"], "change"),
])
self.assertEqual(len(same_split), 1)
self.assertEqual(same_split[0]["target_evidence_id"], "start")
different = _select_quality_distinguish_rows([
stub(2014, 9, ["05:00"], ["05:10"], "start"),
stub(2016, 3, ["05:02"], ["05:12"], "change"),
])
self.assertEqual(len(different), 2)
self.assertEqual(
{item["target_evidence_id"] for item in different},
{"start", "change"},
)
over_cap = _select_quality_distinguish_rows([
stub(2014, 9, ["05:00"], ["05:10"], "a"),
stub(2015, 9, ["05:02"], ["05:12"], "b"),
stub(2016, 9, ["05:04"], ["05:14"], "c"),
])
self.assertEqual(len(over_cap), MAX_QUALITY_DISTINGUISH_PROBES)
if __name__ == "__main__":
unittest.main()