test(credits): cover money paths before go-live - #405
Merged
Conversation
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>
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.
Summary
Verification
npm run type-checknpm run audit:routes(150 pages, 193 API routes)npm run test:unit(73 suites, 774 tests)Scope
Test-only change. No production behavior or schema changes.