Repository navigation
fix(examples): dry_run_example names the admin key it needs and prints the server balance - #380
Conversation
The examples README said to run dry_run_example.py with a wallet-scoped key, but its first call, POST /v1/billing/wallets/sponsor, is admin gated, so that key got 403 admin_access_denied. The failure hint always named http://localhost:8000 even when B2A_API_URL pointed elsewhere. With an admin key the script printed "Initial virtual balance: 0.0" because it printed sim.total_cost, while the server reported a virtual balance of 10000. - README and docstring: the script needs a bootstrap admin key from the server's VALID_API_KEYS; add a troubleshooting row for the 403. - Failure hints use the configured API URL and explain 401/403 and 404. - DryRunSimulation keeps the server's starting virtual_balance as initial_balance, and the example prints it. Fixes #361 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: CS <cs@CSs-MacBook-Pro.local>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 52 minutes. View limit details
Pre-merge checks:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4de2fbd7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a4de2fb. Configure here.
The session tests hand-wrote a session id and successful session responses. They now live in the gateway suite, create the wallet and session through the real app with the SDK, and reshape the gateway's own response for the string and missing-field cases. dry_run_example.py imports httpx after the b2a_sdk guard, so a checkout without the SDK gets the install hint again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: CS <cs@CSs-MacBook-Pro.local>
…dry-run-example-docs Signed-off-by: GitHub <noreply@github.com> # Conflicts: # examples/tests/test_example_scripts.py Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
READY FOR QA 0df43ae Fixes #361. fix(examples): dry_run_example names the admin key it needs and prints the server balance. The branch was updated from main, so this head replaces any earlier one. CI result, License result and gitleaks are green on this commit, the PR is up to date with main, and there are no open review threads. |
…le-docs Signed-off-by: PetrefiedThunder <131207452+PetrefiedThunder@users.noreply.github.com>
PetrefiedThunder
left a comment
There was a problem hiding this comment.
Independent review (claude):
Verdict: PASS (on head 36425de, after merging origin/main into the branch with no conflicts)
CI on 36425de: 49 checks passed and 3 were skipped, including CI result, License result, gitleaks and Cursor Bugbot. The branch is up to date with main (merge state CLEAN).
Scope checked: the five files in the PR diff against main. The merge brought in #397, #214, #335 and #412; none of them touch these files.
Correctness
sdk/python/src/b2a_sdk/client.py:1009-1015:initial_balancereadsvirtual_balancefromPOST /v1/billing/dry-run/session. That matchesDryRunSessionResponse.virtual_balance: floatingateway/app/routers/billing.py:1590and the value the router sets atbilling.py:1689. The change only adds a keyword argument with a default (client.py:112), so existing callers keep working.examples/dry_run_example.py:191-206: the hint text is now status aware and uses the configuredB2A_API_URL. Importinghttpxafter theb2a_sdkguard (dry_run_example.py:36-38) is safe because the SDK depends onhttpx>=0.27.0,<1(sdk/python/pyproject.toml:37).
Docs claims match code
examples/README.md:109-123says amake quickstartkey is wallet-scoped.gateway/scripts/quickstart.py:12confirms it mints a wallet-scoped key. The README and the module docstring also say the sponsor wallet call needs a bootstrap admin key fromVALID_API_KEYS. The code agrees:/wallets/sponsor(billing.py:248) is documented as bootstrap admin only,require_bootstrap_adminreturns403 admin_access_denied(gateway/app/core/auth.py:106-116), andis_bootstrap_admin=Truecomes fromsettings.VALID_API_KEYS(auth.py:386-392).- The new troubleshooting row at
examples/README.md:184agrees with the hint the script prints.
Tests
gateway/tests/test_sandbox_integration.py:607-686drives the SDK through the real app over ASGI. It comparesinitial_balancewith the session body the gateway returned, so the asserted values come from the product. It also covers a string amount and a missing field.examples/tests/test_example_scripts.py:138-167covers the 403, 404 and connection hints and the configured URL. It has no case for 401, which takes the same branch as 403.- CI does not run
examples/tests. The Python matrix covers only the discovered projects (gateway, sdk/python, integrations), and gateway'stestpathsis["tests"]. So the three new example tests above are not gated by CI and pass only in local runs. The gateway tests are gated. - Local runs on the merged head:
examples/testsplussdk/python/testsgave 533 passed and 1 failed. The failure isexamples/tests/test_permit_stripe_refund_retry.py::test_retry_returns_same_receipt_one_debit_and_skips_stripe, which fails withsqlite3.OperationalError: unable to open database fileonly when the wholeexamples/testsdirectory runs. It passes when that file runs alone, and it fails the same way on plainorigin/main(d4f330e), so this PR did not cause it. My guess is that it has gone unnoticed because CI does not run that directory.gateway/tests/test_sandbox_integration.py,test_receipts.pyandtest_refund_amount_evidence.pygave 69 passed and 1 skipped (that test needs PostgreSQL). Ruff check and format are clean on gateway and sdk/python and on the two touched example files.mypy app/is clean.
Non-blocking nits
examples/tests/test_example_scripts.py:145:test_dry_run_403_names_the_admin_keytakes amonkeypatchfixture it never uses.examples/tests/test_example_scripts.py:165-167:test_dry_run_prints_server_initial_balanceonly searches the source text for a string. The gateway integration tests cover the real behavior, so this is fine, but the test would also pass if the print line were dead code.sdk/python/src/b2a_sdk/client.py:1015: the gateway also returnsvirtual_balance_exact(billing.py:1591), and the SDK keeps only the float. That is consistent with the rest ofDryRunSimulation, which uses floats, but callers who need the exact decimal cannot get it frominitial_balance.examples/dry_run_example.py:200-201: every 404 maps to theENABLE_PROOF_SURFACEShint, including404 wallet_not_found. Because the script creates its own wallet, that case should be rare.- The pre-existing order-dependent failure in
examples/testsnoted above, and the fact that CI does not runexamples/tests, should be tracked separately. Both are outside the scope of this PR. examples/dry_run_example.py:19: in the Usage block, the docstring ends a line with\inside a non-raw string. Python joins the two lines, sohelp()and__doc__show the uvicorn command on one wrapped line. This only affects how the text displays.
I could not run the IntelliJ inspections: this worktree is not open as a project in the running IDE, and I did not restart or reconfigure the IDE.

