Files
Jyotisha/frontend/tests/agent-activity-trace.test.ts
T
Jesse_Chen 6b225a288c fix(web): keep later thinking below rectification tool steps
BUG-360: stream thinking and tool activity as an ordered trace so later CoT opens under 正在整理 instead of filling the first 思考 block.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-23 17:02:06 +08:00

58 lines
2.7 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
appendActivityTraceThinking,
completeActivityTrace,
completeActivityTraceStep,
emptyActivityTrace,
startActivityTraceStep,
} from "../src/lib/agent-activity-trace.ts";
test("thinking after a tool starts a new think row instead of filling the first", () => {
let rows = appendActivityTraceThinking(emptyActivityTrace(), "先确认用户说的是入职当天。");
rows = startActivityTraceStep(rows, "rectification-record-evidence-batch", "正在整理多条事件证据…", 1_000);
rows = appendActivityTraceThinking(rows, "再把 2024-04-07 写成经历证据。");
assert.deepEqual(rows.map((row) => row.kind), ["think", "activity", "think"]);
assert.equal(rows[0]?.status, "done");
assert.equal(rows[0]?.text, "先确认用户说的是入职当天。");
assert.equal(rows[1]?.label, "正在整理多条事件证据…");
assert.equal(rows[1]?.status, "live");
assert.equal(rows[2]?.status, "live");
assert.equal(rows[2]?.text, "再把 2024-04-07 写成经历证据。");
assert.notEqual(rows[0]?.id, rows[2]?.id);
});
test("completing a tool then thinking starts a new think under the done activity", () => {
let rows = appendActivityTraceThinking(emptyActivityTrace(), "先读取校正记录。");
rows = startActivityTraceStep(rows, "rectification-record-evidence-batch", "正在整理多条事件证据…", 1_000);
rows = completeActivityTraceStep(rows, "rectification-record-evidence-batch", "整理事件证据");
rows = appendActivityTraceThinking(rows, "用户说转做开发就是 2024-04-07。");
assert.deepEqual(rows.map((row) => `${row.kind}:${row.status}`), [
"think:done",
"activity:done",
"think:live",
]);
assert.equal(rows[1]?.label, "整理事件证据");
assert.equal(rows[2]?.text, "用户说转做开发就是 2024-04-07。");
});
test("the same live tool is not duplicated, and a later tool follows the second think", () => {
let rows = startActivityTraceStep(emptyActivityTrace(), "rectification-read-case", "正在读取校正记录…", 10);
rows = startActivityTraceStep(rows, "rectification-read-case", "正在读取校正记录…", 20);
assert.equal(rows.length, 1);
assert.equal(rows[0]?.startedAt, 10);
rows = completeActivityTraceStep(rows, "rectification-read-case", "读取校正记录");
rows = startActivityTraceStep(rows, "rectification-record-evidence-batch", "正在整理多条事件证据…", 30);
assert.deepEqual(rows.map((row) => `${row.kind}:${row.label}`), [
"activity:读取校正记录",
"activity:正在整理多条事件证据…",
]);
const settled = completeActivityTrace(rows);
assert.ok(settled.every((row) => row.status === "done"));
});