@@ -348,6 +348,87 @@ func TestExportReportingFallbackPricingOnUnseededArchive(t *testing.T) {
348348 assert .Positive (t , hour .Activity .Totals .Cost .Microdollars )
349349}
350350
351+ func TestExportReportingSnapshotStoredPricingOverridesInstalledFallback (
352+ t * testing.T ,
353+ ) {
354+ dataDir := testDataDir (t )
355+ database := dbtest .OpenTestDBAt (t , filepath .Join (dataDir , "sessions.db" ))
356+ t .Cleanup (func () {
357+ require .NoError (t , database .Close ())
358+ })
359+ model := exactFallbackPricedModel (t )
360+ require .NoError (t , database .UpsertSession (db.Session {
361+ ID : "fixture-snapshot-pricing" ,
362+ Machine : "fixture-machine" ,
363+ Agent : "agent snapshot" ,
364+ StartedAt : dbtest .Ptr ("2026-07-28T10:00:00Z" ),
365+ EndedAt : dbtest .Ptr ("2026-07-28T10:06:00Z" ),
366+ MessageCount : 2 ,
367+ UserMessageCount : 1 ,
368+ }))
369+ require .NoError (t , database .InsertMessages ([]db.Message {
370+ {
371+ SessionID : "fixture-snapshot-pricing" ,
372+ Ordinal : 0 ,
373+ Role : "user" ,
374+ Content : "synthetic question" ,
375+ ContentLength : len ("synthetic question" ),
376+ Timestamp : "2026-07-28T10:00:00Z" ,
377+ },
378+ {
379+ SessionID : "fixture-snapshot-pricing" ,
380+ Ordinal : 1 ,
381+ Role : "assistant" ,
382+ Content : "synthetic answer" ,
383+ ContentLength : len ("synthetic answer" ),
384+ Timestamp : "2026-07-28T10:05:00Z" ,
385+ Model : model ,
386+ TokenUsage : json .RawMessage (
387+ `{"input_tokens":1000,"output_tokens":500}` ,
388+ ),
389+ },
390+ }))
391+
392+ deps := defaultExportReportingDeps ()
393+ deps .now = func () time.Time {
394+ return time .Date (2026 , 7 , 29 , 14 , 37 , 0 , 0 , time .UTC )
395+ }
396+ openDatabase := deps .openDatabase
397+ deps .openDatabase = func (
398+ cmd * cobra.Command ,
399+ ) (* db.DB , func (), error ) {
400+ reader , cleanup , err := openDatabase (cmd )
401+ if err != nil {
402+ return nil , func () {}, err
403+ }
404+ if err := database .UpsertModelPricing ([]db.ModelPricing {{
405+ ModelPattern : model ,
406+ InputPerMTok : money .MustParseDollars ("123" ),
407+ OutputPerMTok : money .MustParseDollars ("456" ),
408+ }}); err != nil {
409+ cleanup ()
410+ return nil , func () {}, err
411+ }
412+ return reader , cleanup , nil
413+ }
414+
415+ stdout , stderr , err := executeExportSessionsCommand (
416+ newExportReportingTestRootWithDeps (deps ),
417+ "export" , "hour" , "2026-07-28-10" ,
418+ )
419+ require .NoError (t , err )
420+ assert .Empty (t , stderr )
421+
422+ var hour export.ReportingHour
423+ require .NoError (t , json .Unmarshal ([]byte (stdout ), & hour ))
424+ assert .Equal (
425+ t ,
426+ money.Money {Microdollars : 351_000 },
427+ hour .Usage .Totals .Cost ,
428+ )
429+ assert .Equal (t , hour .Usage .Totals .Cost , hour .Activity .Totals .Cost )
430+ }
431+
351432func newExportReportingTestRoot (now time.Time ) * cobra.Command {
352433 deps := defaultExportReportingDeps ()
353434 deps .now = func () time.Time { return now }
0 commit comments