From 50e5408d948d6aa6df76017e096ee0905334a0d0 Mon Sep 17 00:00:00 2001 From: Shadman Taqi <61359614+iamshadmantaqi@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:27:45 +0600 Subject: [PATCH 1/3] test(shared): keep a usage share short of the whole below 100% --- packages/shared/src/usageFormat.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/shared/src/usageFormat.test.ts b/packages/shared/src/usageFormat.test.ts index 778877a202616..a65b9c0d92f68 100644 --- a/packages/shared/src/usageFormat.test.ts +++ b/packages/shared/src/usageFormat.test.ts @@ -5,6 +5,7 @@ import type { UsageSource } from "@t3tools/contracts"; import { formatDateTimeShort, formatHourShort, + formatPercent, formatTokens, makeWindow, usageSourceMessages, @@ -236,6 +237,16 @@ describe("hourly usage formatting", () => { }); }); +describe("percent formatting", () => { + it("keeps a share short of the whole below 100%", () => { + expect(formatPercent(0.9996)).toBe(">99.9%"); + expect(formatPercent(0.99996, 2)).toBe(">99.99%"); + expect(formatPercent(0.999)).toBe("99.9%"); + expect(formatPercent(1)).toBe("100.0%"); + expect(formatPercent(0.0004)).toBe("<0.1%"); + }); +}); + describe("token formatting", () => { it("moves to the next unit when rounding reaches it", () => { expect(formatTokens(999_999)).toBe("1M"); From df325dcda67ba0c7ff57a37579760677846bfc27 Mon Sep 17 00:00:00 2001 From: Shadman Taqi <61359614+iamshadmantaqi@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:28:14 +0600 Subject: [PATCH 2/3] fix(shared): a usage share short of the whole never reads 100% --- packages/shared/src/usageFormat.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/shared/src/usageFormat.ts b/packages/shared/src/usageFormat.ts index 36c560cf54dce..089bbc13bc7c3 100644 --- a/packages/shared/src/usageFormat.ts +++ b/packages/shared/src/usageFormat.ts @@ -115,6 +115,9 @@ export function formatPercent(share: number, digits = 1): string { const percent = share * 100; const smallest = 10 ** -digits; if (percent > 0 && percent < smallest) return `<${smallest.toFixed(digits)}%`; + // Likewise a share short of the whole never rounds up to 100%. + const largest = 100 - smallest; + if (percent < 100 && percent > largest) return `>${largest.toFixed(digits)}%`; return `${percent.toFixed(digits)}%`; } From 766aeb1b16958cbde6ba09047a1d9ffff69278d2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 27 Nov 2026 14:11:36 +0000 Subject: [PATCH 3/3] test(shared): trim usage share bound test to the new case Co-Authored-By: Claude Opus 5.5 --- packages/shared/src/usageFormat.test.ts | 2 -- packages/shared/src/usageFormat.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/shared/src/usageFormat.test.ts b/packages/shared/src/usageFormat.test.ts index a65b9c0d92f68..fe882bfa3f116 100644 --- a/packages/shared/src/usageFormat.test.ts +++ b/packages/shared/src/usageFormat.test.ts @@ -240,10 +240,8 @@ describe("hourly usage formatting", () => { describe("percent formatting", () => { it("keeps a share short of the whole below 100%", () => { expect(formatPercent(0.9996)).toBe(">99.9%"); - expect(formatPercent(0.99996, 2)).toBe(">99.99%"); expect(formatPercent(0.999)).toBe("99.9%"); expect(formatPercent(1)).toBe("100.0%"); - expect(formatPercent(0.0004)).toBe("<0.1%"); }); }); diff --git a/packages/shared/src/usageFormat.ts b/packages/shared/src/usageFormat.ts index 089bbc13bc7c3..973a72bb445c4 100644 --- a/packages/shared/src/usageFormat.ts +++ b/packages/shared/src/usageFormat.ts @@ -115,7 +115,7 @@ export function formatPercent(share: number, digits = 1): string { const percent = share * 100; const smallest = 10 ** -digits; if (percent > 0 && percent < smallest) return `<${smallest.toFixed(digits)}%`; - // Likewise a share short of the whole never rounds up to 100%. + // A share short of the whole must not round up to 100%, as a nonzero one must not read 0%. const largest = 100 - smallest; if (percent < 100 && percent > largest) return `>${largest.toFixed(digits)}%`; return `${percent.toFixed(digits)}%`;