settings-chrome.e2e.ts 34 KB

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