From 5f1182f4b94dbb3fa8a2d3dbc69120a514b8f22e Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 12:05:49 +0800 Subject: [PATCH] test(home): wait for the panel's lazy import instead of fixed ticks; preload the panel while the first-chart reveal plays (BUG-2307) Gate run 8517 failed on the new BUG-2307 desktop test: it waited 8 x 10 ms for the panel's dynamic import, which a loaded CI runner exceeds. The test now awaits the same import promise inside act. The open state is read from the store, so the product never sticks on an empty or closed panel, but its code and chart only started loading once the reveal ended; the home now preloads them as soon as the chart can be drawn. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq --- docs/BUG_HISTORY.md | 3 ++- frontend/src/app/(app)/page.tsx | 8 ++++++++ .../tests/onboarding-chart-panel-2307.test.tsx | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index bafc54cc7..b5a32c385 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -31038,4 +31038,5 @@ - 验证:新增 `frontend/tests/onboarding-chart-panel-2307.test.tsx` 8 条(引导三屏、帮别人看中途、选了资料不全的人、人员列表未到、动画在放时都不显示;页面接线和收起模式删除;动画放弃时 `onDrop`、播放或取消时不调用;电脑无盘时没有面板和按钮、存储零写入,有盘后面板打开、按钮「收起本命盘」;关过的人仍关着、开着的人仍开着,等待期间不写存储;手机无盘没有按钮、有盘后有按钮且底部面板不开;窄列竖排的 CSS;空状态文字)。按原值 / 新值 / 原因更新:`newcomer-2200-2201`(收起模式两条测试改为只测标题和没有单独的展开行)、`starter-arrive-2282`、`chat-chart-panel-state`、`shell-frame-stable-mount`。相关测试逐个文件跑过;tsc、改动文件 eslint 0 错误。截图(组件渲染,用当前 `globals.css` 经 Tailwind 编译的产品样式表,侧栏用同宽占位,登录态真实页面未起):`/workspace/eval-read-1116/chat-ux-prototype/build/onb-panel/`(引导第 1 屏修复前 / 后,电脑 1280 和手机 390;有盘后电脑 1280、平板 768、手机 390;浅深色)。 - 防复发:上面的测试;面板和按钮必须由同一个 `chartShown` 决定。 - 关联记录:BUG-2144(三屏引导)、BUG-2201(新手首页收起,本条撤销其默认收起)、#114 Q8(面板默认打开)、BUG-2167(保存后面板刷新)、BUG-2282(新对话三问)、BUG-1025(空状态入口)。 -- 修复版本:分支 `claude/onboarding-chart-panel`(本地提交,未推送)。 +- 修复版本:`c000d7750`(已进 staging);跟进提交见下。 +- 跟进(2026-11-24,staging 门禁 run 8517 validate-frontend 5135 过 / 1 失败):失败的是本条新测试「BUG-2307 desktop: without a chart …」的「the panel is open with the chart」。原因只在测试:面板代码是动态 import(`preloadChatChartSplit`),测试用固定的 8 × 10 ms 等它;本机这次 import 恰好在 render 的 act 里就完成(约 110–200 ms),满负载的 CI 上晚于等待时间。产品里开合状态直接读 store(默认打开),不是一次性的 effect,不会停在「按钮在、面板空/关」;但首次排盘后面板代码和星盘要等动画结束才开始加载,会晚一下才填满。修复:测试改为在 act 里等同一个 import promise,不再数时间片(每次挂载各自的存储和 store 状态);`page.tsx` 在盘可以画(资料齐、这个人资料完整)时就预载面板代码和星盘(与幕布预载同一个判断:电脑宽度、已存为打开),动画放的同时加载,结束时面板已完整。验证:本机 6 进程并行(加两份重测试文件、`--no-cache`)跑 30 次 0 失败;旧版测试在本机 24 个满载进程下也未复现(CI 负载更重)。 diff --git a/frontend/src/app/(app)/page.tsx b/frontend/src/app/(app)/page.tsx index d6cb50651..369e9b9f3 100644 --- a/frontend/src/app/(app)/page.tsx +++ b/frontend/src/app/(app)/page.tsx @@ -580,6 +580,14 @@ export default function Home() { // 新值:没有盘时面板和按钮都不出现,有盘后照已存状态(默认打开);原因:负责人 2026-11-24。 // BUG-2201's newcomer fold is gone: owner 2026-11-24, the panel opens as soon as the chart exists. const chartShown = homeChartShown({ profileComplete, subjectChartComplete, revealPlaying: birthSkyReveal.playing }); + // BUG-2307: the panel's code and chart load as soon as the chart can be drawn, while the first-chart + // reveal still plays, so the panel opens complete when the reveal ends instead of filling in a moment later. + const chartDrawable = profileComplete && subjectChartComplete; + useEffect(() => { + if (!hydrated || !chartDrawable) return; + if (!chartPanelPreloadApplicable({ viewportWidth: window.innerWidth, panelOpen: readStoredChatChartOpen(), hasChart: true })) return; + void preloadChatChartPanel(); + }, [chartDrawable, currentSubjectId, hydrated]); // BUG-2282: the three questions show on every new, empty conversation (原值:只在首问免费未用时,BUG-1431; // 原因:内测用户进来不知道问什么,负责人 2026-11-24 同意原型「刚进来」). The first-question billing is unchanged. const starterQuestionsVisible = newcomerHome || (starterHomeVisible diff --git a/frontend/tests/onboarding-chart-panel-2307.test.tsx b/frontend/tests/onboarding-chart-panel-2307.test.tsx index bef0b291e..b84e4a5e0 100644 --- a/frontend/tests/onboarding-chart-panel-2307.test.tsx +++ b/frontend/tests/onboarding-chart-panel-2307.test.tsx @@ -2,7 +2,7 @@ import "./install-test-document"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; -import React from "react"; +import React, { act } from "react"; import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support"; import { ChatChartFrame, ChatChartToggle } from "../src/components/chat-chart-frame"; @@ -10,6 +10,7 @@ import { SidebarProvider } from "../src/components/ui/sidebar"; import { applyBirthTimeDraftPatch, type BirthTimeDraft, type BirthTimeDraftPatch } from "../src/lib/birth-time-intake-model"; import { BIRTH_SKY_REVEAL_TIMEOUT_MS, startBirthSkyReveal } from "../src/lib/birth-sky/reveal"; import { CHAT_CHART_OPEN_STORAGE_KEY, homeChartShown, type ChatChartStorage } from "../src/lib/chat-chart-panel-state"; +import { preloadChatChartSplit } from "../src/lib/chat-chart-preload"; import { CHART_VIEW_COPY } from "../src/lib/chart-view-labels"; import { missingProfileStep, selfChartComplete } from "../src/lib/home-profile"; import { emptyProfile, type Profile } from "../src/lib/home-types"; @@ -70,6 +71,8 @@ test("BUG-2307: the home wires one decision into the panel and the top-bar butto assert.match(page, /const chartShown = homeChartShown\(\{ profileComplete, subjectChartComplete, revealPlaying: birthSkyReveal\.playing \}\);/); assert.match(page, //); assert.match(page, //); + // The panel's code and chart load while the first-chart reveal plays, so it opens complete afterwards. + assert.match(page, /const chartDrawable = profileComplete && subjectChartComplete;\n useEffect\(\(\) => \{\n if \(!hydrated \|\| !chartDrawable\) return;[\s\S]{0,200}void preloadChatChartPanel\(\);/); // 原值:useStarterChartFold(newcomerHome),新手首页默认收起,另存 starter_chart_details_open; // 新值:没有收起模式,只有 chat_chart_panel_open(默认打开);原因:负责人 2026-11-24 要求盘一排好就打开。 assert.doesNotMatch(`${page}\n${frame}\n${read("stores/ui-store.ts")}`, /useStarterChartFold\(|starterChartFold|StarterChartDetailsOpen|STARTER_CHART_DETAILS_STORAGE_KEY/); @@ -116,6 +119,7 @@ async function mountHome(width: number, chart: boolean, seed: Record ( @@ -124,14 +128,19 @@ async function mountHome(width: number, chart: boolean, seed: Record ); await harness.render(view(chart)); - for (let attempt = 0; attempt < 6; attempt += 1) await harness.idle(); + if (chart) await act(async () => { await preloadChatChartSplit(); }); + for (let attempt = 0; attempt < 3; attempt += 1) await harness.idle(); const button = (label: string) => harness.elements().find((node) => node.tagName === "BUTTON" && node.props["aria-label"] === label); const toggle = () => harness.elements().find((node) => node.tagName === "BUTTON" && String(node.props.className ?? "").includes("chat-chart-toggle")); const panel = () => harness.elements().find((node) => node.tagName === "ASIDE" && String(node.props.className ?? "").includes("chat-chart-split")); const text = () => harness.elements().map((node) => String(node.props.children ?? "")).join("\n"); + // The frame loads the panel's code with a dynamic import once a chart exists. A cold import takes + // ~0.5 s (longer on a loaded CI runner), so wait for that same promise, not a number of ticks + // (BUG-2307 gate run 8517 failed on a fixed 8 × 10 ms wait). const rerender = async (shown: boolean) => { await harness.render(view(shown)); - for (let attempt = 0; attempt < 8; attempt += 1) await harness.idle(); + if (shown) await act(async () => { await preloadChatChartSplit(); }); + for (let attempt = 0; attempt < 3; attempt += 1) await harness.idle(); }; return { harness, storage, button, toggle, panel, text, rerender }; }