coverage-tails.spec.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // @vitest-environment jsdom
  2. // Branch tails the acceptance specs do not reach: ToolRow stopped-state dot,
  3. // PendingCard question arm, bash sample state dots, the node-half empty
  4. // apply, and AssistantMarkdown reasoning/unknown block arms.
  5. import { afterEach, describe, expect, it, vi } from 'vitest'
  6. import { cleanup, render } from '@testing-library/react'
  7. import { createSnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
  8. import { bindSnapshotSelector } from '@deepseek-ai/dsh-client-web-react'
  9. import type { RunningToolCall, SessionId, SessionListState, ToolResultNode } from '@deepseek-ai/dsh-client-runtime/client'
  10. import { PendingWait } from '@deepseek-ai/dsh-client-runtime/client'
  11. import { RpcId } from '@deepseek-ai/dsh-client-connection/client'
  12. import type { ToolRowOwnerProps, ToolRowProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
  13. import { apply as nodeApply } from '../src/index.ts'
  14. import { GenericToolCard } from '../src/client/chat/GenericToolCard.tsx'
  15. import { ToolRow } from '../src/client/chat/ToolRow.tsx'
  16. import { PendingCard } from '../src/client/chat/PendingCard.tsx'
  17. import { AssistantMarkdown } from '../src/client/chat/AssistantMarkdown.tsx'
  18. import { BashRow } from '../src/client/toolviews/bash-sample.tsx'
  19. afterEach(cleanup)
  20. describe('tails', () => {
  21. it('node-half apply is an intentional no-op', () => {
  22. expect(nodeApply()).toBeUndefined()
  23. })
  24. it('ToolRow stopped state renders the warning dot in the leading slot', () => {
  25. const view = render(
  26. <ToolRow variant="bash" icon={<i data-testid="icon" />} title="Bash" summary="s" body={null} state="stopped" />,
  27. )
  28. expect(view.queryByTestId('icon')).toBeNull()
  29. expect(view.container.querySelector('[data-state="stopped"]')).not.toBeNull()
  30. })
  31. it('PendingCard renders the question arm with its count', () => {
  32. const view = render(
  33. <PendingCard item={new PendingWait('question', RpcId('r1'), 's1' as SessionId, { questions: [{}, {}] } as PendingWait<'question'>['payload'], vi.fn())} />,
  34. )
  35. expect(view.getByText(/等待回答(2 题)/)).toBeTruthy()
  36. })
  37. it('AssistantMarkdown renders reasoning as a Think row and unknown blocks as JSON fallback', () => {
  38. const view = render(
  39. <AssistantMarkdown
  40. blocks={[
  41. { kind: 'reasoning', text: 'thinking hard\nsecond line' },
  42. { kind: 'tool-call', callId: 'c', name: 'bash', argsRaw: '{}' },
  43. { kind: 'other', block: { type: 'mystery' } },
  44. ]}
  45. streaming
  46. />,
  47. )
  48. expect(view.getByText('Think')).toBeTruthy()
  49. expect(view.getByText('thinking hard')).toBeTruthy()
  50. expect(view.getByText(/未知内容块/)).toBeTruthy()
  51. const stopped = render(
  52. <AssistantMarkdown blocks={[{ kind: 'text', text: 'partial words' }]} streaming={false} interrupted />,
  53. )
  54. expect(stopped.getByText('已停止')).toBeTruthy()
  55. })
  56. it('a settled others-variant row renders the sparkle icon in the leading slot', () => {
  57. const settled: ToolResultNode = {
  58. kind: 'tool-result', seq: 2, time: 2_000, callId: 'c5',
  59. call: { name: 'todo_write', argsRaw: '{"note":"x"}' },
  60. callTime: 1_000,
  61. content: [], isError: false, callView: null, resultView: null,
  62. }
  63. const props: ToolRowOwnerProps = {
  64. callId: 'c5', toolName: 'todo_write', block: settled, openDetails: vi.fn(),
  65. }
  66. const view = render(<GenericToolCard {...props} />)
  67. // Settled ok state keeps the variant icon (sparkle) instead of a StateDot.
  68. expect(view.container.querySelector('[data-variant="others"] svg')).not.toBeNull()
  69. expect(view.container.querySelector('[data-state="ok"]')).not.toBeNull()
  70. })
  71. it('BashRow shows StateDot chrome for running/error/stopped (root session arm)', () => {
  72. const sid = 'root-1' as SessionId
  73. const list = createSnapshotStore<SessionListState>({
  74. ids: [sid],
  75. byId: { [sid]: { id: sid, title: 'r', displayTitle: 'r', running: false, blank: false, updatedAt: 0 } },
  76. current: undefined,
  77. phase: 'ready',
  78. } as SessionListState)
  79. const props = (block: RunningToolCall | ToolResultNode) => ({
  80. callId: 'c1', toolName: 'bash', block, openDetails: vi.fn(),
  81. sessionId: sid, useSessions: bindSnapshotSelector(list),
  82. } as unknown as ToolRowProps)
  83. const running: RunningToolCall = {
  84. callId: 'c1', name: 'bash', argsRaw: '{"command":"ls","description":"List"}',
  85. turn: 1, step: 1, time: 1_000, callView: null,
  86. }
  87. const errorResult: ToolResultNode = {
  88. kind: 'tool-result', seq: 1, time: 1_000, callId: 'c1',
  89. call: { name: 'bash', argsRaw: '{"command":"boom"}' },
  90. callTime: 500,
  91. content: [], isError: true, callView: null, resultView: null,
  92. }
  93. const stoppedResult: ToolResultNode = {
  94. ...errorResult,
  95. error: { name: 'E', code: 'interrupted' },
  96. }
  97. const runningView = render(<BashRow {...props(running)} />)
  98. expect(runningView.container.querySelector('[data-state="running"]')).not.toBeNull()
  99. expect(runningView.getByText('Bash')).toBeTruthy()
  100. expect(runningView.getByText('List')).toBeTruthy()
  101. runningView.unmount()
  102. const errorView = render(<BashRow {...props(errorResult)} />)
  103. expect(errorView.container.querySelector('[data-sample="bash-global"]')).not.toBeNull()
  104. expect(errorView.container.querySelector('[data-state="error"]')).not.toBeNull()
  105. expect(errorView.getByText('失败')).toBeTruthy()
  106. errorView.unmount()
  107. const stoppedView = render(<BashRow {...props(stoppedResult)} />)
  108. expect(stoppedView.container.querySelector('[data-state="stopped"]')).not.toBeNull()
  109. expect(stoppedView.getByText('已停止')).toBeTruthy()
  110. })
  111. })