produced-files.e2e.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Web e2e scenario: the produced-files row a finished turn ends with. Cold-seeds
  2. // a recorded write turn (zero model calls). Package tests cover the derivation
  3. // in isolation, but only the assembled application shows that a turn's writes
  4. // reach the transcript as an openable row (docs/testing.md snapshot rule). The
  5. // click itself is not driven here: it hands the path to the Host's opener,
  6. // which would launch a real application on the machine running the suite.
  7. import { readFile, writeFile, mkdir } from 'node:fs/promises'
  8. import { join } from 'node:path'
  9. import { fileURLToPath } from 'node:url'
  10. import type { Browser, Page } from 'playwright'
  11. import { chromium } from 'playwright'
  12. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  13. import {
  14. launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  15. } from './scaffold.ts'
  16. import { newEnglishPage, saveFailureShot } from './support.ts'
  17. // Borrowed read-only: this scenario needs any settled turn whose tools WROTE a
  18. // file, not a new recording (the message-actions borrowing pattern).
  19. const SEED = fileURLToPath(new URL('./snapshots/permission-policy-context/session.jsonl', import.meta.url))
  20. const MODE = webSnapshotMode()
  21. const SEED_ID = 'produced-files-web-e2e'
  22. /** The file the borrowed recording's write tool produces. */
  23. const PRODUCED = 'policy-neutral.txt'
  24. describe('web e2e: a finished turn ends with the files it produced', () => {
  25. let scaffold: WebScaffold
  26. let browser: Browser
  27. let page: Page
  28. let tripwire: ReturnType<typeof watchConsole>
  29. beforeAll(async () => {
  30. scaffold = await launchWebScaffold({})
  31. // The seeded Session's cwd is the scaffold workspace; the recording's own
  32. // nested directory is created too, so its paths stay resolvable.
  33. await mkdir(join(scaffold.workspaceCwd, 'workspace'), { recursive: true })
  34. await writeFile(join(scaffold.workspaceCwd, PRODUCED), 'neutral\n')
  35. const raw = await readFile(SEED, 'utf8')
  36. expect(raw, 'borrowed recording must carry the write this scenario reads').toContain(PRODUCED)
  37. await seedSession(scaffold, raw, SEED_ID)
  38. browser = await chromium.launch()
  39. page = await newEnglishPage(browser)
  40. tripwire = watchConsole(page)
  41. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  42. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  43. }, 120_000)
  44. afterAll(async () => {
  45. await browser?.close()
  46. await scaffold?.close()
  47. })
  48. it.skipIf(MODE === 'record')('lists the written file under the closing message, as an opener', async () => {
  49. onTestFailed(() => saveFailureShot(page, 'web-e2e-produced-files'))
  50. const groupRow = page.locator('[role="treeitem"]').first()
  51. await groupRow.waitFor({ timeout: 15_000 })
  52. await groupRow.click()
  53. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  54. await sessionRow.waitFor({ timeout: 10_000 })
  55. await sessionRow.click()
  56. // The row the turn ends with — derived from the write call's locations,
  57. // not from whatever the closing message happened to say.
  58. const chip = page.getByRole('button', { name: `Open ${PRODUCED}`, exact: true }).first()
  59. await chip.waitFor({ timeout: 15_000 })
  60. expect(await chip.innerText()).toBe(PRODUCED)
  61. // The full path stays reachable for a reader who wants to copy it.
  62. expect(await chip.getAttribute('title')).toContain(PRODUCED)
  63. // A turn's produced files are labelled, not left as bare chips.
  64. expect(await page.getByText('Produced', { exact: true }).count()).toBeGreaterThan(0)
  65. expect(tripwire.pageErrors).toEqual([])
  66. expect(tripwire.warnings).toEqual([])
  67. }, 90_000)
  68. })