@@ -24,8 +24,27 @@ const HEADER = [
2424 'aic_gross_amount' ,
2525] . join ( ',' )
2626
27- function createCsv ( rows : string [ ] [ ] ) : File {
28- const body = [ HEADER , ...rows . map ( ( row ) => row . join ( ',' ) ) ] . join ( '\n' )
27+ const NATIVE_AI_CREDITS_HEADER = [
28+ 'date' ,
29+ 'username' ,
30+ 'product' ,
31+ 'sku' ,
32+ 'model' ,
33+ 'quantity' ,
34+ 'unit_type' ,
35+ 'applied_cost_per_quantity' ,
36+ 'gross_amount' ,
37+ 'discount_amount' ,
38+ 'net_amount' ,
39+ 'total_monthly_quota' ,
40+ 'organization' ,
41+ 'cost_center_name' ,
42+ 'aic_quantity' ,
43+ 'aic_gross_amount' ,
44+ ] . join ( ',' )
45+
46+ function createCsv ( rows : string [ ] [ ] , header = HEADER ) : File {
47+ const body = [ header , ...rows . map ( ( row ) => row . join ( ',' ) ) ] . join ( '\n' )
2948 return new File ( [ body ] , 'usage.csv' , { type : 'text/csv' } )
3049}
3150
@@ -45,7 +64,36 @@ class CaptureAggregator implements Aggregator<TokenUsageRecord, TokenUsageRecord
4564 }
4665}
4766
48- describe ( 'runPipeline progress' , ( ) => {
67+ describe ( 'runPipeline' , ( ) => {
68+ it ( 'rejects native AI Credits reports before processing rows' , async ( ) => {
69+ const file = createCsv ( [
70+ [
71+ '5/29/26' ,
72+ 'mona' ,
73+ 'copilot' ,
74+ 'copilot_ai_credit' ,
75+ 'Auto: Claude Haiku 4.5' ,
76+ '96.9990345' ,
77+ 'ai-credits' ,
78+ '0.01' ,
79+ '0.969990345' ,
80+ '0' ,
81+ '0.969990345' ,
82+ '3900' ,
83+ 'example-org' ,
84+ '' ,
85+ '96.9990345' ,
86+ '0.969990345' ,
87+ ] ,
88+ ] , NATIVE_AI_CREDITS_HEADER )
89+ const aggregator = new CaptureAggregator ( )
90+
91+ await expect ( runPipeline ( file , [ aggregator ] ) ) . rejects . toThrow (
92+ 'currently supports PRU vs usage-based billing reports generated for the April and May billing periods' ,
93+ )
94+ expect ( aggregator . result ( ) ) . toEqual ( [ ] )
95+ } )
96+
4997 it ( 'filters and normalizes known normalization window rows before AIC allocation' , async ( ) => {
5098 const file = createCsv ( [
5199 [ '2026-04-25' , 'mona' , 'copilot' , 'copilot_premium_request' , 'GPT-5' , '0' , 'requests' , '0.04' , '0' , '0' , '0' , 'False' , '300' , '' , '' , '0' , '0' ] ,
0 commit comments