diff --git a/server/src/__tests__/agent-live-run-routes.test.ts b/server/src/__tests__/agent-live-run-routes.test.ts index 1dedcddc243..67daeba44c8 100644 --- a/server/src/__tests__/agent-live-run-routes.test.ts +++ b/server/src/__tests__/agent-live-run-routes.test.ts @@ -157,6 +157,9 @@ function registerModuleMocks() { })); } +let agentRoutes: typeof import("../routes/agents.js")["agentRoutes"]; +let errorHandler: typeof import("../middleware/index.js")["errorHandler"]; + async function createApp( db: Record = {}, actor: Record = { @@ -168,15 +171,6 @@ async function createApp( }, options: { chatRunRetries?: typeof mockChatRunRetries } = {}, ) { - // Vitest tracks factory-mock resolution in one shared call stack. Importing - // these graphs concurrently can drop the services/index factory mock and - // accidentally run real DB-backed activity logging against this test stub. - const { agentRoutes } = await vi.importActual< - typeof import("../routes/agents.js") - >("../routes/agents.js"); - const { errorHandler } = await vi.importActual< - typeof import("../middleware/index.js") - >("../middleware/index.js"); const app = express(); app.use(express.json()); app.use((req, _res, next) => { @@ -291,7 +285,7 @@ describe("agent live run routes", () => { limit, { summary: query.includes("summary=true") }); expect(mockRunSecretRedactionRegistry.redactForRuns).toHaveBeenCalled(); }); - beforeEach(() => { + beforeEach(async () => { vi.resetModules(); vi.doUnmock("../services/agents.js"); vi.doUnmock("../services/heartbeat.js"); @@ -424,6 +418,17 @@ describe("agent live run routes", () => { skipped: 0, skipReasons: [], }); + + // Module loading is fixture setup; each behavioral case keeps its own timeout. + // Vitest tracks factory-mock resolution in one shared call stack. Importing + // these graphs concurrently can drop the services/index factory mock and + // accidentally run real DB-backed activity logging against this test stub. + ({ agentRoutes } = await vi.importActual< + typeof import("../routes/agents.js") + >("../routes/agents.js")); + ({ errorHandler } = await vi.importActual< + typeof import("../middleware/index.js") + >("../middleware/index.js")); }); describe("heartbeat run ID validation", () => {