built-boot.snapshot.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @vitest-environment jsdom
  2. // The built-bundle boot smoke: the ONE assembled-jsdom test that loads the
  3. // real `packages/client/*/lib/client.js` artifacts through AppWebEntry's
  4. // ModuleLoader path (fetchBundle/executeBundle) and proves the boot graph
  5. // assembles — staged activation across the immediately tier and the inject
  6. // layers, per-plugin CSS injection, and a rendered journey reaching chat
  7. // content from the keyless FixtureApiClient transport.
  8. //
  9. // Behavior assertions do NOT belong here: component and wiring behavior is
  10. // pinned by the per-package suites (SlotTestRuntime benches over src), which
  11. // this smoke's plugin set cannot influence — bundling, module-table
  12. // resolution, and boot layering are the only failure modes left to it.
  13. import { readFileSync } from 'node:fs'
  14. import { join } from 'node:path'
  15. import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
  16. import { afterEach, beforeEach, expect, it, vi } from 'vitest'
  17. import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
  18. import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
  19. const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
  20. { id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
  21. { id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
  22. { id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
  23. { id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
  24. { id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
  25. { id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
  26. { id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
  27. {
  28. id: '@deepseek-ai/dsh-client-ui-workspace',
  29. dir: 'ui-workspace',
  30. url: '/plugins/ui-workspace.js',
  31. rev: 'fx',
  32. inject: [
  33. '@deepseek-ai/dsh-client-runtime',
  34. '@deepseek-ai/dsh-client-ui-conversation',
  35. '@deepseek-ai/dsh-client-ui-sidebar',
  36. ],
  37. },
  38. { id: '@deepseek-ai/dsh-client-ui-trajectory', dir: 'ui-trajectory', url: '/plugins/ui-trajectory.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
  39. ]
  40. const bundles = new Map(PLUGINS.map(plugin => [
  41. plugin.url,
  42. readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
  43. ]))
  44. interface FixtureWindow extends Window {
  45. __DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
  46. __ModuleLoader__?: unknown
  47. }
  48. class ResizeObserverStub {
  49. observe(): void {}
  50. disconnect(): void {}
  51. unobserve(): void {}
  52. }
  53. const win = window as FixtureWindow
  54. let unmount: (() => void) | undefined
  55. beforeEach(() => {
  56. localStorage.clear()
  57. document.title = 'DeepSeek Harness'
  58. vi.stubGlobal('ResizeObserver', ResizeObserverStub)
  59. vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
  60. setTimeout(() => { callback(0) }, 0) as unknown as number)
  61. vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
  62. })
  63. afterEach(() => {
  64. act(() => { unmount?.() })
  65. unmount = undefined
  66. cleanup()
  67. delete win.__DSH_BOOT__
  68. delete win.__ModuleLoader__
  69. document.body.innerHTML = ''
  70. document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
  71. document.title = ''
  72. history.replaceState(null, '', '/')
  73. vi.unstubAllGlobals()
  74. })
  75. it('boots the built plugin graph and renders a fixture session end to end', async () => {
  76. history.replaceState(null, '', '/?fixture')
  77. const root = document.createElement('div')
  78. root.id = 'root'
  79. document.body.appendChild(root)
  80. win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
  81. act(() => {
  82. const entry = new AppWebEntry(root, {
  83. fetchBundle: (url) => {
  84. const code = bundles.get(url)
  85. return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
  86. },
  87. executeBundle: (code) => { (0, eval)(code) },
  88. })
  89. void entry.run()
  90. unmount = () => { entry.dispose() }
  91. })
  92. // The sidebar renders from the boot graph: every inject layer activated.
  93. const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
  94. await within(tree).findByText('4 sessions')
  95. // Opening a session reaches chat content through the fixture transport.
  96. fireEvent.click(await within(tree).findByText('Fixture 历史会话'))
  97. await waitFor(() => {
  98. expect(document.querySelector('[data-sample="bash-global"]')).not.toBeNull()
  99. }, { timeout: 10_000 })
  100. // Every bundle injected its plugin-owned style tag (the loader's CSS path).
  101. const styleOwners = [...document.head.querySelectorAll('style[data-plugin]')]
  102. .map(style => style.getAttribute('data-plugin'))
  103. for (const plugin of ['@deepseek-ai/dsh-client-ui-layout', '@deepseek-ai/dsh-client-ui-sidebar', '@deepseek-ai/dsh-client-ui-conversation']) {
  104. expect(styleOwners).toContain(plugin)
  105. }
  106. })