access-confirmation.e2e.ts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Web e2e scenario: every visible permission picker gates Full access behind
  2. // the same locale-aware, in-page risk confirmation. Zero model calls: the
  3. // scenario boots the shipped Web composition and exercises the real
  4. // permission projection, client command path, HTTP RPC, and pushed update.
  5. import { fileURLToPath } from 'node:url'
  6. import { join } from 'node:path'
  7. import type { Browser, Page } from 'playwright'
  8. import { chromium } from 'playwright'
  9. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  10. import {
  11. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  12. launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold,
  13. } from './scaffold.ts'
  14. import { ZH_BROWSER_LOCALE, connectFreshWorkspaceZh, saveFailureShot } from './support.ts'
  15. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/access-confirmation', import.meta.url))
  16. const UI_EXPECTED = join(SNAPSHOT_DIR, 'ui.expected.md')
  17. const MODE = webSnapshotMode()
  18. describe('web e2e: Full access confirmation', () => {
  19. let scaffold: WebScaffold
  20. let browser: Browser
  21. let page: Page
  22. let tripwire: ReturnType<typeof watchConsole>
  23. beforeAll(async () => {
  24. scaffold = await launchWebScaffold({})
  25. // CI uses Playwright's pinned browser. A developer may point this one
  26. // scenario at an installed Chromium when the matching browser download
  27. // is temporarily unavailable.
  28. const executablePath = process.env.DSH_PLAYWRIGHT_EXECUTABLE_PATH
  29. browser = await chromium.launch(executablePath === undefined ? {} : { executablePath })
  30. // Keep the product default Chinese locale: the golden pins the actual
  31. // registered dictionary rather than a test-local translation callback.
  32. page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  33. tripwire = watchConsole(page)
  34. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  35. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  36. await connectFreshWorkspaceZh(page, scaffold.workspaceCwd)
  37. }, 120_000)
  38. afterAll(async () => {
  39. await browser?.close()
  40. await scaffold?.close()
  41. })
  42. it('requires acknowledgement before the composer picker can enable Full access', async () => {
  43. onTestFailed(() => saveFailureShot(page, 'web-e2e-full-access-confirmation'))
  44. const access = page.locator('button[aria-label^="访问模式"]').first()
  45. await access.waitFor({ timeout: 10_000 })
  46. expect(await access.getAttribute('aria-label')).toBe('访问模式,当前:Workspace Write')
  47. await access.click()
  48. await page.getByRole('menuitem', { name: 'Full access' }).click()
  49. const dialog = page.getByRole('dialog', { name: '确认启用 Full access?' })
  50. await dialog.waitFor({ timeout: 10_000 })
  51. const enable = dialog.getByRole('button', { name: '启用 Full access' })
  52. expect(await enable.isDisabled()).toBe(true)
  53. // The modal is in this page's body (not a native/new window) and escapes
  54. // the sticky composer's stacking context.
  55. expect(await dialog.evaluate(node => node.parentElement?.parentElement === document.body)).toBe(true)
  56. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  57. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  58. await dialog.getByRole('checkbox', { name: '我已了解风险,并愿意继续' }).check()
  59. expect(await enable.isEnabled()).toBe(true)
  60. await enable.click()
  61. await expect.poll(() => access.getAttribute('aria-label'), { timeout: 10_000 })
  62. .toBe('访问模式,当前:Full access')
  63. expect(await dialog.count()).toBe(0)
  64. expect(tripwire.pageErrors).toEqual([])
  65. }, 60_000)
  66. it('keeps its snapshot inventory closed', async () => {
  67. expect(tripwire.warnings).toEqual([])
  68. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  69. })
  70. })