58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import {
|
|
buildSubagentEvidenceSummary,
|
|
normalizeSubagentToolResults,
|
|
} from '../src/modules/netaclaw/service/subagent_evidence.js';
|
|
|
|
describe('subagent evidence summary', () => {
|
|
it('normalizes valid tool results and drops empty items', () => {
|
|
expect(normalizeSubagentToolResults([
|
|
{ name: 'find_files', result: 'a.jpg', toolCallId: 'call-1' },
|
|
{ name: 'bash', result: '' },
|
|
{ name: 1 as any, result: 'ignored' },
|
|
] as any)).toEqual([
|
|
{ name: 'find_files', result: 'a.jpg', toolCallId: 'call-1', label: undefined },
|
|
]);
|
|
});
|
|
|
|
it('builds file-count evidence for image tasks', () => {
|
|
expect(buildSubagentEvidenceSummary(
|
|
{
|
|
goal: 'Count image files on desktop',
|
|
context: 'Use tools',
|
|
},
|
|
[
|
|
{
|
|
name: 'find_files',
|
|
result: ['C:\\Users\\lixin\\Desktop\\1.jpg', 'C:\\Users\\lixin\\Desktop\\2.png'].join('\n'),
|
|
},
|
|
]
|
|
)).toEqual({
|
|
kind: 'file-count',
|
|
title: '图片文件统计',
|
|
count: 2,
|
|
files: ['1.jpg', '2.png'],
|
|
summary: ['根据工具结果统计,图片文件共 2 个。', '- 1.jpg', '- 2.png'].join('\n'),
|
|
});
|
|
});
|
|
|
|
it('falls back to tool previews for non-file-count evidence', () => {
|
|
expect(buildSubagentEvidenceSummary(
|
|
{
|
|
goal: 'Summarize command output',
|
|
context: 'Use bash',
|
|
},
|
|
[
|
|
{
|
|
name: 'bash',
|
|
result: 'line one\nline two\nline three',
|
|
},
|
|
]
|
|
)).toEqual({
|
|
kind: 'tool-preview',
|
|
title: '工具证据摘要',
|
|
summary: ['子代理已完成工具检查,但未输出最终结论。以下是可用工具证据摘要:', '- bash: line one line two line three'].join('\n'),
|
|
previews: ['- bash: line one line two line three'],
|
|
});
|
|
});
|
|
});
|