import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; import { COLUMN_COMPARE_BUDGET_MS, columnTimesForSlowCompare, } from "../src/lib/rectification-agentic/v9/column-times-for-compare.ts"; import { parseDeclaredBirthWindow } from "../src/lib/rectification-agentic/v9/declared-window-utterance.ts"; const ROUTE = readFileSync( new URL("../src/app/api/rectification/agent/route.ts", import.meta.url), "utf8", ); test("dated or event-clock sentences are not treated as a declared birth window", () => { assert.equal(parseDeclaredBirthWindow("2024 年 8 月 8 日 20:00 左右分手"), null); assert.equal(parseDeclaredBirthWindow("下午 3 点到 5 点被车撞"), null); assert.equal(parseDeclaredBirthWindow("2019 年 10 月 23 日 9 点半入职"), null); assert.equal(parseDeclaredBirthWindow("20:00 左右分手"), null); assert.equal(parseDeclaredBirthWindow("2014年入学,大概秋天"), null); }); test("birth-context and bare clock ranges still count as a declared window", () => { assert.deepEqual( parseDeclaredBirthWindow("我的出生时间是 14 点 45 到 14 点 50"), { kind: "range", start: "14:45", end: "14:50" }, ); assert.deepEqual( parseDeclaredBirthWindow("我是 14:47 左右生的"), { kind: "around", time: "14:47" }, ); assert.deepEqual( parseDeclaredBirthWindow("14:45–14:50"), { kind: "range", start: "14:45", end: "14:50" }, ); assert.deepEqual( parseDeclaredBirthWindow("14:47 左右"), { kind: "around", time: "14:47" }, ); assert.deepEqual( parseDeclaredBirthWindow("大概 14:47 左右"), { kind: "around", time: "14:47" }, ); }); test("choice-focus declared window is still answered from the route before the model", () => { const intercept = ROUTE.indexOf('if (action === "message" && parseDeclaredBirthWindow'); const selectedModel = ROUTE.indexOf("const selectedModel = isStructuredChoice"); assert.ok(intercept > 0); assert.ok(selectedModel > intercept); }); test("score persist passes active minutes only after a slow by_time compare", () => { const persist = readFileSync( new URL("../src/lib/rectification-agentic/v9/score-persist.ts", import.meta.url), "utf8", ); assert.match(persist, /columnTimesForSlowCompare/); assert.match(persist, /columnTimes,/); }); test("slow by_time compares may pass only active inference minutes", () => { assert.equal( columnTimesForSlowCompare({ previousColumnCompareMs: 1200, activeTimes: ["14:46", "14:47", "14:48"] }), undefined, ); assert.deepEqual( columnTimesForSlowCompare({ previousColumnCompareMs: COLUMN_COMPARE_BUDGET_MS + 1, activeTimes: ["14:46", "14:47", "14:46", "bad"], }), ["14:46", "14:47"], ); assert.equal( columnTimesForSlowCompare({ previousColumnCompareMs: 4000, activeTimes: [] }), undefined, ); });