mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:10:44 +00:00
test: avoid argv warmup race
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user