From 39e0ef8af26b36ef0aa6271ea196fd1150cd8a21 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 15:24:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(rectification):=20=E7=94=9F=E6=97=B6?= =?UTF-8?q?=E7=BA=A0=E6=AD=A3=20marked=20=E3=80=8C=E9=9A=8F=E7=BC=98?= =?UTF-8?q?=E7=89=88=E3=80=8D,=20every=20step=20recorded=20(adopted=20or?= =?UTF-8?q?=20not)=20in=20chart=5Fchoice=5Fsteps=20for=20later=20checking,?= =?UTF-8?q?=20the=20stale=20=E3=80=8C=E5=BC=80=E5=A4=B4=E4=BC=9A=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E6=98=AF=E4=BD=A0=E9=80=89=E7=9A=84=E3=80=8D=20line?= =?UTF-8?q?=20removed,=20privacy=20policy=20says=20so=20(BUG-2256)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1 --- docs/BUG_HISTORY.md | 12 +++ .../src/app/api/chart-choice/adopt/route.ts | 74 +++++++++--------- .../app/api/chart-choice/astrologer/route.ts | 16 ++-- .../src/app/api/chart-choice/packet/route.ts | 22 ++++-- .../src/app/api/chart-choice/reuse/route.ts | 16 ++-- .../app/api/chart-choice/supplement/route.ts | 38 ++++++---- frontend/src/app/globals.css | 5 ++ frontend/src/components/app-sidebar.tsx | 2 + .../chart-choice/chart-choice-page.tsx | 6 +- frontend/src/components/secondary-header.tsx | 5 +- .../src/components/secondary-page-shell.tsx | 4 + frontend/src/lib/chart-choice/edition.ts | 5 ++ .../src/lib/chart-choice/step-log-core.ts | 55 ++++++++++++++ frontend/src/lib/chart-choice/step-log.ts | 9 +++ frontend/src/lib/legal-documents.ts | 5 +- .../20261123090000_chart_choice_steps.sql | 76 +++++++++++++++++++ .../tests/database-local-business.test.ts | 3 + .../tests/rect-casual-edition-2256.test.ts | 53 +++++++++++++ frontend/tests/rect-step-log-2256.test.ts | 35 +++++++++ 19 files changed, 369 insertions(+), 72 deletions(-) create mode 100644 frontend/src/lib/chart-choice/edition.ts create mode 100644 frontend/src/lib/chart-choice/step-log-core.ts create mode 100644 frontend/src/lib/chart-choice/step-log.ts create mode 100644 frontend/supabase/migrations/20261123090000_chart_choice_steps.sql create mode 100644 frontend/tests/rect-casual-edition-2256.test.ts create mode 100644 frontend/tests/rect-step-log-2256.test.ts diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index d98206275..f740862af 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -30347,3 +30347,15 @@ - 防复发:标题栏里的新按钮一律用 `.title-bar-button`(需要手机只留图标时加 `.title-bar-icon-on-phone` 并给 `aria-label`);回归测试钉住三个入口不能回到 outline / secondary。 - 关联记录:BUG-2081(页面级提问入口)、BUG-2082(标题栏随版本换语言、窄栏让位)、BUG-2093、BUG-2138(导出读取全文)、2026-11-02 顶栏控件 34px 规则。 - 修复版本:分支 `claude/header-buttons-2258`(待父会话推送)。 +## BUG-2256 | 生时纠正没有标出实验性质,中途离开的过程也没有记录,无法检验 + +- 状态:fixed-pending-verify。 +- 现象:产品负责人 2026-11-23:生时纠正对没有出生记录的用户能不能量准,目前没有数据可以回答(#329 因此暂停);后台只在用户点「采用」时写 `chart_choice_records`,中途离开的过程什么都不留。首页还写着「按你自己的选择:报告和问答都按这个时间写,开头会说明是你选的」,而报告与问答自 BUG-2146/2184 起已不在开头说明。 +- 修复(设计稿 2026-11-23 负责人同意): + - 页头标题后、侧栏入口右上角加灰色小标签「随缘版」;删掉首页那句话。 + - 新表 `chart_choice_steps`:生时纠正的五个接口(packet、adopt、supplement、reuse、astrologer)每次请求记一行,包括当时的出生资料与时间来源(由数据库按当时状态读取)、请求内容(经历、换盘选择、范围)、结果(状态、代码、放得下的 decision)、代码版本,不论成功失败、采用与否。随账号(auth.users)或人物档案(chart_profiles)级联删除;表对所有运行角色关闭,只能通过 `chart_choice_log_step_v1`(service_role)写入。写不进去时跳过,不影响用户这一步。没有任何算法读取它。 + - 对照依据不另外问:填资料时时间来源为出生证明或证件的用户,其填写时间即标准答案(负责人 2026-11-23 批注)。 + - 隐私政策「如何使用」与「保存期限」各补一条;原「生时纠正的问题数量与收敛情况,不含出生资料」一句改写(法律文件在内测期间仍隐藏)。 +- 验证与防复发:`rect-casual-edition-2256`(标签、删句、五个接口都记录、表的级联与权限、隐私政策)、`rect-step-log-2256`(结果裁剪、一次调用、写失败不外抛)、`database-local-business`(表清单)。 +- 关联记录:#329、BUG-2146、BUG-2184、BUG-1654。 +- 修复版本:`claude/rect-casual-2256`。 diff --git a/frontend/src/app/api/chart-choice/adopt/route.ts b/frontend/src/app/api/chart-choice/adopt/route.ts index 0191fc77f..60c49e696 100644 --- a/frontend/src/app/api/chart-choice/adopt/route.ts +++ b/frontend/src/app/api/chart-choice/adopt/route.ts @@ -2,6 +2,7 @@ import { NextResponse } from "next/server"; import { isRectQuestionnaireRequest, RECT_QUESTIONNAIRE_ENABLED, RECT_QUESTIONNAIRE_PAUSED } from "@/components/chart-choice/questionnaire-switch"; import { z } from "zod"; +import { recordChartChoiceStep } from "@/lib/chart-choice/step-log"; import { chartAnswersSchema, chartChoiceCaller, chartChoiceErrorResponse, evidenceInput, resolvedSchema, windowSchema } from "@/lib/chart-choice/route-support"; import { adoptCertainTime, adoptChartChoice, adoptDefaultChartChoice, adoptSelfChoice, previewAdaptiveChartChoice, previewChartChoice, previewSelfChoice, readDefaultChartChoice, restoreChartChoiceDefault } from "@/lib/chart-choice/server"; import { createAdminSupabaseClient } from "@/lib/supabase/admin"; @@ -67,42 +68,47 @@ export async function POST(request: Request) { } const parsed = bodySchema.safeParse(body); if (!parsed.success) return NextResponse.json({ error: "请求格式不对", code: "bad_request" }, { status: 400 }); - try { - if ("selfChoice" in parsed.data) { - const admin = createAdminSupabaseClient(); - return NextResponse.json(parsed.data.mode === "preview" - ? await previewSelfChoice(caller.supabase, admin, caller.userId, parsed.data) - : await adoptSelfChoice(caller.supabase, admin, caller.userId, parsed.data)); - } - if (!RECT_QUESTIONNAIRE_ENABLED && (parsed.data.mode === "preview" || parsed.data.mode === "choice")) { - const { subjectId, window, rangeChosen } = parsed.data; + // BUG-2256: every 生时纠正 step is recorded, adopted or not (lib/chart-choice/step-log.ts). + const response = await (async () => { + try { + if ("selfChoice" in parsed.data) { + const admin = createAdminSupabaseClient(); + return NextResponse.json(parsed.data.mode === "preview" + ? await previewSelfChoice(caller.supabase, admin, caller.userId, parsed.data) + : await adoptSelfChoice(caller.supabase, admin, caller.userId, parsed.data)); + } + if (!RECT_QUESTIONNAIRE_ENABLED && (parsed.data.mode === "preview" || parsed.data.mode === "choice")) { + const { subjectId, window, rangeChosen } = parsed.data; + if (parsed.data.mode === "preview") { + const { decision } = await readDefaultChartChoice(caller.supabase, caller.userId, { subjectId, window }); + return NextResponse.json({ decision }); + } + return NextResponse.json(await adoptDefaultChartChoice( + caller.supabase, createAdminSupabaseClient(), caller.userId, { subjectId, window, rangeChosen }, + )); + } + if (parsed.data.mode === "restore_default") { + return NextResponse.json(await restoreChartChoiceDefault( + caller.supabase, createAdminSupabaseClient(), caller.userId, parsed.data, + )); + } if (parsed.data.mode === "preview") { - const { decision } = await readDefaultChartChoice(caller.supabase, caller.userId, { subjectId, window }); - return NextResponse.json({ decision }); + if (parsed.data.adaptive) { + return NextResponse.json(await previewAdaptiveChartChoice(caller.supabase, caller.userId, parsed.data)); + } + return NextResponse.json(await previewChartChoice(caller.supabase, caller.userId, parsed.data, undefined, + parsed.data.resumeRecordId ? createAdminSupabaseClient() : undefined)); } - return NextResponse.json(await adoptDefaultChartChoice( - caller.supabase, createAdminSupabaseClient(), caller.userId, { subjectId, window, rangeChosen }, - )); - } - if (parsed.data.mode === "restore_default") { - return NextResponse.json(await restoreChartChoiceDefault( - caller.supabase, createAdminSupabaseClient(), caller.userId, parsed.data, - )); - } - if (parsed.data.mode === "preview") { - if (parsed.data.adaptive) { - return NextResponse.json(await previewAdaptiveChartChoice(caller.supabase, caller.userId, parsed.data)); + const admin = createAdminSupabaseClient(); + if (parsed.data.mode === "certain") { + return NextResponse.json(await adoptCertainTime(caller.supabase, admin, caller.userId, parsed.data)); } - return NextResponse.json(await previewChartChoice(caller.supabase, caller.userId, parsed.data, undefined, - parsed.data.resumeRecordId ? createAdminSupabaseClient() : undefined)); + const { decision, answers } = await adoptChartChoice(caller.supabase, admin, caller.userId, parsed.data); + return NextResponse.json({ decision, answers }); + } catch (error) { + return chartChoiceErrorResponse(error, "POST /api/chart-choice/adopt"); } - const admin = createAdminSupabaseClient(); - if (parsed.data.mode === "certain") { - return NextResponse.json(await adoptCertainTime(caller.supabase, admin, caller.userId, parsed.data)); - } - const { decision, answers } = await adoptChartChoice(caller.supabase, admin, caller.userId, parsed.data); - return NextResponse.json({ decision, answers }); - } catch (error) { - return chartChoiceErrorResponse(error, "POST /api/chart-choice/adopt"); - } + })(); + await recordChartChoiceStep({ userId: caller.userId, subjectId: parsed.data.subjectId, step: `adopt:${"selfChoice" in parsed.data ? "self_" : ""}${"mode" in parsed.data ? String(parsed.data.mode) : "choice"}`, request: parsed.data, response }); + return response; } diff --git a/frontend/src/app/api/chart-choice/astrologer/route.ts b/frontend/src/app/api/chart-choice/astrologer/route.ts index 550035999..6ba8a4f10 100644 --- a/frontend/src/app/api/chart-choice/astrologer/route.ts +++ b/frontend/src/app/api/chart-choice/astrologer/route.ts @@ -2,6 +2,7 @@ import { NextResponse } from "next/server"; import { RECT_QUESTIONNAIRE_ENABLED, RECT_QUESTIONNAIRE_PAUSED } from "@/components/chart-choice/questionnaire-switch"; import { z } from "zod"; +import { recordChartChoiceStep } from "@/lib/chart-choice/step-log"; import { chartChoiceCaller, chartChoiceErrorResponse, windowSchema } from "@/lib/chart-choice/route-support"; import { runAstrologerMethod } from "@/lib/chart-choice/server"; @@ -34,9 +35,14 @@ export async function POST(request: Request) { } const parsed = bodySchema.safeParse(await request.json().catch(() => null)); if (!parsed.success) return NextResponse.json({ error: "请求格式不对", code: "bad_request" }, { status: 400 }); - try { - return NextResponse.json(await runAstrologerMethod(caller.supabase, caller.userId, parsed.data)); - } catch (error) { - return chartChoiceErrorResponse(error, "POST /api/chart-choice/astrologer"); - } + // BUG-2256: every 生时纠正 step is recorded, adopted or not (lib/chart-choice/step-log.ts). + const response = await (async () => { + try { + return NextResponse.json(await runAstrologerMethod(caller.supabase, caller.userId, parsed.data)); + } catch (error) { + return chartChoiceErrorResponse(error, "POST /api/chart-choice/astrologer"); + } + })(); + await recordChartChoiceStep({ userId: caller.userId, subjectId: parsed.data.subjectId, step: "astrologer", request: parsed.data, response }); + return response; } diff --git a/frontend/src/app/api/chart-choice/packet/route.ts b/frontend/src/app/api/chart-choice/packet/route.ts index c9d342b20..a3abf9c93 100644 --- a/frontend/src/app/api/chart-choice/packet/route.ts +++ b/frontend/src/app/api/chart-choice/packet/route.ts @@ -2,6 +2,7 @@ import { NextResponse } from "next/server"; import { isRectQuestionnaireRequest, RECT_QUESTIONNAIRE_ENABLED, RECT_QUESTIONNAIRE_PAUSED } from "@/components/chart-choice/questionnaire-switch"; import { z } from "zod"; +import { recordChartChoiceStep } from "@/lib/chart-choice/step-log"; import { chartChoiceCaller, chartChoiceErrorResponse, resolvedSchema, windowSchema } from "@/lib/chart-choice/route-support"; import { createAdminSupabaseClient } from "@/lib/supabase/admin"; import { buildChartChoicePacket, readDefaultChartChoice } from "@/lib/chart-choice/server"; @@ -27,13 +28,18 @@ export async function POST(request: Request) { } const parsed = bodySchema.safeParse(body); if (!parsed.success) return NextResponse.json({ error: "请求格式不对", code: "bad_request" }, { status: 400 }); - try { - if (!RECT_QUESTIONNAIRE_ENABLED) { - return NextResponse.json(await readDefaultChartChoice(caller.supabase, caller.userId, parsed.data)); + // BUG-2256: every 生时纠正 step is recorded, adopted or not (lib/chart-choice/step-log.ts). + const response = await (async () => { + try { + if (!RECT_QUESTIONNAIRE_ENABLED) { + return NextResponse.json(await readDefaultChartChoice(caller.supabase, caller.userId, parsed.data)); + } + return NextResponse.json(await buildChartChoicePacket(caller.supabase, caller.userId, parsed.data, undefined, + parsed.data.resumeRecordId ? createAdminSupabaseClient() : undefined)); + } catch (error) { + return chartChoiceErrorResponse(error, "POST /api/chart-choice/packet"); } - return NextResponse.json(await buildChartChoicePacket(caller.supabase, caller.userId, parsed.data, undefined, - parsed.data.resumeRecordId ? createAdminSupabaseClient() : undefined)); - } catch (error) { - return chartChoiceErrorResponse(error, "POST /api/chart-choice/packet"); - } + })(); + await recordChartChoiceStep({ userId: caller.userId, subjectId: parsed.data.subjectId, step: "packet", request: parsed.data, response }); + return response; } diff --git a/frontend/src/app/api/chart-choice/reuse/route.ts b/frontend/src/app/api/chart-choice/reuse/route.ts index 5c86a9a20..64d73301b 100644 --- a/frontend/src/app/api/chart-choice/reuse/route.ts +++ b/frontend/src/app/api/chart-choice/reuse/route.ts @@ -1,6 +1,7 @@ import { NextResponse } from "next/server"; import { z } from "zod"; +import { recordChartChoiceStep } from "@/lib/chart-choice/step-log"; import { chartChoiceCaller, chartChoiceErrorResponse } from "@/lib/chart-choice/route-support"; import { reuseChartChoiceRecord } from "@/lib/chart-choice/server"; import { createAdminSupabaseClient } from "@/lib/supabase/admin"; @@ -15,9 +16,14 @@ export async function POST(request: Request) { if (!caller.ok) return caller.response; const parsed = bodySchema.safeParse(await request.json().catch(() => null)); if (!parsed.success) return NextResponse.json({ error: "请求格式不对", code: "bad_request" }, { status: 400 }); - try { - return NextResponse.json(await reuseChartChoiceRecord(createAdminSupabaseClient(), caller.userId, parsed.data.recordId, parsed.data.subjectId)); - } catch (error) { - return chartChoiceErrorResponse(error, "POST /api/chart-choice/reuse"); - } + // BUG-2256: every 生时纠正 step is recorded, adopted or not (lib/chart-choice/step-log.ts). + const response = await (async () => { + try { + return NextResponse.json(await reuseChartChoiceRecord(createAdminSupabaseClient(), caller.userId, parsed.data.recordId, parsed.data.subjectId)); + } catch (error) { + return chartChoiceErrorResponse(error, "POST /api/chart-choice/reuse"); + } + })(); + await recordChartChoiceStep({ userId: caller.userId, subjectId: parsed.data.subjectId, step: "reuse", request: parsed.data, response }); + return response; } diff --git a/frontend/src/app/api/chart-choice/supplement/route.ts b/frontend/src/app/api/chart-choice/supplement/route.ts index 88a5aeb3d..1f79d2f8e 100644 --- a/frontend/src/app/api/chart-choice/supplement/route.ts +++ b/frontend/src/app/api/chart-choice/supplement/route.ts @@ -1,6 +1,7 @@ import { NextResponse } from "next/server"; import { z } from "zod"; +import { recordChartChoiceStep } from "@/lib/chart-choice/step-log"; import { chartChoiceCaller, chartChoiceErrorResponse } from "@/lib/chart-choice/route-support"; import { readSupplement, supplementPatch } from "@/lib/chart-choice/supplement"; import { isChartSubjectId, SELF_SUBJECT_ID } from "@/lib/subject-birth"; @@ -64,20 +65,25 @@ export async function POST(request: Request) { if (!caller.ok) return caller.response; const parsed = bodySchema.safeParse(await request.json().catch(() => null)); if (!parsed.success) return NextResponse.json({ error: "请求格式不对", code: "bad_request" }, { status: 400 }); - try { - const subject = target(createAdminSupabaseClient(), caller.userId, parsed.data.subjectId); - if (!subject) return NextResponse.json({ error: "星盘不存在", code: "subject_not_found" }, { status: 404 }); - const { data, error } = await subject.read(); - if (error) throw error; - if (!data) return NextResponse.json({ error: "星盘不存在", code: "subject_not_found" }, { status: 404 }); - const answer = parsed.data.field === "timeSource" - ? { field: "timeSource" as const, value: parsed.data.value } - : { field: "date" as const, value: parsed.data.value }; - const patch = supplementPatch(data, answer); - const written = await subject.write(patch); - if (written.error) throw written.error; - return NextResponse.json({ supplement: readSupplement({ ...data, ...patch }) }); - } catch (error) { - return chartChoiceErrorResponse(error, "POST /api/chart-choice/supplement"); - } + // BUG-2256: every 生时纠正 step is recorded, adopted or not (lib/chart-choice/step-log.ts). + const response = await (async () => { + try { + const subject = target(createAdminSupabaseClient(), caller.userId, parsed.data.subjectId); + if (!subject) return NextResponse.json({ error: "星盘不存在", code: "subject_not_found" }, { status: 404 }); + const { data, error } = await subject.read(); + if (error) throw error; + if (!data) return NextResponse.json({ error: "星盘不存在", code: "subject_not_found" }, { status: 404 }); + const answer = parsed.data.field === "timeSource" + ? { field: "timeSource" as const, value: parsed.data.value } + : { field: "date" as const, value: parsed.data.value }; + const patch = supplementPatch(data, answer); + const written = await subject.write(patch); + if (written.error) throw written.error; + return NextResponse.json({ supplement: readSupplement({ ...data, ...patch }) }); + } catch (error) { + return chartChoiceErrorResponse(error, "POST /api/chart-choice/supplement"); + } + })(); + await recordChartChoiceStep({ userId: caller.userId, subjectId: parsed.data.subjectId, step: `supplement:${parsed.data.field}`, request: parsed.data, response }); + return response; } diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 73c660002..d64c802fc 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -8733,3 +8733,8 @@ button.report-ask-clear:hover { color: var(--color-ink); } text-align: center; } } +/* BUG-2256 (产品负责人 2026-11-23): 生时纠正「随缘版」. A small grey tag after the page title, and in the + top-right corner of the sidebar tile. */ +.secondary-header-tag { flex: none; padding: 3px 7px; border-radius: 999px; background: var(--color-canvas-muted); color: var(--color-ink-secondary); font-size: 12px; font-weight: 400; line-height: 1.2; white-space: nowrap; } +.sidebar-nav-link:has(.sidebar-nav-tag) { position: relative; } +.sidebar-nav-tag { position: absolute; top: 4px; right: 4px; padding: 2px 5px; border-radius: 999px; background: var(--sidebar-solid, var(--color-canvas)); color: var(--color-ink-secondary); font-size: 10px; line-height: 1.2; white-space: nowrap; pointer-events: none; } diff --git a/frontend/src/components/app-sidebar.tsx b/frontend/src/components/app-sidebar.tsx index 94d7df05e..8ee3aa0cd 100644 --- a/frontend/src/components/app-sidebar.tsx +++ b/frontend/src/components/app-sidebar.tsx @@ -61,6 +61,7 @@ import type { BeamAvatar } from "@/lib/beam-avatar"; import { groupSessionsByRecency } from "@/lib/session-groups"; import { markNewChatClick } from "@/lib/new-chat-timing"; import { homeWarmStartReady, waitForHomeWarmStart } from "@/lib/home-warm-prefetch"; +import { RECTIFICATION_EDITION_TAG } from "@/lib/chart-choice/edition"; import { navigateInApp } from "@/lib/app-navigation"; export type SidebarAccount = { @@ -418,6 +419,7 @@ export function AppSidebar({ {active ? : null}