mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Hand fixes for the findings --fix cannot touch, mirroring the fixes already applied on the fe-docs feature branch (same file, same shape) so its eventual rebase resolves cleanly: - restore the return the no-confusing-void-expression autofix ate in useAbsentSnapshot (typed S | undefined; hook call kept for hook-order stability, undefined returned explicitly); - re-type DOM queries the no-unnecessary-type-assertion autofix broke: getByRole<HTMLButtonElement>(...) generics instead of the removed as-casts (the eslint program and the client tsconfig aggregate disagree about these casts; the generic form satisfies both); - justified eslint-disable for the deliberate legacy paths: keyCode 229 IME-composition detection, execCommand clipboard fallbacks, lib.dom clipboard optionality, and the any-typed Reflect.get/this probes in test fakes; - drop the dead react/no-danger directive (eslint-plugin-react is not loaded, so the rule never applied) keeping its shiki rationale; - delete the tautological 'Z' comparison and the renameTarget null check already implied by renameBlocked; - css-module non-null assertions replaced by type widening (Button className, TAG_CLASS Record) per the established pattern; - misc: max-len comment wraps, void generic drop in the deferred test helper, unused type imports, floating selectWorkspace promises voided, member-delimiter newlines in inline type literals.
124 lines
5.6 KiB
TypeScript
124 lines
5.6 KiB
TypeScript
// @vitest-environment jsdom
|
||
// Branch tails the acceptance specs do not reach: ToolRow stopped-state dot,
|
||
// PendingCard question arm, bash sample state dots, the node-half empty
|
||
// apply, and AssistantMarkdown reasoning/unknown block arms.
|
||
|
||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||
import { cleanup, render } from '@testing-library/react'
|
||
import { createSnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
|
||
import { bindSnapshotSelector } from '@deepseek-ai/dsh-client-web-react'
|
||
import type { RunningToolCall, SessionId, SessionListState, ToolResultNode } from '@deepseek-ai/dsh-client-runtime/client'
|
||
import { PendingWait } from '@deepseek-ai/dsh-client-runtime/client'
|
||
import { RpcId } from '@deepseek-ai/dsh-client-connection/client'
|
||
import type { ToolRowOwnerProps, ToolRowProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||
import { apply as nodeApply } from '../src/index.ts'
|
||
import { GenericToolCard } from '../src/client/chat/GenericToolCard.tsx'
|
||
import { ToolRow } from '../src/client/chat/ToolRow.tsx'
|
||
import { PendingCard } from '../src/client/chat/PendingCard.tsx'
|
||
import { AssistantMarkdown } from '../src/client/chat/AssistantMarkdown.tsx'
|
||
import { BashRow } from '../src/client/toolviews/bash-sample.tsx'
|
||
|
||
afterEach(cleanup)
|
||
|
||
describe('tails', () => {
|
||
it('node-half apply is an intentional no-op', () => {
|
||
expect(() => { nodeApply() }).not.toThrow()
|
||
})
|
||
|
||
it('ToolRow stopped state renders the warning dot in the leading slot', () => {
|
||
const view = render(
|
||
<ToolRow variant="bash" icon={<i data-testid="icon" />} title="Bash" summary="s" body={null} state="stopped" />,
|
||
)
|
||
expect(view.queryByTestId('icon')).toBeNull()
|
||
expect(view.container.querySelector('[data-state="stopped"]')).not.toBeNull()
|
||
})
|
||
|
||
it('PendingCard renders the question arm with its count', () => {
|
||
const view = render(
|
||
<PendingCard item={new PendingWait('question', RpcId('r1'), 's1' as SessionId, { questions: [{}, {}] } as PendingWait<'question'>['payload'], vi.fn())} />,
|
||
)
|
||
expect(view.getByText(/等待回答(2 题)/)).toBeTruthy()
|
||
})
|
||
|
||
it('AssistantMarkdown renders reasoning as a Think row and unknown blocks as JSON fallback', () => {
|
||
const view = render(
|
||
<AssistantMarkdown
|
||
blocks={[
|
||
{ kind: 'reasoning', text: 'thinking hard\nsecond line' },
|
||
{ kind: 'tool-call', callId: 'c', name: 'bash', argsRaw: '{}' },
|
||
{ kind: 'other', block: { type: 'mystery' } },
|
||
]}
|
||
streaming
|
||
/>,
|
||
)
|
||
expect(view.getByText('Think')).toBeTruthy()
|
||
expect(view.getByText('thinking hard')).toBeTruthy()
|
||
expect(view.getByText(/未知内容块/)).toBeTruthy()
|
||
const stopped = render(
|
||
<AssistantMarkdown blocks={[{ kind: 'text', text: 'partial words' }]} streaming={false} interrupted />,
|
||
)
|
||
expect(stopped.getByText('已停止')).toBeTruthy()
|
||
})
|
||
|
||
it('a settled others-variant row renders the sparkle icon in the leading slot', () => {
|
||
const settled: ToolResultNode = {
|
||
kind: 'tool-result', seq: 2, time: 2_000, callId: 'c5',
|
||
call: { name: 'todo_write', argsRaw: '{"note":"x"}' },
|
||
callTime: 1_000,
|
||
content: [], isError: false, callView: null, resultView: null,
|
||
}
|
||
const props: ToolRowOwnerProps = {
|
||
callId: 'c5', toolName: 'todo_write', block: settled, openDetails: vi.fn(),
|
||
}
|
||
const view = render(<GenericToolCard {...props} />)
|
||
// Settled ok state keeps the variant icon (sparkle) instead of a StateDot.
|
||
expect(view.container.querySelector('[data-variant="others"] svg')).not.toBeNull()
|
||
expect(view.container.querySelector('[data-state="ok"]')).not.toBeNull()
|
||
})
|
||
|
||
it('BashRow shows StateDot chrome for running/error/stopped (root session arm)', () => {
|
||
const sid = 'root-1' as SessionId
|
||
const list = createSnapshotStore<SessionListState>({
|
||
ids: [sid],
|
||
byId: { [sid]: { id: sid, title: 'r', displayTitle: 'r', running: false, blank: false, updatedAt: 0 } },
|
||
current: undefined,
|
||
phase: 'ready',
|
||
})
|
||
const props = (block: RunningToolCall | ToolResultNode) => ({
|
||
callId: 'c1', toolName: 'bash', block, openDetails: vi.fn(),
|
||
sessionId: sid, useSessions: bindSnapshotSelector(list),
|
||
} as unknown as ToolRowProps)
|
||
|
||
const running: RunningToolCall = {
|
||
callId: 'c1', name: 'bash', argsRaw: '{"command":"ls","description":"List"}',
|
||
turn: 1, step: 1, time: 1_000, callView: null,
|
||
}
|
||
const errorResult: ToolResultNode = {
|
||
kind: 'tool-result', seq: 1, time: 1_000, callId: 'c1',
|
||
call: { name: 'bash', argsRaw: '{"command":"boom"}' },
|
||
callTime: 500,
|
||
content: [], isError: true, callView: null, resultView: null,
|
||
}
|
||
const stoppedResult: ToolResultNode = {
|
||
...errorResult,
|
||
error: { name: 'E', code: 'interrupted' },
|
||
}
|
||
|
||
const runningView = render(<BashRow {...props(running)} />)
|
||
expect(runningView.container.querySelector('[data-state="running"]')).not.toBeNull()
|
||
expect(runningView.getByText('Bash')).toBeTruthy()
|
||
expect(runningView.getByText('List')).toBeTruthy()
|
||
runningView.unmount()
|
||
|
||
const errorView = render(<BashRow {...props(errorResult)} />)
|
||
expect(errorView.container.querySelector('[data-sample="bash-global"]')).not.toBeNull()
|
||
expect(errorView.container.querySelector('[data-state="error"]')).not.toBeNull()
|
||
expect(errorView.getByText('失败')).toBeTruthy()
|
||
errorView.unmount()
|
||
|
||
const stoppedView = render(<BashRow {...props(stoppedResult)} />)
|
||
expect(stoppedView.container.querySelector('[data-state="stopped"]')).not.toBeNull()
|
||
expect(stoppedView.getByText('已停止')).toBeTruthy()
|
||
})
|
||
})
|