fix(rectification): persist refresh attempts and map collect focus kinds (BUG-656/657/658)
Empty engine refresh now records an already_answered attempt so GET can leave wait-to-narrow; collect kinds map onto the table CHECK; remaining candidates drive probe refresh. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import test from "node:test";
|
||||
import { buildInferenceState } from "../src/lib/rectification-agentic/core/build-state.ts";
|
||||
import {
|
||||
COLLECT_FOCUS_RETRY_SUFFIX,
|
||||
FOCUS_TARGET_KIND_CHECK,
|
||||
collectFocusTargetKind,
|
||||
openQuestionFromPersistedFocus,
|
||||
persistableFocusDomain,
|
||||
persistServerOwnedFocus,
|
||||
@@ -924,3 +926,55 @@ test("frameless precision-stage distinguish is skipped instead of opening GENERI
|
||||
GENERIC_COLLECT_QUESTION,
|
||||
);
|
||||
});
|
||||
|
||||
function targetKindCheckFromSql(): string[] {
|
||||
const sql = readFileSync(new URL(
|
||||
"../supabase/migrations/20260814020000_rectification_v10_runtime.sql",
|
||||
import.meta.url,
|
||||
), "utf8");
|
||||
const match = /target_kind text check \(\s*target_kind is null or target_kind in \(\s*([\s\S]*?)\)\s*\)/.exec(sql);
|
||||
assert.ok(match?.[1], "target_kind CHECK missing");
|
||||
return [...match[1].matchAll(/'([a-z_]+)'/g)].map((item) => item[1]);
|
||||
}
|
||||
|
||||
test("T1: collect focus kinds map to the table CHECK enum", async () => {
|
||||
const allowed = targetKindCheckFromSql();
|
||||
assert.deepEqual([...FOCUS_TARGET_KIND_CHECK], allowed);
|
||||
const cases: ReadonlyArray<{
|
||||
kind_hint: string;
|
||||
domain: string;
|
||||
collectKind: string;
|
||||
}> = [
|
||||
{ kind_hint: "targeted:family", domain: "family", collectKind: "targeted:family" },
|
||||
{ kind_hint: "anchor:education_start:2016", domain: "education", collectKind: "anchor:education_start:2016" },
|
||||
{ kind_hint: "generic:relationship", domain: "relationship", collectKind: "generic:relationship" },
|
||||
];
|
||||
for (const item of cases) {
|
||||
const mapped = collectFocusTargetKind({ kind_hint: item.kind_hint, domain: item.domain });
|
||||
assert.ok(mapped && allowed.includes(mapped), `${item.kind_hint} -> ${mapped}`);
|
||||
const accounting = fakeAccounting({
|
||||
set_agentic_rectification_conversation_focus: (_fn, args) => focusRowFromArgs(args),
|
||||
});
|
||||
const persisted = await persistServerOwnedFocus({
|
||||
accounting: accounting.client,
|
||||
userId: USER_ID,
|
||||
caseId: CASE_ID,
|
||||
activeFocus: null,
|
||||
decisionReceipt: null,
|
||||
followup: collectFollowup({
|
||||
domain: item.domain,
|
||||
kind_hint: item.kind_hint,
|
||||
collection_key: item.kind_hint.startsWith("targeted:")
|
||||
? `collect:targeted:${item.domain}`
|
||||
: undefined,
|
||||
}),
|
||||
});
|
||||
assert.equal(persisted.status, "created", item.kind_hint);
|
||||
assert.ok(
|
||||
persisted.focus?.targetKind && allowed.includes(persisted.focus.targetKind),
|
||||
`${item.kind_hint} wrote ${persisted.focus?.targetKind}`,
|
||||
);
|
||||
assert.equal(persisted.focus?.expectedAnswerSchema.collect_kind, item.collectKind);
|
||||
assert.equal(accounting.calls[0]?.args.p_target_kind, persisted.focus?.targetKind);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user