From 2cbf00c439d116c6d0e9ff26119efdf7a8af5157 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 11:11:50 +0800 Subject: [PATCH] fix(rectification): a failed recompute and a stale save report through toasts (BUG-2058) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1 --- docs/BUG_HISTORY.md | 10 ++++++++++ .../chart-choice/astrologer-stage.tsx | 11 ++++++++--- .../chart-choice/chart-choice-page.tsx | 18 +++++++++--------- ...oice-self-choice-scenario-20261117.test.tsx | 3 ++- frontend/tests/results-as-toasts-2056.test.ts | 12 ++++++++++-- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 7d4f7e26e..c5b37eaeb 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -27695,3 +27695,13 @@ - 验证与防复发:相关前端测试(2013/2015/2019/2028/2037/2038、生时纠正两份页面测试)与 Python 测试改为新句,各处注明原值/新值/原因;`report-grade-display-2015` 新增断言:带旧「情况」句的报告仍算受出生时间影响的段落。完整前端测试除本机缺 PostgreSQL / rsync / YAML 的 26 项外全过,后端快速门禁通过,eslint 0 错误。 - 关联记录:BUG-2028、BUG-2032、BUG-1971。 - 修复版本:`claude/rect-wording`。 + +## BUG-2058 | 生时纠正页两处操作结果仍是页内一行:「按她的方法算」失败、保存时出生资料已改 + +- 状态:fixed-pending-verify(待 staging 真机)。 +- 现象:点「按她的方法算」失败后,报错作为一行显示在按钮下方;保存时遇到出生资料已改(stale_choice),提示句作为一行显示在结果页顶部。负责人 2026-11-20 定:操作的成功或失败一律用系统提示(BUG-2056)。 +- 根因:两处早于该规则,BUG-2056 排查时交给生时纠正窗口判断。 +- 修复:`astrologer-stage.tsx` 首次取数失败仍是页面状态(整页只有这一句和返回);之后重算失败改用 `notifyError`。`chart-choice-page.tsx` 去掉 `step.notice`,stale_choice 改用 `notifyInfo` 后重新取数。带「重试」的失败页仍是页面状态。 +- 验证与防复发:`results-as-toasts-2056` 白名单两文件各从 2 降为 1,新增源码断言;`chart-choice-self-choice-scenario-20261117` 原断言页内有该句,改为页内没有(注明原值/新值/原因)。 +- 关联记录:BUG-2056、BUG-1971。 +- 修复版本:`claude/rect-wording`。 diff --git a/frontend/src/components/chart-choice/astrologer-stage.tsx b/frontend/src/components/chart-choice/astrologer-stage.tsx index 526699c34..220d3468a 100644 --- a/frontend/src/components/chart-choice/astrologer-stage.tsx +++ b/frontend/src/components/chart-choice/astrologer-stage.tsx @@ -24,6 +24,7 @@ import { type AstrologerDraft, } from "@/lib/chart-choice/astrologer-view"; import type { ChartChoiceWindow } from "@/lib/chart-choice/contract"; +import { notifyError } from "@/lib/notify"; import { cn } from "@/lib/utils"; /** @@ -51,6 +52,7 @@ function AstrologerQuestionnaire({ const [busy, setBusy] = useState(true); const [error, setError] = useState(null); const ticket = useRef(0); + const loaded = useRef(false); const run = useCallback(async (next: AstrologerDraft) => { const mine = ++ticket.current; @@ -64,9 +66,13 @@ function AstrologerQuestionnaire({ }); const payload = await response.json().catch(() => null) as (AstrologerPacket & { error?: string }) | null; if (!response.ok || !payload) throw new Error(payload?.error || "暂时没有响应,请稍后再试。"); - if (mine === ticket.current) setPacket(payload); + if (mine === ticket.current) { loaded.current = true; setPacket(payload); } } catch (failure) { - if (mine === ticket.current) setError((failure as Error).message); + // BUG-2058: a failed first read is the page's state; a failed 「按她的方法算」 is the action's outcome → toast + if (mine === ticket.current) { + if (loaded.current) notifyError((failure as Error).message, { id: "astrologer-run" }); + else setError((failure as Error).message); + } } finally { if (mine === ticket.current) setBusy(false); } @@ -210,7 +216,6 @@ function AstrologerQuestionnaire({ {busy ? "计算中…" : "按她的方法算"} - {error ?

