Skip to content

Commit cf2d4fe

Browse files
committed
fix(doctor): validate provider catalog model iteration
1 parent e5136d2 commit cf2d4fe

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

‎src/flows/doctor-core-checks.runtime.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,45 @@ describe("doctor provider catalog projection checks", () => {
691691
);
692692
});
693693

694+
it("reports provider catalog model lists with invalid iterators", async () => {
695+
const models = [{ id: "mock-model" }];
696+
Object.defineProperty(models, Symbol.iterator, {
697+
value: () => {
698+
throw new Error("model iterator failed");
699+
},
700+
});
701+
mocks.resolvePluginProviders.mockReturnValueOnce([
702+
{
703+
id: "mockplugin",
704+
pluginId: "mockplugin",
705+
label: "Mock",
706+
auth: [],
707+
staticCatalog: {
708+
order: "simple",
709+
run: async () => ({
710+
provider: {
711+
api: "openai-completions" as const,
712+
baseUrl: "https://mockplugin.test/v1",
713+
models,
714+
},
715+
}),
716+
},
717+
},
718+
]);
719+
720+
await expect(collectProviderCatalogProjectionFindings({})).resolves.toContainEqual(
721+
expect.objectContaining({
722+
checkId: "core/doctor/provider-catalog-projection",
723+
severity: "error",
724+
path: "plugins.entries.mockplugin",
725+
target: "mockplugin",
726+
message:
727+
"Provider catalog mockplugin model rows cannot be enumerated during doctor validation.",
728+
requirement: "model iterator failed",
729+
}),
730+
);
731+
});
732+
694733
it("reports provider catalog results without provider containers", async () => {
695734
mocks.resolvePluginProviders.mockReturnValueOnce([
696735
{

‎src/flows/doctor-core-checks.runtime.ts‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,14 @@ function collectProviderCatalogModelFindings(params: {
158158
}),
159159
];
160160
}
161-
let indexes: number[];
161+
let modelEntries: Array<[number, unknown]>;
162162
try {
163-
indexes = [...models.keys()];
163+
modelEntries = [];
164+
let index = 0;
165+
for (const model of models) {
166+
modelEntries.push([index, model]);
167+
index += 1;
168+
}
164169
} catch (error) {
165170
return [
166171
providerCatalogProjectionFinding({
@@ -171,21 +176,7 @@ function collectProviderCatalogModelFindings(params: {
171176
}),
172177
];
173178
}
174-
for (const index of indexes) {
175-
let model: unknown;
176-
try {
177-
model = models[index];
178-
} catch (error) {
179-
findings.push(
180-
providerCatalogProjectionFinding({
181-
providerId: params.providerId,
182-
pluginId: params.pluginId,
183-
message: `Provider catalog ${params.providerId} model row ${index} cannot be read during doctor validation.`,
184-
error,
185-
}),
186-
);
187-
continue;
188-
}
179+
for (const [index, model] of modelEntries) {
189180
const modelId = readProviderCatalogValue({
190181
value: model,
191182
key: "id",

0 commit comments

Comments
 (0)