Open source CapCut alternative.
TypeScript
test(site): guard model pricing and eval configuration
David Le8e4e0c6e1430
diff --git a/AGENTS.md b/AGENTS.mdindex db47d4d5..64280efa 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -62,6 +62,7 @@ Every Cut change has to hold on all four surfaces, and the plan for it says how:- Prefer deleting over documenting what was removed. Guides describe what is supported now, not what used to be.- Build forward by default. Prefer updating callers and contracts to the new supported shape instead of preserving old compatibility paths; ask before adding or keeping backwards-compatibility shims.- Configuration is code with a runtime override. Tunables, switches and thresholds are declared in the settings registry (`site/src/lib/config/registry.ts`) with a default and a schema, overridden from su, and read through it everywhere; env is for secrets. An experiment is variants over settings, drawn by an audience; a feature that people might tune ships its setting in the same change.+- Every model change must verify official availability and pricing, update billing, and pass affected evals before shipping.- Fail hard. One provider, one model, one code path per job; a missing API key, service, or capability is an error surfaced to the caller. No secondary providers, no retry-on-another-model paths, no `env.X || default` softening. A fallback exists only when it is absolutely necessary — a surface that genuinely cannot carry the feature — and the summary and the guide say so.- After finishing a task, summarize what you did. Ground the summary in the actual code changes — name the files and behavior that changed, not the intent you set out with. If nothing changed, say so. When the change has a shape worth seeing — a system flow or a UI layout — include a small ASCII diagram of it.- This is an open source project. Stay alert for security concerns, and never commit PII, API keys, tokens, credentials, private config, or other secrets.diff --git a/site/package.json b/site/package.jsonindex baa4ac6a..44f4958e 100644--- a/site/package.json+++ b/site/package.json@@ -24,7 +24,7 @@"eval:cut-chat": "bun run scripts/eval-cut-chat.ts","eval:cut-headless": "bun run scripts/eval-cut-headless.ts","email:dev": "email dev --dir src/emails --port 3001",- "test": "bun test src packages/effects-kit/src packages/abexp/src",+ "test": "bun test src packages/effects-kit/src packages/abexp/src scripts/lib/cut-eval","analytics:rollup-fixture": "bun run scripts/analytics-rollup-fixture.ts","test:genvideo": "bun run scripts/genvideo-selftest.ts","eval:genvideo": "bun run scripts/genvideo-eval.ts",diff --git a/site/scripts/eval-cut-chat.ts b/site/scripts/eval-cut-chat.tsindex 8f68fb40..3de7829d 100644--- a/site/scripts/eval-cut-chat.ts+++ b/site/scripts/eval-cut-chat.ts@@ -34,14 +34,13 @@ import { mkdirSync, writeFileSync } from "node:fs";import { dirname, join, resolve } from "node:path";import { fileURLToPath } from "node:url";import {- geminiModelRoleNames,geminiModelRoles,geminiModels,resolveGeminiModel,} from "../src/lib/inference/gemini-models";import { cases, type Bucket, type EvalCase } from "./lib/cut-eval/cases";import { makeFixtureAudio } from "./lib/cut-eval/fixtures";-import { runCase, type RunConfig } from "./lib/cut-eval/harness";+import { defaultRunConfig, runCase, type RunConfig } from "./lib/cut-eval/harness";import {buildBucketSummaries,buildCaseReport,@@ -174,7 +173,8 @@ async function main() {// --simple-model / --complex-model override a role each. The default is// production's routed pair.const both = argValue("--model");- const judgeModel = NO_JUDGE ? null : geminiModelRoles.fastDecision;+ const defaults = defaultRunConfig(BASE);+ const judgeModel = NO_JUDGE ? null : defaults.judgeModel;const configs = MATRIX? CANDIDATES.map((cand) => ({label: cand.label,@@ -192,13 +192,13 @@ async function main() {cfg: {base: BASE,simpleModel: resolveModel(- argValue("--simple-model") ?? both ?? geminiModelRoleNames.chatSimple+ argValue("--simple-model") ?? both ?? defaults.simpleModel),complexModel: resolveModel(- argValue("--complex-model") ?? both ?? geminiModelRoleNames.chat+ argValue("--complex-model") ?? both ?? defaults.complexModel),gateModel: resolveModel(- argValue("--gate-model") ?? geminiModelRoleNames.fastDecision+ argValue("--gate-model") ?? defaults.gateModel),judgeModel,},diff --git a/site/scripts/lib/cut-eval/harness.test.ts b/site/scripts/lib/cut-eval/harness.test.tsnew file mode 100644index 00000000..8cce4ea7--- /dev/null+++ b/site/scripts/lib/cut-eval/harness.test.ts@@ -0,0 +1,40 @@+import { describe, expect, test } from "bun:test";+import { readFileSync } from "node:fs";+import { defaultRunConfig } from "./harness";+import { providerCreditPricing } from "../../../src/lib/credits/provider-pricing";+import {+ geminiModelRoleNames,+ geminiModelRoles,+ resolveGeminiModel,+} from "../../../src/lib/inference/gemini-models";++describe("chat eval model selection", () => {+ test("the eval sends the same role names as the editor and headless runner", () => {+ const config = defaultRunConfig("http://localhost:3000");+ expect(config.simpleModel).toBe(geminiModelRoleNames.chatSimple);+ expect(config.complexModel).toBe(geminiModelRoleNames.chat);+ expect(config.gateModel).toBe(geminiModelRoleNames.fastDecision);+ expect(config.judgeModel).toBe(geminiModelRoles.fastDecision);+ });++ test("every eval role resolves to a priced hosted model", () => {+ const config = defaultRunConfig("http://localhost:3000");+ for (const model of [config.simpleModel, config.complexModel, config.gateModel, config.judgeModel!]) {+ expect(providerCreditPricing("gemini", resolveGeminiModel(model))).toBeTruthy();+ }+ });++ test("the committed eval baseline covers the production model configuration", () => {+ const report = JSON.parse(readFileSync(+ new URL("../../../../evals/cut-chat.latest-report.json", import.meta.url),+ "utf8",+ )) as { configs: { chatModel: string; gateModel: string }[] };+ const config = defaultRunConfig("http://localhost:3000");+ const simple = resolveGeminiModel(config.simpleModel);+ const complex = resolveGeminiModel(config.complexModel);+ const chatModel = simple === complex ? simple : `${simple} | complex→${complex}`;+ expect(report.configs.some((baseline) =>+ baseline.chatModel === chatModel && baseline.gateModel === resolveGeminiModel(config.gateModel),+ )).toBe(true);+ });+});diff --git a/site/src/lib/credits/provider-pricing.test.ts b/site/src/lib/credits/provider-pricing.test.tsnew file mode 100644index 00000000..90defb05--- /dev/null+++ b/site/src/lib/credits/provider-pricing.test.ts@@ -0,0 +1,58 @@+import { describe, expect, test } from "bun:test";+import { providerCreditPricing } from "@/lib/credits/provider-pricing";+import {+ geminiModels,+ geminiModelRoles,+ geminiMusicModels,+ geminiOmniModels,+ geminiTranscribeModels,+ geminiTtsModels,+} from "@/lib/inference/gemini-models";++describe("Gemini credit prices", () => {+ test("every hosted model and chat role has a price", () => {+ const catalogs = [+ ["gemini", geminiModels],+ ["gemini", geminiModelRoles],+ ["gemini", geminiTranscribeModels],+ ["gemini-music", geminiMusicModels],+ ["gemini-omni", geminiOmniModels],+ ["gemini-tts", geminiTtsModels],+ ] as const;+ for (const [provider, models] of catalogs) {+ for (const model of Object.values(models)) {+ expect(providerCreditPricing(provider, model)).toBeTruthy();+ }+ }+ });++ // Vertex global rates per million tokens, including Donkey's 30% margin.+ test("Flash-Lite 3.1 bills text, cached text, audio, and output at their rates", () => {+ const price = providerCreditPricing("gemini", geminiModels.flashLite);+ expect(price?.inputTokenCostMicrosPerMillion).toBe(BigInt(325000));+ expect(price?.cachedInputTokenCostMicrosPerMillion).toBe(BigInt(32500));+ expect(price?.inputAudioTokenCostMicrosPerMillion).toBe(BigInt(650000));+ expect(price?.outputTokenCostMicrosPerMillion).toBe(BigInt(1950000));+ });++ test("Flash 3.8 changes from launch to standard pricing at the UTC boundary", () => {+ const originalNow = Date.now;+ try {+ Date.now = () => Date.UTC(2026, 11, 31, 23, 59, 59, 999);+ const launch = providerCreditPricing("gemini", geminiModels.flash);+ expect(launch?.inputTokenCostMicrosPerMillion).toBe(BigInt(975000));+ expect(launch?.cachedInputTokenCostMicrosPerMillion).toBe(BigInt(97500));+ expect(launch?.inputAudioTokenCostMicrosPerMillion).toBe(BigInt(975000));+ expect(launch?.outputTokenCostMicrosPerMillion).toBe(BigInt(4875000));++ Date.now = () => Date.UTC(2027, 0, 1);+ const standard = providerCreditPricing("gemini", geminiModels.flash);+ expect(standard?.inputTokenCostMicrosPerMillion).toBe(BigInt(1950000));+ expect(standard?.cachedInputTokenCostMicrosPerMillion).toBe(BigInt(195000));+ expect(standard?.inputAudioTokenCostMicrosPerMillion).toBe(BigInt(1950000));+ expect(standard?.outputTokenCostMicrosPerMillion).toBe(BigInt(9750000));+ } finally {+ Date.now = originalNow;+ }+ });+});