Skip to content

Add usage report adapter layer#132

Merged
asizikov merged 1 commit into
mainfrom
asizikov/report-adapter-layer
Jun 5, 2026
Merged

Add usage report adapter layer#132
asizikov merged 1 commit into
mainfrom
asizikov/report-adapter-layer

Conversation

@asizikov

@asizikov asizikov commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

Usage report parsing needs a format-aware entry point so current Transition Period Billing Preview reports keep working while newer native AI Credits reports can be identified separately. This PR adds that adapter layer without changing downstream normalization or aggregation behavior.

Commit Change
refactor: add usage report adapter layer Adds report format metadata, adapter selection, and first-row validation routing while preserving the existing Transition Period Billing Preview parser path and native AI Credits unsupported error.

Changes

  • Adds transition-period-billing-preview and native-ai-credits report format metadata and adapters.
  • Detects the report format from the parsed header plus the first non-empty data row.
  • Routes pipeline preflight validation through the selected adapter while keeping immediate shared header validation for malformed or pre-AIC reports.
  • Preserves native AI Credits behavior by detecting those reports and throwing UnsupportedNativeAiCreditsReportError for this slice.
  • Adds focused adapter selection tests and pipeline header-only validation coverage.

Testing

  • npm test
  • npm run lint
  • npm run build

Checklist

  • Specs lint passes (npm run lint)
  • Tests updated if applicable
  • Documentation updated if applicable

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 5, 2026 07:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a small adapter layer to make usage report preflight validation format-aware, so the existing Transition Period Billing Preview CSVs continue to work while “native AI Credits” CSVs are detected and rejected with the existing unsupported error—without changing downstream parsing/normalization/aggregation.

Changes:

  • Adds reportAdapters with report-format metadata, detection (header + first data row), and adapter-selected first-row validation.
  • Updates runPipeline preflight validation to use the adapter entry points while keeping header-only validation for malformed / pre-AIC reports.
  • Adds targeted tests for adapter selection and for header-only report validation behavior in the pipeline.
Show a summary per file
File Description
src/pipeline/runPipeline.ts Routes preflight header + first-row validation through the new adapter entry points.
src/pipeline/runPipeline.test.ts Adds coverage for valid/malformed/pre-AIC header-only reports and preserves native-report rejection behavior.
src/pipeline/reportAdapters.ts New adapter layer: report format metadata, detection, adapter selection, and validation routing.
src/pipeline/reportAdapters.test.ts New tests validating format detection/selection and early header validation behavior.
src/pipeline/parser.ts Extracts native-report signature detection into hasNativeAiCreditsReportSignature and reuses it in validation.
src/pipeline/parser.test.ts Renames variables for clarity (“legacyHeader” → “preAicHeader”) without behavior changes.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 6/6 changed files
  • Comments generated: 0

@asizikov asizikov merged commit fdad591 into main Jun 5, 2026
10 checks passed
@asizikov asizikov deleted the asizikov/report-adapter-layer branch June 5, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants