fix(codex): preserve transcript sync across mode switches

This commit is contained in:
weishu
2026-07-28 12:20:54 +08:00
parent f0c7d0b7e7
commit 92958890de
6 changed files with 118 additions and 9 deletions
@@ -59,6 +59,27 @@ describe('codexSessionScanner', () => {
expect(events[0]?.type).toBe('event_msg');
});
it('flushes an appended tail without waiting for the watcher', async () => {
await writeFile(
transcriptPath,
JSON.stringify({ type: 'session_meta', payload: { id: 'session-flush' } }) + '\n'
);
scanner = await createCodexSessionScanner({
transcriptPath,
onEvent: (event) => events.push(event)
});
await appendFile(
transcriptPath,
JSON.stringify({ type: 'event_msg', payload: { type: 'agent_message', message: 'final tail' } }) + '\n'
);
await scanner.flush();
expect(events).toHaveLength(1);
expect(events[0]?.payload).toEqual({ type: 'agent_message', message: 'final tail' });
});
it('reads exactly the requested transcript byte range', async () => {
const initial = 'existing transcript\n';
const appended = 'new event\n';
@@ -11,6 +11,7 @@ interface CodexSessionScannerOptions {
}
export interface CodexSessionScanner {
flush: () => Promise<void>;
cleanup: () => Promise<void>;
setTranscriptPath: (transcriptPath: string) => Promise<void>;
}
@@ -20,6 +21,9 @@ export async function createCodexSessionScanner(opts: CodexSessionScannerOptions
await scanner.start();
return {
flush: async () => {
await scanner.flush();
},
cleanup: async () => {
await scanner.cleanup();
},