test(usage): cover negative prompt_tokens alias clamp

This commit is contained in:
Peter Steinberger
2026-03-02 03:31:19 +00:00
parent 20467d987d
commit 0fa5d6ed2e

View File

@@ -105,6 +105,20 @@ describe("normalizeUsage", () => {
});
});
it("clamps negative prompt_tokens alias to zero", () => {
const usage = normalizeUsage({
prompt_tokens: -12,
completion_tokens: 4,
});
expect(usage).toEqual({
input: 0,
output: 4,
cacheRead: undefined,
cacheWrite: undefined,
total: undefined,
});
});
it("returns undefined when no valid fields are provided", () => {
const usage = normalizeUsage(null);
expect(usage).toBeUndefined();