Moving tests into existing file.

This commit is contained in:
Michael Drury 2025-11-20 11:56:16 +00:00
parent 4c05ee015d
commit 930f24c0ba
2 changed files with 45 additions and 74 deletions

View File

@ -1,74 +0,0 @@
import type { AgentFinish } from 'langchain/agents';
import { handleAgentFinishOutput } from './common';
describe('handleAgentFinishOutput', () => {
it('handles multi-output with only text blocks', () => {
const steps = {
returnValues: {
output: [
{ index: 0, type: 'text', text: 'First output' },
{ index: 1, type: 'text', text: 'Second output' },
],
},
log: '',
} as AgentFinish;
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('First output\nSecond output');
});
it('filters out thinking blocks and returns only text blocks', () => {
const steps = {
returnValues: {
output: [
{ index: 0, type: 'thinking', thinking: 'Internal reasoning...' },
{ index: 1, type: 'text', text: 'User-facing output' },
],
},
log: '',
} as AgentFinish;
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('User-facing output');
});
it('returns thinking content when no text blocks exist', () => {
const steps = {
returnValues: {
output: [
{ index: 0, type: 'thinking', thinking: 'Only thinking content' },
{ index: 1, type: 'thinking', thinking: 'More thinking' },
],
},
log: '',
} as AgentFinish;
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('Only thinking content\nMore thinking');
});
it('returns empty string when no text or thinking blocks exist', () => {
const steps = {
returnValues: {
output: [{ index: 0, type: 'unknown' }],
},
log: '',
} as AgentFinish;
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('');
});
it('returns original steps when not multi-output', () => {
const steps = {
returnValues: {
output: 'Simple string output',
},
log: '',
} as AgentFinish;
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('Simple string output');
});
});

View File

@ -740,4 +740,49 @@ describe('handleAgentFinishOutput', () => {
expect(result).toEqual(steps);
});
it('should filter out thinking blocks and return only text blocks', () => {
const steps: AgentFinish = {
returnValues: {
output: [
{ index: 0, type: 'thinking', thinking: 'Internal reasoning...' },
{ index: 1, type: 'text', text: 'User-facing output' },
],
},
log: '',
};
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('User-facing output');
});
it('should return thinking content when no text blocks exist', () => {
const steps: AgentFinish = {
returnValues: {
output: [
{ index: 0, type: 'thinking', thinking: 'Only thinking content' },
{ index: 1, type: 'thinking', thinking: 'More thinking' },
],
},
log: '',
};
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('Only thinking content\nMore thinking');
});
it('should return empty string when no text or thinking blocks exist', () => {
const steps: AgentFinish = {
returnValues: {
output: [{ index: 0, type: 'unknown' }],
},
log: '',
};
const result = handleAgentFinishOutput(steps) as AgentFinish;
expect(result.returnValues.output).toBe('');
});
});