test(ai-review): 補使用量統計 NaN 安全測試並排除微優化誤報 #46

Merged
jiantw83 merged 14 commits from ai-review-resolve/20260623-163642 into develop 2026-06-23 09:35:21 +00:00
Showing only changes of commit ec8773d54d - Show all commits
+7
View File
1
@@ -210,6 +210,13 @@ describe('resolveRemainingPercent', () => {
}
});
it('returns null percent when rate.remaining is null/undefined', () => {
for (const remaining of [null, undefined]) {
const pct = resolveRemainingPercent({ available: false, reason: 'x' }, { hasData: true, remaining, limit: 200000, kind: 'tokens' });
assert.equal(pct.percent, null, `rate.remaining=${remaining} 應算不出百分比`);
}
Review

嚴重等級🔵 建議
審查員:Maya
問題:測試案例 returns null percent when rate.remaining is null/undefined 僅驗證了 remaining 為 null/undefined,但未驗證當 rate.limit 為 null/undefined 時的情況。雖然這可能由 calculatePercent 內部處理,但針對 resolveRemainingPercent 這一層級的整合測試仍不完整。
建議:建議補上一個測試案例,明確測試當 rate.limit 為 null/undefined 時,resolveRemainingPercent 的行為是否符合預期。

**嚴重等級**:🔵 建議 **審查員**:Maya **問題**:測試案例 `returns null percent when rate.remaining is null/undefined` 僅驗證了 remaining 為 null/undefined,但未驗證當 rate.limit 為 null/undefined 時的情況。雖然這可能由 `calculatePercent` 內部處理,但針對 `resolveRemainingPercent` 這一層級的整合測試仍不完整。 **建議**:建議補上一個測試案例,明確測試當 `rate.limit` 為 null/undefined 時,`resolveRemainingPercent` 的行為是否符合預期。
});
it('returns null percent when limit is finite but remaining is non-finite', () => {
const pct = resolveRemainingPercent({ available: true, used: 0, limit: 100, remaining: Infinity, currency: 'USD' }, null);
assert.equal(pct.percent, null);