8b3d1ac943
The data layer no longer depends on the React glue package, and business plugins no longer depend on web-react at all: - The store engine (zustand vanilla + immer + persist + dev freeze), defineStore, and shallowEqual move to @deepseek-ai/dsh-client-runtime, exported from the ./client main entry — no ./store subpath survives on either package (the web-react one is deleted, none is opened on runtime). - Store products are bare snapshot sources: useSelector leaves SnapshotStore/StoreInstance and Session; every hook is composed at the binding site in web-react's renderer (per-source cached uSES binding). The SlotRendererHost sessions face carries bare observables only. - SessionProvider becomes a standard-kit seat: an entry whose children declare a session-scope slot receives the framework component as a prop, retiring the last value import of web-react from plugin packages. UseSession and the session-area types now live in ui-slots. - web-react shrinks to the shell-only React glue (renderer, providers, uSES bridge); zustand/immer belong to runtime alone; the module-table seed and tsdown externals drop the web-react/store seat. - NODE_ENV replacement is defined once in the shared tsdown client preset (browser bundles inline the engine and lost vite's define); the 3-line process.env typecheck shim moves to runtime with the engine. - Stray tsc artifacts (.js/.d.ts/.d.ts.map beside sources under src/) swept repo-wide; they shadow real sources under vitest resolution. Verified: both aggregate typecheck programs at zero; 604 client tests green; repo-wide grep for web-react/store at zero; real-host playwright run 7/7 including persist round-trip. ci: fix test/docs
101 lines
4.5 KiB
TypeScript
101 lines
4.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
// Final branch tails for the coverage gate, terminal slot form: apply's
|
|
// need() throw, AssistantMarkdown non-final reasoning, StatsLine usage-less
|
|
// node, DetailsPanel titleless selection, registry disposer after a foreign
|
|
// removal emptied the list. (The old cwd WeakMap-cache account retired with
|
|
// the mechanism — derivation lives in EmptyState now, covered by the
|
|
// skeleton specs.)
|
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { cleanup, render } from '@testing-library/react'
|
|
import { hookOf } from './hook.ts'
|
|
import { createSnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
|
|
import type { UseSession } from '@deepseek-ai/dsh-client-ui-slots'
|
|
import type { ConversationSnapshot, SessionId, SessionListState } from '@deepseek-ai/dsh-client-runtime/client'
|
|
import { ToolViewRegistry } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
import type { SelectionTarget } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
import { createChatStore } from '../src/client/stores.ts'
|
|
import { AssistantMarkdown } from '../src/client/chat/AssistantMarkdown.tsx'
|
|
import { StatsLine } from '../src/client/chat/StatsLine.tsx'
|
|
import { DetailsPanel } from '../src/client/skeleton/DetailsPanel.tsx'
|
|
|
|
afterEach(cleanup)
|
|
|
|
const SID = 's1' as SessionId
|
|
|
|
function snapshotBase(): ConversationSnapshot {
|
|
return {
|
|
sessionId: SID, nodes: [], foldDegraded: false, partial: null, runningCalls: [],
|
|
pending: [], running: false, removed: false, openState: 'open', openError: null,
|
|
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null,
|
|
} as ConversationSnapshot
|
|
}
|
|
|
|
describe('render branch tails', () => {
|
|
it('AssistantMarkdown reasoning row is ok-state when not the streaming tail', () => {
|
|
const view = render(
|
|
<AssistantMarkdown
|
|
blocks={[{ kind: 'reasoning', text: 'done thinking' }, { kind: 'text', text: 'answer' }]}
|
|
streaming
|
|
/>,
|
|
)
|
|
// reasoning at index 0 with a later block: running is false → ok state.
|
|
expect(view.container.querySelector('[data-state="ok"]')).not.toBeNull()
|
|
})
|
|
|
|
it('StatsLine skips usage-less nodes and defaults each absent counter to zero', () => {
|
|
const snap = {
|
|
nodes: [
|
|
{ kind: 'assistant', seq: 1, turn: 1, step: 1, blocks: [] },
|
|
{ kind: 'assistant', seq: 2, turn: 1, step: 2, blocks: [], usage: { inputTokens: 4, outputTokens: 6 } },
|
|
// outputTokens absent: the tokens sum's ?? 0 arm for output.
|
|
{ kind: 'assistant', seq: 3, turn: 2, step: 1, blocks: [], usage: { inputTokens: 5 } },
|
|
],
|
|
}
|
|
const source = { getSnapshot: () => snap, subscribe: () => () => {} }
|
|
const view = render(
|
|
<StatsLine sessionId={SID} useSession={hookOf(source) as unknown as UseSession<ConversationSnapshot>} />,
|
|
)
|
|
expect(view.getByText('cache hit 0% · 15 tokens · 2 turns · 3 steps')).toBeTruthy()
|
|
})
|
|
|
|
it('AssistantMarkdown reasoning as the streaming tail renders the running ring', () => {
|
|
const view = render(
|
|
<AssistantMarkdown blocks={[{ kind: 'reasoning', text: 'still thinking' }]} streaming />,
|
|
)
|
|
expect(view.container.querySelector('[data-state="running"]')).not.toBeNull()
|
|
})
|
|
|
|
it('DetailsPanel title falls to 详情 when the selection has no toolName and no material', () => {
|
|
localStorage.clear()
|
|
const snap = snapshotBase()
|
|
const chat = createChatStore().create()
|
|
chat.actions.select({ turnSeq: 1, callId: 'ghost' } satisfies SelectionTarget)
|
|
const emptyList = createSnapshotStore<SessionListState>(
|
|
{ ids: [], byId: {}, current: undefined } as SessionListState)
|
|
const view = render(
|
|
<DetailsPanel
|
|
sessionId={SID}
|
|
useSession={hookOf({ getSnapshot: () => snap, subscribe: () => () => {} }) as unknown as UseSession<ConversationSnapshot>}
|
|
useSessions={hookOf(emptyList)}
|
|
useStore={hookOf(chat)}
|
|
actions={chat.actions}
|
|
closeDetails={vi.fn()}
|
|
/>,
|
|
)
|
|
expect(view.getByText('详情')).toBeTruthy()
|
|
expect(view.getByText('该调用不在当前窗口内')).toBeTruthy()
|
|
})
|
|
|
|
it('registry disposer tolerates the list already emptied by a sibling disposer', () => {
|
|
const registry = new ToolViewRegistry()
|
|
const offA = registry.register('bash', () => null)
|
|
const offB = registry.register('bash', () => null)
|
|
offA()
|
|
offB()
|
|
// Both entries gone; a re-register works from a fresh list.
|
|
registry.register('bash', () => null)
|
|
expect(registry.resolve('bash', SID)).toBeDefined()
|
|
})
|
|
})
|