feat(audit-trail): add reconciliation mode against indexer DB - #997
Merged
orunganiekan merged 2 commits intoAug 31, 2026
Merged
Conversation
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
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #890
Adds
--reconcilemode toaudit-trail.tsso 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--reconcileflag dispatches to the reconciliation path before existing trail modeaggregateExportByDay()— groups charged/pay_per_use entries from the audit export by UTC calendar day, summing volume and fees as BigInt stringsaggregateIndexerByDay(db)— queries the indexer SQLite DB (same schema asindexer.ts) with a single grouped SELECT over charged/pay_per_use rowsreconcileAggregates()— compares every day present in either source; days present only in one source are treated as all-zeros in the otherDayReconcileResultlists field-level diffs (charge_count,volume_stroops,fees_stroops)scripts/fixtures/audit-trail-reconcile.jsonTwo 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.tsIn-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.jsonAdds
test:audit-trail-reconcilescript; fixes pre-existing duplicatetest:renewal-forecastentryAcceptance criteria