built-boot.snapshot.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // @vitest-environment jsdom
  2. // The built-bundle boot smoke: the assembled-jsdom test that owns the boot
  3. // graph itself. Other files share the same scaffolding (assembled-boot.ts) to
  4. // reach a surface only the built bundles expose; this one asserts that the
  5. // graph assembles at all — staged activation across the immediately tier and
  6. // the inject layers, per-plugin CSS injection, and a rendered journey reaching
  7. // chat content from the keyless FixtureApiClient transport.
  8. //
  9. // Component behavior remains owned by per-package suites (SlotTestRuntime
  10. // benches over src). This smoke additionally pins the resident interaction
  11. // fixture's cross-plugin projection because only the built connection/runtime/
  12. // workspace graph can prove that transport-to-row path end to end.
  13. import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'
  14. import { expect, it } from 'vitest'
  15. import { installAssembledBootEnv, mountAssembledApp } from './assembled-boot.ts'
  16. installAssembledBootEnv()
  17. it('boots the built plugin graph and renders a fixture session end to end', async () => {
  18. mountAssembledApp()
  19. // The sidebar renders from the boot graph: every inject layer activated.
  20. const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
  21. // The compact layout dropped group session counts; the fixture workspace
  22. // group row renders immediately with its sessions beneath it.
  23. const fixtureGroup = (await within(tree).findAllByText('fixture'))
  24. .map(el => el.closest<HTMLElement>('[role="treeitem"]'))
  25. .find(el => el?.getAttribute('aria-expanded') !== null)
  26. if (fixtureGroup === undefined) throw new Error('fixture Workspace group missing')
  27. // The resident fixture has both a question and an approval; composer routing
  28. // exposes the question first, and the assembled workspace plugin mirrors that
  29. // actionable wait instead of the underlying running state.
  30. const waitingTitle = await within(tree).findByText('Fixture 历史会话')
  31. const waitingRow = waitingTitle.closest<HTMLElement>('[role="treeitem"]')
  32. if (waitingRow === null) throw new Error('fixture Session title must belong to a tree row')
  33. expect(waitingRow.querySelector('[data-state="warning"]')).not.toBeNull()
  34. expect(waitingRow.querySelector('[data-state="ongoing"]')).toBeNull()
  35. within(waitingRow).getByText('Waiting for answer')
  36. // Opening a session reaches chat content through the fixture transport.
  37. fireEvent.click(waitingTitle)
  38. await waitFor(() => {
  39. expect(document.querySelector('[data-sample="bash"]')).not.toBeNull()
  40. }, { timeout: 10_000 })
  41. // Resolve the resident approval so the ordinary composer bar (which owns
  42. // ContextMeter) resumes without replacing the session shell. This minimal
  43. // boot graph intentionally does not mount the separate question UI plugin.
  44. fireEvent.click(await screen.findByRole('button', { name: 'Allow once' }))
  45. // The fixture mirrors all three token-meter projections, so the assembled
  46. // ContextMeter reaches its composition panel instead of only the occupancy
  47. // fallback path.
  48. const contextTrigger = await screen.findByRole('button', { name: /of context used/ })
  49. fireEvent.click(contextTrigger)
  50. const contextPanel = await screen.findByRole('dialog', { name: 'of context used' })
  51. within(contextPanel).getByText('System prompt')
  52. within(contextPanel).getByText('Tools')
  53. within(contextPanel).getByText('Messages')
  54. // The write/edit turns render a real diff card through the assembled graph
  55. // (the keyed FileMutationRow composing ToolRow + DiffBlock), not just the
  56. // fixture's raw text. The card is collapsed by default, so expand each edit/
  57. // write row first. The write turn's `hello fixture\n` proves the terminator
  58. // rule end to end: a trailing newline terminates its line, so the footer reads
  59. // `+1` (not a phantom `+2`) and one distinct file. The `+ ` prefix is a CSS
  60. // ::before, so it is absent from textContent — assert on the line body and the
  61. // footer.
  62. const mutationRows = [...document.querySelectorAll('[data-variant="write"],[data-variant="edit"]')]
  63. expect(mutationRows.length).toBeGreaterThan(0)
  64. for (const row of mutationRows) {
  65. const toggle = row.querySelector('[data-expandable]')
  66. if (toggle !== null) act(() => { fireEvent.click(toggle) })
  67. }
  68. const diffCards = [...document.querySelectorAll('[data-diff]')]
  69. expect(diffCards.length).toBeGreaterThan(0)
  70. const footers = diffCards.map(card => card.textContent ?? '')
  71. expect(footers.some(text => text.includes('hello fixture') && text.includes('+1 -0 · 1 file'))).toBe(true)
  72. // The web render intent reaches the assembled boot graph: the fixture's
  73. // web_search / web_fetch turns render their keyed WebRow cards, proving the
  74. // registration, wire projection, and card rendering survive the real bundle
  75. // path (not just the per-package src benches). WebRow composes ToolRow, so the
  76. // card is collapsed behind the row; the keyed row is pinned by its `data-tool`
  77. // (ToolRow sets it from the wire tool name).
  78. const webSearchRow = await waitFor(() => {
  79. const row = document.querySelector('[data-tool="web_search"]')
  80. expect(row).not.toBeNull()
  81. expect(document.querySelector('[data-tool="web_fetch"]')).not.toBeNull()
  82. return row!
  83. }, { timeout: 10_000 })
  84. // Expand the web_search row to prove its WebBlock card renders end to end.
  85. const webToggle = webSearchRow.querySelector('[data-expandable]')
  86. if (webToggle !== null) act(() => { fireEvent.click(webToggle) })
  87. await waitFor(() => {
  88. expect(webSearchRow.querySelector('[data-web]')).not.toBeNull()
  89. }, { timeout: 10_000 })
  90. // Every bundle injected its plugin-owned style tag (the loader's CSS path).
  91. const styleOwners = [...document.head.querySelectorAll('style[data-plugin]')]
  92. .map(style => style.getAttribute('data-plugin'))
  93. for (const plugin of ['@deepseek-ai/dsh-client-ui-layout', '@deepseek-ai/dsh-client-ui-sidebar', '@deepseek-ai/dsh-client-ui-conversation', '@deepseek-ai/dsh-client-ui-tool']) {
  94. expect(styleOwners).toContain(plugin)
  95. }
  96. })