settings-chrome.e2e.ts 35 KB

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