Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import {
3 RateCardError,
4 bindInputs,
5 cardCurrency,
6 cardParams,
7 cardPrice,
8 price,
9 priceDetailed,
10 verifyExamples,
11} from './evaluate.ts'
12import { z } from 'zod'
13
14import { CORE_OPS } from './card.ts'
15import { rateCardSchema } from './rate-card.schema.ts'
16import type { Expr, RateCard } from './card.ts'
17import { compileTokenCard } from './token-card.ts'
18
19const source = {
20 url: 'https://example.test/llms.txt',
21 hash: 'a'.repeat(64),
22 extractedAt: '2026-09-13T00:00:00Z',
23}
24
25/** A card whose price is `expr`, over number inputs `x` (default 4) and `y` (default 2). */
26const cardFor = (expr: Expr, extra: Partial<RateCard> = {}): RateCard => ({
27 inputs: {
28 x: { param: 'x', kind: 'number', default: 4 },
29 y: { param: 'y', kind: 'number', default: 2 },
30 },
31 tables: { t: { a: { p: 1.5 }, b: { p: 3 } } },
32 price: expr,
33 examples: [],
34 source,
35 ...extra,
36})
37
38const usd = (expr: Expr, params: Record<string, unknown> = {}) =>
39 price(cardFor(expr), params)
40
41describe('ops', () => {
42 it.each<[string, Expr, number]>([
43 ['+ variadic', { '+': [{ var: 'x' }, { var: 'y' }, 1] }, 7],
44 ['- binary', { '-': [{ var: 'x' }, { var: 'y' }] }, 2],
45 ['* variadic', { '*': [{ var: 'x' }, { var: 'y' }, 0.5] }, 4],
46 ['/', { '/': [{ var: 'x' }, { var: 'y' }] }, 2],
47 ['max', { max: [1, { var: 'x' }, 3] }, 4],
48 ['min', { min: [{ var: 'x' }, 3, { var: 'y' }] }, 2],
49 ['ceil', { ceil: [{ '/': [{ var: 'x' }, 3] }] }, 2],
50 ['floor', { floor: [{ '/': [{ var: 'x' }, 3] }] }, 1],
51 [
52 'if chain',
53 {
54 if: [
55 { '<': [{ var: 'x' }, 2] },
56 10,
57 { '<': [{ var: 'x' }, 5] },
58 20,
59 30,
60 ],
61 },
62 20,
63 ],
64 ['== literal', { if: [{ '==': [{ var: 'x' }, 4] }, 1, 2] }, 1],
65 ['!=', { if: [{ '!=': [{ var: 'x' }, 4] }, 1, 2] }, 2],
66 ['<=', { if: [{ '<=': [{ var: 'x' }, 4] }, 1, 2] }, 1],
67 ['>', { if: [{ '>': [{ var: 'x' }, 4] }, 1, 2] }, 2],
68 ['>=', { if: [{ '>=': [{ var: 'x' }, 4] }, 1, 2] }, 1],
69 ['and', { if: [{ and: [true, { '>': [{ var: 'x' }, 1] }] }, 1, 2] }, 1],
70 ['or', { if: [{ or: [false, { '>': [{ var: 'x' }, 1] }] }, 1, 2] }, 1],
71 [
72 'missing → falsy when nothing is missing',
73 { if: [{ missing: ['x'] }, 1, 2] },
74 2,
75 ],
76 [
77 'missing → truthy when something is',
78 { if: [{ missing: ['x', 'nope'] }, 1, 2] },
79 1,
80 ],
81 ['lookup nested', { lookup: { table: 't', keys: ['b', 'p'] } }, 3],
82 [
83 'lookup default',
84 { lookup: { table: 't', keys: ['zzz'], default: 9 } },
85 9,
86 ],
87 ])('%s', (_name, expr, expected) => {
88 expect(usd(expr)).toBe(expected)
89 })
90})
91
92describe('binding', () => {
93 const card: RateCard = {
94 inputs: {
95 duration: { param: 'duration', kind: 'number', default: 5 },
96 res: {
97 param: 'resolution',
98 kind: 'enum',
99 values: ['480p', '720p'],
100 default: '480p',
101 },
102 audio: { param: 'generate_audio', kind: 'boolean', default: true },
103 refs: { param: 'image_urls', kind: 'count' },
104 size: {
105 param: 'image_size',
106 kind: 'dimensions',
107 presets: { square_hd: [1024, 1024] },
108 default: 'square_hd',
109 },
110 },
111 tables: {},
112 price: 1,
113 examples: [],
114 source,
115 }
116
117 it('binds by request param name, falling back to defaults', () => {
118 expect(bindInputs(card, {})).toEqual({
119 duration: 5,
120 res: '480p',
121 audio: true,
122 refs: 0,
123 size: { width: 1024, height: 1024 },
124 })
125 })
126
127 it('reads a numeric string duration, a list length and explicit pixels', () => {
128 expect(
129 bindInputs(card, {
130 duration: '8',
131 resolution: '720p',
132 generate_audio: false,
133 image_urls: ['a', 'b'],
134 image_size: { width: 1920, height: 1080 },
135 }),
136 ).toEqual({
137 duration: 8,
138 res: '720p',
139 audio: false,
140 refs: 2,
141 size: { width: 1920, height: 1080 },
142 })
143 })
144
145 it('reads WxH as pixels and a level by name', () => {
146 const c: RateCard = {
147 ...card,
148 inputs: {
149 ...card.inputs,
150 size: { param: 'image_size', kind: 'dimensions', levels: ['2K'] },
151 },
152 }
153 expect(bindInputs(c, { image_size: '2048x1152' }).size).toEqual({
154 width: 2048,
155 height: 1152,
156 })
157 expect(bindInputs(c, { image_size: '2K' }).size).toEqual({ level: '2K' })
158 expect(() => bindInputs(c, { image_size: '4K' })).toThrow(RateCardError)
159 })
160
161 it('var walks dotted paths into dimensions', () => {
162 const c: RateCard = {
163 ...card,
164 price: { '*': [{ var: 'size.width' }, 0.001] },
165 }
166 expect(price(c, {})).toBe(1.024)
167 })
168
169 it.each<[string, Record<string, unknown>]>([
170 ['enum outside values', { resolution: '1080p' }],
171 ['non-numeric number', { duration: 'five' }],
172 ['non-boolean boolean', { generate_audio: 'yes' }],
173 ['non-list count', { image_urls: 'a' }],
174 ['unknown size preset', { image_size: 'portrait_4_3' }],
175 ])('refuses %s', (_name, params) => {
176 expect(() => price(card, params)).toThrow(RateCardError)
177 })
178})
179
180/** Outside the vocabulary; parsed so no assertion has to lie about its type. */
181const unknownOp = JSON.parse('{"cat":[1,2]}') as Expr
182
183describe('refusals', () => {
184 it.each<[string, Expr, string]>([
185 ['unknown op', unknownOp, 'unknown-op'],
186 ['unbound var', { var: 'nope' }, 'unbound-var'],
187 [
188 'missing lookup key without default',
189 { lookup: { table: 't', keys: ['zzz', 'p'] } },
190 'missing-key',
191 ],
192 ['non-numeric operand', { '+': [{ var: 'x' }, 'text'] }, 'not-a-number'],
193 // JSONLogic's == is loose; ours refuses a type mismatch instead of returning false.
194 [
195 '== across types',
196 { if: [{ '==': [{ var: 'x' }, '4'] }, 1, 2] },
197 'not-comparable',
198 ],
199 [
200 '!= across types',
201 { if: [{ '!=': [{ var: 'x' }, '4'] }, 1, 2] },
202 'not-comparable',
203 ],
204 [
205 '== on a list',
206 { if: [{ '==': [{ missing: ['x'] }, 0] }, 1, 2] },
207 'not-comparable',
208 ],
209 ['zero price', { '-': [{ var: 'x' }, 4] }, 'bad-result'],
210 ['negative price', { '-': [1, { var: 'x' }] }, 'bad-result'],
211 ['non-finite price', { '/': [{ var: 'x' }, 0] }, 'bad-result'],
212 ['non-numeric price', { '<': [1, 2] }, 'bad-result'],
213 ])('%s', (_name, expr, code) => {
214 expect(() => usd(expr)).toThrow(expect.objectContaining({ code }))
215 })
216
217 const doubleX: Expr = { '*': [{ var: 'x' }, 2] }
218 const yuan = { ...cardFor(doubleX), price: { currency: ['CNY', doubleX] } }
219
220 it('accepts source-published literal free prices in USD and CNY', () => {
221 const free = cardFor(0, { inputs: {}, tables: {} })
222 expect(priceDetailed(rateCardSchema.parse(free))).toEqual({
223 amount: 0,
224 currency: 'USD',
225 usd: 0,
226 estimated: [],
227 defaulted: [],
228 ignored: [],
229 })
230 const cny = rateCardSchema.parse({
231 ...free,
232 price: { currency: ['CNY', 0] },
233 })
234 expect(priceDetailed(cny)).toEqual({
235 amount: 0,
236 currency: 'CNY',
237 estimated: [],
238 defaulted: [],
239 ignored: [],
240 })
241 expect(price(cny)).toBe(0)
242 })
243
244 it('rejects negative native currency and computed zero paid prices', () => {
245 const negative = rateCardSchema.parse({
246 ...cardFor(1),
247 price: { currency: ['CNY', -1] },
248 })
249 expect(() => price(negative)).toThrow(
250 expect.objectContaining({ code: 'bad-result' }),
251 )
252 const paid = rateCardSchema.parse(yuan)
253 expect(() => price(paid, { x: 0 })).toThrow(
254 expect.objectContaining({ code: 'bad-result' }),
255 )
256 })
257
258 it('prices a card in its own currency and never calls it USD', () => {
259 const parsed = rateCardSchema.parse(yuan)
260 expect(cardCurrency(parsed)).toBe('CNY')
261 expect(priceDetailed(parsed)).toEqual({
262 amount: 8,
263 currency: 'CNY',
264 estimated: [],
265 defaulted: ['x', 'y'],
266 ignored: [],
267 })
268 // The wrapper changes the label, never the amount.
269 expect(price(parsed)).toBe(price(cardFor(doubleX)))
270 // A bare price is USD: a card stored before currencies reads unchanged.
271 expect(cardCurrency(cardFor(1))).toBe('USD')
272 expect(priceDetailed(cardFor(1))).toMatchObject({ currency: 'USD', usd: 1 })
273 })
274
275 it.each(['yuan', 'cny', '¥', 'RMBX', ''])(
276 'schema rejects %j as a currency',
277 (currency) => {
278 const card = { ...cardFor(1), price: { currency: [currency, 1] } }
279 expect(rateCardSchema.safeParse(card).success).toBe(false)
280 },
281 )
282
283 it('schema takes the currency wrapper at the root of price only', () => {
284 const nested = { '+': [1, { currency: ['CNY', 1] }] }
285 expect(
286 rateCardSchema.safeParse({ ...cardFor(1), price: nested }).success,
287 ).toBe(false)
288 const beside = { currency: ['CNY', 1], '+': [1, 2] }
289 expect(
290 rateCardSchema.safeParse({ ...cardFor(1), price: beside }).success,
291 ).toBe(false)
292 })
293
294 it('schema refuses a top-level currency rather than read the card as USD', () => {
295 for (const currency of ['CNY', 'USD', null, 156]) {
296 expect(
297 rateCardSchema.safeParse({ ...cardFor(1), currency }).success,
298 ).toBe(false)
299 }
300 })
301
302 it('schema refuses a USD wrapper: USD is said only by having none', () => {
303 const card = { ...cardFor(1), price: { currency: ['USD', 1] } }
304 expect(rateCardSchema.safeParse(card).success).toBe(false)
305 })
306
307 // Wrappers the schema refuses, handed to the evaluator unparsed.
308 it.each([
309 ['a lowercase code', { currency: ['cny', 1] }],
310 ['a numeric code', { currency: [156, 1] }],
311 ['USD', { currency: ['USD', 1] }],
312 ['three items', { currency: ['CNY', 1, 2] }],
313 ['a sibling op', { currency: ['CNY', 1], '+': [1, 2] }],
314 ['a bare code', { currency: 'CNY' }],
315 ['no price', undefined],
316 ['a null price', null],
317 ['a null wrapper payload', { currency: null }],
318 ['a null wrapped expression', { currency: ['CNY', null] }],
319 ])('evaluator refuses %s with its own error', (_name, bad) => {
320 const card = { ...cardFor(1), price: bad } as unknown as RateCard
321 expect(rateCardSchema.safeParse(card).success).toBe(false)
322 for (const read of [cardPrice, cardCurrency, price, priceDetailed]) {
323 expect(() => read(card)).toThrow(RateCardError)
324 expect(() => read(card)).toThrow(
325 expect.objectContaining({ code: 'unknown-op' }),
326 )
327 }
328 })
329
330 it('evaluator refuses a stray top-level currency on an unparsed card', () => {
331 const card = { ...cardFor(1), currency: 'CNY' } as unknown as RateCard
332 for (const read of [cardCurrency, price, priceDetailed]) {
333 expect(() => read(card)).toThrow(
334 expect.objectContaining({ code: 'unknown-op' }),
335 )
336 }
337 })
338
339 it('evaluator refuses a null card with its own error', () => {
340 expect(() => cardCurrency(null as unknown as RateCard)).toThrow(
341 RateCardError,
342 )
343 })
344
345 /**
346 * What @modelschemas/rate-card 0.1.0 (and a service rolled back to before
347 * currencies) does with an expression node: its schema accepts only the
348 * ops below, and its evaluator throws `unknown-op` on any other key. The
349 * op list is the published one, frozen here on purpose.
350 */
351 const OPS_0_1_0 = [
352 'var',
353 'missing',
354 '+',
355 '-',
356 '*',
357 '/',
358 'max',
359 'min',
360 'if',
361 '==',
362 '!=',
363 '<',
364 '<=',
365 '>',
366 '>=',
367 'and',
368 'or',
369 'ceil',
370 'floor',
371 ]
372 const expr010: z.ZodType = z.lazy(() =>
373 z.union([
374 z.number(),
375 z.string(),
376 z.boolean(),
377 z.strictObject({ lookup: z.unknown() }),
378 z
379 .partialRecord(z.enum(OPS_0_1_0), z.union([expr010, z.array(expr010)]))
380 .refine((ops) => Object.keys(ops).length === 1, 'one op per node'),
381 ]),
382 )
383
384 it('a pre-currency evaluator refuses a non-USD card instead of calling it dollars', () => {
385 // It reads USD cards as before, so the reproduction is not just strict.
386 expect(expr010.safeParse(doubleX).success).toBe(true)
387 expect(expr010.safeParse(yuan.price).success).toBe(false)
388 // Its evaluator would throw `unknown-op` on the root key.
389 expect(Object.keys(yuan.price)).toEqual(['currency'])
390 expect(OPS_0_1_0).not.toContain('currency')
391 // The op must never become a core op, or old schemas that are handed
392 // the new list would start reading yuan as dollars.
393 expect(CORE_OPS).toEqual(OPS_0_1_0)
394 })
395
396 it('schema rejects an op outside the vocabulary', () => {
397 expect(rateCardSchema.safeParse(cardFor(unknownOp)).success).toBe(false)
398 })
399
400 it('schema rejects a lookup node carrying a sibling op (would be stripped silently)', () => {
401 const expr = JSON.parse(
402 '{"lookup":{"table":"t","keys":["a","p"]},"+":[1,2]}',
403 ) as Expr
404 expect(rateCardSchema.safeParse(cardFor(expr)).success).toBe(false)
405 })
406
407 it.each<[string, Partial<RateCard>]>([
408 [
409 'enum default outside values',
410 {
411 inputs: {
412 r: { param: 'r', kind: 'enum', values: ['a'], default: 'zzz' },
413 },
414 },
415 ],
416 [
417 'dimensions default that is not a preset',
418 {
419 inputs: {
420 s: { param: 's', kind: 'dimensions', presets: {}, default: 'nope' },
421 },
422 },
423 ],
424 [
425 'extractedAt that is not a date',
426 { source: { ...source, extractedAt: 'yesterday' } },
427 ],
428 [
429 'expiresAt that is not a date',
430 { source: { ...source, expiresAt: 'soon' } },
431 ],
432 ])('schema rejects %s', (_name, extra) => {
433 expect(rateCardSchema.safeParse(cardFor(1, extra)).success).toBe(false)
434 })
435})
436
437describe('verifyExamples', () => {
438 const expr: Expr = { '*': [{ var: 'x' }, 0.1] }
439 it('passes within 1% and fails outside it, reporting the priced USD', () => {
440 const card = cardFor(expr, {
441 examples: [
442 { params: { x: 10 }, usd: 1.0, quote: 'ten' },
443 { params: { x: 10 }, usd: 1.009, quote: 'ten-ish' },
444 { params: { x: 10 }, usd: 1.02, quote: 'not ten' },
445 ],
446 })
447 const [exact, close, off] = verifyExamples(card)
448 expect(exact).toMatchObject({ ok: true, usd: 1 })
449 expect(close).toMatchObject({ ok: true })
450 expect(off).toMatchObject({
451 ok: false,
452 usd: 1,
453 error: expect.stringContaining('1.02') as string,
454 })
455 })
456
457 it('reports a refusal as a failed example instead of throwing', () => {
458 const card = cardFor(expr, {
459 examples: [{ params: { x: 'many' }, usd: 1, quote: 'bad input' }],
460 })
461 expect(verifyExamples(card)[0]).toMatchObject({
462 ok: false,
463 error: expect.stringContaining('bad-input') as string,
464 })
465 })
466})
467
468describe('estimate', () => {
469 // rate × tokens; tokens estimated as seconds × per-second[resolution].
470 const card: RateCard = {
471 inputs: {
472 resolution: { param: 'resolution', kind: 'enum', values: ['480p'] },
473 tokens: {
474 param: 'tokens',
475 bound: 'usage',
476 kind: 'number',
477 estimate: {
478 inputs: { seconds: { param: 'seconds', kind: 'number' } },
479 value: {
480 '*': [
481 { var: 'seconds' },
482 {
483 lookup: { table: 'per_second', keys: [{ var: 'resolution' }] },
484 },
485 ],
486 },
487 source: { url: 'https://example.test/guide', hash: 'b'.repeat(64) },
488 },
489 },
490 },
491 tables: { per_second: { '480p': 1000 } },
492 price: { '*': [{ var: 'tokens' }, 0.001] },
493 examples: [],
494 source,
495 }
496
497 it('prices supplied usage as billed, without the estimate inputs', () => {
498 expect(rateCardSchema.parse(card)).toEqual(card)
499 expect(
500 priceDetailed(card, { resolution: '480p' }, { tokens: 500 }),
501 ).toEqual({
502 amount: 0.5,
503 currency: 'USD',
504 usd: 0.5,
505 estimated: [],
506 defaulted: [],
507 ignored: [],
508 })
509 })
510
511 it('labels an estimated input and binds its own inputs only then', () => {
512 expect(priceDetailed(card, { resolution: '480p', seconds: 2 }, {})).toEqual(
513 {
514 amount: 2,
515 currency: 'USD',
516 usd: 2,
517 estimated: ['tokens'],
518 defaulted: [],
519 ignored: [],
520 },
521 )
522 expect(() => priceDetailed(card, { resolution: '480p' }, {})).toThrow(
523 /tokens \(tokens\): not supplied, and cannot be estimated.*seconds.*required/,
524 )
525 })
526
527 it('names the unsupplied card input on the error', () => {
528 const thrown = (fn: () => unknown) => {
529 try {
530 fn()
531 } catch (error) {
532 return error as RateCardError
533 }
534 throw new Error('did not throw')
535 }
536 expect(thrown(() => priceDetailed(card, {}, {}))).toMatchObject({
537 code: 'bad-input',
538 input: 'resolution',
539 })
540 expect(
541 thrown(() => priceDetailed(card, { resolution: '480p' }, {})),
542 ).toMatchObject({ code: 'estimate-unavailable', input: 'tokens' })
543 expect(
544 thrown(() => priceDetailed(card, { resolution: 'nope' }, {})).input,
545 ).toBeUndefined()
546 })
547
548 it('never estimates through price(), the billed entry point', () => {
549 expect(price(card, { resolution: '480p' }, { tokens: 500 })).toBe(0.5)
550 expect(() => price(card, { resolution: '480p', seconds: 2 }, {})).toThrow(
551 /tokens \(tokens\): required/,
552 )
553 })
554
555 it('refuses a non-positive estimate rather than pricing it', () => {
556 expect(() =>
557 priceDetailed(card, { resolution: '480p', seconds: -1 }, {}),
558 ).toThrow(
559 expect.objectContaining({ code: 'estimate-unavailable' }) as Error,
560 )
561 })
562
563 it('rejects an estimate beside a default, or shadowing a card input', () => {
564 const tokens = card.inputs.tokens
565 if (tokens?.kind !== 'number' || !tokens.estimate) throw new Error('shape')
566 const withDefault = {
567 ...card,
568 inputs: { ...card.inputs, tokens: { ...tokens, default: 1 } },
569 }
570 expect(rateCardSchema.safeParse(withDefault).success).toBe(false)
571 const shadowing = {
572 ...card,
573 inputs: {
574 ...card.inputs,
575 tokens: {
576 ...tokens,
577 estimate: {
578 ...tokens.estimate,
579 inputs: {
580 resolution: { param: 'resolution', kind: 'enum', values: ['1'] },
581 },
582 },
583 },
584 },
585 }
586 expect(rateCardSchema.safeParse(shadowing).success).toBe(false)
587 })
588})
589
590describe('unread keys and defaults', () => {
591 // Anthropic-style rates: $3 in, $15 out, $0.30 cache read per 1M.
592 const card = compileTokenCard(
593 {
594 input_tokens: 3 / 1e6,
595 output_tokens: 15 / 1e6,
596 cache_read_tokens: 0.3 / 1e6,
597 },
598 [],
599 source,
600 )
601 if (!card) throw new Error('did not compile')
602
603 it("refuses Anthropic's native cache_read_input_tokens instead of pricing it at 0", () => {
604 expect(() =>
605 priceDetailed(
606 card,
607 {},
608 {
609 input_tokens: 12_000,
610 output_tokens: 800,
611 cache_read_input_tokens: 4000,
612 },
613 ),
614 ).toThrow(
615 expect.objectContaining({
616 code: 'unknown-usage-key',
617 message:
618 'usage.cache_read_input_tokens: not read by this card; it reads usage.input_tokens, usage.output_tokens, usage.cache_read_tokens',
619 }),
620 )
621 })
622
623 it("prices the card's own cache_read_tokens with nothing defaulted", () => {
624 const result = priceDetailed(
625 card,
626 {},
627 { input_tokens: 12_000, output_tokens: 800, cache_read_tokens: 4000 },
628 )
629 // 12000 × 3/M + 800 × 15/M + 4000 × 0.3/M
630 expect(result.amount).toBeCloseTo(0.0492, 9)
631 expect(result).toMatchObject({ estimated: [], defaulted: [], ignored: [] })
632 })
633
634 it('names a usage-bound default it applied', () => {
635 expect(
636 priceDetailed(card, {}, { input_tokens: 12_000, output_tokens: 800 }),
637 ).toMatchObject({ amount: 0.048, defaulted: ['cache_read_tokens'] })
638 })
639
640 it('lists a request field sent in usage as a request key', () => {
641 expect(() => priceDetailed(cardFor({ var: 'x' }), {}, { x: 3 })).toThrow(
642 /usage\.x: not read by this card; it reads request\.x, request\.y$/,
643 )
644 })
645
646 it('lists request keys the card does not read as ignored', () => {
647 const result = priceDetailed(cardFor({ '*': [{ var: 'x' }, 2] }), {
648 x: 3,
649 prompt: 'a cat',
650 seed: 7,
651 })
652 expect(result).toMatchObject({
653 amount: 6,
654 defaulted: ['y'],
655 ignored: ['prompt', 'seed'],
656 })
657 })
658
659 it('leaves price() lenient for flat example bags', () => {
660 expect(
661 price(
662 card,
663 { model: 'm' },
664 { input_tokens: 1, output_tokens: 0, model: 'm' },
665 ),
666 ).toBeCloseTo(3 / 1e6, 12)
667 })
668
669 it('reads estimate inputs as card params', () => {
670 const estimated = rateCardSchema.parse({
671 ...cardFor({ var: 'tokens' }),
672 inputs: {
673 tokens: {
674 param: 'tokens',
675 bound: 'usage',
676 kind: 'number',
677 estimate: {
678 inputs: { seconds: { param: 'seconds', kind: 'number' } },
679 value: { var: 'seconds' },
680 source,
681 },
682 },
683 },
684 })
685 expect(cardParams(estimated)).toEqual({
686 request: ['seconds'],
687 usage: ['tokens'],
688 })
689 })
690
691 it('names a default an estimate input took', () => {
692 const estimated = rateCardSchema.parse({
693 ...cardFor({ var: 'tokens' }),
694 inputs: {
695 tokens: {
696 param: 'tokens',
697 bound: 'usage',
698 kind: 'number',
699 estimate: {
700 inputs: {
701 seconds: { param: 'seconds', kind: 'number', default: 0 },
702 },
703 value: { '+': [{ var: 'seconds' }, 1] },
704 source,
705 },
706 },
707 },
708 })
709 expect(priceDetailed(estimated, {}, {})).toMatchObject({
710 amount: 1,
711 estimated: ['tokens'],
712 defaulted: ['seconds'],
713 })
714 expect(priceDetailed(estimated, { seconds: 4 }, {})).toMatchObject({
715 amount: 5,
716 estimated: ['tokens'],
717 defaulted: [],
718 })
719 })
720})