fix(quota): drop NeuralWatt key-name valueLabel so allowance windows render percent (#3385)

This commit is contained in:
Pablo Gonzalez
2026-09-07 20:26:33 +03:00
committed by GitHub
parent 21011cfe0a
commit cf02d405c6
4 changed files with 19 additions and 25 deletions
+7 -7
View File
@@ -605,7 +605,7 @@ describe('NeuralWatt quota provider (VS Code parity)', () => {
assert.equal(result.usage!.windows.credits_balance!.valueLabel, '$32.68');
});
test('surfaces subscription and allowance windows (allowance keyed by period, key name in valueLabel)', async () => {
test('surfaces subscription and allowance windows (allowance keyed by period, percent value)', async () => {
const payload = {
...DOCUMENTED_SUBSCRIPTION_PAYLOAD,
balance: { credits_remaining_usd: 200 },
@@ -623,11 +623,11 @@ describe('NeuralWatt quota provider (VS Code parity)', () => {
assert.ok(Math.abs((subWindow!.usedPercent as number) - (13.9023 / 20.0) * 100) < 1e-2);
// Allowance window is keyed by the localized period label ("monthly");
// key name flows through valueLabel for identification.
// the usage value stays a percent — no key-name valueLabel.
const allowWindow = result.usage!.windows.monthly;
assert.ok(allowWindow);
assert.equal(allowWindow!.usedPercent, 25);
assert.equal(allowWindow!.valueLabel, 'Prod');
assert.equal(allowWindow!.valueLabel, undefined);
assert.equal(allowWindow!.resetAt, Date.parse('2026-08-01T00:00:00Z'));
assert.equal(result.usage!.windows.credits_balance, undefined);
@@ -652,7 +652,7 @@ describe('NeuralWatt quota provider (VS Code parity)', () => {
assert.ok(Math.abs((window!.usedPercent as number) - (25 / 55) * 100) < 1e-2);
assert.equal(window!.windowSeconds, 30 * 86400);
assert.equal(window!.resetAt, Date.parse('2026-08-01T00:00:00Z'));
assert.equal(window!.valueLabel, 'prod-key');
assert.equal(window!.valueLabel, undefined);
assert.equal(result.usage!.windows.credits_balance, undefined);
});
@@ -691,7 +691,7 @@ describe('NeuralWatt quota provider (VS Code parity)', () => {
assert.ok(window);
assert.equal(window!.windowSeconds, 604800);
assert.equal(window!.resetAt, Date.parse('2026-07-04T00:00:00Z'));
assert.equal(window!.valueLabel, 'Prod');
assert.equal(window!.valueLabel, undefined);
});
test('uses daily as the allowance key when period is daily', async () => {
@@ -731,7 +731,7 @@ describe('NeuralWatt quota provider (VS Code parity)', () => {
assert.equal(window!.usedPercent, 25);
});
test('marks blocked allowance as 100% with valueLabel set', async () => {
test('marks blocked allowance as 100% with percent value', async () => {
const payload = {
balance: { credits_remaining_usd: 30 },
subscription: null,
@@ -747,7 +747,7 @@ describe('NeuralWatt quota provider (VS Code parity)', () => {
const window = result.usage!.windows.monthly;
assert.ok(window);
assert.equal(window!.usedPercent, 100);
assert.equal(window!.valueLabel, 'sample');
assert.equal(window!.valueLabel, undefined);
});
test('falls back to credits_balance when neither subscription nor allowance exists', async () => {
+2 -5
View File
@@ -2567,7 +2567,6 @@ const fetchNeuralwattQuota = async (): Promise<ProviderResult> => {
const subscription = payload?.subscription ?? null;
const inOverage = Boolean(subscription?.in_overage);
const allowance = payload?.key?.allowance ?? null;
const keyName = payload?.key?.name ?? null;
const creditsRemaining = toNumber(payload?.balance?.credits_remaining_usd);
const windows: Record<string, UsageWindow> = {};
@@ -2613,19 +2612,17 @@ const fetchNeuralwattQuota = async (): Promise<ProviderResult> => {
: (spent !== null && effectiveLimit !== null && effectiveLimit > 0
? Math.max(0, Math.min(100, (spent / effectiveLimit) * 100))
: null);
// Window title is the localized period label (daily/weekly/monthly); key
// name is attached via valueLabel for identification (wafer precedent).
// Window title is the localized period label (daily/weekly/monthly); the
// usage value stays a percent so the UI's display-mode toggle applies.
const periodKey = (period === 'daily' || period === 'weekly' || period === 'monthly' || period === 'month')
? (period === 'month' ? 'monthly' : period)
: 'billing_cycle';
const labelName = typeof keyName === 'string' && keyName.trim() ? keyName.trim() : null;
const resetAt = toTimestamp(allowance.reset_at);
const windowSeconds = period ? neuralwattWindowSeconds(period) : null;
windows[periodKey] = toUsageWindow({
usedPercent,
windowSeconds,
resetAt,
...(labelName ? { valueLabel: labelName } : {}),
});
} else if (creditsRemaining !== null) {
windows.credits_balance = toUsageWindow({
@@ -74,7 +74,6 @@ export const fetchQuota = async () => {
const subscription = payload?.subscription ?? null;
const inOverage = Boolean(subscription?.in_overage);
const allowance = payload?.key?.allowance ?? null;
const keyName = payload?.key?.name ?? null;
const creditsRemaining = toNumber(payload?.balance?.credits_remaining_usd);
const windows = {};
@@ -116,19 +115,17 @@ export const fetchQuota = async () => {
: (spent !== null && effectiveLimit !== null && effectiveLimit > 0
? Math.max(0, Math.min(100, (spent / effectiveLimit) * 100))
: null);
// Window title is the localized period label (daily/weekly/monthly); key
// name is attached via valueLabel for identification (wafer precedent).
// Window title is the localized period label (daily/weekly/monthly); the
// usage value stays a percent so the UI's display-mode toggle applies.
const periodKey = (period === 'daily' || period === 'weekly' || period === 'monthly' || period === 'month')
? (period === 'month' ? 'monthly' : period)
: 'billing_cycle';
const labelName = asNonEmptyString(keyName);
const resetAt = toTimestamp(allowance.reset_at);
const windowSeconds = period ? periodToWindowSeconds(period) : null;
windows[periodKey] = toUsageWindow({
usedPercent,
windowSeconds,
resetAt,
...(labelName ? { valueLabel: labelName } : {})
resetAt
});
} else if (creditsRemaining !== null) {
windows.credits_balance = toUsageWindow({
@@ -89,7 +89,7 @@ describe('NeuralWatt quota provider', () => {
expect(result.usage.windows.credits_balance.valueLabel).toBe('$32.68');
});
it('surfaces subscription and allowance windows (allowance keyed by period, key name in valueLabel)', async () => {
it('surfaces subscription and allowance windows (allowance keyed by period, percent value)', async () => {
const payload = {
...DOCUMENTED_SUBSCRIPTION_PAYLOAD,
balance: { credits_remaining_usd: 200 },
@@ -107,11 +107,11 @@ describe('NeuralWatt quota provider', () => {
expect(subWindow.usedPercent).toBeCloseTo((13.9023 / 20.0) * 100, 4);
// Allowance window is keyed by the localized period label ("monthly");
// key name flows through valueLabel for identification.
// the usage value stays a percent — no key-name valueLabel.
const allowWindow = result.usage.windows.monthly;
expect(allowWindow).toBeDefined();
expect(allowWindow.usedPercent).toBe(25);
expect(allowWindow.valueLabel).toBe('Prod');
expect(allowWindow.valueLabel).toBeUndefined();
expect(allowWindow.resetAt).toBe(Date.parse('2026-08-01T00:00:00Z'));
// credits_balance suppressed because allowance is present
@@ -137,7 +137,7 @@ describe('NeuralWatt quota provider', () => {
expect(window.usedPercent).toBeCloseTo((25 / 55) * 100, 4);
expect(window.windowSeconds).toBe(30 * 86400);
expect(window.resetAt).toBe(Date.parse('2026-08-01T00:00:00Z'));
expect(window.valueLabel).toBe('prod-key');
expect(window.valueLabel).toBeUndefined();
expect(result.usage.windows.credits_balance).toBeUndefined();
});
@@ -176,7 +176,7 @@ describe('NeuralWatt quota provider', () => {
expect(window).toBeDefined();
expect(window.windowSeconds).toBe(604800);
expect(window.resetAt).toBe(Date.parse('2026-07-04T00:00:00Z'));
expect(window.valueLabel).toBe('Prod');
expect(window.valueLabel).toBeUndefined();
});
it('uses daily as the allowance key when period is daily', async () => {
@@ -216,7 +216,7 @@ describe('NeuralWatt quota provider', () => {
expect(window.usedPercent).toBe(25);
});
it('marks blocked allowance as 100% with valueLabel set', async () => {
it('marks blocked allowance as 100% with percent value', async () => {
const payload = {
balance: { credits_remaining_usd: 30 },
subscription: null,
@@ -231,7 +231,7 @@ describe('NeuralWatt quota provider', () => {
const window = result.usage.windows.monthly;
expect(window.usedPercent).toBe(100);
expect(window.valueLabel).toBe('sample');
expect(window.valueLabel).toBeUndefined();
});
it('falls back to credits_balance when neither subscription nor allowance exists', async () => {