fix(models-dev): sanitize models.dev registry entries and harden pricing resolver (#1345)

* fix(models-dev): sanitize cached model entries before pricing lookup

* style: apply prettier formatting
This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-05-23 17:03:49 -04:00
1 parent e2ef66d7d6
commit 9cd9b796ca
4 files changed
+65 -5

No files matched your search

+17
View File
@@ -467,5 +467,22 @@ describe('model-pricing', () => {
expect(calculateCost(usage, 'gpt-5.5', { provider: 'openai' })).toBe(35.5);
expect(calculateCost(usage, 'gpt-5.5', { provider: 'ghcp' })).toBe(0);
});
it('gracefully ignores malformed cached model entries', () => {
setCachedModelsDevRegistry(
{
openai: {
id: 'openai',
models: {
'null-entry': null,
'gpt-5.5': { id: 'gpt-5.5', cost: { input: 5, output: 30 } },
},
},
} as unknown as Parameters<typeof setCachedModelsDevRegistry>[0]
);
expect(() => getModelPricing('openai/gpt-5.5')).not.toThrow();
expect(getModelPricing('openai/gpt-5.5').inputPerMillion).toBe(5);
});
});
});