Skip to content

Commit 4276180

Browse files
asizikovCopilot
andcommitted
fix: keep native AI Credits fields authoritative
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c7f4f98 commit 4276180

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

src/pipeline/parser.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,13 @@ describe('native AI Credits parsing helpers', () => {
724724
cost_center_name: 'Cost Center A',
725725
aic_quantity: 96.9990345,
726726
aic_gross_amount: 0.969990345,
727+
aic_net_amount: 0.819990345,
727728
has_aic_quantity: true,
728729
has_aic_gross_amount: true,
729730
})
730731
})
731732

732-
it('uses native quantity and gross amount as AIC alias fallbacks when alias columns are blank', () => {
733+
it('uses native quantity and cost fields as AIC aliases when alias columns are blank', () => {
733734
const header = parseTokenUsageHeader(HEADER_WITHOUT_EXCEEDS_QUOTA)
734735
const record = parseNativeAiCreditsUsageRecord(
735736
buildRow([
@@ -761,6 +762,44 @@ describe('native AI Credits parsing helpers', () => {
761762
net_amount: 0.1,
762763
aic_quantity: 12.5,
763764
aic_gross_amount: 0.125,
765+
aic_net_amount: 0.1,
766+
has_aic_quantity: true,
767+
has_aic_gross_amount: true,
768+
})
769+
})
770+
771+
it('keeps native quantity and cost fields authoritative when alias columns differ', () => {
772+
const header = parseTokenUsageHeader(HEADER_WITHOUT_EXCEEDS_QUOTA)
773+
const record = parseNativeAiCreditsUsageRecord(
774+
buildRow([
775+
'5/29/26',
776+
'octocat',
777+
'copilot',
778+
'copilot_ai_credit',
779+
'GPT-5.2',
780+
'50',
781+
'ai-credits',
782+
'0.01',
783+
'0.50',
784+
'0.20',
785+
'0.30',
786+
'3900',
787+
'example-org',
788+
'Cost Center A',
789+
'75',
790+
'0.75',
791+
]),
792+
header,
793+
)
794+
795+
expect(record).toMatchObject({
796+
quantity: 50,
797+
gross_amount: 0.5,
798+
discount_amount: 0.2,
799+
net_amount: 0.3,
800+
aic_quantity: 50,
801+
aic_gross_amount: 0.5,
802+
aic_net_amount: 0.3,
764803
has_aic_quantity: true,
765804
has_aic_gross_amount: true,
766805
})

src/pipeline/parser.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,16 @@ export function normalizeNativeAiCreditsReportDate(rawDate: string): string {
326326

327327
export function parseNativeAiCreditsUsageRecord(line: string, header: TokenUsageHeader): TokenUsageRecord {
328328
const record = parseTokenUsageRecord(line, header)
329-
const aicQuantity = record.has_aic_quantity ? record.aic_quantity : record.quantity
330-
const aicGrossAmount = record.has_aic_gross_amount ? record.aic_gross_amount : record.gross_amount
331329
const nativeRecord: TokenUsageRecord = {
332330
...record,
333331
date: normalizeNativeAiCreditsReportDate(record.date),
334-
aic_quantity: aicQuantity,
335-
aic_gross_amount: aicGrossAmount,
332+
aic_quantity: record.quantity,
333+
aic_gross_amount: record.gross_amount,
334+
aic_net_amount: record.net_amount,
336335
has_aic_quantity: true,
337336
has_aic_gross_amount: true,
338337
}
339338

340-
nativeRecord.aic_net_amount = getAicUsageMetrics(nativeRecord).aicGrossAmount
341339
return nativeRecord
342340
}
343341

0 commit comments

Comments
 (0)