|
|
@@ -14,69 +14,20 @@
|
|
|
// derivation over the result view, pinned at every render site by the
|
|
|
// ui-conversation suite; here the fixture turn exercises the assembled card
|
|
|
// shape and its cap.
|
|
|
-import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
|
+import { mkdirSync, writeFileSync } from 'node:fs'
|
|
|
import { dirname, join } from 'node:path'
|
|
|
-import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
|
|
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
-import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
|
|
-import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
|
|
+import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
|
|
+import { describe, expect, it } from 'vitest'
|
|
|
+import { hasClass, installAssembledBootEnv, mountAssembledApp } from './assembled-boot.ts'
|
|
|
|
|
|
const EXPECTED = join(process.cwd(), 'apps/web/tests/snapshots/search-card/grep-card.expected.txt')
|
|
|
const refreshing = process.env.DSH_SNAPSHOT === 'record' || process.env.DSH_SNAPSHOT === 'refresh'
|
|
|
|
|
|
-const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
|
|
- { id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
|
|
- { id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
|
|
- { id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
|
|
- { id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
|
|
- { id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
|
|
- { id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
|
|
- { id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
|
|
- {
|
|
|
- id: '@deepseek-ai/dsh-client-ui-workspace',
|
|
|
- dir: 'ui-workspace',
|
|
|
- url: '/plugins/ui-workspace.js',
|
|
|
- rev: 'fx',
|
|
|
- inject: [
|
|
|
- '@deepseek-ai/dsh-client-runtime',
|
|
|
- '@deepseek-ai/dsh-client-ui-conversation',
|
|
|
- '@deepseek-ai/dsh-client-ui-sidebar',
|
|
|
- ],
|
|
|
- },
|
|
|
- { id: '@deepseek-ai/dsh-client-ui-trajectory', dir: 'ui-trajectory', url: '/plugins/ui-trajectory.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
|
|
|
-]
|
|
|
-
|
|
|
-const bundles = new Map(PLUGINS.map(plugin => [
|
|
|
- plugin.url,
|
|
|
- readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
|
|
-]))
|
|
|
-
|
|
|
-interface FixtureWindow extends Window {
|
|
|
- __DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
|
|
- __ModuleLoader__?: unknown
|
|
|
-}
|
|
|
-
|
|
|
-class ResizeObserverStub {
|
|
|
- observe(): void {}
|
|
|
- disconnect(): void {}
|
|
|
- unobserve(): void {}
|
|
|
-}
|
|
|
-
|
|
|
-const win = window as FixtureWindow
|
|
|
-let unmount: (() => void) | undefined
|
|
|
+installAssembledBootEnv()
|
|
|
|
|
|
/** Normalize a rendered search card to a stable text shape: the kind, the banner
|
|
|
* summary, each file header (path + count), each visible match line, the expand
|
|
|
- * control label, and the recovery footer. CSS-module class names carry a
|
|
|
- * per-build hash in one of two schemes — ui-primitives emits `_<name>_<hash>`
|
|
|
- * (name bounded by underscores), ui-conversation emits `<hash>_<name>` (name at
|
|
|
- * the end). `hasClass` matches a module class by its logical name under either,
|
|
|
- * without matching a longer name that contains it (`line` must not hit
|
|
|
- * `lineNumber`). */
|
|
|
-function hasClass(el: Element, name: string): boolean {
|
|
|
- return [...el.classList].some(cls => cls === name || cls.endsWith(`_${name}`) || cls.startsWith(`_${name}_`) || cls.includes(`_${name}_`))
|
|
|
-}
|
|
|
-
|
|
|
+ * control label, and the recovery footer. */
|
|
|
function cardShape(root: Element): string {
|
|
|
const card = root.querySelector('[data-search]')
|
|
|
if (card === null) return '<no search card>'
|
|
|
@@ -94,49 +45,9 @@ function cardShape(root: Element): string {
|
|
|
return lines.join('\n')
|
|
|
}
|
|
|
|
|
|
-beforeEach(() => {
|
|
|
- localStorage.clear()
|
|
|
- // English pinned before boot so the sidebar's role/text locators stay
|
|
|
- // deterministic (the built-boot smoke's convention).
|
|
|
- localStorage.setItem('dsh.locale', 'en')
|
|
|
- document.title = 'DeepSeek Harness'
|
|
|
- vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
|
|
- vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
|
|
- setTimeout(() => { callback(0) }, 0) as unknown as number)
|
|
|
- vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
|
|
-})
|
|
|
-
|
|
|
-afterEach(() => {
|
|
|
- act(() => { unmount?.() })
|
|
|
- unmount = undefined
|
|
|
- cleanup()
|
|
|
- delete win.__DSH_BOOT__
|
|
|
- delete win.__ModuleLoader__
|
|
|
- document.body.innerHTML = ''
|
|
|
- document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
|
|
- document.title = ''
|
|
|
- history.replaceState(null, '', '/')
|
|
|
- vi.unstubAllGlobals()
|
|
|
-})
|
|
|
-
|
|
|
describe('assembled search card', () => {
|
|
|
it('renders the grep card, its truncation summary, and its capped head/tail slice from the built bundles', async () => {
|
|
|
- history.replaceState(null, '', '/?fixture')
|
|
|
- const root = document.createElement('div')
|
|
|
- root.id = 'root'
|
|
|
- document.body.appendChild(root)
|
|
|
- win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
|
|
- act(() => {
|
|
|
- const entry = new AppWebEntry(root, {
|
|
|
- loadBundle: async (url) => {
|
|
|
- const code = bundles.get(url)
|
|
|
- if (code === undefined) throw new Error(`missing built bundle ${url}`)
|
|
|
- ;(0, eval)(code)
|
|
|
- },
|
|
|
- })
|
|
|
- void entry.run()
|
|
|
- unmount = () => { entry.dispose() }
|
|
|
- })
|
|
|
+ mountAssembledApp()
|
|
|
|
|
|
const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
|
|
fireEvent.click(await within(tree).findByText('Fixture 历史会话'))
|