Skip to content

Commit 6fa2abe

Browse files
test(server): usage long-context pricing tests stay at the pricing layer
AI-assisted; verified with the tests and tools listed above.
1 parent 2f56191 commit 6fa2abe

3 files changed

Lines changed: 1 addition & 122 deletions

File tree

‎apps/server/src/usage/UsageService.test.ts‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,70 +2408,6 @@ describe("UsageService", () => {
24082408
}).pipe(Effect.scoped),
24092409
);
24102410

2411-
it.live("prices a Codex turn above 272K prompt tokens at the long-context rates", () =>
2412-
Effect.gen(function* () {
2413-
const { home, settings } = yield* setup;
2414-
const dir = NodePath.join(home, "codex", "sessions");
2415-
yield* Effect.promise(async () => {
2416-
await NodeFSP.mkdir(dir, { recursive: true });
2417-
await NodeFSP.writeFile(
2418-
NodePath.join(dir, "rollout.jsonl"),
2419-
[
2420-
{ type: "turn_context", payload: { model: "gpt-6-sol" } },
2421-
{
2422-
type: "event_msg",
2423-
timestamp: "2026-08-01T10:00:00Z",
2424-
payload: {
2425-
type: "token_count",
2426-
info: {
2427-
last_token_usage: {
2428-
input_tokens: 300_000,
2429-
cached_input_tokens: 280_000,
2430-
output_tokens: 1_000,
2431-
reasoning_output_tokens: 0,
2432-
total_tokens: 301_000,
2433-
},
2434-
},
2435-
},
2436-
},
2437-
]
2438-
.map((line) => encodeUnknownJsonString(line))
2439-
.join("\n") + "\n",
2440-
);
2441-
});
2442-
// The restart reads the persisted scan and rate caches while the rates endpoint fails.
2443-
for (const ratesStatus of [200, 500]) {
2444-
const summary = yield* Effect.gen(function* () {
2445-
const service = yield* UsageService.make;
2446-
return yield* service.readSummary(WINDOW);
2447-
}).pipe(
2448-
Effect.scoped,
2449-
Effect.provide(
2450-
layerService({
2451-
prefix: "usage-service-long-context-test",
2452-
home,
2453-
settings,
2454-
ratesStatus: () => ratesStatus,
2455-
ratesDocument: {
2456-
"gpt-6-sol": {
2457-
input_cost_per_token: 2e-6,
2458-
cache_read_input_token_cost: 2e-7,
2459-
output_cost_per_token: 1e-5,
2460-
input_cost_per_token_above_272k_tokens: 4e-6,
2461-
cache_read_input_token_cost_above_272k_tokens: 4e-7,
2462-
output_cost_per_token_above_272k_tokens: 1.5e-5,
2463-
},
2464-
},
2465-
}),
2466-
),
2467-
);
2468-
const bucket = summary.buckets.find((bucket) => bucket.model === "gpt-6-sol");
2469-
assert.strictEqual(bucket?.costSource, "modelPriced");
2470-
assert.closeTo(bucket?.costUsd ?? NaN, 0.207, 1e-9);
2471-
}
2472-
}).pipe(Effect.scoped),
2473-
);
2474-
24752411
it.live(
24762412
"retains Codex reconciliation and partial coverage through persisted restart, append and repair",
24772413
() =>

‎apps/server/src/usage/usageAggregation.test.ts‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from "@effect/vitest";
22

33
import { resolveModelAliases, UsageAggregator } from "./usageAggregation.ts";
4-
import { parseRateTable, type RateTable } from "./usagePricing.ts";
4+
import type { RateTable } from "./usagePricing.ts";
55
import type { UsageRecord } from "@t3tools/provider-core/server/usage";
66

77
const rates: RateTable = new Map([
@@ -69,41 +69,6 @@ function aggregate(
6969
}
7070

7171
describe("UsageAggregator", () => {
72-
it("prices each request against the long-context threshold, not the bucket total", () => {
73-
const aggregator = new UsageAggregator({
74-
timeZone: "UTC",
75-
sinceDay: "2026-08-01",
76-
untilDay: "2026-08-31",
77-
resolution: "day",
78-
rates: parseRateTable({
79-
"gpt-6-sol": {
80-
input_cost_per_token: 2e-6,
81-
output_cost_per_token: 1e-5,
82-
input_cost_per_token_above_272k_tokens: 4e-6,
83-
output_cost_per_token_above_272k_tokens: 1.5e-5,
84-
},
85-
}),
86-
});
87-
const request = (uncachedInputTokens: number) =>
88-
record({
89-
model: "gpt-6-sol",
90-
totals: {
91-
uncachedInputTokens,
92-
cachedInputTokens: 0,
93-
cacheCreationTokens: 0,
94-
outputTokens: 1_000,
95-
reasoningTokens: 0,
96-
},
97-
});
98-
for (let index = 0; index < 4; index += 1) aggregator.add(request(100_000));
99-
aggregator.add(request(300_000));
100-
const [bucket] = aggregator.finish().buckets;
101-
102-
expect(bucket?.costUsd).toBeCloseTo(
103-
4 * (100_000 * 2e-6 + 1_000 * 1e-5) + 300_000 * 4e-6 + 1_000 * 1.5e-5,
104-
12,
105-
);
106-
});
10772
it("splits a bucket's cost by category and speed", () => {
10873
const [bucket] = aggregate([record(), record({ speed: "fast" })]).buckets;
10974

‎apps/server/src/usage/usagePricing.test.ts‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -293,28 +293,6 @@ describe("usage pricing", () => {
293293
expect(cost(272_001, "fast")).toBeCloseTo(72_001 * 4e-6 + 200_000 * 4e-7 + 1_000 * 2e-5, 12);
294294
});
295295

296-
it("leaves price overrides and models without above-tier rates at their flat rates", () => {
297-
const table = parseRateTable({ "gpt-6-sol": rate(2e-6) });
298-
const overrides = createOverrideRateTable({
299-
"claude-haiku-5-5": { inputCostPerMillionTokens: 1, outputCostPerMillionTokens: 5 },
300-
});
301-
const long = (model: string) => ({
302-
model,
303-
speed: "standard" as const,
304-
reportedCostUsd: null,
305-
totals: {
306-
uncachedInputTokens: 500_000,
307-
cachedInputTokens: 0,
308-
cacheCreationTokens: 0,
309-
outputTokens: 0,
310-
reasoningTokens: 0,
311-
},
312-
});
313-
314-
expect(priceUsage(table, long("gpt-6-sol")).costUsd).toBeCloseTo(1, 12);
315-
expect(priceUsage(table, long("claude-haiku-5-5"), overrides).costUsd).toBeCloseTo(0.5, 12);
316-
});
317-
318296
it("keeps the canonical Fable rate separate from DeepInfra in either order", () => {
319297
const canonical = ["claude-fable-5", rate(1e-5, 1e-6)] as const;
320298
const deepInfra = ["deepinfra/anthropic/claude-fable-5", rate(1e-5)] as const;

0 commit comments

Comments
 (0)