diff --git a/src/agents/context.lookup.test.ts b/src/agents/context.lookup.test.ts index 1bf9341e2b7..32863184e27 100644 --- a/src/agents/context.lookup.test.ts +++ b/src/agents/context.lookup.test.ts @@ -196,40 +196,26 @@ describe("lookupContextTokens", () => { }); it("only warms eagerly for real openclaw startup commands that need model metadata", async () => { - const argvSnapshot = process.argv; - try { - for (const scenario of [ - { - argv: ["node", "openclaw", "chat"], - expectedCalls: 1, - }, - { - argv: ["node", "openclaw", "--profile", "--", "config", "validate"], - expectedCalls: 0, - }, - { - argv: ["node", "openclaw", "logs", "--limit", "5"], - expectedCalls: 0, - }, - { - argv: ["node", "openclaw", "status", "--json"], - expectedCalls: 0, - }, - { - argv: ["node", "scripts/test-built-plugin-singleton.mjs"], - expectedCalls: 0, - }, - ]) { - const loadConfigMock = vi.fn(() => ({ models: {} })); - const { ensureOpenClawModelsJson } = mockContextModuleDeps(loadConfigMock); - process.argv = scenario.argv; - await importFreshContextModule(); - expect(loadConfigMock).toHaveBeenCalledTimes(scenario.expectedCalls); - expect(ensureOpenClawModelsJson).toHaveBeenCalledTimes(scenario.expectedCalls); - } - } finally { - process.argv = argvSnapshot; - } + const { shouldEagerWarmContextWindowCache } = await importContextModule(); + + expect(shouldEagerWarmContextWindowCache(["node", "openclaw", "chat"])).toBe(true); + expect( + shouldEagerWarmContextWindowCache([ + "node", + "openclaw", + "--profile", + "--", + "config", + "validate", + ]), + ).toBe(false); + expect(shouldEagerWarmContextWindowCache(["node", "openclaw", "logs", "--limit", "5"])).toBe( + false, + ); + expect(shouldEagerWarmContextWindowCache(["node", "openclaw", "status", "--json"])).toBe(false); + expect( + shouldEagerWarmContextWindowCache(["node", "scripts/test-built-plugin-singleton.mjs"]), + ).toBe(false); }); it("retries config loading after backoff when an initial load fails", async () => { diff --git a/src/agents/context.ts b/src/agents/context.ts index 3ad6f564d44..59715f0e536 100644 --- a/src/agents/context.ts +++ b/src/agents/context.ts @@ -149,7 +149,7 @@ const SKIP_EAGER_WARMUP_PRIMARY_COMMANDS = new Set([ "webhooks", ]); -function shouldEagerWarmContextWindowCache(argv: string[] = process.argv): boolean { +export function shouldEagerWarmContextWindowCache(argv: string[] = process.argv): boolean { // Keep this gate tied to the real OpenClaw CLI entrypoints. // // This module can also land inside shared dist chunks that are imported from