skill-tool-row.e2e.ts 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 { expandOwningTurnProcess, newEnglishPage, saveFailureShot } from './support.ts'
  14. const FIXTURE = fileURLToPath(new URL('../../../snapshots/session/skill-load/session.v3.jsonl', import.meta.url))
  15. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/skill-tool-row', import.meta.url))
  16. const UI_EXPECTED = fileURLToPath(new URL('../../../snapshots/web/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 editing-cordis-compositions 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.authenticatedUrl, { 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. const skillRow = page.locator('[data-tool="skill"]')
  42. await expandOwningTurnProcess(page, skillRow)
  43. await skillRow.waitFor({ timeout: 15_000 })
  44. }, 120_000)
  45. afterAll(async () => {
  46. await browser?.close()
  47. await scaffold?.close()
  48. })
  49. it('expands the loaded skill to its exact recorded instructions', async () => {
  50. onTestFailed(() => saveFailureShot(page, 'web-e2e-skill-tool-row'))
  51. const call = page.locator('[data-tool="skill"]')
  52. const row = call.getByRole('button', { name: 'Skill editing-cordis-compositions' })
  53. await expect.poll(() => row.getAttribute('aria-expanded')).toBe('false')
  54. expect(await call.getByText('editing-cordis-compositions', { exact: true }).count()).toBe(1)
  55. await row.click()
  56. await expect.poll(() => row.getAttribute('aria-expanded')).toBe('true')
  57. await call.getByText('Instructions', { exact: true }).waitFor()
  58. const output = call.locator('pre')
  59. await output.waitFor()
  60. expect(await output.textContent()).toContain('<skill_content name="editing-cordis-compositions">')
  61. expect(await output.textContent()).toContain('Each Bundle registers its dormant default provider and exclusively uses its pinned package-local platform CLI')
  62. expect(await output.evaluate(element => getComputedStyle(element.parentElement!).maxHeight)).toBe('260px')
  63. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  64. .replace(/\b\d{1,2}\/\d{1,2}(?= \{\{clock\}\})/g, '{{date}}')
  65. .replace(/\{\{date\}\} (?=\{\{clock\}\} Ran for)/g, '')
  66. .split(SEED_ID).join('{{seededId}}')
  67. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  68. expect(tripwire.pageErrors).toEqual([])
  69. expect(tripwire.warnings).toEqual([])
  70. }, 60_000)
  71. it('keeps its snapshot inventory closed', async () => {
  72. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  73. })
  74. })