Files
Jyotisha/frontend/tests/rectification-spoken-answer.test.ts
T
Jesse_Chen 04463e9af3 feat(web): show consult runs as a Lucide timeline with sliced compose
Keep provider thinking on a separate channel so process talk is not billed as the spoken reply (BUG-359).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-23 14:38:50 +08:00

108 lines
4.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from "node:assert/strict";
import test from "node:test";
import {
finalizeRectificationSpokenAndThinking,
isRectificationProcessNarration,
nextStableChannelDelta,
settleRectificationSpokenAndThinking,
splitRectificationSpokenAndThinking,
} from "../src/lib/rectification-agentic/v9/spoken-answer.ts";
test("a plain spoken follow-up stays on the answer channel", () => {
const spoken = [
"记下了,大约六岁入学小学。",
"接下来你大概哪一年上的初中?说个大概年份或范围就行。",
].join("\n\n");
assert.deepEqual(splitRectificationSpokenAndThinking(spoken), {
thinking: "",
spoken,
});
});
test("process self-talk leaves the spoken conclusion on the answer channel", () => {
const processTalk = [
"用户提到先给了一个很晚的年份,后又改口说六岁入学。这里有个明显的内部矛盾。",
"但按 skill 规则,日期精度真实保留,不得猜补。datePrecision 用 yearoccurredFrom 只能按用户原话来。",
"我决定先按六岁入学记下来,再在正文里确认那句晚年份是不是口误。",
"让我调用 batch 写入 education_start。",
].join("\n\n");
const spoken = [
"入学小学这条先按大约六岁记下。你第一句提到的那个很晚的年份,我理解是口误对吗?",
"接下来你大概哪一年上的初中?说个大概年份或范围就行。",
].join("\n\n");
assert.deepEqual(splitRectificationSpokenAndThinking(`${processTalk}\n\n${spoken}`), {
thinking: processTalk,
spoken,
});
});
test("English process talk is classified as thinking, not the spoken answer", () => {
const split = splitRectificationSpokenAndThinking([
"The proposedKind value was rejected. Retrying with education_start.",
"记下了,那年九月上大学。",
].join("\n\n"));
assert.match(split.thinking, /proposedKind/);
assert.equal(split.spoken, "记下了,那年九月上大学。");
});
test("stable channel deltas only emit the newly classified suffix", () => {
assert.equal(nextStableChannelDelta("", "先核对升学年份。"), "先核对升学年份。");
assert.equal(
nextStableChannelDelta("先核对升学年份。", "先核对升学年份。\n\n再问初中。"),
"\n\n再问初中。",
);
assert.equal(nextStableChannelDelta("先核对升学年份。", "另一段"), "");
});
test("a lone process paragraph stays in thinking until a spoken conclusion arrives", () => {
const processTalk = "用户提到先给了一个很晚的年份。这里有个明显的内部矛盾。";
assert.deepEqual(splitRectificationSpokenAndThinking(`${processTalk}\n\n`), {
thinking: processTalk,
spoken: "",
});
});
test("truncated third-person batch-tool narration stays in thinking", () => {
const truncated = "用户在上一轮里提供了两件带日期的经历。我需要用批量工具写入这些证据。用户";
assert.equal(isRectificationProcessNarration(truncated), true);
assert.deepEqual(splitRectificationSpokenAndThinking(truncated), {
thinking: truncated,
spoken: "",
});
assert.deepEqual(finalizeRectificationSpokenAndThinking(truncated), {
thinking: truncated,
spoken: "",
});
});
test("finalizing does not promote process-only self-talk into the spoken answer", () => {
const first = "用户提到先给了一个很晚的年份。这里有个明显的内部矛盾。";
const last = "但按 skill 规则,日期精度真实保留,不得猜补。";
const processTalk = `${first}\n\n${last}`;
assert.deepEqual(finalizeRectificationSpokenAndThinking(processTalk), {
thinking: processTalk,
spoken: "",
});
});
test("leaked process text on the answer channel is not mixed into native thinking", () => {
const processTalk = "用户在上一轮里提供了两件带日期的经历。我需要用批量工具写入这些证据。用户";
const spoken = "记下了升学这两件。接下来有没有一件带大概年份的工作变化?";
assert.deepEqual(settleRectificationSpokenAndThinking(processTalk, ""), {
thinking: processTalk,
spoken: "",
});
assert.deepEqual(settleRectificationSpokenAndThinking(spoken, processTalk), {
thinking: processTalk,
spoken,
});
assert.deepEqual(settleRectificationSpokenAndThinking(processTalk, processTalk), {
thinking: processTalk,
spoken: "",
});
});