skill-tool-row.e2e.ts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Web e2e scenario: the real skill-load recording, seeded cold through the
  2. // persistence seam, renders through ui-skill's keyed toolview without a model
  3. // call. The disclosure proves replay-stable naming and exact durable output.
  4. import { readFile } from 'node:fs/promises'
  5. import { fileURLToPath } from 'node:url'
  6. import type { Browser, Page } from 'playwright'
  7. import { chromium } from 'playwright'
  8. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  9. import {
  10. assertFixtureInventory, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
  11. launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  12. } from './scaffold.ts'
  13. import { newEnglishPage, saveFailureShot } from './support.ts'
  14. const FIXTURE = fileURLToPath(new URL('../../../examples/acp-agent/tests/snapshots/skill-load/session.jsonl', import.meta.url))
  15. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/skill-tool-row', import.meta.url))
  16. const UI_EXPECTED = fileURLToPath(new URL('./snapshots/skill-tool-row/ui.expected.md', import.meta.url))
  17. const MODE = webSnapshotMode()
  18. const SEED_ID = 'skill-tool-row-web-e2e'
  19. const PROMPT = 'Load the snapshot-skill skill with the skill tool, then reply DONE.'
  20. describe.skipIf(MODE === 'record')('web e2e: dedicated Skill tool row', () => {
  21. let scaffold: WebScaffold
  22. let browser: Browser
  23. let page: Page
  24. let tripwire: ReturnType<typeof watchConsole>
  25. beforeAll(async () => {
  26. const fixture = await readFile(FIXTURE, 'utf8')
  27. expect(fixtureUserPrompts(fixture)).toEqual([PROMPT])
  28. scaffold = await launchWebScaffold({})
  29. await seedSession(scaffold, fixture, SEED_ID)
  30. browser = await chromium.launch()
  31. page = await newEnglishPage(browser)
  32. tripwire = watchConsole(page)
  33. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  34. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  35. const groupRow = page.locator('[role="treeitem"]').first()
  36. await groupRow.waitFor({ timeout: 15_000 })
  37. await groupRow.click()
  38. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  39. await sessionRow.waitFor({ timeout: 10_000 })
  40. await sessionRow.click()
  41. await page.locator('[data-tool="skill"]').waitFor({ timeout: 15_000 })
  42. }, 120_000)
  43. afterAll(async () => {
  44. await browser?.close()
  45. await scaffold?.close()
  46. })
  47. it('expands the loaded skill to its exact recorded instructions', async () => {
  48. onTestFailed(() => saveFailureShot(page, 'web-e2e-skill-tool-row'))
  49. const call = page.locator('[data-tool="skill"]')
  50. const row = call.getByRole('button', { name: 'Skill snapshot-skill' })
  51. await expect.poll(() => row.getAttribute('aria-expanded')).toBe('false')
  52. expect(await call.getByText('snapshot-skill', { exact: true }).count()).toBe(1)
  53. await row.click()
  54. await expect.poll(() => row.getAttribute('aria-expanded')).toBe('true')
  55. await call.getByText('Instructions', { exact: true }).waitFor()
  56. const output = call.locator('pre')
  57. await output.waitFor()
  58. expect(await output.textContent()).toContain('<skill_content name="snapshot-skill">')
  59. expect(await output.textContent()).toContain('Follow these snapshot-only instructions.')
  60. expect(await output.evaluate(element => getComputedStyle(element.parentElement!).maxHeight)).toBe('260px')
  61. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  62. .replace(/\b\d{1,2}\/\d{1,2}(?= \{\{clock\}\})/g, '{{date}}')
  63. .split(SEED_ID).join('{{seededId}}')
  64. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  65. expect(tripwire.pageErrors).toEqual([])
  66. expect(tripwire.warnings).toEqual([])
  67. }, 60_000)
  68. it('keeps its snapshot inventory closed', async () => {
  69. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  70. })
  71. })