From eee940c1c38cf5e672563aaa7c9be15419bd2fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Ara=C3=BAjo?= Date: Tue, 21 Jul 2026 23:29:13 -0300 Subject: [PATCH] test(agent): avoid global pause gate spy --- packages/agent/test/pause-gate.test.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/agent/test/pause-gate.test.ts b/packages/agent/test/pause-gate.test.ts index fffc15e16..24c2e87f6 100644 --- a/packages/agent/test/pause-gate.test.ts +++ b/packages/agent/test/pause-gate.test.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it, vi } from "bun:test"; +import { afterEach, describe, expect, it } from "bun:test"; import { agentLoop, agentPauseGate } from "@oh-my-pi/pi-agent-core"; import type { AgentContext, AgentLoopConfig, AgentMessage, AgentTool } from "@oh-my-pi/pi-agent-core/types"; import type { Message } from "@oh-my-pi/pi-ai"; @@ -29,7 +29,6 @@ describe("agentPauseGate", () => { afterEach(() => { // The gate is process-global: never leak an engaged pause into other files. agentPauseGate.resume(); - vi.restoreAllMocks(); }); it("holds the next model call while paused and releases it on resume", async () => { @@ -66,14 +65,11 @@ describe("agentPauseGate", () => { const context: AgentContext = { systemPrompt: ["Test"], messages: [], tools: [makeEchoTool(executed)] }; const config: AgentLoopConfig = { model: mock.model, convertToLlm: identityConverter }; - const toolBoundary = Promise.withResolvers(); - const waitUntilResumed = agentPauseGate.waitUntilResumed.bind(agentPauseGate); - vi.spyOn(agentPauseGate, "waitUntilResumed").mockImplementation(signal => { - toolBoundary.resolve(); - return waitUntilResumed(signal); - }); + // Let queued microtasks consume the scripted tool response. This verifies the + // observable contract without a process-global spy that sibling test files can + // restore while this turn is suspended. const result = agentLoop([createUserMessage("run echo")], context, config, undefined, mock.stream).result(); - await toolBoundary.promise; + for (let tick = 0; tick < 10; tick++) await Promise.resolve(); expect(executed).toEqual([]); // tool parked, not started expect(mock.calls.length).toBe(1); // and no follow-up model call either