refactor: migrate to ModelRegistry.create factory

ModelRegistry's public constructor became private in pi-coding-agent 0.64.
Direct `new ModelRegistry(...)` calls no longer compile. Switch the five
production sites to the factory (`ModelRegistry.create`) and update the
four test modules that mocked the class as a constructor to now mock it
as an object with `create` and `inMemory` static methods.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-23 17:13:26 -07:00
parent d8a1158d40
commit 9cfd09c5d9
9 changed files with 27 additions and 14 deletions

View File

@@ -553,7 +553,10 @@ vi.mock("@mariozechner/pi-coding-agent", () => ({
DefaultPackageManager: vi.fn().mockImplementation(() => ({
resolve: vi.fn().mockResolvedValue({ extensions: [] }),
})),
ModelRegistry: vi.fn().mockImplementation(() => mocks.modelRegistry),
ModelRegistry: {
create: vi.fn(() => mocks.modelRegistry),
inMemory: vi.fn(() => mocks.modelRegistry),
},
SettingsManager: {
create: vi.fn(() => ({})),
},

View File

@@ -345,7 +345,10 @@ vi.mock("@mariozechner/pi-coding-agent", () => ({
DefaultPackageManager: vi.fn().mockImplementation(() => ({
resolve: vi.fn().mockResolvedValue({ extensions: [] }),
})),
ModelRegistry: vi.fn().mockImplementation(() => mockModelRegistry),
ModelRegistry: {
create: vi.fn(() => mockModelRegistry),
inMemory: vi.fn(() => mockModelRegistry),
},
SettingsManager: {
create: vi.fn(() => ({})),
},
@@ -459,8 +462,9 @@ describe("runDashboard — AuthStorage & ModelRegistry wiring", () => {
await runDashboard(0, {});
expect(ModelRegistry).toHaveBeenCalledTimes(1);
const registryAuthStorage = (ModelRegistry as ReturnType<typeof vi.fn>).mock.calls[0][0];
const createMock = ModelRegistry.create as unknown as ReturnType<typeof vi.fn>;
expect(createMock).toHaveBeenCalledTimes(1);
const registryAuthStorage = createMock.mock.calls[0][0];
expect(registryAuthStorage).not.toBe(mockAuthStorage);
expect(registryAuthStorage.getApiKey).toBeTypeOf("function");
});

View File

@@ -592,7 +592,10 @@ vi.mock("@mariozechner/pi-coding-agent", () => ({
DefaultPackageManager: vi.fn().mockImplementation(() => ({
resolve: vi.fn().mockResolvedValue({ extensions: [] }),
})),
ModelRegistry: vi.fn().mockImplementation(() => mocks.modelRegistry),
ModelRegistry: {
create: vi.fn(() => mocks.modelRegistry),
inMemory: vi.fn(() => mocks.modelRegistry),
},
SettingsManager: {
create: vi.fn(() => ({})),
},