bash-abort-row.e2e.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Web e2e scenario: a cancelled Bash call can settle without terminal-card
  2. // material. Borrow the real cancellation fixture and prove the keyed Bash row
  3. // still exposes the recorded command and full error without any model call.
  4. import { readFile } from 'node:fs/promises'
  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, fixtureUserPrompts,
  12. launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  13. } from './scaffold.ts'
  14. import { newEnglishPage, saveFailureShot } from './support.ts'
  15. const FIXTURE = fileURLToPath(new URL('../../../snapshots/acp/cancel-tool-calls/session.v2.jsonl', import.meta.url))
  16. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/bash-abort-row', import.meta.url))
  17. const UI_EXPECTED = join(SNAPSHOT_DIR, 'ui.expected.md')
  18. const MODE = webSnapshotMode()
  19. const SEED_ID = 'bash-abort-row-web-e2e'
  20. const PROMPT = 'Run two shell commands: wait for cancellation, then write skipped.txt.'
  21. describe.skipIf(MODE === 'record')('web e2e: cancelled Bash row disclosure', () => {
  22. let scaffold: WebScaffold
  23. let browser: Browser
  24. let page: Page
  25. let tripwire: ReturnType<typeof watchConsole>
  26. beforeAll(async () => {
  27. const fixture = await readFile(FIXTURE, 'utf8')
  28. expect(fixtureUserPrompts(fixture)).toEqual([PROMPT])
  29. scaffold = await launchWebScaffold({})
  30. await seedSession(scaffold, fixture, SEED_ID)
  31. browser = await chromium.launch()
  32. page = await newEnglishPage(browser)
  33. tripwire = watchConsole(page)
  34. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  35. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  36. const groupRow = page.locator('[role="treeitem"]').first()
  37. await groupRow.waitFor({ timeout: 15_000 })
  38. await groupRow.click()
  39. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  40. await sessionRow.waitFor({ timeout: 10_000 })
  41. await sessionRow.click()
  42. await page.locator('[data-sample="bash"]').nth(1).waitFor({ timeout: 15_000 })
  43. }, 120_000)
  44. afterAll(async () => {
  45. await browser?.close()
  46. await scaffold?.close()
  47. })
  48. it('expands the aborted row to its command and full error', async () => {
  49. onTestFailed(() => saveFailureShot(page, 'web-e2e-bash-abort-row'))
  50. const row = page.locator('[data-sample="bash"]').first()
  51. const call = row.locator('xpath=..')
  52. await expect.poll(() => row.getAttribute('aria-expanded')).toBe('false')
  53. await expect.poll(() => call.getByText('Error: tool call aborted', { exact: true }).count()).toBe(1)
  54. await row.click()
  55. await expect.poll(() => row.getAttribute('aria-expanded')).toBe('true')
  56. await call.getByText('IN', { exact: true }).waitFor()
  57. await call.getByText('OUT', { exact: true }).waitFor()
  58. await call.getByText('Wait until cancellation', { exact: false }).waitFor()
  59. await call.getByText('setInterval(() => {}, 1000)', { exact: false }).waitFor()
  60. await expect.poll(() => call.getByText('Error: tool call aborted', { exact: true }).count()).toBe(2)
  61. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  62. // The borrowed fixture's UTC date is still the previous day in PDT;
  63. // the disclosure golden must not depend on the runner timezone.
  64. .replace(/\b\d{1,2}\/\d{1,2}(?= \{\{clock\}\})/g, '{{date}}')
  65. .split(SEED_ID).join('{{seededId}}')
  66. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  67. expect(tripwire.pageErrors).toEqual([])
  68. expect(tripwire.warnings).toEqual([])
  69. }, 60_000)
  70. it('keeps its snapshot inventory closed', async () => {
  71. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  72. })
  73. })