|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { render, screen } from '../_helpers/render'; |
| 3 | +import { Transcript } from '@/canvas/Transcript'; |
| 4 | +import type { AgentRun, ToolCall } from '@/api/types'; |
| 5 | + |
| 6 | +const intakeRun: AgentRun = { |
| 7 | + agent: 'intake', started_at: '2026-05-15T14:16:30Z', ended_at: '2026-05-15T14:16:32Z', |
| 8 | + summary: 'Triage observed elevated p99 latency.', confidence: 0.92, |
| 9 | + confidence_rationale: null, signal: null, |
| 10 | +}; |
| 11 | +const triageRun: AgentRun = { |
| 12 | + agent: 'triage', started_at: '2026-05-15T14:16:50Z', ended_at: '2026-05-15T14:16:54Z', |
| 13 | + summary: 'Correlated with deploy.', confidence: 0.88, |
| 14 | + confidence_rationale: null, signal: null, |
| 15 | +}; |
| 16 | +const tcLogs: ToolCall = { |
| 17 | + agent: 'triage', tool: 'obs:get_logs', args: { service: 'api' }, result: { lines: 12 }, |
| 18 | + ts: '2026-05-15T14:16:52Z', risk: 'low', status: 'executed', |
| 19 | + approver: null, approved_at: null, approval_rationale: null, |
| 20 | +}; |
| 21 | +const tcPending: ToolCall = { |
| 22 | + agent: 'investigate', tool: 'rem:restart_service', |
| 23 | + args: { service: 'payments-svc' }, result: null, ts: '2026-05-15T14:18:00Z', |
| 24 | + risk: 'high', status: 'pending_approval', |
| 25 | + approver: null, approved_at: null, approval_rationale: null, |
| 26 | +}; |
| 27 | + |
| 28 | +describe('<Transcript>', () => { |
| 29 | + it('renders one Turn per completed agent run', () => { |
| 30 | + render( |
| 31 | + <Transcript |
| 32 | + agentsRun={[intakeRun, triageRun]} |
| 33 | + toolCalls={[]} |
| 34 | + activeAgent={null} |
| 35 | + hitlContext={null} |
| 36 | + onSelectTool={() => {}} |
| 37 | + onApprove={() => {}} |
| 38 | + onReject={() => {}} |
| 39 | + onApproveWithRationale={() => {}} |
| 40 | + />, |
| 41 | + ); |
| 42 | + expect(screen.getByText('intake')).toBeInTheDocument(); |
| 43 | + expect(screen.getByText('triage')).toBeInTheDocument(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('renders active Turn for currently-running agent (not yet in agentsRun)', () => { |
| 47 | + render( |
| 48 | + <Transcript |
| 49 | + agentsRun={[intakeRun]} |
| 50 | + toolCalls={[]} |
| 51 | + activeAgent={{ name: 'investigate', startedAt: '2026-05-15T14:17:00Z', currentBody: 'Reading deploy diff...' }} |
| 52 | + hitlContext={null} |
| 53 | + onSelectTool={() => {}} |
| 54 | + onApprove={() => {}} |
| 55 | + onReject={() => {}} |
| 56 | + onApproveWithRationale={() => {}} |
| 57 | + />, |
| 58 | + ); |
| 59 | + expect(screen.getByText('investigate')).toBeInTheDocument(); |
| 60 | + expect(screen.getByText(/Reading deploy diff/)).toBeInTheDocument(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('groups tool calls by agent and renders them in the matching Turn sidenote', () => { |
| 64 | + render( |
| 65 | + <Transcript |
| 66 | + agentsRun={[intakeRun, triageRun]} |
| 67 | + toolCalls={[tcLogs]} |
| 68 | + activeAgent={null} |
| 69 | + hitlContext={null} |
| 70 | + onSelectTool={() => {}} |
| 71 | + onApprove={() => {}} |
| 72 | + onReject={() => {}} |
| 73 | + onApproveWithRationale={() => {}} |
| 74 | + />, |
| 75 | + ); |
| 76 | + // tcLogs.agent === 'triage', so it appears in triage's sidenote |
| 77 | + expect(screen.getByText('obs:get_logs')).toBeInTheDocument(); |
| 78 | + }); |
| 79 | + |
| 80 | + it('renders HITLBand when hitlContext is provided', () => { |
| 81 | + render( |
| 82 | + <Transcript |
| 83 | + agentsRun={[intakeRun]} |
| 84 | + toolCalls={[tcPending]} |
| 85 | + activeAgent={null} |
| 86 | + hitlContext={{ |
| 87 | + toolCall: tcPending, |
| 88 | + waitedSeconds: 18, |
| 89 | + question: 'Restart payments-svc?', |
| 90 | + confidence: 0.78, |
| 91 | + turn: 3, |
| 92 | + requestedBy: 'u1', |
| 93 | + policy: 'risk:high requires approval', |
| 94 | + }} |
| 95 | + onSelectTool={() => {}} |
| 96 | + onApprove={() => {}} |
| 97 | + onReject={() => {}} |
| 98 | + onApproveWithRationale={() => {}} |
| 99 | + />, |
| 100 | + ); |
| 101 | + expect(screen.getByText(/APPROVAL/)).toBeInTheDocument(); |
| 102 | + expect(screen.getByText('Restart payments-svc?')).toBeInTheDocument(); |
| 103 | + }); |
| 104 | + |
| 105 | + it('renders empty state when there are no turns', () => { |
| 106 | + render( |
| 107 | + <Transcript |
| 108 | + agentsRun={[]} |
| 109 | + toolCalls={[]} |
| 110 | + activeAgent={null} |
| 111 | + hitlContext={null} |
| 112 | + onSelectTool={() => {}} |
| 113 | + onApprove={() => {}} |
| 114 | + onReject={() => {}} |
| 115 | + onApproveWithRationale={() => {}} |
| 116 | + />, |
| 117 | + ); |
| 118 | + expect(screen.getByText(/No turns yet/i)).toBeInTheDocument(); |
| 119 | + }); |
| 120 | +}); |
0 commit comments