todo-row.expected.e2e.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // @vitest-environment jsdom
  2. // Assembled todo snapshot: boots the real built `packages/client/*/lib/
  3. // client.js` bundles through AppWebEntry's ModuleLoader path against the
  4. // keyless fixture Connection RPC, opens the fixture session, and pins the
  5. // two surfaces the fixture's parallel plan (turn 74, two items `in_progress`)
  6. // reaches — the `todo_write` tool row and the dock's plan strip.
  7. //
  8. // The row is pinned as three separate fields on purpose. `summary=` is the
  9. // ellipsized text and `suffix=` is ToolRow's non-shrinking `summarySuffix`
  10. // slot, so a regression that folds the `+N` count back into the summary string
  11. // changes this file even though the concatenated text would read the same; the
  12. // jsdom package suites bench over src and cannot see the bundled registration.
  13. import { mkdirSync, writeFileSync } from 'node:fs'
  14. import { dirname, join } from 'node:path'
  15. import { fireEvent, screen, waitFor, within } from '@testing-library/react'
  16. import { describe, expect, it } from 'vitest'
  17. import { hasClass, installAssembledBootEnv, mountAssembledApp, REFRESHING_GOLDEN } from './assembled-boot.ts'
  18. const EXPECTED = join(process.cwd(), 'apps/web/tests/expected/todo-row/parallel-plan.expected.txt')
  19. installAssembledBootEnv()
  20. /** Normalize the todo row and the plan strip to stable text fields: the row's
  21. * title, its truncatable summary, its non-shrinking suffix, then the panel's
  22. * per-status header and every list item with its status. */
  23. function todoShape(row: Element, panel: Element): string {
  24. const pick = (from: Element, name: string): Element[] =>
  25. [...from.querySelectorAll('*')].filter(el => hasClass(el, name))
  26. const first = (from: Element, name: string): string =>
  27. pick(from, name)[0]?.textContent?.trim() ?? '<absent>'
  28. const items = [...panel.querySelectorAll('[data-status]')]
  29. .map(item => `item=${item.getAttribute('data-status')} ${item.textContent?.trim() ?? ''}`)
  30. return [
  31. `row=${row.getAttribute('data-tool')}`,
  32. `title=${first(row, 'title')}`,
  33. `summary=${first(row, 'summary')}`,
  34. `suffix=${first(row, 'summarySuffix')}`,
  35. `panel=${first(panel, 'progress')}`,
  36. ...items,
  37. ].join('\n')
  38. }
  39. describe('assembled todo surfaces', () => {
  40. it('renders the parallel plan as a row summary, a separate active count, and the dock plan strip', async () => {
  41. mountAssembledApp()
  42. const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
  43. fireEvent.click(await within(tree).findByText('Fixture 历史会话'))
  44. // The todo turn is the fixture's last, so wait for its keyed row rather
  45. // than for chat content in general.
  46. const row = await waitFor(() => {
  47. const found = document.querySelector('[data-tool="todo_write"]')
  48. expect(found).not.toBeNull()
  49. return found!
  50. }, { timeout: 10_000 })
  51. // The panel is the standing plan the turn's `todo/write` event feeds; it
  52. // mounts above the composer, outside the row, and starts collapsed — its
  53. // list only exists once expanded.
  54. const panel = await screen.findByTestId('todo-panel', undefined, { timeout: 10_000 })
  55. const toggle = panel.querySelector('button[aria-expanded]')
  56. if (toggle === null) throw new Error('the plan strip must expose its expand toggle')
  57. if (toggle.getAttribute('aria-expanded') === 'false') fireEvent.click(toggle)
  58. const shape = todoShape(row, panel)
  59. if (REFRESHING_GOLDEN) {
  60. mkdirSync(dirname(EXPECTED), { recursive: true })
  61. writeFileSync(EXPECTED, shape)
  62. }
  63. await expect(shape).toMatchFileSnapshot(EXPECTED)
  64. })
  65. })