mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 23:02:02 +03:00
perf(test): lighten models list e2e registry mock
This commit is contained in:
@@ -50,41 +50,34 @@ vi.mock("../agents/model-auth.js", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@mariozechner/pi-coding-agent", async () => {
|
vi.mock("@mariozechner/pi-coding-agent", async () => {
|
||||||
const actual = await vi.importActual<typeof import("@mariozechner/pi-coding-agent")>(
|
|
||||||
"@mariozechner/pi-coding-agent",
|
|
||||||
);
|
|
||||||
|
|
||||||
class MockAuthStorage {}
|
class MockAuthStorage {}
|
||||||
|
|
||||||
class MockModelRegistry {
|
class MockModelRegistry {
|
||||||
find(provider: string, id: string): ReturnType<typeof actual.ModelRegistry.prototype.find> {
|
find(provider: string, id: string) {
|
||||||
const found =
|
const found =
|
||||||
modelRegistryState.models.find((model) => model.provider === provider && model.id === id) ??
|
modelRegistryState.models.find((model) => model.provider === provider && model.id === id) ??
|
||||||
null;
|
null;
|
||||||
return found as ReturnType<typeof actual.ModelRegistry.prototype.find>;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll(): ReturnType<typeof actual.ModelRegistry.prototype.getAll> {
|
getAll() {
|
||||||
if (modelRegistryState.getAllError !== undefined) {
|
if (modelRegistryState.getAllError !== undefined) {
|
||||||
throw modelRegistryState.getAllError;
|
throw modelRegistryState.getAllError;
|
||||||
}
|
}
|
||||||
return modelRegistryState.models as ReturnType<typeof actual.ModelRegistry.prototype.getAll>;
|
return modelRegistryState.models;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAvailable(): ReturnType<typeof actual.ModelRegistry.prototype.getAvailable> {
|
getAvailable() {
|
||||||
if (modelRegistryState.getAvailableError !== undefined) {
|
if (modelRegistryState.getAvailableError !== undefined) {
|
||||||
throw modelRegistryState.getAvailableError;
|
throw modelRegistryState.getAvailableError;
|
||||||
}
|
}
|
||||||
return modelRegistryState.available as ReturnType<
|
return modelRegistryState.available;
|
||||||
typeof actual.ModelRegistry.prototype.getAvailable
|
|
||||||
>;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...actual,
|
AuthStorage: MockAuthStorage,
|
||||||
AuthStorage: MockAuthStorage as unknown as typeof actual.AuthStorage,
|
ModelRegistry: MockModelRegistry,
|
||||||
ModelRegistry: MockModelRegistry as unknown as typeof actual.ModelRegistry,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user