Files
Jyotisha/frontend/tests/rectification-spoken-prompt.test.ts
T
Jesse_ChenandCursor d94049769e
Independent Staging Quality Gate / validate (push) Successful in 25m7s
Independent Staging Quality Gate / publish (push) Successful in 2m8s
fix(rectification): put each question inside the assistant message
Focuses now carry asked_turn_id so GET rebuilds stem and options on the
same turn. Agent writes spokenPrompt; the live question slot is gone.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 19:55:20 +08:00

83 lines
3.2 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { validateSpokenPrompt } from "../src/lib/rectification-agentic/v9/spoken-prompt.ts";
import { MACHINE_VOICE_LEXICON } from "../src/lib/rectification-agentic/v9/agent-voice-lexicon.ts";
import type { MethodFollowup } from "../src/lib/rectification-agentic/v9/method-followup.ts";
function followup(overrides: Partial<MethodFollowup> = {}): MethodFollowup {
return {
method_id: "d9_relationship",
intent: "distinguish_candidates",
ask_theme: "relationship_style",
domain: "relationship",
kind_hint: "relationship_change",
user_prompt_hint: "probe",
must_not_label: false,
choice_frame: {
question_id: "d9:relationship:2023",
method_id: "d9_relationship",
period: "2023 年前后",
prompt: "2023 年前后,你有没有一段认真开始或结束的关系?",
varga: "D9",
why: "区分",
option_a_hint: "明确发生且时间吻合",
option_b_hint: "发生过但时间偏了",
neither_label: "没有这回事",
unsure_label: "记不清",
option_a_answer_class: "yes",
option_b_answer_class: "weak_yes",
option_c_answer_class: "no",
option_d_answer_class: "unsure",
choice_mode: "A/B/C/D",
stop_label: "先这样,先看当前范围",
stop_message: "先这样",
scoring: true,
},
source: "event_probe",
probe_year: 2023,
...overrides,
};
}
test("spokenPrompt rejects length, option literals, unique-minute claims, and machine voice", () => {
assert.equal(validateSpokenPrompt({ spokenPrompt: "太短了" }).ok, false);
const optionLiteral = validateSpokenPrompt({
spokenPrompt: "2023 年这段感情,选项怎么选你还记得吗?",
});
assert.equal(optionLiteral.ok, false);
assert.equal(optionLiteral.ok ? null : optionLiteral.reason, "option_literal");
const uniqueMinute = validateSpokenPrompt({
spokenPrompt: "这能定下唯一的出生分钟吗,你还记得医院的钟点?",
});
assert.equal(uniqueMinute.ok, false);
assert.equal(uniqueMinute.ok ? null : uniqueMinute.reason, "unique_minute");
assert.equal(validateSpokenPrompt({
spokenPrompt: MACHINE_VOICE_LEXICON[3],
}).ok, false);
});
test("spokenPrompt rejects a different year or domain than the server probe", () => {
const probe = followup();
const yearMismatch = validateSpokenPrompt({
spokenPrompt: "2018 年前后,你有没有一段认真开始或结束的关系?",
followup: probe,
targetDomain: "relationship",
questionId: "d9_relationship:relationship:2023",
});
assert.equal(yearMismatch.ok ? null : yearMismatch.reason, "year_mismatch");
const domainMismatch = validateSpokenPrompt({
spokenPrompt: "2023 年前后,你有没有换过工作?",
followup: probe,
targetDomain: "career",
questionId: "d9_relationship:relationship:2023",
});
assert.equal(domainMismatch.ok ? null : domainMismatch.reason, "domain_mismatch");
assert.equal(validateSpokenPrompt({
spokenPrompt: "工作记下了。2023 年前后,有没有一段认真开始或结束的关系?",
followup: probe,
targetDomain: "relationship",
questionId: "d9_relationship:relationship:2023",
}).ok, true);
});