mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-15 20:20:09 +00:00
fix(codex-quota): guard feature label type in quota windows (#1346)
This commit is contained in:
@@ -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: [
|
||||
|
||||
@@ -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,
|
||||
|
||||
+2
-2
@@ -384,8 +384,8 @@ function getCodexWindowKindFromLabel(label: string): CodexWindowKind {
|
||||
* "OmniReview" -> "OmniReview"
|
||||
* "" -> ""
|
||||
*/
|
||||
export function prettifyCodexFeatureLabel(featureLabel: string): string {
|
||||
const trimmed = (featureLabel || '').trim();
|
||||
export function prettifyCodexFeatureLabel(featureLabel: unknown): string {
|
||||
const trimmed = typeof featureLabel === 'string' ? featureLabel.trim() : '';
|
||||
if (!trimmed) return '';
|
||||
const stripped = trimmed.replace(/^GPT-[\d.]+-Codex-/i, '');
|
||||
if (stripped !== trimmed && stripped.length > 0) {
|
||||
|
||||
@@ -37,6 +37,11 @@ describe('prettifyCodexFeatureLabel', () => {
|
||||
expect(prettifyCodexFeatureLabel(' ')).toBe('');
|
||||
expect(prettifyCodexFeatureLabel(' GPT-5.3-Codex-Spark ')).toBe('Codex Spark');
|
||||
});
|
||||
|
||||
it('returns empty string for non-string input', () => {
|
||||
expect(prettifyCodexFeatureLabel({ label: 'Spark' })).toBe('');
|
||||
expect(prettifyCodexFeatureLabel(123)).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCodexWindowKind', () => {
|
||||
|
||||
Reference in New Issue
Block a user