fix(cli): harden ACP/Codex event handling (#211)

Co-authored-by: Lihengwannafly <Lihengwannafly@users.noreply.github.com>
This commit is contained in:
Lihengwannafly
2026-02-25 16:57:28 +08:00
committed by GitHub
co-authored by Lihengwannafly
parent 77cfa715f9
commit 10f7e1404e
17 changed files with 1529 additions and 67 deletions
@@ -0,0 +1,94 @@
import { describe, expect, it } from 'vitest';
import { shouldIgnoreTerminalEvent } from './terminalEventGuard';
describe('shouldIgnoreTerminalEvent', () => {
it('returns false for non app-server mode', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: false,
eventTurnId: null,
currentTurnId: 'turn-1',
turnInFlight: true
});
expect(ignored).toBe(false);
});
it('ignores terminal events without turn_id when current turn id exists', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: null,
currentTurnId: 'turn-1',
turnInFlight: true
});
expect(ignored).toBe(true);
});
it('ignores terminal events without turn_id while a turn is still in flight', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: null,
currentTurnId: null,
turnInFlight: true
});
expect(ignored).toBe(true);
});
it('accepts terminal events without turn_id when anonymous terminal is explicitly allowed', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: null,
currentTurnId: null,
turnInFlight: true,
allowAnonymousTerminalEvent: true
});
expect(ignored).toBe(false);
});
it('still ignores terminal events without turn_id when current turn id exists', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: null,
currentTurnId: 'turn-1',
turnInFlight: true,
allowAnonymousTerminalEvent: true
});
expect(ignored).toBe(true);
});
it('ignores stale terminal events from another turn', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: 'turn-old',
currentTurnId: 'turn-current',
turnInFlight: true
});
expect(ignored).toBe(true);
});
it('accepts terminal events that match the current turn id', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: 'turn-current',
currentTurnId: 'turn-current',
turnInFlight: true
});
expect(ignored).toBe(false);
});
it('accepts terminal events without turn_id when no turn is active', () => {
const ignored = shouldIgnoreTerminalEvent({
useAppServer: true,
eventTurnId: null,
currentTurnId: null,
turnInFlight: false
});
expect(ignored).toBe(false);
});
});