mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:50:43 +00:00
test: route acp runtime tests through fast lane
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user