Skip to content

test(credits): cover money paths before go-live - #405

Merged
catomean merged 2 commits into
mainfrom
test/money-path-coverage
Jul 17, 2026
Merged

test(credits): cover money paths before go-live#405
catomean merged 2 commits into
mainfrom
test/money-path-coverage

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

Summary

  • cover paid assistant charging, including 95/5 settlement and failed-debit safeguards
  • cover Lightning credit top-ups, owner scoping, settlement idempotency, and expiry
  • cover Cat Credits ledger RPC mapping and failure behavior

Verification

  • npm run type-check
  • npm run audit:routes (150 pages, 193 API routes)
  • npm run test:unit (73 suites, 774 tests)
  • pre-push fast E2E skipped because no local server was running; CI runs the P0 matrix

Scope

Test-only change. No production behavior or schema changes.

catomean and others added 2 commits July 16, 2026 12:13
The paid ai_assistant charge path (95/5 split, debit payer → grant creator)
goes live the moment PLATFORM_NWC_URI is provisioned, yet had zero tests.
Pin the balance-protecting rules: free/non-per_message/invalid prices bill 0,
the SANE_MAX guard refuses a mis-scaled legacy sats-in-BTC-column value, and
settlement never pays the creator when the payer debit didn't land.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds the two remaining untested money paths that go live with PLATFORM_NWC_URI:

- credit-topup.ts (money IN): both entry points hard-gate on
  platformReceiveEnabled(); amounts are bounded (NaN/out-of-range never mint an
  invoice); settlement credits the top-up's recorded OWNER idempotently on
  payment_hash; an already-paid row is never credited twice; an unsettled
  invoice past its window expires instead of hanging pending.
- credits.ts: the cat_credit_append / cat_credit_balance RPC contract —
  param mapping, numeric coercion, and the never-throw / return-null-or-0 rule
  callers rely on. (Atomicity/overdraw live in the SECURITY DEFINER RPC.)

33 new tests; money-path coverage now 46 across metering + charge + top-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@catomean
catomean marked this pull request as ready for review July 17, 2026 12:05
@catomean
catomean merged commit 090edc7 into main Jul 17, 2026
5 of 6 checks passed
@catomean
catomean deleted the test/money-path-coverage branch July 17, 2026 12:05
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.

1 participant