test: add stopReason edge case tests; update state.json with recent fixes
- Added tests for finish_reason 'tool_calls' with empty array → 'end_turn' - Added test for finish_reason 'length' → 'max_tokens' - Updated state.json with 4 new entries for today's fixes (SOUL.md, message normalization, agent loop resilience, stopReason normalization) - Test count: 1329 → 1331
This commit is contained in:
@@ -74,4 +74,50 @@ describe('OpenAIClient tool use', () => {
|
||||
args: { command: 'ls' },
|
||||
});
|
||||
});
|
||||
|
||||
it('maps finish_reason "tool_calls" with empty tool_calls to end_turn', async () => {
|
||||
mockCreate.mockResolvedValueOnce({
|
||||
choices: [{
|
||||
message: {
|
||||
content: 'I tried to call a tool but none matched.',
|
||||
tool_calls: [],
|
||||
},
|
||||
finish_reason: 'tool_calls',
|
||||
}],
|
||||
usage: { prompt_tokens: 15, completion_tokens: 10 },
|
||||
});
|
||||
|
||||
const client = new OpenAIClient({
|
||||
apiKey: 'test-key',
|
||||
model: 'gpt-4o',
|
||||
});
|
||||
|
||||
const response = await client.chat({
|
||||
messages: [{ role: 'user', content: 'do something' }],
|
||||
});
|
||||
|
||||
expect(response.stopReason).toBe('end_turn');
|
||||
expect(response.toolCalls).toBeUndefined();
|
||||
});
|
||||
|
||||
it('maps finish_reason "length" to max_tokens', async () => {
|
||||
mockCreate.mockResolvedValueOnce({
|
||||
choices: [{
|
||||
message: { content: 'Truncated output...' },
|
||||
finish_reason: 'length',
|
||||
}],
|
||||
usage: { prompt_tokens: 100, completion_tokens: 4096 },
|
||||
});
|
||||
|
||||
const client = new OpenAIClient({
|
||||
apiKey: 'test-key',
|
||||
model: 'gpt-4o',
|
||||
});
|
||||
|
||||
const response = await client.chat({
|
||||
messages: [{ role: 'user', content: 'write a long essay' }],
|
||||
});
|
||||
|
||||
expect(response.stopReason).toBe('max_tokens');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user