settings-chrome.e2e.ts 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // Web e2e scenarios: the settings surface — the modal shell (trigger, nav,
  2. // section switching, both close paths), the Appearance preference row (the
  3. // real theme gesture — click 深色 and the whole cascade runs: ThemeRuntime preference -> Host settings
  4. // -> theme/change -> ui-layout's presenter -> body attribute -> alias token +
  5. // browser theme-color metadata)
  6. // the Language row and busy-state Enter preference (both Host-backed), plus
  7. // Permission as the persisted default for subsequently created sessions.
  8. // Zero model calls: everything is pure client + persistence state on a blank
  9. // frame, so there is no fixture and a stray stream would fail loud on the
  10. // open llm seam.
  11. import { readFile } from 'node:fs/promises'
  12. import { fileURLToPath } from 'node:url'
  13. import type { Browser, Page } from 'playwright'
  14. import { chromium } from 'playwright'
  15. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  16. import { join } from 'node:path'
  17. import { SessionId } from '@deepseek-ai/dsh-session'
  18. import {
  19. acknowledgeReloadConnectionLoss, assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  20. launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold,
  21. } from './scaffold.ts'
  22. import { ZH_BROWSER_LOCALE, saveFailureShot } from './support.ts'
  23. const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/settings-chrome', import.meta.url))
  24. const DIALOG_EXPECTED = join(SNAPSHOT_DIR, 'dialog.expected.md')
  25. const PLUGINS_EXPECTED = join(SNAPSHOT_DIR, 'plugins.expected.md')
  26. // The English fallback surface: a browser naming no shipped language.
  27. const DIALOG_EN_EXPECTED = join(SNAPSHOT_DIR, 'dialog-en.expected.md')
  28. const PLUGIN_ROW_SELECTOR = '[data-plugin-entry$="ui-settings"]'
  29. const MODE = webSnapshotMode()
  30. describe('web e2e: settings modal and General preferences', () => {
  31. let scaffold: WebScaffold
  32. let browser: Browser
  33. let page: Page
  34. let tripwire: ReturnType<typeof watchConsole>
  35. beforeAll(async () => {
  36. scaffold = await launchWebScaffold({})
  37. browser = await chromium.launch()
  38. // Chinese browser: the shared page asserts the localized settings surface
  39. // the client derives from it (the English default has its own spec below).
  40. page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  41. tripwire = watchConsole(page)
  42. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  43. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  44. }, 120_000)
  45. afterAll(async () => {
  46. await browser?.close()
  47. await scaffold?.close()
  48. })
  49. it('opens the settings dialog, switches sections, and closes by every path', async () => {
  50. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-shell'))
  51. const trigger = page.getByRole('button', { name: '设置', exact: true })
  52. expect(await trigger.getAttribute('aria-haspopup')).toBe('dialog')
  53. expect(await trigger.getAttribute('aria-expanded')).toBe('false')
  54. await trigger.click()
  55. const dialog = page.getByRole('dialog', { name: '设置' })
  56. await dialog.waitFor({ timeout: 10_000 })
  57. expect(await trigger.getAttribute('aria-expanded')).toBe('true')
  58. // General is active by default; Permission, Language and Appearance are functional.
  59. expect(await dialog.getByRole('button', { name: '通用设置' }).getAttribute('aria-current')).toBe('true')
  60. await dialog.getByRole('button', { name: '工作区内修改' }).waitFor({ timeout: 10_000 })
  61. await expect.poll(() => dialog.getByText('语言', { exact: true }).count(), { timeout: 5_000 }).toBe(1)
  62. await expect.poll(() => dialog.getByText('外观', { exact: true }).count(), { timeout: 5_000 }).toBe(1)
  63. const openDocument = dialog.getByRole('button', { name: '打开配置文件' })
  64. await openDocument.waitFor({ timeout: 10_000 })
  65. let openRequests = 0
  66. await page.route('**/api/settings/openSettingsDocument', async (route) => {
  67. const envelope = route.request().postDataJSON() as {
  68. rpcId: string
  69. payload: { args: Record<string, never> }
  70. }
  71. expect(envelope.payload).toEqual({ args: {} })
  72. openRequests += 1
  73. await route.fulfill({
  74. status: 200,
  75. contentType: 'application/json',
  76. body: JSON.stringify({
  77. type: 'server-response',
  78. rpcId: envelope.rpcId,
  79. result: { ok: true, value: { opened: true } },
  80. }),
  81. })
  82. })
  83. await openDocument.click()
  84. await expect.poll(() => openRequests, { timeout: 5_000 }).toBe(1)
  85. await expect.poll(() => openDocument.isEnabled(), { timeout: 5_000 }).toBe(true)
  86. await page.unroute('**/api/settings/openSettingsDocument')
  87. // Golden of the freshly opened dialog (default zh, General active).
  88. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  89. await compareOrRefreshGolden(DIALOG_EXPECTED, snapshot, MODE)
  90. // Section switch: aria-current moves (the Models page itself has its own scenario file).
  91. await dialog.getByRole('button', { name: '模型' }).click()
  92. await expect.poll(() => dialog.getByRole('button', { name: '模型' }).getAttribute('aria-current'), { timeout: 5_000 }).toBe('true')
  93. expect(await dialog.getByRole('button', { name: '通用设置' }).getAttribute('aria-current')).toBeNull()
  94. // Plugins is a read-only projection of the same assembled Loader tree.
  95. // Capture one stable shipped row rather than the whole inventory so adding
  96. // an unrelated plugin does not rewrite this surface's golden.
  97. await dialog.getByRole('button', { name: '插件', exact: true }).click()
  98. await dialog.getByRole('heading', { name: '插件', exact: true }).waitFor({ timeout: 10_000 })
  99. await dialog.getByRole('tab', { name: '插件列表', exact: true }).click()
  100. // The preset group opens first with its display-only switcher; the global
  101. // plane starts collapsed and expands on demand.
  102. const presetSwitcher = dialog.getByRole('button', { name: '选择要查看的 Agent 预设' })
  103. await presetSwitcher.waitFor({ timeout: 10_000 })
  104. // The shipped default's zh display name comes from the zh dictionaries.
  105. expect(await presetSwitcher.textContent()).toBe('标准模式(默认)')
  106. await dialog.getByRole('button', { name: /^全局/ }).click()
  107. const pluginRow = dialog.locator(PLUGIN_ROW_SELECTOR)
  108. await pluginRow.waitFor({ timeout: 10_000 })
  109. const expectedPluginCount = [...scaffold.ctx.loader.entries()]
  110. .filter(entry => !entry.options.group)
  111. .length
  112. expect(await dialog.getByRole('searchbox', { name: '搜索插件' }).count()).toBe(1)
  113. // Every Loader entry appears exactly once in the global group — rows the
  114. // presets took over included, preset compositions excluded.
  115. expect(await dialog.locator('[data-plugin-scope="global"] [data-plugin-entry]').count())
  116. .toBe(expectedPluginCount)
  117. expect(await dialog.locator('[data-plugin-count]').getAttribute('data-plugin-count'))
  118. .toBe(String(expectedPluginCount))
  119. expect(await dialog.getByRole('button', { name: '插件', exact: true }).getAttribute('aria-current')).toBe('true')
  120. expect(await dialog.getByRole('tab', { name: '插件列表', exact: true }).getAttribute('aria-selected')).toBe('true')
  121. expect(await dialog.getByRole('button', { name: '模型' }).getAttribute('aria-current')).toBeNull()
  122. const pluginsSnapshot = await captureStableAria(
  123. page,
  124. PLUGIN_ROW_SELECTOR,
  125. scaffold.workspaceCwd,
  126. )
  127. await compareOrRefreshGolden(PLUGINS_EXPECTED, pluginsSnapshot, MODE)
  128. // Close path 1: Escape.
  129. await page.keyboard.press('Escape')
  130. await expect.poll(() => page.getByRole('dialog', { name: '设置' }).count(), { timeout: 5_000 }).toBe(0)
  131. expect(await trigger.getAttribute('aria-expanded')).toBe('false')
  132. // Close path 2: the header close button (focus lands there on open).
  133. await trigger.click()
  134. await page.getByRole('dialog', { name: '设置' }).getByRole('button', { name: '关闭' }).click()
  135. await expect.poll(() => page.getByRole('dialog', { name: '设置' }).count(), { timeout: 5_000 }).toBe(0)
  136. expect(tripwire.pageErrors).toEqual([])
  137. }, 60_000)
  138. it('stores Permission as the default for future sessions without changing an existing session', async () => {
  139. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-permission'))
  140. const existing = scaffold.ctx.sessions.create(SessionId('settings-permission-before'))
  141. expect(existing.snapshotEvents().find(event => event.type === 'permission/preset')?.data)
  142. .toEqual({ preset: 'workspace-write' })
  143. await page.getByRole('button', { name: '设置', exact: true }).click()
  144. const dialog = page.getByRole('dialog', { name: '设置' })
  145. await dialog.waitFor({ timeout: 10_000 })
  146. const selector = dialog.getByRole('button', { name: '工作区内修改' })
  147. await selector.waitFor({ timeout: 10_000 })
  148. await expect.poll(() => selector.isEnabled(), { timeout: 5_000 }).toBe(true)
  149. await selector.click()
  150. await page.getByRole('menuitem', { name: '仅可查看' }).click()
  151. await dialog.getByRole('button', { name: '仅可查看' }).waitFor({ timeout: 10_000 })
  152. const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  153. expect(document).toContain('permission:')
  154. expect(document).toContain('defaultPreset: read-only')
  155. expect(existing.snapshotEvents().find(event => event.type === 'permission/preset')?.data)
  156. .toEqual({ preset: 'workspace-write' })
  157. const created = scaffold.ctx.sessions.create(SessionId('settings-permission-after'))
  158. expect(created.snapshotEvents().map(event => [event.type, event.data])).toEqual([
  159. ['permission/preset', { preset: 'read-only' }],
  160. ['sandbox/mode', { mode: 'read-only' }],
  161. ['approval/policy', { policy: 'ask' }],
  162. ])
  163. await dialog.getByRole('button', { name: '仅可查看' }).click()
  164. await page.getByRole('menuitem', { name: '完全权限' }).click()
  165. const confirmation = page.getByRole('dialog', { name: '确认启用完全权限?' })
  166. const enable = confirmation.getByRole('button', { name: '启用完全权限' })
  167. expect(await enable.isDisabled()).toBe(true)
  168. await confirmation.getByRole('checkbox').click()
  169. await enable.click()
  170. await dialog.getByRole('button', { name: '完全权限' }).waitFor({ timeout: 10_000 })
  171. const confirmedDocument = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  172. expect(confirmedDocument).toContain('defaultPreset: danger-full-access')
  173. const confirmed = scaffold.ctx.sessions.create(SessionId('settings-permission-confirmed'))
  174. expect(confirmed.snapshotEvents().map(event => [event.type, event.data])).toEqual([
  175. ['permission/preset', { preset: 'danger-full-access' }],
  176. ['sandbox/mode', { mode: 'danger-full-access' }],
  177. ['approval/policy', { policy: 'never' }],
  178. ])
  179. await page.keyboard.press('Escape')
  180. expect(tripwire.pageErrors).toEqual([])
  181. }, 60_000)
  182. it('uses the persisted dark preference while plugins are still loading', async () => {
  183. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-boot-theme'))
  184. await page.emulateMedia({ colorScheme: 'light' })
  185. await page.getByRole('button', { name: '设置', exact: true }).click()
  186. const initialDialog = page.getByRole('dialog', { name: '设置' })
  187. const darkCube = initialDialog.getByRole('button', { name: '深色' })
  188. await darkCube.click()
  189. await expect.poll(() => darkCube.getAttribute('aria-pressed'), { timeout: 5_000 }).toBe('true')
  190. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  191. .toMatch(/ui-theme:\n\s+preference: dark/)
  192. await page.keyboard.press('Escape')
  193. // Hold the real application batch so the shell-owned loading page remains observable.
  194. const pluginPattern = /\/plugins\/\?\?.+\/client\.js,.+\/client\.js&rev=[a-f\d]{12}$/
  195. let releaseBundles = (): void => {}
  196. const bundlesReleased = new Promise<void>((resolve) => { releaseBundles = resolve })
  197. await page.route(pluginPattern, async (route) => {
  198. await bundlesReleased
  199. await route.continue()
  200. })
  201. const warningStart = tripwire.warnings.length
  202. let reload: ReturnType<Page['reload']> | undefined
  203. try {
  204. reload = page.reload({ waitUntil: 'domcontentloaded' })
  205. const loading = page.getByText('Loading plugins…', { exact: true })
  206. await loading.waitFor({ timeout: 10_000 })
  207. const state = await loading.evaluate((element) => {
  208. const boot = element.parentElement?.parentElement
  209. if (boot === undefined || boot === null) throw new Error('loading hint is detached from the boot page')
  210. return {
  211. attr: document.body.hasAttribute('data-ds-dark-theme'),
  212. background: getComputedStyle(boot).backgroundColor,
  213. colorScheme: document.documentElement.style.colorScheme,
  214. }
  215. })
  216. expect(state).toEqual({
  217. attr: true,
  218. background: 'rgb(21, 21, 23)',
  219. colorScheme: 'dark',
  220. })
  221. } finally {
  222. releaseBundles()
  223. await reload
  224. await page.unroute(pluginPattern)
  225. }
  226. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  227. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  228. await page.getByRole('button', { name: '设置', exact: true }).click()
  229. const restoredDialog = page.getByRole('dialog', { name: '设置' })
  230. const systemCube = restoredDialog.getByRole('button', { name: '跟随系统' })
  231. await systemCube.click()
  232. await expect.poll(() => systemCube.getAttribute('aria-pressed'), { timeout: 5_000 }).toBe('true')
  233. await expect.poll(() => page.evaluate(() => document.body.hasAttribute('data-ds-dark-theme')), {
  234. timeout: 5_000,
  235. }).toBe(false)
  236. await page.keyboard.press('Escape')
  237. expect(tripwire.pageErrors).toEqual([])
  238. }, 90_000)
  239. it('flips the theme through the Appearance cubes and persists across reload and a distinct port', async () => {
  240. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-appearance'))
  241. interface ThemeState {
  242. attr: boolean
  243. background: string
  244. /** Pre-migration localStorage key; the Host-backed world never writes it. */
  245. legacy: string | null
  246. themeColor: string | null
  247. themeColorCount: number
  248. token: string
  249. }
  250. const readState = async (target: Page = page): Promise<ThemeState> => await target.evaluate(() => {
  251. const metas = document.head.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]')
  252. const computed = getComputedStyle(document.body)
  253. return {
  254. attr: document.body.hasAttribute('data-ds-dark-theme'),
  255. background: computed.backgroundColor,
  256. legacy: localStorage.getItem('dsh.theme'),
  257. themeColor: metas[0]?.content ?? null,
  258. themeColorCount: metas.length,
  259. token: computed.getPropertyValue('--dsw-alias-bg-base').trim(),
  260. }
  261. })
  262. const expectThemeColorSynchronized = (state: ThemeState): void => {
  263. expect(state.themeColorCount).toBe(1)
  264. expect(state.background).not.toBe('rgba(0, 0, 0, 0)')
  265. expect(state.themeColor).toBe(state.background)
  266. }
  267. // Pin the OS scheme to light so the default `system` preference resolves
  268. // light and the dark flip below is unambiguously the gesture's doing.
  269. await page.emulateMedia({ colorScheme: 'light' })
  270. const light = await readState()
  271. expect(light.attr).toBe(false)
  272. expectThemeColorSynchronized(light)
  273. await page.getByRole('button', { name: '设置', exact: true }).click()
  274. const dialog = page.getByRole('dialog', { name: '设置' })
  275. await dialog.waitFor({ timeout: 10_000 })
  276. const darkCube = dialog.getByRole('button', { name: '深色' })
  277. expect(await darkCube.getAttribute('aria-pressed')).toBe('false')
  278. await darkCube.click()
  279. // The full cascade: pressed state, Host-backed preference, body attribute,
  280. // alias token flip — all from one real user gesture.
  281. await expect.poll(() => darkCube.getAttribute('aria-pressed'), { timeout: 5_000 }).toBe('true')
  282. const dark = await readState()
  283. expect(dark.attr).toBe(true)
  284. expect(dark.legacy).toBeNull()
  285. expect(dark.token).not.toBe(light.token)
  286. expectThemeColorSynchronized(dark)
  287. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  288. .toMatch(/ui-theme:\n\s+preference: dark/)
  289. await page.keyboard.press('Escape')
  290. // Reload: the preference survives the background Host read + presenter update.
  291. const warningStart = tripwire.warnings.length
  292. await page.reload({ waitUntil: 'load' })
  293. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  294. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  295. await page.emulateMedia({ colorScheme: 'light' })
  296. await expect.poll(async () => (await readState()).attr, { timeout: 5_000 }).toBe(true)
  297. const reloaded = await readState()
  298. expect(reloaded.legacy).toBeNull()
  299. expectThemeColorSynchronized(reloaded)
  300. // A second live Host binds another ephemeral port but shares the same
  301. // user-settings home. Its fresh origin has no theme localStorage and still
  302. // converges to dark before the settings dialog opens.
  303. const second = await launchWebScaffold({ harnessHome: scaffold.harnessHome })
  304. const secondPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  305. const secondTripwire = watchConsole(secondPage)
  306. try {
  307. expect(second.baseUrl).not.toBe(scaffold.baseUrl)
  308. await secondPage.emulateMedia({ colorScheme: 'light' })
  309. await secondPage.goto(second.authenticatedUrl, { waitUntil: 'load' })
  310. await secondPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  311. await expect.poll(async () => (await readState(secondPage)).attr, { timeout: 5_000 }).toBe(true)
  312. const secondState = await readState(secondPage)
  313. expect(secondState.legacy).toBeNull()
  314. expectThemeColorSynchronized(secondState)
  315. expect(secondTripwire.pageErrors).toEqual([])
  316. expect(secondTripwire.warnings).toEqual([])
  317. } finally {
  318. await secondPage.close()
  319. await second.close()
  320. }
  321. // `system` follows the emulated OS scheme (dark stays dark, light clears).
  322. await page.getByRole('button', { name: '设置', exact: true }).click()
  323. const systemCube = page.getByRole('dialog', { name: '设置' }).getByRole('button', { name: '跟随系统' })
  324. await systemCube.click()
  325. await expect.poll(() => systemCube.getAttribute('aria-pressed'), { timeout: 5_000 }).toBe('true')
  326. await expect.poll(async () => (await readState()).attr, { timeout: 5_000 }).toBe(false)
  327. expectThemeColorSynchronized(await readState())
  328. await page.emulateMedia({ colorScheme: 'dark' })
  329. await expect.poll(async () => (await readState()).attr, { timeout: 5_000 }).toBe(true)
  330. expectThemeColorSynchronized(await readState())
  331. // Restore for the specs that follow: light preference beats the emulated
  332. // dark OS scheme, leaving the shared page in the light default.
  333. await page.getByRole('dialog', { name: '设置' }).getByRole('button', { name: '浅色' }).click()
  334. await expect.poll(async () => (await readState()).attr, { timeout: 5_000 }).toBe(false)
  335. expectThemeColorSynchronized(await readState())
  336. await page.keyboard.press('Escape')
  337. expect(tripwire.pageErrors).toEqual([])
  338. }, 90_000)
  339. it('steps the content font size, applies it to body, and persists across reload', async () => {
  340. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-font-size'))
  341. const readFontSize = async (target: Page = page): Promise<string> => await target.evaluate(
  342. () => document.body.style.getPropertyValue('--dsh-content-font-size'),
  343. )
  344. // The secondary tier resolved by the real engine: a probe element's
  345. // font-size forces min/max/calc evaluation, which the CSS-text specs
  346. // cannot exercise. Setting −1 at ≤14, setting −2 above.
  347. const readSecondaryFontSize = async (): Promise<string> => await page.evaluate(() => {
  348. const probe = document.createElement('div')
  349. probe.style.fontSize = 'var(--dsh-content-font-size-secondary, 13px)'
  350. document.body.appendChild(probe)
  351. const size = getComputedStyle(probe).fontSize
  352. probe.remove()
  353. return size
  354. })
  355. expect(await readFontSize()).toBe('14px')
  356. expect(await readSecondaryFontSize()).toBe('13px')
  357. await page.getByRole('button', { name: '设置', exact: true }).click()
  358. const dialog = page.getByRole('dialog', { name: '设置' })
  359. await dialog.waitFor({ timeout: 10_000 })
  360. // The stepper reveals its arrows on hover; the up arrow steps 14 → 15 → 16.
  361. await dialog.getByText('14', { exact: true }).hover()
  362. const increase = dialog.getByRole('button', { name: '增大字号' })
  363. await increase.click()
  364. await dialog.getByText('15', { exact: true }).waitFor({ timeout: 5_000 })
  365. // 15 is the piecewise boundary: the secondary tier holds at 13px (−2)
  366. // where the ≤14 branch would have given 14px (−1).
  367. await expect.poll(readSecondaryFontSize, { timeout: 5_000 }).toBe('13px')
  368. await increase.click()
  369. await dialog.getByText('16', { exact: true }).waitFor({ timeout: 5_000 })
  370. await expect.poll(readFontSize, { timeout: 5_000 }).toBe('16px')
  371. await expect.poll(readSecondaryFontSize, { timeout: 5_000 }).toBe('14px')
  372. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  373. .toMatch(/ui-theme:\n(?:\s+\w+: .*\n)*?\s+fontSize: 16/)
  374. await page.keyboard.press('Escape')
  375. // Reload: the boot script embeds the durable size and ThemeRuntime seeds
  376. // its initial snapshot from the boot-written body variable, so activation
  377. // never flashes the default while the settings read is in flight.
  378. const warningStart = tripwire.warnings.length
  379. await page.reload({ waitUntil: 'load' })
  380. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  381. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  382. await expect.poll(readFontSize, { timeout: 5_000 }).toBe('16px')
  383. expect(await readSecondaryFontSize()).toBe('14px')
  384. // Restore the default for the specs that follow (and the dialog golden).
  385. await page.getByRole('button', { name: '设置', exact: true }).click()
  386. const restored = page.getByRole('dialog', { name: '设置' })
  387. await restored.waitFor({ timeout: 10_000 })
  388. await restored.getByText('16', { exact: true }).hover()
  389. const decrease = restored.getByRole('button', { name: '减小字号' })
  390. await decrease.click()
  391. await restored.getByText('15', { exact: true }).waitFor({ timeout: 5_000 })
  392. await decrease.click()
  393. await restored.getByText('14', { exact: true }).waitFor({ timeout: 5_000 })
  394. await expect.poll(readFontSize, { timeout: 5_000 }).toBe('14px')
  395. await page.keyboard.press('Escape')
  396. expect(tripwire.pageErrors).toEqual([])
  397. }, 90_000)
  398. it('persists the completed-Turn transcript mode across reload', async () => {
  399. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-transcript-view'))
  400. await page.getByRole('button', { name: '设置', exact: true }).click()
  401. const dialog = page.getByRole('dialog', { name: '设置' })
  402. await dialog.waitFor({ timeout: 10_000 })
  403. await dialog.getByText('对话显示', { exact: true }).waitFor({ timeout: 10_000 })
  404. await dialog.getByRole('button', { name: 'Compact', exact: true }).click()
  405. await page.getByRole('menuitem', { name: 'Normal', exact: true }).click()
  406. await dialog.getByRole('button', { name: 'Normal', exact: true }).waitFor({ timeout: 10_000 })
  407. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  408. .toMatch(/ui-chat:\n\s+transcriptView: normal/)
  409. await page.keyboard.press('Escape')
  410. const warningStart = tripwire.warnings.length
  411. await page.reload({ waitUntil: 'load' })
  412. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  413. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  414. await page.getByRole('button', { name: '设置', exact: true }).click()
  415. const reloaded = page.getByRole('dialog', { name: '设置' })
  416. await reloaded.getByRole('button', { name: 'Normal', exact: true }).waitFor({ timeout: 10_000 })
  417. await reloaded.getByRole('button', { name: 'Normal', exact: true }).click()
  418. await page.getByRole('menuitem', { name: 'Compact', exact: true }).click()
  419. await reloaded.getByRole('button', { name: 'Compact', exact: true }).waitFor({ timeout: 10_000 })
  420. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  421. .toMatch(/ui-chat:\n\s+transcriptView: compact/)
  422. await page.keyboard.press('Escape')
  423. expect(tripwire.pageErrors).toEqual([])
  424. }, 90_000)
  425. it('persists the busy-state Enter behavior across reload and a distinct port', async () => {
  426. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-enter-behavior'))
  427. await page.getByRole('button', { name: '设置', exact: true }).click()
  428. const dialog = page.getByRole('dialog', { name: '设置' })
  429. await dialog.waitFor({ timeout: 10_000 })
  430. await dialog.getByRole('button', { name: '排队发送' }).click()
  431. await page.getByRole('menuitem', { name: '插话发送' }).click()
  432. await dialog.getByRole('button', { name: '插话发送' }).waitFor({ timeout: 10_000 })
  433. expect(await page.evaluate(() => localStorage.getItem('dsh.conversation.busyEnter'))).toBeNull()
  434. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  435. .toMatch(/ui-conversation:\n\s+busyEnter: steer/)
  436. await page.keyboard.press('Escape')
  437. const warningStart = tripwire.warnings.length
  438. await page.reload({ waitUntil: 'load' })
  439. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  440. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  441. await page.getByRole('button', { name: '设置', exact: true }).click()
  442. const reloaded = page.getByRole('dialog', { name: '设置' })
  443. await reloaded.getByRole('button', { name: '插话发送' }).waitFor({ timeout: 10_000 })
  444. const second = await launchWebScaffold({ harnessHome: scaffold.harnessHome })
  445. const secondPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  446. const secondTripwire = watchConsole(secondPage)
  447. try {
  448. expect(second.baseUrl).not.toBe(scaffold.baseUrl)
  449. await secondPage.goto(second.authenticatedUrl, { waitUntil: 'load' })
  450. await secondPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  451. await secondPage.getByRole('button', { name: '设置', exact: true }).click()
  452. await secondPage.getByRole('dialog', { name: '设置' })
  453. .getByRole('button', { name: '插话发送' }).waitFor({ timeout: 10_000 })
  454. expect(await secondPage.evaluate(() => localStorage.getItem('dsh.conversation.busyEnter'))).toBeNull()
  455. expect(secondTripwire.pageErrors).toEqual([])
  456. expect(secondTripwire.warnings).toEqual([])
  457. } finally {
  458. await secondPage.close()
  459. await second.close()
  460. }
  461. await reloaded.getByRole('button', { name: '插话发送' }).click()
  462. await page.getByRole('menuitem', { name: '排队发送' }).click()
  463. await reloaded.getByRole('button', { name: '排队发送' }).waitFor({ timeout: 10_000 })
  464. expect(await page.evaluate(() => localStorage.getItem('dsh.conversation.busyEnter'))).toBeNull()
  465. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  466. .toMatch(/ui-conversation:\n\s+busyEnter: queue/)
  467. await page.keyboard.press('Escape')
  468. expect(tripwire.pageErrors).toEqual([])
  469. }, 90_000)
  470. it('persists the settings language across reload and a distinct port', async () => {
  471. onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-language'))
  472. await page.getByRole('button', { name: '设置', exact: true }).click()
  473. const zhDialog = page.getByRole('dialog', { name: '设置' })
  474. await zhDialog.waitFor({ timeout: 10_000 })
  475. // The document language follows the active locale in the assembled app, not
  476. // only on a directly-mounted plugin. This is a zh browser, so the served
  477. // markup's `en` must already have been replaced — asserting it here (rather
  478. // than only in an English scenario) is what makes the check discriminating.
  479. expect(await page.evaluate(() => document.documentElement.lang)).toBe('zh-CN')
  480. // The Language selector pill shows the active locale's own name.
  481. const selector = zhDialog.getByRole('button', { name: '中文' })
  482. expect(await selector.getAttribute('aria-haspopup')).toBe('menu')
  483. await selector.click()
  484. await page.getByRole('menuitem', { name: 'English' }).click()
  485. // The settings-owned copy re-registers localized: dialog title, nav,
  486. // Appearance labels. (Only the settings namespaces are localized —
  487. // the rest of the app's copy is intentionally out of this row's scope.)
  488. const enDialog = page.getByRole('dialog', { name: 'Settings' })
  489. await enDialog.waitFor({ timeout: 10_000 })
  490. // ...and the attribute follows that switch, in the assembled app.
  491. await expect.poll(() => page.evaluate(() => document.documentElement.lang), { timeout: 5_000 }).toBe('en')
  492. expect(await enDialog.getByRole('button', { name: 'General' }).getAttribute('aria-current')).toBe('true')
  493. await expect.poll(() => enDialog.getByText('Appearance', { exact: true }).count(), { timeout: 5_000 }).toBe(1)
  494. expect(await page.evaluate(() => localStorage.getItem('dsh.locale'))).toBeNull()
  495. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  496. .toMatch(/locale:\n\s+preference: en/)
  497. // Reload keeps English; then restore zh so shared page state (and the
  498. // other specs' 设置-anchored selectors + goldens) see the default again.
  499. const warningStart = tripwire.warnings.length
  500. await page.reload({ waitUntil: 'load' })
  501. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  502. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  503. const enTrigger = page.getByRole('button', { name: 'Settings' })
  504. await enTrigger.waitFor({ timeout: 10_000 })
  505. // A Chinese browser on another port still receives the explicit English
  506. // preference from the shared Host settings document.
  507. const second = await launchWebScaffold({ harnessHome: scaffold.harnessHome })
  508. const secondPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  509. const secondTripwire = watchConsole(secondPage)
  510. try {
  511. expect(second.baseUrl).not.toBe(scaffold.baseUrl)
  512. await secondPage.goto(second.authenticatedUrl, { waitUntil: 'load' })
  513. await secondPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  514. await secondPage.getByRole('button', { name: 'Settings', exact: true }).click()
  515. await secondPage.getByRole('dialog', { name: 'Settings' })
  516. .getByRole('button', { name: 'English' }).waitFor({ timeout: 10_000 })
  517. expect(await secondPage.evaluate(() => localStorage.getItem('dsh.locale'))).toBeNull()
  518. expect(secondTripwire.pageErrors).toEqual([])
  519. expect(secondTripwire.warnings).toEqual([])
  520. } finally {
  521. await secondPage.close()
  522. await second.close()
  523. }
  524. await enTrigger.click()
  525. await page.getByRole('dialog', { name: 'Settings' }).getByRole('button', { name: 'English' }).click()
  526. await page.getByRole('menuitem', { name: '中文' }).click()
  527. await page.getByRole('dialog', { name: '设置' }).waitFor({ timeout: 10_000 })
  528. expect(await page.evaluate(() => localStorage.getItem('dsh.locale'))).toBeNull()
  529. await expect.poll(async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'), { timeout: 5_000 })
  530. .toMatch(/locale:\n\s+preference: zh/)
  531. await page.keyboard.press('Escape')
  532. expect(tripwire.pageErrors).toEqual([])
  533. }, 90_000)
  534. it('opens an English browser in English without any stored preference', async () => {
  535. // A fresh Host home has no locale preference, so its surface follows the
  536. // browser. English is also FALLBACK_LOCALE, so this scenario alone cannot
  537. // distinguish detection from the default — the zh scenarios above supply
  538. // the discriminating half (a Chinese browser must NOT land on the default).
  539. const fresh = await launchWebScaffold({})
  540. const enPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'en-US' })
  541. const enTripwire = watchConsole(enPage)
  542. onTestFailed(() => saveFailureShot(enPage, 'web-e2e-settings-browser-language'))
  543. try {
  544. await enPage.goto(fresh.authenticatedUrl, { waitUntil: 'load' })
  545. await enPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  546. expect(await enPage.evaluate(() => localStorage.getItem('dsh.locale'))).toBeNull()
  547. await enPage.getByRole('button', { name: 'Settings', exact: true }).click()
  548. const dialog = enPage.getByRole('dialog', { name: 'Settings' })
  549. await dialog.waitFor({ timeout: 10_000 })
  550. await dialog.getByRole('button', { name: 'English' }).waitFor({ timeout: 10_000 })
  551. // The plugin list resolves shipped preset names through the en
  552. // dictionaries instead of echoing the preset files' Chinese metadata.
  553. await dialog.getByRole('button', { name: 'Plugins', exact: true }).click()
  554. await dialog.getByRole('tab', { name: 'Plugin list', exact: true }).click()
  555. const presetSwitcher = dialog.getByRole('button', { name: 'Choose the agent preset to inspect' })
  556. await presetSwitcher.waitFor({ timeout: 10_000 })
  557. expect(await presetSwitcher.textContent()).toBe('Standard mode (default)')
  558. // This page has no closing inventory spec to sweep its console, so the
  559. // scenario clears both tripwire channels itself.
  560. expect(enTripwire.pageErrors).toEqual([])
  561. expect(enTripwire.warnings).toEqual([])
  562. } finally {
  563. await enPage.close()
  564. await fresh.close()
  565. }
  566. }, 90_000)
  567. it('opens a browser asking for no shipped language in English', async () => {
  568. // The product default for "no usable signal": a French browser ships
  569. // neither zh nor en, so resolution falls to FALLBACK_LOCALE (en) rather
  570. // than to Chinese.
  571. const fresh = await launchWebScaffold({})
  572. const frPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'fr-FR' })
  573. const frTripwire = watchConsole(frPage)
  574. onTestFailed(() => saveFailureShot(frPage, 'web-e2e-settings-unshipped-language'))
  575. try {
  576. await frPage.goto(fresh.authenticatedUrl, { waitUntil: 'load' })
  577. await frPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  578. expect(await frPage.evaluate(() => localStorage.getItem('dsh.locale'))).toBeNull()
  579. await frPage.getByRole('button', { name: 'Settings', exact: true }).click()
  580. const dialog = frPage.getByRole('dialog', { name: 'Settings' })
  581. await dialog.waitFor({ timeout: 10_000 })
  582. await dialog.getByRole('button', { name: 'English' }).waitFor({ timeout: 10_000 })
  583. // A locale-owned nav label proves the dictionaries resolved to en.
  584. await dialog.getByRole('button', { name: 'Agent presets' }).waitFor({ timeout: 10_000 })
  585. // The markup already ships `en`, so this alone cannot prove the sync ran
  586. // — the zh scenario above is the discriminating half. Asserted here too
  587. // so a future change that resolves en but writes the wrong tag is caught.
  588. expect(await frPage.evaluate(() => document.documentElement.lang)).toBe('en')
  589. // Golden of the English fallback dialog — the visible output this change
  590. // produces. The zh golden above covers the detected-locale surface, so
  591. // the pair pins both directions of the resolution.
  592. const snapshot = await captureStableAria(frPage, '[role="dialog"]', fresh.workspaceCwd)
  593. await compareOrRefreshGolden(DIALOG_EN_EXPECTED, snapshot, MODE)
  594. expect(frTripwire.pageErrors).toEqual([])
  595. expect(frTripwire.warnings).toEqual([])
  596. } finally {
  597. await frPage.close()
  598. await fresh.close()
  599. }
  600. }, 90_000)
  601. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  602. expect(tripwire.warnings).toEqual([])
  603. await assertFixtureInventory(SNAPSHOT_DIR, ['dialog-en.expected.md', 'dialog.expected.md', 'plugins.expected.md'])
  604. })
  605. })