@@ -11,6 +11,8 @@ import * as Layer from "effect/Layer";
1111import * as Path from "effect/Path" ;
1212import * as SqlClient from "effect/sql/SqlClient" ;
1313
14+ import { parseRateTable , priceUsage } from "../../usage/usagePricing.ts" ;
15+
1416import { makeAntigravityUsageCache , readAntigravityUsage } from "./antigravityUsageReader.ts" ;
1517
1618const openDatabase = Effect . fn ( "openDatabase" ) ( function * ( filename : string ) {
@@ -162,6 +164,72 @@ describe("readAntigravityUsage", () => {
162164 } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
163165 ) ;
164166
167+ it . effect ( "prices Antigravity effort and routing variants at their base model" , ( ) =>
168+ Effect . gen ( function * ( ) {
169+ const path = yield * Path . Path ;
170+ const dir = yield * tempDir ;
171+ yield * seedDatabase ( path . join ( dir , "variants.db" ) , ( db ) =>
172+ Effect . gen ( function * ( ) {
173+ yield * createTables ( db ) ;
174+ yield * db . run ( "INSERT INTO gen_metadata VALUES (?, ?)" , [
175+ 0 ,
176+ new Uint8Array ( protoBytes ( 1 , protoText ( 19 , "Gemini 3.7 Flash Control" ) ) ) ,
177+ ] ) ;
178+ yield * db . run ( "INSERT INTO steps VALUES (?, ?)" , [
179+ 0 ,
180+ new Uint8Array ( protoBytes ( 9 , protoNumber ( 2 , 10 ) ) ) ,
181+ ] ) ;
182+ yield * db . run ( "INSERT INTO steps VALUES (?, ?)" , [
183+ 1 ,
184+ new Uint8Array ( protoBytes ( 9 , [ ...protoNumber ( 1 , 1319 ) , ...protoNumber ( 2 , 11 ) ] ) ) ,
185+ ] ) ;
186+ yield * db . run ( "INSERT INTO steps VALUES (?, ?)" , [
187+ 2 ,
188+ new Uint8Array ( protoBytes ( 9 , [ ...protoNumber ( 1 , 1132 ) , ...protoNumber ( 2 , 12 ) ] ) ) ,
189+ ] ) ;
190+ // A model-less step that only learns its model by merging with a named generation.
191+ yield * db . run ( "INSERT INTO steps VALUES (?, ?)" , [
192+ 5 ,
193+ new Uint8Array ( protoBytes ( 9 , [ ...protoNumber ( 2 , 100 ) , ...protoText ( 11 , "response" ) ] ) ) ,
194+ ] ) ;
195+ yield * db . run ( "INSERT INTO gen_metadata VALUES (?, ?)" , [
196+ 3 ,
197+ new Uint8Array (
198+ protoBytes ( 1 , [
199+ ...protoText ( 19 , "Gemini 3.8 Flash High" ) ,
200+ ...protoBytes ( 4 , [ ...protoNumber ( 2 , 100 ) , ...protoText ( 11 , "response" ) ] ) ,
201+ ] ) ,
202+ ) ,
203+ ] ) ;
204+ } ) ,
205+ ) ;
206+ const result = yield * readAntigravityUsage ( dir , 0 ) ;
207+ assert . deepStrictEqual ( result . errors , [ ] ) ;
208+ assert . deepStrictEqual (
209+ records ( result ) . map ( ( record ) => [ record . model , record . rateModel ] ) ,
210+ [
211+ [ "gemini-3.7-flash-control" , "gemini-3.7-flash" ] ,
212+ [ "gemini-3.8-flash-medium" , "gemini-3.8-flash" ] ,
213+ [ "gemini-3-flash-agent" , "gemini-3-flash-preview" ] ,
214+ [ "gemini-3.8-flash-high" , "gemini-3.8-flash" ] ,
215+ ] ,
216+ ) ;
217+ const table = parseRateTable ( {
218+ "gemini-3.7-flash" : { input_cost_per_token : 0.75e-6 , output_cost_per_token : 3.75e-6 } ,
219+ "gemini-3.8-flash" : { input_cost_per_token : 0.75e-6 , output_cost_per_token : 3.75e-6 } ,
220+ "gemini-3-flash-preview" : { input_cost_per_token : 0.5e-6 , output_cost_per_token : 3e-6 } ,
221+ } ) ;
222+ const priced = records ( result ) . map ( ( record ) => priceUsage ( table , record ) ) ;
223+ assert . deepStrictEqual (
224+ priced . map ( ( { costSource } ) => costSource ) ,
225+ Array ( 4 ) . fill ( "modelPriced" ) ,
226+ ) ;
227+ for ( const [ index , expected ] of [ 7.5e-6 , 8.25e-6 , 6e-6 , 75e-6 ] . entries ( ) ) {
228+ assert . closeTo ( priced [ index ] ! . costUsd , expected , 1e-12 ) ;
229+ }
230+ } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
231+ ) ;
232+
165233 it . effect ( "prices ACP effort variants at the base model rate" , ( ) =>
166234 Effect . gen ( function * ( ) {
167235 const path = yield * Path . Path ;
0 commit comments