Files
Jyotisha/frontend/tests/rectification-step-state-20260906.test.ts
T
Jesse_Chen 1ded6bb0d4 fix(rectification): hide option hover impact and composer step strip (BUG-575)
Hovering A/B/C/D rewrote a leading/lagging time line and made the card flicker; the step-state sentence above the composer was instructional filler, not something the user needed to answer.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-07 14:07:49 +08:00

74 lines
2.8 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { PROBE_EXPLAIN_COPY } from "../src/lib/rectification-agentic/v9/probe-explain.ts";
import { projectRectificationStepState, STEP_STATE_COPY } from "../src/lib/rectification-agentic/v9/step-state.ts";
import { parseRectificationStepState } from "../src/lib/rectification-candidate-result.ts";
test("step state covers collect, discriminate, deliver, and post-adopt", () => {
const collect = projectRectificationStepState({
nextAction: "ask_fact_collection",
methodsCovered: false,
});
assert.equal(collect.stage, "collect");
assert.equal(collect.index, 1);
assert.match(collect.headline, /第 1 步/);
const discriminate = projectRectificationStepState({
nextAction: "ask_candidate_discriminator",
methodsCovered: true,
});
assert.equal(discriminate.stage, "discriminate");
assert.equal(discriminate.index, 2);
assert.match(discriminate.next, /先这样/);
const exhausted = projectRectificationStepState({
nextAction: "complete_with_range",
methodsCovered: true,
stopReason: "probe_pool_exhausted",
});
assert.equal(exhausted.stage, "deliver");
assert.match(exhausted.reason, /已经问完/);
const uncertain = projectRectificationStepState({
nextAction: "complete_with_range",
stopReason: "user_uncertainty_too_high",
});
assert.equal(uncertain.stage, "deliver");
assert.match(uncertain.reason, /说不好/);
const adopted = projectRectificationStepState({
accepted: true,
nextAction: "ask_holdout_validation",
});
assert.equal(adopted.stage, "post_adopt");
assert.equal(adopted.index, 4);
});
test("step state parser rejects forbidden certainty words", () => {
const parsed = parseRectificationStepState(projectRectificationStepState({
nextAction: "offer_provisional_range",
}));
assert.ok(parsed);
const blob = `${parsed.headline}${parsed.reason}${parsed.next}`;
assert.doesNotMatch(blob, /概率|置信度|确定/);
});
test("chat does not render the step-state strip above the composer", () => {
const chat = readFileSync(new URL("../src/components/rectification-agentic-chat.tsx", import.meta.url), "utf8");
const route = readFileSync(new URL("../src/app/api/rectification/cases/[caseId]/route.ts", import.meta.url), "utf8");
assert.doesNotMatch(chat, /rectification-step-state/);
assert.doesNotMatch(chat, /下一步:\{stepState\.next\}/);
assert.match(chat, /rectification-composer-meta/);
assert.match(route, /step_state: stepStateFromCaseDossier/);
});
test("explain-layer copy avoids probability words", () => {
const blob = [
...Object.values(PROBE_EXPLAIN_COPY),
...Object.values(STEP_STATE_COPY).flatMap((item) => Object.values(item)),
].join("\n");
assert.doesNotMatch(blob, /概率|置信度|确定/);
});