mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +03:00
Mostra a % de cache nos logs de requisição, com teste próprio (`request-logger-cache-percentage.test.ts`). Validado no worktree combinado do lote. Pequeno ajuste feito por cima: `formatCachePercentage` movida de `RequestLoggerV2.tsx` para `src/shared/utils/formatting.ts`. `RequestLoggerV2.tsx` importa `RequestLoggerDetail`, que desde o #11703 (mergeado nesta mesma sessão) importa CSS bruto de `react18-json-view` — algo que o Node native test runner não consegue carregar. O teste original importava a função direto do componente e quebrava por causa dessa cadeia de import, não por bug na PR. Movida a função (pura, sem dependências) para o utils compartilhado; ajustado o import do componente e do teste. Typecheck limpo, teste passando (6/6).
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { formatCachePercentage } from "../../src/shared/utils/formatting";
|
|
|
|
test("formatCachePercentage", async (t) => {
|
|
await t.test("returns 0 when tokensIn is 0, null, or undefined", () => {
|
|
assert.strictEqual(formatCachePercentage(0, 100), 0);
|
|
assert.strictEqual(formatCachePercentage(null, 100), 0);
|
|
assert.strictEqual(formatCachePercentage(undefined, 100), 0);
|
|
});
|
|
|
|
await t.test("returns 0 when cacheRead is 0, null, or undefined", () => {
|
|
assert.strictEqual(formatCachePercentage(100, 0), 0);
|
|
assert.strictEqual(formatCachePercentage(100, null), 0);
|
|
assert.strictEqual(formatCachePercentage(100, undefined), 0);
|
|
});
|
|
|
|
await t.test("returns 0 for negative values", () => {
|
|
assert.strictEqual(formatCachePercentage(-100, 50), 0);
|
|
assert.strictEqual(formatCachePercentage(100, -50), 0);
|
|
});
|
|
|
|
await t.test("calculates standard percentages correctly", () => {
|
|
assert.strictEqual(formatCachePercentage(100, 50), 50);
|
|
assert.strictEqual(formatCachePercentage(1000, 250), 25);
|
|
assert.strictEqual(formatCachePercentage(3, 1), 33);
|
|
});
|
|
|
|
await t.test("clamps percentage at 100 when cacheRead > tokensIn", () => {
|
|
assert.strictEqual(formatCachePercentage(100, 150), 100);
|
|
assert.strictEqual(formatCachePercentage(50, 1000), 100);
|
|
});
|
|
});
|