Skip to content

feat(audit-trail): add reconciliation mode against indexer DB - #997

Merged
orunganiekan merged 2 commits into
SiLioLabs:masterfrom
ogaziedaniel80-droid:feat/audit-trail-reconcile
Aug 31, 2026
Merged

feat(audit-trail): add reconciliation mode against indexer DB#997
orunganiekan merged 2 commits into
SiLioLabs:masterfrom
ogaziedaniel80-droid:feat/audit-trail-reconcile

Conversation

@ogaziedaniel80-droid

Copy link
Copy Markdown
Contributor

Closes #890

Adds --reconcile mode to audit-trail.ts so exports can be validated against the indexer SQLite database before compliance use. Mismatches exit non-zero so CI/ops pipelines catch divergence automatically.

Changes

scripts/audit-trail.ts

  • New --reconcile flag dispatches to the reconciliation path before existing trail mode
  • aggregateExportByDay() — groups charged/pay_per_use entries from the audit export by UTC calendar day, summing volume and fees as BigInt strings
  • aggregateIndexerByDay(db) — queries the indexer SQLite DB (same schema as indexer.ts) with a single grouped SELECT over charged/pay_per_use rows
  • reconcileAggregates() — compares every day present in either source; days present only in one source are treated as all-zeros in the other
  • Per-day DayReconcileResult lists field-level diffs (charge_count, volume_stroops, fees_stroops)
  • Exits 1 on any mismatch, prints mismatched days to stderr; exits 0 on clean pass
  • JSON and CSV output formats

scripts/fixtures/audit-trail-reconcile.json

Two fixture scenarios: matching (export and indexer agree) and mismatch (one event missing from indexer, producing diffs on all three fields)

scripts/test-audit-trail-reconcile.ts

In-memory SQLite test runner, no network required. Five suites: unit tests for each aggregation function, full pipeline matching/mismatch, and edge cases (export-only day, indexer-only day, both empty, multi-day partial mismatch)

scripts/package.json

Adds test:audit-trail-reconcile script; fixes pre-existing duplicate test:renewal-forecast entry

Acceptance criteria

  • Mismatch exits non-zero
  • Report shows per-day diffs
  • Tests with fixtures

Adds --reconcile mode to audit-trail.ts that compares per-day
charge/fee aggregates from a previously produced audit export JSON
against the live indexer SQLite database.

Changes:
- scripts/audit-trail.ts: add ReconcileArgs type, aggregateExportByDay(),
  aggregateIndexerByDay(), reconcileAggregates(), runReconcile(), and
  renderReconcileCsv/Json helpers; --reconcile flag dispatches to this
  path before normal trail mode; exits non-zero on any day mismatch
- scripts/fixtures/audit-trail-reconcile.json: fixture with matching
  and mismatch scenarios including expected per-day diffs
- scripts/test-audit-trail-reconcile.ts: fixture-driven test runner
  (in-memory SQLite, no network) covering aggregation unit tests,
  full pipeline matching/mismatch scenarios, and edge cases
- scripts/package.json: add test:audit-trail-reconcile script; fix
  duplicate test:renewal-forecast entry

Closes SiLioLabs#96
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@ogaziedaniel80-droid Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@orunganiekan
orunganiekan merged commit f3af46b into SiLioLabs:master Aug 31, 2026
0 of 3 checks passed
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.

Issue 096: Implement audit-trail export reconciliation against indexer

2 participants