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:
William Valentin
2026-02-11 09:51:19 -08:00
parent 01c3175fdb
commit 85d7a6bfec
2 changed files with 78 additions and 3 deletions
+46
View File
@@ -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');
});
});