{error}

: null} diff --git a/frontend/src/components/chart-choice/chart-choice-page.tsx b/frontend/src/components/chart-choice/chart-choice-page.tsx index f0a848b1a..ebe20e64b 100644 --- a/frontend/src/components/chart-choice/chart-choice-page.tsx +++ b/frontend/src/components/chart-choice/chart-choice-page.tsx @@ -51,7 +51,7 @@ import { } from "@/lib/chart-choice/view"; import { CHART_CHOICE_DOMAIN_CHARTS } from "@/lib/chart-choice-both-versions"; import { useCurrentSubject, useCurrentSubjectReady } from "@/lib/current-subject"; -import { notifySuccess } from "@/lib/notify"; +import { notifyInfo, notifySuccess } from "@/lib/notify"; import { cn } from "@/lib/utils"; type Choose = Extract; @@ -76,14 +76,14 @@ type Step = | { kind: "home" } | { kind: "packet_loading" } | { kind: "narrow"; packet: Extract } - | { kind: "certain"; packet: Extract; notice?: string } + | { kind: "certain"; packet: Extract } | { kind: "range"; packet: Choose | Complete; request: ChartChoiceRequest } | { kind: "choose"; packet: Choose; request: ChartChoiceRequest; previous?: Step; draft?: RoundDraft } | { kind: "result"; packet: Choose; decision: ChartChoiceDecision; saving: boolean; overrideSide?: ChartChoiceSide } | { kind: "chart_range"; packet: ChartChoiceQuestionnaire; request: ChartChoiceRequest; previous?: Step } | { kind: "chart_question"; packet: ChartChoiceQuestionnaire; request: ChartChoiceRequest; back: Step; submitted: ChartChoiceChartAnswers; answer: ChartAnswer } - | { kind: "final"; packet: FinalPacket; decision: FinalDecision; body: ResultRequest; back: Step; notice?: string } + | { kind: "final"; packet: FinalPacket; decision: FinalDecision; body: ResultRequest; back: Step } | { kind: "self_choice"; preview: SelfChoicePreviewResponse; final: Extract; /** Earlier previews, oldest first: steps[i] is the state after i picks (BUG-1971). */ steps: readonly SelfChoicePreviewResponse[] }; @@ -162,7 +162,7 @@ export function ChartChoiceFlow({ subjectId }: { readonly subjectId: string }) { const [rangeChosen, setRangeChosen] = useState(false); const generation = useRef(0); - const loadPacket = useCallback(async (request: ChartChoiceRequest, showRange = true, previous?: Step, notice?: string) => { + const loadPacket = useCallback(async (request: ChartChoiceRequest, showRange = true, previous?: Step) => { const ticket = ++generation.current; setWindow(request.window); setAnswers({}); @@ -176,11 +176,11 @@ export function ChartChoiceFlow({ subjectId }: { readonly subjectId: string }) { if (ticket !== generation.current) return; if (!RECT_QUESTIONNAIRE_ENABLED) { if (packet.status === "certain") { - setStep({ kind: "certain", packet, notice }); + setStep({ kind: "certain", packet }); } else if (packet.status === "complete" && packet.decision.reported_choice) { setStep({ kind: "final", packet, decision: packet.decision, body: { subjectId, adaptive: true, mode: "choice", ...(request.window ? { window: request.window } : {}) }, - back: { kind: "home" }, notice, + back: { kind: "home" }, }); } else { throw new Error("暂时没有可用的结果,请重试。"); @@ -285,8 +285,6 @@ export function ChartChoiceFlow({ subjectId }: { readonly subjectId: string }) { : null); return <> - {(step.kind === "final" || step.kind === "certain") && step.notice - ?

{step.notice}

: null} {renderStep()} ; @@ -367,7 +365,9 @@ export function ChartChoiceFlow({ subjectId }: { readonly subjectId: string }) { if ("ready" in refreshed) { setStart(refreshed.ready); setRangeChosen(false); - await loadPacket({}, false, undefined, error.message); + // BUG-2058: the save's outcome (the basis changed, recomputed) is a toast, not a line in the page + notifyInfo(error.message); + await loadPacket({}, false); } else setStep(refreshed); } else setStep({ kind: "failed", message: (error as Error).message, retry: { kind: "back", step: back } }); } finally { diff --git a/frontend/tests/chart-choice-self-choice-scenario-20261117.test.tsx b/frontend/tests/chart-choice-self-choice-scenario-20261117.test.tsx index 189769ec4..06f59687c 100644 --- a/frontend/tests/chart-choice-self-choice-scenario-20261117.test.tsx +++ b/frontend/tests/chart-choice-self-choice-scenario-20261117.test.tsx @@ -120,7 +120,8 @@ test("stale self-choice save reloads the current start and returns to a fresh re assert.equal(starts, 2); assert.equal(packets, 2); assert.equal(saves, 1); - assert.ok(h.elements().some((item) => item.text === "出生资料改过了,这次的结果不能再用。")); + // 原值:页面里有一行「出生资料改过了,这次的结果不能再用。」;新值:这句改成系统提示,不在页面里(断言在 results-as-toasts-2056);原因:BUG-2058,操作结果一律用系统提示 + assert.ok(!h.elements().some((item) => item.text === "出生资料改过了,这次的结果不能再用。")); assert.ok(h.elements().some((item) => item.text === "开始")); assert.equal(h.errors.length, 0); } finally { diff --git a/frontend/tests/results-as-toasts-2056.test.ts b/frontend/tests/results-as-toasts-2056.test.ts index 3b9f4f487..859650a27 100644 --- a/frontend/tests/results-as-toasts-2056.test.ts +++ b/frontend/tests/results-as-toasts-2056.test.ts @@ -58,6 +58,14 @@ test("annual: a failed start is a toast; only 'not enough credits' stays in the assert.doesNotMatch(source, /setStartError\(\{ message:/); }); +test("rectification: a stale save and a failed 「按她的方法算」 are toasts (BUG-2058)", () => { + const page = read("src/components/chart-choice/chart-choice-page.tsx"); + assert.match(page, /notifyInfo\(error\.message\);\n\s*await loadPacket\(\{\}, false\);/); + assert.doesNotMatch(page, /step\.notice/); + const stage = read("src/components/chart-choice/astrologer-stage.tsx"); + assert.match(stage, /if \(loaded\.current\) notifyError\(/); +}); + /** * Guard. `role="alert"` in a component is how an inline result usually gets written. * These files may keep theirs, for the reason given; any other file, or one more @@ -83,8 +91,8 @@ const ALERT_ALLOWED: Readonly> = why: "the start card: not-enough-credits with 去补点数, or a price that could not be read", }, "src/components/personal-report/report-run-card.tsx": { count: 1, why: "the failed run with its 重新生成 button: page state" }, - "src/components/chart-choice/astrologer-stage.tsx": { count: 2, why: "rectification page (other owner): computation state" }, - "src/components/chart-choice/chart-choice-page.tsx": { count: 2, why: "rectification page (other owner): step notice and failed step with retry" }, + "src/components/chart-choice/astrologer-stage.tsx": { count: 1, why: "rectification: the first read failed, nothing else on the page (BUG-2058)" }, + "src/components/chart-choice/chart-choice-page.tsx": { count: 1, why: "rectification: failed step with 重试 (BUG-2058; the save notice is a toast)" }, }; function sources(dir: string): string[] {