Files
OmniRoute/tests/unit/modalCost.test.ts
Diego Rodrigues de Sa e Souza 3c9883bb73 Release v3.8.29 (#4126)
OmniRoute v3.8.29 — 115 commits since v3.8.28. Full CHANGELOG + 41 i18n mirrors. All content quality gates green (build, unit 8/8, vitest 188/188, PR test policy, quality gates extended, docs sync, quality ratchet). Remaining red CI checks are pre-existing release flakes (coverage-shard/integration/node-compat teardown), a new transitive undici advisory in electron devDeps, and a workflow-level CodeQL fail (0 open alerts). VPS-validated by the operator.
2026-06-19 06:49:01 -03:00

33 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from "node:test";
import assert from "node:assert/strict";
import {
computeImageCost,
computeAudioCost,
computeRerankCost,
computeVideoCost,
calculateModalCost,
} from "../../src/lib/usage/costCalculator.ts";
test("computeImageCost: per-image flat × n", () => {
assert.equal(computeImageCost({ output_cost_per_image: 0.04 }, { n: 3 }), 0.12);
assert.equal(computeImageCost({}, { n: 3 }), 0);
assert.equal(computeImageCost({ output_cost_per_image: 0.04 }, { n: 0 }), 0);
});
test("computeAudioCost: per-second OR per-character, else 0", () => {
assert.equal(computeAudioCost({ input_cost_per_second: 0.0001 }, { seconds: 30 }), 0.003);
assert.equal(computeAudioCost({ input_cost_per_character: 0.000015 }, { characters: 1000 }), 0.015);
assert.equal(computeAudioCost({ input_cost_per_second: 0.0001 }, {}), 0);
});
test("computeRerankCost: per search unit", () => {
assert.equal(computeRerankCost({ search_unit_cost: 0.002 }, { searchUnits: 5 }), 0.01);
assert.equal(computeRerankCost({}, { searchUnits: 5 }), 0);
});
test("computeVideoCost: per video-second", () => {
assert.equal(computeVideoCost({ output_cost_per_video_per_second: 0.5 }, { seconds: 8 }), 4);
assert.equal(computeVideoCost({}, { seconds: 8 }), 0);
});
test("calculateModalCost returns 0 for unknown pricing (fail-open)", async () => {
const cost = await calculateModalCost("image", "no-such-provider", "no-such-model", { n: 2 });
assert.equal(cost, 0);
});