fix(worker): surface nonzero-exit agent turns as failed even when text streamed
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user