项目文件夹

文件
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

83 行
3.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { ToolCall } from '@/sync/typesMessage';
import {
getTerminalToolCommand,
getToolSummaryCategory,
getToolSummaryDetail,
isTerminalToolName,
shouldRenderToolCardHeader,
} from './toolDisplay';
function tool(name: string, input: unknown): ToolCall {
return {
name,
state: 'completed',
input,
createdAt: 1,
startedAt: 1,
completedAt: 2,
description: null,
};
}
describe('terminal tool display helpers', () => {
it('detects command-like terminal tools', () => {
expect(isTerminalToolName('Bash')).toBe(true);
expect(isTerminalToolName('CodexBash')).toBe(true);
expect(isTerminalToolName('GeminiBash')).toBe(true);
expect(isTerminalToolName('execute')).toBe(true);
expect(isTerminalToolName('Read')).toBe(false);
});
it('extracts one-line command summaries from shell tools', () => {
expect(getTerminalToolCommand(tool('Bash', { command: 'pnpm test' }))).toBe('pnpm test');
expect(getTerminalToolCommand(tool(
'CodexBash',
{
command: ['/usr/bin/zsh', '-lc', 'git status --short'],
parsed_cmd: [{ type: 'bash', cmd: 'git status --short' }],
},
))).toBe('git status --short');
});
it('extracts Gemini execute titles without cwd metadata', () => {
expect(getTerminalToolCommand(tool(
'execute',
{ toolCall: { title: 'rm tmp.txt [current working directory /repo] (cleanup)' } },
))).toBe('rm tmp.txt');
});
it('hides Codex patch card headers on web only', () => {
expect(shouldRenderToolCardHeader('CodexPatch', 'web')).toBe(false);
expect(shouldRenderToolCardHeader('CodexPatch', 'ios')).toBe(true);
expect(shouldRenderToolCardHeader('CodexPatch', 'android')).toBe(true);
expect(shouldRenderToolCardHeader('CodexBash', 'web')).toBe(true);
});
it('classifies tools for compact transcript rows', () => {
expect(getToolSummaryCategory('CodexBash')).toBe('terminal');
expect(getToolSummaryCategory('CodexPatch')).toBe('edit');
expect(getToolSummaryCategory('Read')).toBe('read');
expect(getToolSummaryCategory('Grep')).toBe('search');
expect(getToolSummaryCategory('WebFetch')).toBe('web');
});
it('extracts compact transcript row details', () => {
expect(getToolSummaryDetail(tool('CodexBash', {
command: ['/usr/bin/zsh', '-lc', 'git status --short'],
parsed_cmd: [{ type: 'bash', cmd: 'git status --short' }],
}))).toBe('git status --short');
expect(getToolSummaryDetail(tool('CodexPatch', {
changes: {
'README-RU.md': { kind: { type: 'update' } },
},
}))).toBe('README-RU.md');
expect(getToolSummaryDetail(tool('MultiEdit', {
file_path: '/repo/src/app.tsx',
}))).toBe('/repo/src/app.tsx');
});
});