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:
@@ -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(() => ({})),
|
||||
},
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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(() => ({})),
|
||||
},
|
||||
|
||||
@@ -375,7 +375,7 @@ export async function runDaemon(opts: DaemonOptions = {}) {
|
||||
const authStorage = AuthStorage.create(getFusionAuthPath());
|
||||
const legacyAuthStorage = createReadOnlyAuthFileStorage(getLegacyAuthPaths());
|
||||
const mergedAuthStorage = mergeAuthStorageReads(authStorage, [legacyAuthStorage]);
|
||||
const modelRegistry = new ModelRegistry(mergedAuthStorage, getModelRegistryModelsPath());
|
||||
const modelRegistry = ModelRegistry.create(mergedAuthStorage, getModelRegistryModelsPath());
|
||||
const dashboardAuthStorage = wrapAuthStorageWithApiKeyProviders(mergedAuthStorage, modelRegistry);
|
||||
|
||||
// PackageManager may be used for skills adapter even if extension loading fails
|
||||
|
||||
@@ -656,7 +656,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(() => ({})),
|
||||
},
|
||||
@@ -2683,7 +2686,7 @@ describe("runDashboard — merge stream sink routing", () => {
|
||||
(DefaultPackageManager as unknown as ReturnType<typeof vi.fn>).mockImplementation(() => ({
|
||||
resolve: vi.fn().mockResolvedValue({ extensions: [] }),
|
||||
}));
|
||||
(ModelRegistry as unknown as ReturnType<typeof vi.fn>).mockImplementation(() => ({
|
||||
(ModelRegistry.create as unknown as ReturnType<typeof vi.fn>).mockImplementation(() => ({
|
||||
registerProvider: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
}));
|
||||
|
||||
@@ -744,7 +744,7 @@ export async function runDashboard(port: number, opts: { paused?: boolean; dev?:
|
||||
const authStorage = AuthStorage.create(getFusionAuthPath());
|
||||
const legacyAuthStorage = createReadOnlyAuthFileStorage(getLegacyAuthPaths());
|
||||
const mergedAuthStorage = mergeAuthStorageReads(authStorage, [legacyAuthStorage]);
|
||||
const modelRegistry = new ModelRegistry(mergedAuthStorage, getModelRegistryModelsPath());
|
||||
const modelRegistry = ModelRegistry.create(mergedAuthStorage, getModelRegistryModelsPath());
|
||||
const dashboardAuthStorage = wrapAuthStorageWithApiKeyProviders(mergedAuthStorage, modelRegistry);
|
||||
|
||||
// PackageManager may be used for skills adapter even if extension loading fails
|
||||
|
||||
@@ -429,7 +429,7 @@ export async function runServe(
|
||||
const authStorage = AuthStorage.create(getFusionAuthPath());
|
||||
const legacyAuthStorage = createReadOnlyAuthFileStorage(getLegacyAuthPaths());
|
||||
const mergedAuthStorage = mergeAuthStorageReads(authStorage, [legacyAuthStorage]);
|
||||
const modelRegistry = new ModelRegistry(mergedAuthStorage, getModelRegistryModelsPath());
|
||||
const modelRegistry = ModelRegistry.create(mergedAuthStorage, getModelRegistryModelsPath());
|
||||
const dashboardAuthStorage = wrapAuthStorageWithApiKeyProviders(mergedAuthStorage, modelRegistry);
|
||||
|
||||
// PackageManager may be used for skills adapter even if extension loading fails
|
||||
|
||||
@@ -514,14 +514,14 @@ export class TaskExecutor {
|
||||
private totalSpawnedCount = 0;
|
||||
/** Token cap detector for proactive context compaction. */
|
||||
private tokenCapDetector = new TokenCapDetector();
|
||||
private _modelRegistry?: InstanceType<typeof ModelRegistry>;
|
||||
private _modelRegistry?: ModelRegistry;
|
||||
/** Current run context for mutation correlation. Set at execute() start, cleared in finally. */
|
||||
private currentRunContext: RunMutationContext | undefined;
|
||||
|
||||
private get modelRegistry(): InstanceType<typeof ModelRegistry> {
|
||||
private get modelRegistry(): ModelRegistry {
|
||||
if (!this._modelRegistry) {
|
||||
const authStorage = createFusionAuthStorage();
|
||||
this._modelRegistry = new ModelRegistry(authStorage, getModelRegistryModelsPath());
|
||||
this._modelRegistry = ModelRegistry.create(authStorage, getModelRegistryModelsPath());
|
||||
this._modelRegistry.refresh();
|
||||
}
|
||||
return this._modelRegistry;
|
||||
|
||||
@@ -674,7 +674,7 @@ export function wrapToolsWithBoundary(
|
||||
export async function createFnAgent(options: AgentOptions): Promise<AgentResult> {
|
||||
piLog.log(`createFnAgent called (cwd=${options.cwd}, tools=${options.tools}, provider=${options.defaultProvider}, model=${options.defaultModelId})`);
|
||||
const authStorage = createFusionAuthStorage();
|
||||
const modelRegistry = new ModelRegistry(authStorage, getModelRegistryModelsPath());
|
||||
const modelRegistry = ModelRegistry.create(authStorage, getModelRegistryModelsPath());
|
||||
await registerExtensionProviders(options.cwd, modelRegistry);
|
||||
|
||||
const tools =
|
||||
|
||||
Reference in New Issue
Block a user