Fixes #361
Root cause
Three separate problems in
examples/dry_run_example.pyand its README section:examples/README.mdsaid to run the script withB2A_API_KEY=<wallet-scoped-local-key>. Its first call,POST /v1/billing/wallets/sponsor, is admin gated, so a wallet-scoped key gets403 admin_access_denied.B2A_API_URLpointed elsewhere and the real problem was the key.sim.total_cost(0.0 at session start), not the balance the server reported.DryRunSimulationdropped thevirtual_balancefield from the session response.Fix
VALID_API_KEYS), and the run block sets it on both sides. Added a troubleshooting row for the 403._failure_hints()uses the configuredB2A_API_URL. A 401 or 403 names the admin key requirement, and a 404 points atENABLE_PROOF_SURFACES=true.DryRunSimulationgainsinitial_balance, thevirtual_balancefromPOST /v1/billing/dry-run/session(Noneif absent). The example prints it. This is an additive SDK attribute inclient.py; PR Reject a None idempotency key from @billable factories #315 touchesdecorators.pyonly.Verification
Live, against a local gateway with
ENABLE_PROOF_SURFACES=trueand a locally generated bootstrap admin key:mainInitial virtual balance: 0.0 creditsInitial virtual balance: 10000.0 credits, demo completesB2A_API_URL=http://127.0.0.1:9gateway/tests/test_sandbox_integration.pythat create the wallet and session through the real gateway app with the SDK (initial_balancefrom the gateway's session response, including a string amount and a missing field) and three tests inexamples/tests/test_example_scripts.py(403 hint, configured URL in the connection and 404 hints, printed balance).python -m pytest examples/tests sdk/python/tests: 532 passed. Ruff check and format on all detected projects and the touched example files: clean.uv build sdk/python: builds wheel and sdist.No CHANGELOG entry, so the sibling SDK fix PRs from the same verification pass do not conflict in that section.
Merge order note
#378 (issue #359) also appends a test to the end of
examples/tests/test_example_scripts.py. Whichever of #378 and #380 merges second will need its branch updated from main, with both test blocks kept.🤖 Generated with Claude Code
Note
Low Risk
Additive SDK field and example/docs/test fixes on proof-surface dry-run paths; no change to production billing or auth core.
Overview
Fixes #361 by aligning the dry-run example, docs, and SDK with how the gateway actually behaves for sponsor-wallet creation and session balances.
Documentation and example behavior:
examples/README.mdanddry_run_example.pynow state that a bootstrap admin key (VALID_API_KEYS) is required—not a wallet-scoped quickstart key—because sponsor wallet creation is admin-gated. Run instructions setVALID_API_KEYSon the server and matchingB2A_API_KEYon the client, plus a troubleshooting row for403. On failure,_failure_hints()gives status-aware messages (admin key for 401/403, proof surfaces for 404, configuredB2A_API_URLfor connectivity) instead of always blaminglocalhost:8000. The demo printssim.initial_balancerather thansim.total_costat session start.SDK:
DryRunSimulationgainsinitial_balance, populated from the gateway’svirtual_balancewhen openingsimulate_session(coerced tofloat,Noneif missing).Tests: New coverage in
examples/tests/test_example_scripts.pyfor hints and the balance print string, and ingateway/tests/test_sandbox_integration.py(TestSdkSimulateSession) for SDK ↔ gateway balance handling.Reviewed by Cursor Bugbot for commit 07e202f. Bugbot is set up for automated code reviews on this repo. Configure here.