mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:40: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 { AcpRuntime } from "../runtime/types.js";
|
||||||
import type { AcpRuntimeHandle } from "../runtime/types.js";
|
import type { AcpRuntimeHandle } from "../runtime/types.js";
|
||||||
import type { CachedRuntimeState } from "./runtime-cache.js";
|
import type { CachedRuntimeState } from "./runtime-cache.js";
|
||||||
@@ -6,17 +6,19 @@ import { RuntimeCache } from "./runtime-cache.js";
|
|||||||
|
|
||||||
function mockState(sessionKey: string): CachedRuntimeState {
|
function mockState(sessionKey: string): CachedRuntimeState {
|
||||||
const runtime = {
|
const runtime = {
|
||||||
ensureSession: vi.fn(async () => ({
|
async ensureSession() {
|
||||||
sessionKey,
|
return {
|
||||||
backend: "acpx",
|
sessionKey,
|
||||||
runtimeSessionName: `runtime:${sessionKey}`,
|
backend: "acpx",
|
||||||
})),
|
runtimeSessionName: `runtime:${sessionKey}`,
|
||||||
runTurn: vi.fn(async function* () {
|
};
|
||||||
|
},
|
||||||
|
async *runTurn() {
|
||||||
yield { type: "done" as const };
|
yield { type: "done" as const };
|
||||||
}),
|
},
|
||||||
cancel: vi.fn(async () => {}),
|
async cancel() {},
|
||||||
close: vi.fn(async () => {}),
|
async close() {},
|
||||||
} as unknown as AcpRuntime;
|
} satisfies AcpRuntime;
|
||||||
return {
|
return {
|
||||||
runtime,
|
runtime,
|
||||||
handle: {
|
handle: {
|
||||||
@@ -32,21 +34,16 @@ function mockState(sessionKey: string): CachedRuntimeState {
|
|||||||
|
|
||||||
describe("RuntimeCache", () => {
|
describe("RuntimeCache", () => {
|
||||||
it("tracks idle candidates with touch-aware lookups", () => {
|
it("tracks idle candidates with touch-aware lookups", () => {
|
||||||
vi.useFakeTimers();
|
const cache = new RuntimeCache();
|
||||||
try {
|
const actor = "agent:codex:acp:s1";
|
||||||
const cache = new RuntimeCache();
|
cache.set(actor, mockState(actor), { now: 1_000 });
|
||||||
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: 1_999 })).toHaveLength(0);
|
||||||
expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 2_000 })).toHaveLength(1);
|
expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 2_000 })).toHaveLength(1);
|
||||||
|
|
||||||
cache.get(actor, { now: 2_500 });
|
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_200 })).toHaveLength(0);
|
||||||
expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_500 })).toHaveLength(1);
|
expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_500 })).toHaveLength(1);
|
||||||
} finally {
|
|
||||||
vi.useRealTimers();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns snapshot entries with idle durations", () => {
|
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 { AcpRuntimeError } from "./errors.js";
|
||||||
import {
|
import {
|
||||||
__testing,
|
__testing,
|
||||||
@@ -11,16 +11,18 @@ import type { AcpRuntime } from "./types.js";
|
|||||||
|
|
||||||
function createRuntimeStub(): AcpRuntime {
|
function createRuntimeStub(): AcpRuntime {
|
||||||
return {
|
return {
|
||||||
ensureSession: vi.fn(async (input) => ({
|
async ensureSession(input) {
|
||||||
sessionKey: input.sessionKey,
|
return {
|
||||||
backend: "stub",
|
sessionKey: input.sessionKey,
|
||||||
runtimeSessionName: `${input.sessionKey}:runtime`,
|
backend: "stub",
|
||||||
})),
|
runtimeSessionName: `${input.sessionKey}:runtime`,
|
||||||
runTurn: vi.fn(async function* () {
|
};
|
||||||
|
},
|
||||||
|
async *runTurn() {
|
||||||
// no-op stream
|
// no-op stream
|
||||||
}),
|
},
|
||||||
cancel: vi.fn(async () => {}),
|
async cancel() {},
|
||||||
close: vi.fn(async () => {}),
|
async close() {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +31,10 @@ describe("acp runtime registry", () => {
|
|||||||
__testing.resetAcpRuntimeBackendsForTests();
|
__testing.resetAcpRuntimeBackendsForTests();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
__testing.resetAcpRuntimeBackendsForTests();
|
||||||
|
});
|
||||||
|
|
||||||
it("registers and resolves backends by id", () => {
|
it("registers and resolves backends by id", () => {
|
||||||
const runtime = createRuntimeStub();
|
const runtime = createRuntimeStub();
|
||||||
registerAcpRuntimeBackend({ id: "acpx", runtime });
|
registerAcpRuntimeBackend({ id: "acpx", runtime });
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ describe("unit-fast vitest lane", () => {
|
|||||||
expect(config.test?.include).toContain(
|
expect(config.test?.include).toContain(
|
||||||
"src/agents/pi-tools.deferred-followup-guidance.test.ts",
|
"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/commands/status-overview-values.test.ts");
|
||||||
expect(config.test?.include).toContain("src/plugins/config-policy.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");
|
expect(config.test?.include).toContain("src/plugin-sdk/provider-entry.test.ts");
|
||||||
|
|||||||
Reference in New Issue
Block a user