65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import { resolveTurnOutcome } from '../../src/runtime/turn-outcome';
|
|
|
|
describe('resolveTurnOutcome', () => {
|
|
test('partial streamed text + error is surfaced as failed and text preserved', () => {
|
|
const outcome = resolveTurnOutcome({
|
|
assistantText: 'partial answer before crash',
|
|
error: 'exit code 1: rate limited',
|
|
runtime: 'codex',
|
|
});
|
|
expect(outcome.text).toBe('partial answer before crash');
|
|
expect(outcome.failure).toBe('codex failed:\nexit code 1: rate limited');
|
|
});
|
|
|
|
test('successful turn with streamed text and no error has no failure', () => {
|
|
const outcome = resolveTurnOutcome({
|
|
assistantText: 'complete answer',
|
|
runtime: 'codex',
|
|
});
|
|
expect(outcome.text).toBe('complete answer');
|
|
expect(outcome.failure).toBeUndefined();
|
|
});
|
|
|
|
test('empty turn with error is surfaced as failed', () => {
|
|
const outcome = resolveTurnOutcome({
|
|
assistantText: ' ',
|
|
error: 'exit code 137',
|
|
runtime: 'claude',
|
|
});
|
|
expect(outcome.failure).toBe('claude failed:\nexit code 137');
|
|
});
|
|
|
|
test('empty turn with no error reports the no-response failure', () => {
|
|
const outcome = resolveTurnOutcome({
|
|
assistantText: '',
|
|
runtime: 'codex',
|
|
});
|
|
expect(outcome.failure).toBe(
|
|
'Codex completed without producing an assistant response.',
|
|
);
|
|
});
|
|
|
|
test('recovers finalMessage text when nothing streamed and no error', () => {
|
|
const outcome = resolveTurnOutcome({
|
|
assistantText: '',
|
|
recoveredText: 'recovered from last-message file',
|
|
runtime: 'codex',
|
|
});
|
|
expect(outcome.text).toBe('recovered from last-message file');
|
|
expect(outcome.failure).toBeUndefined();
|
|
});
|
|
|
|
test('recovered finalMessage text + error is still surfaced as failed', () => {
|
|
const outcome = resolveTurnOutcome({
|
|
assistantText: '',
|
|
recoveredText: 'recovered partial',
|
|
error: 'network drop',
|
|
runtime: 'codex',
|
|
});
|
|
expect(outcome.text).toBe('recovered partial');
|
|
expect(outcome.failure).toBe('codex failed:\nnetwork drop');
|
|
});
|
|
});
|