fix(worker): make cancellation teardown failure-safe

This commit is contained in:
Gabriel Brown
2026-07-10 18:04:40 -04:00
parent 470af043fa
commit ac68484059
8 changed files with 604 additions and 162 deletions
@@ -0,0 +1,37 @@
import { describe, expect, test, vi } from 'vitest';
import {
abortManagedCodexProcess,
managedCodexCommand,
} from '../../src/codex-process';
describe('managed Codex process', () => {
test('launches Codex in a job-specific process session', () => {
const command = managedCodexCommand({
jobId: 'job-1',
pidFile: '/home/alice/.codex/job-1.pid',
command: ['codex', 'exec', '--json', 'fix it'],
});
expect(command.slice(0, 2)).toEqual(['python3', '-c']);
expect(command).toContain('/home/alice/.codex/job-1.pid');
expect(command).toContain('job-1');
expect(command.slice(-4)).toEqual(['codex', 'exec', '--json', 'fix it']);
});
test('invokes an isolated in-box kill for the matching job', async () => {
const execute = vi.fn().mockResolvedValue({ exitCode: 0, output: '' });
await abortManagedCodexProcess({
jobId: 'job-1',
pidFile: '/home/alice/.codex/job-1.pid',
execute,
});
expect(execute).toHaveBeenCalledOnce();
const [command] = execute.mock.calls[0] as [string[]];
expect(command.slice(0, 2)).toEqual(['python3', '-c']);
expect(command).toContain('/home/alice/.codex/job-1.pid');
expect(command).toContain('job-1');
});
});