test: avoid argv warmup race

This commit is contained in:
Peter Steinberger
2026-04-22 22:42:35 +01:00
parent 2e13f224d6
commit 207d7303b7
2 changed files with 21 additions and 35 deletions

View File

@@ -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 () => {

View File

@@ -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