Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions frontend/src/components/NormalizedConversation/TurnActivity.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { describe, expect, it, vi } from 'vitest';
import type { ContentBlock } from 'shared/types';
import i18n from '@/i18n';
import { TurnActivity } from './TurnActivity';
import { planTurnBlocks } from './messageTurnBlocks';

vi.mock('@/contexts/PanelActionsContext', () => ({
useOptionalPanelActionsContext: () => null,
}));

vi.mock('@/components/ConfigProvider', () => ({
useUserSystem: () => ({ config: { theme: 'light' } }),
useOptionalUserSystem: () => ({ config: { theme: 'light' } }),
}));

vi.mock('@/components/common/RawLogText', () => ({
default: ({ content }: { content: string }) => <pre>{content}</pre>,
}));

vi.mock('./AstryxMarkdown', () => ({
AstryxMarkdown: ({ value }: { value: string }) => <pre>{value}</pre>,
}));

function renderCommand({
id,
status = 'failed',
code,
backgrounded = false,
}: {
id: string;
status?: 'failed' | 'completed' | 'in_progress';
code?: number;
backgrounded?: boolean;
}) {
const blocks: ContentBlock[] = [
{
type: 'tool_use',
tool_use_id: id,
tool_name: 'exec_command',
kind: 'execute',
status,
input_preview: JSON.stringify({ cmd: 'powershell.exe -Command test' }),
meta: backgrounded ? { asyncTasks: { backgrounded: true } } : null,
},
];
if (status !== 'in_progress') {
blocks.push({
type: 'tool_result',
tool_use_id: id,
is_error: status === 'failed',
output_preview: JSON.stringify({
stdout: 'original stdout',
stderr: 'original stderr',
...(code !== undefined ? { exit_code: code } : {}),
}),
});
}
const view = render(
<QueryClientProvider
client={
new QueryClient({ defaultOptions: { queries: { retry: false } } })
}
>
<TurnActivity
turnId={id}
timestamp="2026-11-18T00:00:00.000Z"
items={planTurnBlocks(blocks).map((item, index) => ({ item, index }))}
attempt={{ id: 'attempt-1', container_ref: null } as never}
task={null}
/>
</QueryClientProvider>
);
if (!screen.queryByTestId('turn-tool-chip-row')) {
fireEvent.click(
screen.getByRole('button', { name: /运行 1 个命令|Ran 1 command/ })
);
}
return view;
}

describe('terminal failure summaries in the timeline', () => {
it('shows a reported nonzero exit code while collapsed and preserves output on expansion', () => {
renderCommand({ id: 'exit-23', code: 23 });
expect(screen.getByText('命令退出码 23')).toBeVisible();
expect(screen.queryByText('工具调用失败')).not.toBeInTheDocument();
const row = screen.getByTestId('turn-tool-chip-row');
expect(row).toHaveAttribute('aria-expanded', 'false');
expect(screen.getByTestId('turn-tool-chip-item')).toHaveAttribute(
'data-tool-status',
'error'
);
fireEvent.click(row);
expect(screen.getByText(/original stdout/)).toBeVisible();
expect(screen.getByText(/original stderr/)).toBeVisible();
expect(screen.getByText('exit 23')).toBeVisible();
});

it('uses the command result when the transport reports completion', () => {
renderCommand({ id: 'completed-exit-1', status: 'completed', code: 1 });
expect(screen.getByText('命令退出码 1')).toBeVisible();
expect(screen.getByTestId('turn-tool-chip-item')).toHaveAttribute(
'data-tool-status',
'error'
);
});

it.each([
['successful', 'completed', 0, false, 'complete'],
['running', 'in_progress', undefined, false, 'running'],
['background', 'failed', 23, true, 'complete'],
] as const)(
'does not invent a failure for %s commands',
(id, status, code, backgrounded, expected) => {
renderCommand({ id, status, code, backgrounded });
expect(screen.getByTestId('turn-tool-chip-item')).toHaveAttribute(
'data-tool-status',
expected
);
expect(
screen.queryByText(/命令退出码|工具调用失败/)
).not.toBeInTheDocument();
}
);

it('keeps an unknown failure generic instead of inventing an exit code', () => {
renderCommand({ id: 'unknown-failure' });
expect(screen.getByText('工具调用失败')).toBeVisible();
expect(screen.queryByText(/命令退出码/)).not.toBeInTheDocument();
});

it('localizes the reported exit code in English', async () => {
await i18n.changeLanguage('en');
renderCommand({ id: 'english-exit', code: 7 });
expect(screen.getByText('Command exited with code 7')).toBeVisible();
});
});
25 changes: 18 additions & 7 deletions frontend/src/components/NormalizedConversation/TurnActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from './tools/subagentCardModel';
import {
getToolCallDescription,
getToolExitStatus,
getToolSummary,
} from './conversation-entry-utils';
import type { IndexedTurnItem } from './messageTurnAggregate';
Expand Down Expand Up @@ -632,6 +633,21 @@ export function TurnActivity({
const expansionKey = `${turnId}-${index}`;
const action = toolEntry.action_type;
const backgrounded = isToolCallBackgrounded(use.meta);
const status = backgrounded
? 'complete'
: getToolExitStatus(toolEntry) === 'error'
? 'error'
: getToolChatStatus(toolEntry.status);
const exitStatus =
action.action === 'command_run' ? action.result?.exit_status : null;
const errorMessage =
status === 'error'
? exitStatus?.type === 'exit_code' && exitStatus.code !== 0
? t('messageTurnView.toolSummary.commandExitCode', {
code: exitStatus.code,
})
: t('messageTurnView.toolSummary.failed')
: undefined;
callCategories.set(
toolUseId || expansionKey,
summaryCategory(action.action)
Expand Down Expand Up @@ -710,13 +726,8 @@ export function TurnActivity({
monoChip: !description && isMonoToolChip(action),
additions: editStats.additions,
deletions: editStats.deletions,
status: backgrounded
? 'complete'
: getToolChatStatus(toolEntry.status),
errorMessage:
toolEntry.status.status === 'failed'
? t('messageTurnView.toolSummary.failed')
: undefined,
status,
errorMessage,
rawEntry: entry,
resultDetail: (
<ToolCallResultDetail>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ export function TurnToolChipRow({
) : null}

{isError && errorMessage && !expanded ? (
<span className="conv-tool-chip-error-badge">{errorMessage}</span>
<span className="conv-tool-chip-error-badge tabular-nums">
{errorMessage}
</span>
) : null}
</div>

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/locales/en/conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@
"otherActivities_one": "{{count}} other activity",
"otherActivities_other": "{{count}} other activities",
"separator": ", ",
"failed": "Tool call failed"
"failed": "Tool call failed",
"commandExitCode": "Command exited with code {{code}}"
},
"fileReadRange": "Lines {{start}}–{{end}}",
"fileReadFrom": "From line {{start}}",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/locales/zh-CN/conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@
"otherActivities_one": "{{count}} 项其他活动",
"otherActivities_other": "{{count}} 项其他活动",
"separator": "、",
"failed": "工具调用失败"
"failed": "工具调用失败",
"commandExitCode": "命令退出码 {{code}}"
},
"fileReadRange": "第 {{start}}–{{end}} 行",
"fileReadFrom": "从第 {{start}} 行开始",
Expand Down