mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
fix(dashboard): preserve combo success percentage scale (#11595)
Merged via /merge-batch (lote 2026-08-26, v3.8.51). Boarded no worktree combinado junto com outras ~30 PRs; validação única: typecheck/complexity/cognitive-complexity/changelog-integrity verdes, file-size rebaseado onde necessário (crescimento legítimo), lint com os mesmos 228 achados pré-existentes confirmados via sonda contra o tip puro (não introduzidos por este lote), e ~370 testes focados (unit + vitest) passando. Obrigado pela contribuição.
This commit is contained in:
1
changelog.d/fixes/11595-combo-success-rate-scale.md
Normal file
1
changelog.d/fixes/11595-combo-success-rate-scale.md
Normal file
@@ -0,0 +1 @@
|
||||
- **fix(dashboard):** Provider Stats now displays combo success rates on their native 0–100 percentage scale instead of multiplying them twice ([#11595](https://github.com/diegosouzapw/OmniRoute/pull/11595)) — thanks @pacocartones
|
||||
@@ -9,8 +9,10 @@
|
||||
|
||||
import { useState, useEffect, useCallback, Fragment } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
|
||||
import { useProviderNodeMap, resolveProviderName } from "@/lib/display/useProviderNodeMap";
|
||||
import { formatComboSuccessRate } from "@/lib/usage/providerStatsFormatters";
|
||||
import { Card } from "@/shared/components";
|
||||
|
||||
interface ProviderStat {
|
||||
provider: string;
|
||||
@@ -493,7 +495,7 @@ export default function ProviderStatsPage() {
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right tabular-nums">
|
||||
{typeof m.successRate === "number"
|
||||
? `${(m.successRate * 100).toFixed(1)}%`
|
||||
? formatComboSuccessRate(m.successRate)
|
||||
: "—"}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
3
src/lib/usage/providerStatsFormatters.ts
Normal file
3
src/lib/usage/providerStatsFormatters.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function formatComboSuccessRate(successRatePercent: number): string {
|
||||
return `${successRatePercent.toFixed(1)}%`;
|
||||
}
|
||||
38
tests/unit/provider-stats-formatters.test.ts
Normal file
38
tests/unit/provider-stats-formatters.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
getComboMetrics,
|
||||
recordComboRequest,
|
||||
resetAllComboMetrics,
|
||||
} from "../../open-sse/services/comboMetrics.ts";
|
||||
import { formatComboSuccessRate } from "../../src/lib/usage/providerStatsFormatters.ts";
|
||||
|
||||
test.after(resetAllComboMetrics);
|
||||
|
||||
test("formatComboSuccessRate preserves the producer's 0-100 percentage scale", () => {
|
||||
resetAllComboMetrics();
|
||||
recordComboRequest("format-test", "openai/gpt-4o-mini", {
|
||||
success: true,
|
||||
latencyMs: 10,
|
||||
});
|
||||
|
||||
const metrics = getComboMetrics("format-test");
|
||||
assert.ok(metrics);
|
||||
assert.equal(metrics.successRate, 100);
|
||||
assert.equal(formatComboSuccessRate(metrics.successRate), "100.0%");
|
||||
assert.equal(formatComboSuccessRate(50), "50.0%");
|
||||
assert.equal(formatComboSuccessRate(0), "0.0%");
|
||||
});
|
||||
|
||||
test("Provider Stats renders combo metrics through the percentage-scale formatter", () => {
|
||||
const source = fs.readFileSync(
|
||||
path.resolve("src/app/(dashboard)/dashboard/provider-stats/page.tsx"),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
assert.match(source, /formatComboSuccessRate\(m\.successRate\)/);
|
||||
assert.doesNotMatch(source, /m\.successRate\s*\*\s*100/);
|
||||
});
|
||||
Reference in New Issue
Block a user