mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 12:27:40 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
43
src/agents/model-catalog.test-harness.ts
Normal file
43
src/agents/model-catalog.test-harness.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { afterEach, beforeEach, vi } from "vitest";
|
||||
import { __setModelCatalogImportForTest, resetModelCatalogCacheForTest } from "./model-catalog.js";
|
||||
|
||||
export type PiSdkModule = typeof import("./pi-model-discovery.js");
|
||||
|
||||
vi.mock("./models-config.js", () => ({
|
||||
ensureOpenClawModelsJson: vi.fn().mockResolvedValue({ agentDir: "/tmp", wrote: false }),
|
||||
}));
|
||||
|
||||
vi.mock("./agent-paths.js", () => ({
|
||||
resolveOpenClawAgentDir: () => "/tmp/openclaw",
|
||||
}));
|
||||
|
||||
export function installModelCatalogTestHooks() {
|
||||
beforeEach(() => {
|
||||
resetModelCatalogCacheForTest();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
__setModelCatalogImportForTest();
|
||||
resetModelCatalogCacheForTest();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
}
|
||||
|
||||
export function mockCatalogImportFailThenRecover() {
|
||||
let call = 0;
|
||||
__setModelCatalogImportForTest(async () => {
|
||||
call += 1;
|
||||
if (call === 1) {
|
||||
throw new Error("boom");
|
||||
}
|
||||
return {
|
||||
AuthStorage: class {},
|
||||
ModelRegistry: class {
|
||||
getAll() {
|
||||
return [{ id: "gpt-4.1", name: "GPT-4.1", provider: "openai" }];
|
||||
}
|
||||
},
|
||||
} as unknown as PiSdkModule;
|
||||
});
|
||||
return () => call;
|
||||
}
|
||||
Reference in New Issue
Block a user