mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-26 22:30:50 +00:00
fix: codex session selection
This commit is contained in:
@@ -73,4 +73,79 @@ describe('codexSessionScanner', () => {
|
||||
expect(events).toHaveLength(1);
|
||||
expect(events[0].type).toBe('response_item');
|
||||
});
|
||||
|
||||
it('limits session scan to dates within the start window', async () => {
|
||||
const referenceTimestampMs = Date.parse('2025-12-22T00:00:30.000Z');
|
||||
const windowMs = 2 * 60 * 1000;
|
||||
const matchingSessionId = 'session-222';
|
||||
const outsideSessionId = 'session-999';
|
||||
const outsideDir = join(testDir, 'sessions', '2025', '12', '20');
|
||||
const matchingFile = join(sessionsDir, `codex-${matchingSessionId}.jsonl`);
|
||||
const outsideFile = join(outsideDir, `codex-${outsideSessionId}.jsonl`);
|
||||
|
||||
await mkdir(outsideDir, { recursive: true });
|
||||
const baseLines = [
|
||||
JSON.stringify({ type: 'session_meta', payload: { id: matchingSessionId, cwd: '/data/github/happy/hapi', timestamp: '2025-12-22T00:00:00.000Z' } }),
|
||||
JSON.stringify({ type: 'event_msg', payload: { type: 'agent_message', message: 'hello' } })
|
||||
];
|
||||
await writeFile(matchingFile, baseLines.join('\n') + '\n');
|
||||
await writeFile(
|
||||
outsideFile,
|
||||
JSON.stringify({ type: 'session_meta', payload: { id: outsideSessionId, cwd: '/data/github/happy/hapi', timestamp: '2025-12-20T00:00:00.000Z' } }) + '\n'
|
||||
);
|
||||
|
||||
scanner = await createCodexSessionScanner({
|
||||
sessionId: null,
|
||||
cwd: '/data/github/happy/hapi',
|
||||
startupTimestampMs: referenceTimestampMs,
|
||||
sessionStartWindowMs: windowMs,
|
||||
onEvent: (event) => events.push(event)
|
||||
});
|
||||
|
||||
await wait(200);
|
||||
expect(events).toHaveLength(0);
|
||||
|
||||
const newLine = JSON.stringify({
|
||||
type: 'response_item',
|
||||
payload: { type: 'function_call', name: 'Tool', call_id: 'call-2', arguments: '{}' }
|
||||
});
|
||||
await appendFile(matchingFile, newLine + '\n');
|
||||
|
||||
await wait(200);
|
||||
expect(events).toHaveLength(1);
|
||||
expect(events[0].type).toBe('response_item');
|
||||
});
|
||||
|
||||
it('fails fast when cwd is missing and no sessionId is provided', async () => {
|
||||
const sessionId = 'session-missing-cwd';
|
||||
const matchFailedMessage = 'No cwd provided for Codex session matching; refusing to fallback.';
|
||||
sessionFile = join(sessionsDir, `codex-${sessionId}.jsonl`);
|
||||
|
||||
await writeFile(
|
||||
sessionFile,
|
||||
JSON.stringify({ type: 'session_meta', payload: { id: sessionId } }) + '\n'
|
||||
);
|
||||
|
||||
let failureMessage: string | null = null;
|
||||
scanner = await createCodexSessionScanner({
|
||||
sessionId: null,
|
||||
onEvent: (event) => events.push(event),
|
||||
onSessionMatchFailed: (message) => {
|
||||
failureMessage = message;
|
||||
}
|
||||
});
|
||||
|
||||
await wait(150);
|
||||
expect(failureMessage).toBe(matchFailedMessage);
|
||||
expect(events).toHaveLength(0);
|
||||
|
||||
const newLine = JSON.stringify({
|
||||
type: 'response_item',
|
||||
payload: { type: 'function_call', name: 'Tool', call_id: 'call-3', arguments: '{}' }
|
||||
});
|
||||
await appendFile(sessionFile, newLine + '\n');
|
||||
|
||||
await wait(200);
|
||||
expect(events).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user