fix(codex-quota): guard feature label type in quota windows (#1346)

This commit is contained in:
Kai (Tam Nhu) Tran
2026-05-23 16:55:55 -04:00
committed by GitHub
parent 66966f3527
commit b71fe5dd6e
4 changed files with 32 additions and 3 deletions
@@ -342,6 +342,26 @@ describe('Codex Quota Fetcher', () => {
expect(windows.find((w) => w.category === 'additional')).toBeUndefined();
});
it('should coerce non-string additional limit_name values to fallback label', () => {
const response = {
additional_rate_limits: [
{
limit_name: { unexpected: true },
rate_limit: {
primary_window: { used_percent: 10, reset_after_seconds: 3600 },
},
},
],
};
const windows = buildCodexQuotaWindows(response as never);
expect(windows).toHaveLength(1);
expect(windows[0].category).toBe('additional');
expect(windows[0].featureLabel).toBe('Additional');
expect(windows[0].label).toBe('Additional (Primary)');
});
it('should accept camelCase additionalRateLimits and rateLimit fields', () => {
const response = {
additionalRateLimits: [
+5 -1
View File
@@ -380,7 +380,11 @@ function buildCodexQuotaWindows(payload: CodexUsageResponse): CodexQuotaWindow[]
const entryRateLimit = entry.rate_limit || entry.rateLimit;
if (!entryRateLimit) continue;
const featureLabel = entry.limit_name || entry.limitName || 'Additional';
const rawFeatureLabel = entry.limit_name ?? entry.limitName;
const featureLabel =
typeof rawFeatureLabel === 'string' && rawFeatureLabel.trim().length > 0
? rawFeatureLabel.trim()
: 'Additional';
addWindow(
`${featureLabel} (Primary)`,
entryRateLimit.primary_window || entryRateLimit.primaryWindow,