test(ai-review): 補使用量統計 NaN 安全測試並排除微優化誤報 #46
@@ -244,4 +244,13 @@ describe('formatUsageStatsLine', () => {
|
||||
const line = formatUsageStatsLine('ollama', 'llama3', usage, { available: false, reason: '本地服務,無帳號額度概念' }, { hasData: false });
|
||||
assert.match(line, /;剩餘可用: 無法計算(本地服務,無帳號額度概念)/);
|
||||
});
|
||||
|
||||
it('produces safe text (no NaN) when quota/rate carry invalid numbers', () => {
|
||||
// quota.limit 為 NaN、rate.limit 為 NaN → 不應算出百分比、不得輸出 NaN
|
||||
const line = formatUsageStatsLine('openai', 'm', usage,
|
||||
{ available: true, used: 5, limit: NaN, currency: 'USD' },
|
||||
{ hasData: true, remaining: NaN, limit: NaN, kind: 'tokens' });
|
||||
assert.doesNotMatch(line, /NaN/);
|
||||
assert.match(line, /剩餘可用: 無法計算/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user