built-boot.snapshot.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. await within(tree).findByText('4 sessions')
  22. // The resident fixture has both a question and an approval; composer routing
  23. // exposes the question first, and the assembled workspace plugin mirrors that
  24. // actionable wait instead of the underlying running state.
  25. const waitingTitle = await within(tree).findByText('Fixture 历史会话')
  26. const waitingRow = waitingTitle.closest<HTMLElement>('[role="treeitem"]')
  27. if (waitingRow === null) throw new Error('fixture Session title must belong to a tree row')
  28. expect(waitingRow.querySelector('[data-state="warning"]')).not.toBeNull()
  29. expect(waitingRow.querySelector('[data-state="ongoing"]')).toBeNull()
  30. within(waitingRow).getByText('Waiting for answer')
  31. // Opening a session reaches chat content through the fixture transport.
  32. fireEvent.click(waitingTitle)
  33. await waitFor(() => {
  34. expect(document.querySelector('[data-sample="bash"]')).not.toBeNull()
  35. }, { timeout: 10_000 })
  36. // Resolve the resident approval so the ordinary composer bar (which owns
  37. // ContextMeter) resumes without replacing the session shell. This minimal
  38. // boot graph intentionally does not mount the separate question UI plugin.
  39. fireEvent.click(await screen.findByRole('button', { name: 'Allow once' }))
  40. // The fixture mirrors all three token-meter projections, so the assembled
  41. // ContextMeter reaches its composition panel instead of only the occupancy
  42. // fallback path.
  43. const contextTrigger = await screen.findByRole('button', { name: /of context used/ })
  44. fireEvent.click(contextTrigger)
  45. const contextPanel = await screen.findByRole('dialog', { name: 'of context used' })
  46. within(contextPanel).getByText('System prompt')
  47. within(contextPanel).getByText('Tools')
  48. within(contextPanel).getByText('Messages')
  49. // The write/edit turns render a real diff card through the assembled graph
  50. // (the keyed FileMutationRow composing ToolRow + DiffBlock), not just the
  51. // fixture's raw text. The card is collapsed by default, so expand each edit/
  52. // write row first. The write turn's `hello fixture\n` proves the terminator
  53. // rule end to end: a trailing newline terminates its line, so the footer reads
  54. // `+1` (not a phantom `+2`) and one distinct file. The `+ ` prefix is a CSS
  55. // ::before, so it is absent from textContent — assert on the line body and the
  56. // footer.
  57. const mutationRows = [...document.querySelectorAll('[data-variant="write"],[data-variant="edit"]')]
  58. expect(mutationRows.length).toBeGreaterThan(0)
  59. for (const row of mutationRows) {
  60. const toggle = row.querySelector('[data-expandable]')
  61. if (toggle !== null) act(() => { fireEvent.click(toggle) })
  62. }
  63. const diffCards = [...document.querySelectorAll('[data-diff]')]
  64. expect(diffCards.length).toBeGreaterThan(0)
  65. const footers = diffCards.map(card => card.textContent ?? '')
  66. expect(footers.some(text => text.includes('hello fixture') && text.includes('+1 -0 · 1 file'))).toBe(true)
  67. // The web render intent reaches the assembled boot graph: the fixture's
  68. // web_search / web_fetch turns render their keyed WebRow cards, proving the
  69. // registration, wire projection, and card rendering survive the real bundle
  70. // path (not just the per-package src benches). WebRow composes ToolRow, so the
  71. // card is collapsed behind the row; the keyed row is pinned by its `data-tool`
  72. // (ToolRow sets it from the wire tool name).
  73. const webSearchRow = await waitFor(() => {
  74. const row = document.querySelector('[data-tool="web_search"]')
  75. expect(row).not.toBeNull()
  76. expect(document.querySelector('[data-tool="web_fetch"]')).not.toBeNull()
  77. return row!
  78. }, { timeout: 10_000 })
  79. // Expand the web_search row to prove its WebBlock card renders end to end.
  80. const webToggle = webSearchRow.querySelector('[data-expandable]')
  81. if (webToggle !== null) act(() => { fireEvent.click(webToggle) })
  82. await waitFor(() => {
  83. expect(webSearchRow.querySelector('[data-web]')).not.toBeNull()
  84. }, { timeout: 10_000 })
  85. // Every bundle injected its plugin-owned style tag (the loader's CSS path).
  86. const styleOwners = [...document.head.querySelectorAll('style[data-plugin]')]
  87. .map(style => style.getAttribute('data-plugin'))
  88. 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']) {
  89. expect(styleOwners).toContain(plugin)
  90. }
  91. })