Repository navigation
Description
Summary
product-sidebar-session-list--project-groups intermittently fails the smoke:storybook step. Two independent boundaries in the play function can each fail under the smoke runner's four-page concurrency (scripts/storybook-visual-smoke.mjs calls runJobs(..., 4)):
- Focus assertion after closing the rename dialog — the story clicks 关闭 and immediately asserts
expect(action).toHaveFocus(). The StorybooktoHaveFocusmatcher is a one-shot synchronous check (activeElement === element, no polling). The product closes the dialog viacloseRename()(packages/ui/src/session-history-list.tsx:408) and restores focus throughwindow.requestAnimationFrame(() => opener.focus()), which can only succeed after the modal unmounts. When the assertion runs before the next frame paints,activeElementis still<body>and the story fails — the product then restores focus correctly one frame later. - Dialog query right after picking 重命名 —
getByRole('dialog', { name: '重命名项目' })runs while the menu-close → dialog-mount handover is still mid-flight (the product comment atsession-history-list.tsx:362-369documents this one-frame race). CI has failed withmissing dialog role "重命名项目"as a separate assertion mode.
Observed failure modes on CI (multiple runs, including PRs whose diffs do not touch the sidebar): expected maka-agent 项目操作 button to hold focus, actual body; and missing dialog role "重命名项目".
Evidence
- Historical failure: run 33992802279 / job 101377914164 — stack points at
assets/session-list-panel.stories-BCpYL2Ip.js:1:10335, which maps exactly to theawait expect(action).toHaveFocus()line after clicking 关闭 (source:packages/ui/stories/session-list-panel.stories.tsx:677). - The story,
session-history-list.tsx, and the smoke runner are byte-identical between the failing merge (0467fbc4…) and current main (411512bd9…). - Reproduction on macOS arm64 Chromium, real runner, four-page concurrency, no artificial delays: 120 runs of the original assertions → 17 failures at the focus assertion + 17 dialog-not-ready failures; post-failure observation confirmed the product restored focus within ~300 ms every time (53/53), so this is a test-waiting defect, not a product bug. Converting the two assertion points to
waitFor/findByRole→ 240/240 pass; reverting to the original assertions reproduced the failure again (36 focus failures / 120). - The same story has kept failing CI after this report window, including a run where the failure mode was
missing dialog role "重命名项目"(see PR fix(desktop): localize expected errors #4457 discussion), and a reviewer reproduced a focus failure on the unmodified base.
Proposed fix (test-only)
In packages/ui/stories/session-list-panel.stories.tsx, ProjectGroups play:
await userEvent.click(page.getByRole('menuitem', { name: '重命名' }));
await expect(await page.findByRole('dialog', { name: '重命名项目' })).toBeVisible();
await userEvent.click(page.getByRole('button', { name: '关闭' }));
await waitFor(() => expect(action).toHaveFocus());waitFor is already imported by the file. No product change: closing the dialog and refocusing the opener on the next frame is intended behavior, and the post-failure probe showed the restore always completes.
Note: Desktop Nightly does not run smoke:storybook, so there is no green main baseline to compare against; the same flake is currently blocking unrelated PRs (e.g. #4457).
Activity