Fix MCP abort test hang
This commit is contained in:
@@ -844,6 +844,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
|
||||
let durationMs = 0;
|
||||
let sawSleepCommand = false;
|
||||
let interruptIssued = false;
|
||||
let interruptTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
try {
|
||||
session = await client.createSession(config);
|
||||
@@ -854,6 +855,12 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
|
||||
|
||||
runStartedAt = Date.now();
|
||||
const stream = session.stream(prompt);
|
||||
interruptTimer = setTimeout(() => {
|
||||
if (!interruptIssued) {
|
||||
interruptIssued = true;
|
||||
void session?.interrupt();
|
||||
}
|
||||
}, 10_000);
|
||||
|
||||
for await (const event of stream) {
|
||||
if (event.type === "permission_requested" && session) {
|
||||
@@ -870,6 +877,10 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
|
||||
sawSleepCommand = true;
|
||||
if (!interruptIssued) {
|
||||
interruptIssued = true;
|
||||
if (interruptTimer) {
|
||||
clearTimeout(interruptTimer);
|
||||
interruptTimer = null;
|
||||
}
|
||||
await session.interrupt();
|
||||
}
|
||||
}
|
||||
@@ -887,6 +898,10 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
|
||||
if (durationMs === 0 && runStartedAt !== null) {
|
||||
durationMs = Date.now() - runStartedAt;
|
||||
}
|
||||
if (interruptTimer) {
|
||||
clearTimeout(interruptTimer);
|
||||
interruptTimer = null;
|
||||
}
|
||||
await session?.close();
|
||||
rmSync(cwd, { recursive: true, force: true });
|
||||
restoreSessionDir();
|
||||
|
||||
@@ -93,11 +93,11 @@ const MODE_PRESETS: Record<
|
||||
{ approvalPolicy: string; sandbox: string }
|
||||
> = {
|
||||
"read-only": {
|
||||
approvalPolicy: "untrusted",
|
||||
approvalPolicy: "on-request",
|
||||
sandbox: "read-only",
|
||||
},
|
||||
auto: {
|
||||
approvalPolicy: "untrusted",
|
||||
approvalPolicy: "on-request",
|
||||
sandbox: "workspace-write",
|
||||
},
|
||||
"full-access": {
|
||||
@@ -510,6 +510,19 @@ class CodexMcpAgentSession implements AgentSession {
|
||||
|
||||
async interrupt(): Promise<void> {
|
||||
this.currentAbortController?.abort();
|
||||
if (
|
||||
this.eventQueue &&
|
||||
this.turnState &&
|
||||
!this.turnState.completed &&
|
||||
!this.turnState.failed
|
||||
) {
|
||||
this.emitEvent({
|
||||
type: "turn_failed",
|
||||
provider: "codex-mcp",
|
||||
error: "Codex MCP turn interrupted",
|
||||
});
|
||||
this.eventQueue.end();
|
||||
}
|
||||
}
|
||||
|
||||
async *streamHistory(): AsyncGenerator<AgentStreamEvent> {
|
||||
|
||||
Reference in New Issue
Block a user