35e5781e66
Public can_adopt follows session_outcome; reverse_verify reuses the persisted question id; offer cards settle on the owning message with a status-bar handoff. Co-authored-by: Cursor <cursoragent@cursor.com>
139 lines
5.5 KiB
TypeScript
139 lines
5.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
import {
|
|
createRectificationActivityReceiptState,
|
|
reduceRectificationActivityReceipt,
|
|
receiptFromRectificationActivityState,
|
|
} from "../src/lib/rectification-activity-receipt";
|
|
|
|
test("a successful retry clears the same tool's earlier failure", () => {
|
|
let state = createRectificationActivityReceiptState();
|
|
for (const event of [
|
|
{ tool: "rectification-read-case", status: "completed" },
|
|
{ tool: "rectification-propose-evidence", status: "failed" },
|
|
{ tool: "rectification-propose-evidence", status: "started" },
|
|
{ tool: "rectification-propose-evidence", status: "completed" },
|
|
{ tool: "rectification-confirm-evidence", status: "completed" },
|
|
] as const) {
|
|
state = reduceRectificationActivityReceipt(state, event);
|
|
}
|
|
|
|
assert.deepEqual(receiptFromRectificationActivityState(state), {
|
|
steps: [
|
|
"rectification-read-case",
|
|
"rectification-propose-evidence",
|
|
"rectification-confirm-evidence",
|
|
],
|
|
methods: [],
|
|
});
|
|
});
|
|
|
|
test("an unrecovered latest tool failure remains visible", () => {
|
|
let state = createRectificationActivityReceiptState();
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-read-case",
|
|
status: "completed",
|
|
});
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-propose-evidence",
|
|
status: "failed",
|
|
});
|
|
|
|
assert.deepEqual(receiptFromRectificationActivityState(state), {
|
|
steps: ["rectification-read-case"],
|
|
methods: [],
|
|
failedTool: "rectification-propose-evidence",
|
|
});
|
|
});
|
|
|
|
test("a later failure overrides an earlier completion for the same tool", () => {
|
|
let state = createRectificationActivityReceiptState();
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-read-case",
|
|
status: "completed",
|
|
});
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-read-case",
|
|
status: "failed",
|
|
});
|
|
|
|
assert.deepEqual(receiptFromRectificationActivityState(state), {
|
|
steps: [],
|
|
methods: [],
|
|
failedTool: "rectification-read-case",
|
|
});
|
|
});
|
|
|
|
test("a later failure removes methods contributed by the failed tool", () => {
|
|
let state = createRectificationActivityReceiptState();
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-compare-candidates",
|
|
status: "completed",
|
|
methods: ["d1-rashi", "vimshottari-dasha"],
|
|
});
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-read-diagnostics",
|
|
status: "completed",
|
|
methods: ["d1-rashi", "shadbala"],
|
|
});
|
|
state = reduceRectificationActivityReceipt(state, {
|
|
tool: "rectification-compare-candidates",
|
|
status: "failed",
|
|
});
|
|
|
|
assert.deepEqual(receiptFromRectificationActivityState(state), {
|
|
steps: ["rectification-read-diagnostics"],
|
|
methods: ["d1-rashi", "shadbala"],
|
|
failedTool: "rectification-compare-candidates",
|
|
});
|
|
});
|
|
|
|
const chatSource = readFileSync(
|
|
new URL("../src/components/rectification-agentic-chat.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
|
|
test("answer deltas preserve a still-running server activity", () => {
|
|
const deltaBranch = chatSource.slice(
|
|
chatSource.indexOf('event.type === "answer.delta"'),
|
|
chatSource.indexOf('event.type === "run.failed"'),
|
|
);
|
|
// Former locks: `state: raw.trim() ? "streaming" : "thinking"` and `text: raw,` inside the
|
|
// delta branch. Those pinned one setMessages per network chunk (BUG-473); the same state
|
|
// derivation now lives in the frame buffer's flush, which the delta branch feeds.
|
|
const frameFlush = chatSource.slice(
|
|
chatSource.indexOf("const frames = createStreamFrameBuffer"),
|
|
chatSource.indexOf("const abortController = new AbortController()"),
|
|
);
|
|
assert.match(frameFlush, /state: text\.trim\(\) \? "streaming" : "thinking"/);
|
|
assert.match(frameFlush, /^\s*text,$/m);
|
|
assert.match(deltaBranch, /frames\.setAnswer\(raw\)/);
|
|
assert.match(deltaBranch, /event\.replace === true \? event\.text : raw \+ event\.text/);
|
|
assert.doesNotMatch(deltaBranch, /settled\.spoken/);
|
|
assert.match(deltaBranch, /正在组织回答/);
|
|
assert.doesNotMatch(deltaBranch, /activeActivity:\s*undefined/);
|
|
});
|
|
|
|
test("failed server turns retain their receipt state without parsing activity from answer text", () => {
|
|
assert.match(chatSource, /failed:\s*true/);
|
|
assert.match(chatSource, /completedReceipt/);
|
|
// Former lock: `message.state === "settled" && message.failed`, the inline red banner above a
|
|
// failed reply. That banner was the second, rectification-only failure surface (BUG-476);
|
|
// failure now reaches the shared error notice while the receipt state still gates actions.
|
|
assert.match(chatSource, /&& !message\.failed/);
|
|
assert.doesNotMatch(chatSource, /rectification-activity-failure/);
|
|
assert.doesNotMatch(chatSource, /parsed\.(?:activity|receipt|tools|methods)/);
|
|
});
|
|
|
|
test("candidate acceptance copy never presents adoption as confirmation", () => {
|
|
assert.match(chatSource, /当前可能的出生时间/);
|
|
assert.match(chatSource, /采用不等于确认出生时间/);
|
|
assert.match(chatSource, /rectification-candidate-badge">已采用/);
|
|
assert.match(chatSource, /已确认校正时间/);
|
|
assert.match(chatSource, /rectification-adopt-status/);
|
|
assert.doesNotMatch(chatSource, /rectification-consult-handoff/);
|
|
assert.doesNotMatch(chatSource, /本轮校正已收口|当前排盘时间(代表性时间|本会话以代表性时间收口/);
|
|
assert.doesNotMatch(chatSource, /candidateResult\.confirmationAllowed \? "确认校正时间"/);
|
|
});
|