Skip to content

test(webui): appearance 跟随系统/覆盖/落盘 三条真浏览器证据 - #31

Merged
stevenjj33 merged 1 commit into
webuifrom
test/webui-settings-theme
Oct 6, 2026
Merged

stevenjj33 merged 1 commit into
webuifrom
test/webui-settings-theme

Conversation

@stevenjj33

Copy link
Copy Markdown
Collaborator

Change

Roadmap P 区「跟随系统」一行是 9-30 的截图口径。结构性事实此前已有(resolveThemePreference 的四条单测映射、三个主题按钮在 DOM 里),但没有任何用例真的切一次系统主题、看界面跟不跟着变——这是「结构对 ≠ 能用」的又一个形状,本 PR 补的就是这块证据。

新增 test/webui-browser/settings-theme.spec.mjs 三条用例(经 harness 的 test,带 /health 与 serverId 守卫;经用户菜单 → 设置 真实路径进 Appearance):

  1. 跟随系统生效:选「跟随系统」→ emulateMedia 切 dark → <html> 有 dark 无 light;切回 light → 反之。套件全局 pin 在 colorScheme: "light"(playwright.config.mjs:30),所以不 emulate 的用例永远是浅色,「默认浅色」不能当「跟随生效」的证据——这条用例就是这个坑的反面。
  2. 手动覆盖系统:先在「跟随系统」下证明同一次 flip 能推动页面(对照腿,否则「还是 dark」在监听器死了的情况下也会空转通过),再点「深色模式」、flip 系统到 light——页面必须仍是 dark。断言前先 poll 页面自己的 matchMedia 为 false,保证 change 事件已派发到监听器。
  3. 落盘:localStorage.webui-theme 存的是点击的偏好串——OS 为 dark 时点「跟随系统」存 "system" 而不是解析后的 "dark"(存后者等于把今晚的 OS 状态快照进偏好,明早开机就不再跟随且无任何 UI 迹象);三档各验一次。

全部断言走 expect.poll,无 sleep。选中态用行内 aria-pressed 合同验证点击落地。

结果

三条全绿;全量浏览器套件 96 passed(此前 93);pnpm verify 20 门全绿;typecheck 含在 verify 内。无需改产品代码——按证据该行可以从 🟡 改 ✅(roadmap 层由 bot 执行)。

一个与任务书认知相反的实证(重要)

任务边界里预期「关掉设置弹窗后系统切主题、界面不再跟」(if (!open) return null 导致没人动 <html>)。实测不成立:UserMenu.tsx:918 对 <SettingsModal> 是常挂载 + open prop 形态,return null 只影响渲染输出、不卸载 hooks——matchMedia 监听与 class effect 在弹窗关闭后仍然活着。开发期用一次性探针实证过:关闭弹窗 → emulateMedia dark → <html> 仍变为 dark(探针已删,未进套件——该行为依赖 UserMenu 的挂载形态这一实现细节,不是主题行该钉死的合同,但 roadmap 侧不必按「关弹窗即失联」的已知缺口降格该行)。

Publication

  • 无产品代码变更,纯测试 + 清单登记(release/public-source.json +1)。
  • scripts/source-inventory.mjs --write 已重跑。
  • 无新增 vitest 单测文件(浏览器 spec 不进 test/vitest-suites.json,与套件现状一致)。

Validation

  • pnpm build:webui
  • pnpm test:webui-browser:96 passed(含新增 3)
  • pnpm verify:20 gates PASS on darwin(浏览器门在 darwin 上按平台策略跳过,已手动全量跑过)
  • CI 三平台(macOS / Ubuntu / Windows)

The P-zone roadmap row for 跟随系统 dates from a 9-30 screenshot, and the
only existing coverage was four unit assertions on resolveThemePreference's
input mapping -- nothing ever switched the OS scheme once and watched the
page follow. This adds a browser spec that does, three ways:

- following: select 跟随系统, emulate dark then light, assert <html> tracks
  both directions (with a control leg proving the change event fires);
- overriding: under 跟随系统 prove the flip moves the page, then pin 深色模式
  and flip the OS to light -- the page must stay dark;
- persisting: localStorage webui-theme holds the clicked preference string
  (system under a dark OS, not the resolved dark).

All three pass against the current webui HEAD, so the row's evidence is
now green; no product change was needed.
@stevenjj33
stevenjj33 merged commit 738ae1c into webui Oct 6, 2026
8 checks passed
@stevenjj33
stevenjj33 deleted the test/webui-settings-theme branch October 6, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant