import assert from "node:assert/strict"; import test from "node:test"; import { DATE_RELIABILITY_PROMPT, classifyDateReliabilityUtterance, pendingDateReliabilityEvidence, } from "../src/lib/rectification-agentic/v9/date-reliability.ts"; import { buildMethodFollowupPlan, planWithDateReliability, } from "../src/lib/rectification-agentic/v9/method-followup.ts"; const TURN_ID = "33333333-3333-4333-8333-333333333333"; const monthEvent = { id: "ev-month", status: "confirmed", domain: "education", datePrecision: "month", occurredFrom: "2016-09-01", occurredTo: "2016-09-30", eventKind: "education_start", sourceTurnId: TURN_ID, }; const dayEvent = { id: "ev-day", status: "confirmed", domain: "relationship", datePrecision: "day", occurredFrom: "2024-08-08", occurredTo: "2024-08-08", eventKind: "relationship_end", sourceTurnId: TURN_ID, }; test("a day-precision event recorded this turn becomes the date reliability prompt", () => { const plan = planWithDateReliability( buildMethodFollowupPlan({ evidence: [dayEvent], sessionOutcome: "collect_evidence", }), [dayEvent], TURN_ID, ); assert.equal(plan.next_followup?.user_prompt_hint, DATE_RELIABILITY_PROMPT); assert.equal(plan.next_followup?.date_reliability_evidence_id, "ev-day"); }); test("a month-precision event does not ask date reliability", () => { const plan = planWithDateReliability( buildMethodFollowupPlan({ evidence: [monthEvent], sessionOutcome: "collect_evidence", }), [monthEvent], TURN_ID, ); assert.notEqual(plan.next_followup?.user_prompt_hint, DATE_RELIABILITY_PROMPT); }); test("凭记忆 maps to medium and 查过 maps to high", () => { assert.equal(classifyDateReliabilityUtterance("凭记忆"), "medium"); assert.equal(classifyDateReliabilityUtterance("那天是查过记录的"), "high"); assert.equal(classifyDateReliabilityUtterance(""), null); }); test("an already tagged day event is not asked again", () => { const tagged = { ...dayEvent, dateReliability: "medium" }; const plan = planWithDateReliability( buildMethodFollowupPlan({ evidence: [tagged], sessionOutcome: "collect_evidence", }), [tagged], TURN_ID, ); assert.notEqual(plan.next_followup?.user_prompt_hint, DATE_RELIABILITY_PROMPT); }); test("historical day events are not asked on a later collect turn", () => { assert.equal(pendingDateReliabilityEvidence([dayEvent], "other-turn"), null); const plan = buildMethodFollowupPlan({ evidence: [dayEvent], sessionOutcome: "collect_evidence", }); assert.notEqual(plan.next_followup?.user_prompt_hint, DATE_RELIABILITY_PROMPT); });