























@@ -1,22 +1,24 @@
1-import { describe, expect, it, vi } from "vitest";
1+import { describe, expect, it } from "vitest";
22import type { AcpRuntime } from "../runtime/types.js";
33import type { AcpRuntimeHandle } from "../runtime/types.js";
44import type { CachedRuntimeState } from "./runtime-cache.js";
55import { RuntimeCache } from "./runtime-cache.js";
6677function mockState(sessionKey: string): CachedRuntimeState {
88const runtime = {
9-ensureSession: vi.fn(async () => ({
10- sessionKey,
11-backend: "acpx",
12-runtimeSessionName: `runtime:${sessionKey}`,
13-})),
14-runTurn: vi.fn(async function* () {
9+async ensureSession() {
10+return {
11+ sessionKey,
12+backend: "acpx",
13+runtimeSessionName: `runtime:${sessionKey}`,
14+};
15+},
16+async *runTurn() {
1517yield { type: "done" as const };
16-}),
17-cancel: vi.fn(async () => {}),
18-close: vi.fn(async () => {}),
19-} as unknown as AcpRuntime;
18+},
19+async cancel() {},
20+async close() {},
21+} satisfies AcpRuntime;
2022return {
2123 runtime,
2224handle: {
@@ -32,21 +34,16 @@ function mockState(sessionKey: string): CachedRuntimeState {
32343335describe("RuntimeCache", () => {
3436it("tracks idle candidates with touch-aware lookups", () => {
35-vi.useFakeTimers();
36-try {
37-const cache = new RuntimeCache();
38-const actor = "agent:codex:acp:s1";
39-cache.set(actor, mockState(actor), { now: 1_000 });
37+const cache = new RuntimeCache();
38+const actor = "agent:codex:acp:s1";
39+cache.set(actor, mockState(actor), { now: 1_000 });
404041- expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 1_999 })).toHaveLength(0);
42- expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 2_000 })).toHaveLength(1);
41+expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 1_999 })).toHaveLength(0);
42+expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 2_000 })).toHaveLength(1);
434344-cache.get(actor, { now: 2_500 });
45-expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_200 })).toHaveLength(0);
46-expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_500 })).toHaveLength(1);
47-} finally {
48-vi.useRealTimers();
49-}
44+cache.get(actor, { now: 2_500 });
45+expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_200 })).toHaveLength(0);
46+expect(cache.collectIdleCandidates({ maxIdleMs: 1_000, now: 3_500 })).toHaveLength(1);
5047});
51485249it("returns snapshot entries with idle durations", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。