mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Validado em lote numa worktree combinada com #12524, #12538, #12277 e #12367 sobre o tip de release/v3.8.51: os quatro boardaram sem conflito (áreas disjuntas — zai-web, nvidia, clova, cursor/devin/fable). typecheck:core limpo, check:provider-consistency OK (272 entradas REGISTRY, 355 providers canônicos), check:known-symbols OK, e 305/305 nos testes tocados pelos quatro PRs. Os IDs de modelo adicionados foram conferidos individualmente. Obrigado, @backryun.
53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
// Characterization of the pricing.ts split (god-file decomposition): the host became a barrel that
|
|
// re-exports DEFAULT_PRICING (merged from semantic family files that import shared tier consts)
|
|
// and keeps the helper functions. Pure-data move → behavior identical. Locks: public surface, the
|
|
// spread-merge integrity, and that lookups/cost math resolve unchanged.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const P = await import("../../src/shared/constants/pricing.ts");
|
|
|
|
test("barrel still exports DEFAULT_PRICING + supported helpers", () => {
|
|
for (const name of ["DEFAULT_PRICING", "getPricingForModel", "getDefaultPricing"]) {
|
|
assert.ok(name in P, `missing export: ${name}`);
|
|
}
|
|
assert.equal(Object.hasOwn(P, "calculateCostFromTokens"), false);
|
|
});
|
|
|
|
test("DEFAULT_PRICING merges every family file; families partition all entries", async () => {
|
|
const merged = Object.keys((P as Record<string, object>).DEFAULT_PRICING).length;
|
|
const families: [string, string][] = [
|
|
["oauth-subscriptions", "DEFAULT_PRICING_OAUTH"],
|
|
["frontier-labs", "DEFAULT_PRICING_FRONTIER"],
|
|
["inference-hosts", "DEFAULT_PRICING_INFERENCE"],
|
|
["regional", "DEFAULT_PRICING_REGIONAL"],
|
|
["devin", "DEFAULT_PRICING_DEVIN"],
|
|
];
|
|
let famTotal = 0;
|
|
const seen = new Set<string>();
|
|
for (const [file, exportName] of families) {
|
|
const mod = await import(`../../src/shared/constants/pricing/${file}.ts`);
|
|
for (const k of Object.keys(mod[exportName])) {
|
|
assert.ok(!seen.has(k), `pricing key ${k} appears in more than one family`);
|
|
seen.add(k);
|
|
famTotal++;
|
|
}
|
|
}
|
|
assert.equal(merged, famTotal, "spread-merge lost/duplicated a top-level key");
|
|
assert.ok(merged > 25);
|
|
});
|
|
|
|
test("shared tier consts feed the parts (a known model resolves to a shared rate)", () => {
|
|
const pricing = (P as Record<string, (p: string, m: string) => unknown>).getPricingForModel(
|
|
"openai",
|
|
"gpt-4o"
|
|
);
|
|
assert.ok(pricing && typeof pricing === "object");
|
|
assert.equal(typeof (pricing as { input?: number }).input, "number");
|
|
});
|
|
|
|
test("formatCost remains re-exported from the pricing barrel", () => {
|
|
const fn = (P as Record<string, (value: number) => string>).formatCost;
|
|
assert.equal(fn(0.0123), "$0.0123");
|
|
});
|