From 4e6c0965cb3761a401979aaefa856f95a409fb01 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 28 Apr 2026 07:17:02 +0100 Subject: [PATCH] test: route acp runtime tests through fast lane --- src/acp/control-plane/runtime-cache.test.ts | 45 ++++++++++----------- src/acp/runtime/registry.test.ts | 26 +++++++----- test/vitest-unit-fast-config.test.ts | 2 + 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/acp/control-plane/runtime-cache.test.ts b/src/acp/control-plane/runtime-cache.test.ts index ea0aa2f7124..51cc20db610 100644 --- a/src/acp/control-plane/runtime-cache.test.ts +++ b/src/acp/control-plane/runtime-cache.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; import type { AcpRuntime } from "../runtime/types.js"; import type { AcpRuntimeHandle } from "../runtime/types.js"; import type { CachedRuntimeState } from "./runtime-cache.js"; @@ -6,17 +6,19 @@ import { RuntimeCache } from "./runtime-cache.js"; function mockState(sessionKey: string): CachedRuntimeState { const runtime = { - ensureSession: vi.fn(async () => ({ - sessionKey, - backend: "acpx", - runtimeSessionName: `runtime:${sessionKey}`, - })), - runTurn: vi.fn(async function* () { + async ensureSession() { + return { + sessionKey, + backend: "acpx", + runtimeSessionName: `runtime:${sessionKey}`, + }; + }, + async *runTurn() { yield { type: "done" as const }; - }), - cancel: vi.fn(async () => {}), - close: vi.fn(async () => {}), - } as unknown as AcpRuntime; + }, + async cancel() {}, + async close() {}, + } satisfies AcpRuntime; return { runtime, handle: { @@ -32,21 +34,16 @@ function mockState(sessionKey: string): CachedRuntimeState { describe("RuntimeCache", () => { it("tracks idle candidates with touch-aware lookups", () => { - vi.useFakeTimers(); - try { - const cache = new RuntimeCache(); - const actor = "agent:codex:acp:s1"; - cache.set(actor, mockState(actor), { now: 1_000 }); + const cache = new RuntimeCache(); + const actor = "agent:codex:acp:s1"; + cache.set(actor, mockState(actor), { now: 1_000 }); - expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 1_999 })).toHaveLength(0); - expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 2_000 })).toHaveLength(1); + expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 1_999 })).toHaveLength(0); + expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 2_000 })).toHaveLength(1); - cache.get(actor, { now: 2_500 }); - expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_200 })).toHaveLength(0); - expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_500 })).toHaveLength(1); - } finally { - vi.useRealTimers(); - } + cache.get(actor, { now: 2_500 }); + expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_200 })).toHaveLength(0); + expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_500 })).toHaveLength(1); }); it("returns snapshot entries with idle durations", () => { diff --git a/src/acp/runtime/registry.test.ts b/src/acp/runtime/registry.test.ts index 1115a543267..95cb9e71b8c 100644 --- a/src/acp/runtime/registry.test.ts +++ b/src/acp/runtime/registry.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { AcpRuntimeError } from "./errors.js"; import { __testing, @@ -11,16 +11,18 @@ import type { AcpRuntime } from "./types.js"; function createRuntimeStub(): AcpRuntime { return { - ensureSession: vi.fn(async (input) => ({ - sessionKey: input.sessionKey, - backend: "stub", - runtimeSessionName: `${input.sessionKey}:runtime`, - })), - runTurn: vi.fn(async function* () { + async ensureSession(input) { + return { + sessionKey: input.sessionKey, + backend: "stub", + runtimeSessionName: `${input.sessionKey}:runtime`, + }; + }, + async *runTurn() { // no-op stream - }), - cancel: vi.fn(async () => {}), - close: vi.fn(async () => {}), + }, + async cancel() {}, + async close() {}, }; } @@ -29,6 +31,10 @@ describe("acp runtime registry", () => { __testing.resetAcpRuntimeBackendsForTests(); }); + afterEach(() => { + __testing.resetAcpRuntimeBackendsForTests(); + }); + it("registers and resolves backends by id", () => { const runtime = createRuntimeStub(); registerAcpRuntimeBackend({ id: "acpx", runtime }); diff --git a/test/vitest-unit-fast-config.test.ts b/test/vitest-unit-fast-config.test.ts index a0eace01585..4073c185979 100644 --- a/test/vitest-unit-fast-config.test.ts +++ b/test/vitest-unit-fast-config.test.ts @@ -23,6 +23,8 @@ describe("unit-fast vitest lane", () => { expect(config.test?.include).toContain( "src/agents/pi-tools.deferred-followup-guidance.test.ts", ); + expect(config.test?.include).toContain("src/acp/control-plane/runtime-cache.test.ts"); + expect(config.test?.include).toContain("src/acp/runtime/registry.test.ts"); expect(config.test?.include).toContain("src/commands/status-overview-values.test.ts"); expect(config.test?.include).toContain("src/plugins/config-policy.test.ts"); expect(config.test?.include).toContain("src/plugin-sdk/provider-entry.test.ts");