Skip to content

test(client,identity): pin nonce and IPFS fail-closed guards at their entry points - #17

Merged
SaulBuilds merged 3 commits into
mainfrom
test/call-site-guard-pins
Nov 29, 2026
Merged

SaulBuilds merged 3 commits into
mainfrom
test/call-site-guard-pins

Conversation

@SaulBuilds

Copy link
Copy Markdown
Contributor

Summary

Tests only. No production code, version or dependency changes.

Pins two fail-closed guards at their public entry points. Before this PR, each guard could be removed with the rest of the suite still green, because a later check masked the removal.

Guard Entry point New test(s)
Up-front "nonce required" check in exchange_code IdentityClient.exchange_code test_exchange_code_without_a_nonce_is_refused_before_the_token_request[None], [""]. Positive control: test_exchange_code_with_the_matching_nonce_still_succeeds
IPFS upload failure aborts the deploy (no placeholder CID) CitrateClient.deploy_model test_deploy_model_aborts_when_the_ipfs_upload_fails. Positive control: test_deploy_model_carries_the_cid_the_upload_returned
  • Without the nonce check, nonce="" was still caught later by the ID-token claim comparison. nonce=None, however, skipped the nonce check entirely and the token verified. The new test asserts that both values raise IdentityError before the authorization code is redeemed: no request reaches the token endpoint.
  • The deploy test makes upload_to_ipfs raise. It then asserts that deploy_model raises CitrateError and that no eth_sendRawTransaction is made.

All transports are in-process fakes, so no test opens a socket.

Standard: met

  • Revert check: each guard was neutralised in turn (if not nonce: → if False:; the raise CitrateError(...) in _upload_to_ipfs → return "fallback_…"), and the suite was run each time:
    • nonce check off → 2 red (both parametrisations, on assertion: "DID NOT RAISE" / message mismatch, plus the token endpoint was hit).
    • IPFS fail-closed off → 1 red (test_deploy_model_aborts_when_the_ipfs_upload_fails).
    • Restored → green.
  • Before this PR, both reverts left the suite green: 806 passed, 49 skipped (economics simulation excluded for the mutation runs; it imports only citrate_sdk.economics).
  • Suite: uv run --frozen pytest -q collects 907 → 912 tests (5 new). The new file passes, and the suite without the economics simulation runs 811 passed, 49 skipped.
  • Lint and types: ruff check . and mypy . are clean.
  • Wider sweep: 14 further guard reverts in the client, transport, identity and envelope code were checked in the same pass. Each one already went red in the existing suite, so no new tests were needed for them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KGMeatV8UjtCB4CTbWuAv4

… entry points

Two fail-closed guards were only covered through a check elsewhere that
masked their removal:

- IdentityClient.exchange_code: the up-front "nonce required" check. With
  it removed, nonce="" was still caught later by the ID-token claim
  comparison, and nonce=None silently skipped the nonce check. The new test
  drives exchange_code with None and "" and asserts it refuses before the
  authorization code is redeemed (no token-endpoint request).
- CitrateClient.deploy_model: an IPFS upload failure must abort the deploy.
  The new test makes upload_to_ipfs raise and asserts deploy_model raises
  and broadcasts no transaction; a positive control checks the returned CID
  is what lands in the calldata.

Revert check: each guard neutralised in turn, full suite run, the new tests
go red on assertion; restored, green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGMeatV8UjtCB4CTbWuAv4
@SaulBuilds
SaulBuilds requested a review from a team as a code owner October 22, 2026 22:53

@BerryManifold BerryManifold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval at d8e7207373ed3a4e6a5d5ec50b0ddddd69e87d34 after focused differential review of changed files, history, security guards and immediate callers. All 5 targeted tests pass; both nonce-guard-removal and IPFS fail-open mutants fail assertions, restoring source returns 5/5 green.

Limits: No deployments, live authority/chain/storage operations, full cross-repository integration or full historical security audit. Required CI/branch/owner gates still apply. Both account submissions reflect the same automated review.

@Matr0xshka Matr0xshka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval at d8e7207373ed3a4e6a5d5ec50b0ddddd69e87d34 after focused differential review of changed files, history, security guards and immediate callers. All 5 targeted tests pass; both nonce-guard-removal and IPFS fail-open mutants fail assertions, restoring source returns 5/5 green.

Limits: No deployments, live authority/chain/storage operations, full cross-repository integration or full historical security audit. Required CI/branch/owner gates still apply. Both account submissions reflect the same automated review.

BerryManifold
BerryManifold previously approved these changes Oct 28, 2026

@BerryManifold BerryManifold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Codex static review of d8e7207373ed3a4e6a5d5ec50b0ddddd69e87d34 is complete. Result: clean; details retained privately. Details and coverage limits are recorded in the project's private review log. No tests were executed by this reviewer. Both account submissions represent the same Codex review, not independent reviews.

Matr0xshka
Matr0xshka previously approved these changes Oct 28, 2026

@Matr0xshka Matr0xshka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Codex static review of d8e7207373ed3a4e6a5d5ec50b0ddddd69e87d34 is complete. Result: clean; details retained privately. Details and coverage limits are recorded in the project's private review log. No tests were executed by this reviewer. Both account submissions represent the same Codex review, not independent reviews.

@BerryManifold BerryManifold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Codex static review of d8e7207373ed3a4e6a5d5ec50b0ddddd69e87d34 is complete. Result: clean; details retained privately. Details and coverage limits are recorded in the project's private review log. No tests were executed by this reviewer. Both account submissions represent the same Codex review, not independent reviews.

@Matr0xshka Matr0xshka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Codex static review of d8e7207373ed3a4e6a5d5ec50b0ddddd69e87d34 is complete. Result: clean; details retained privately. Details and coverage limits are recorded in the project's private review log. No tests were executed by this reviewer. Both account submissions represent the same Codex review, not independent reviews.

SaulBuilds and others added 2 commits November 28, 2026 12:58
Signed-off-by: Larry Klosowski <larryklosowski@proton.me>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FPJzHJptQTtnapM2Jio6AY
main now checks block 0 before deploy; this fake RPC serves no block 0,
and the guard has its own pins in test_r1006_network_guard.py.

Signed-off-by: Larry Klosowski <larryklosowski@proton.me>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FPJzHJptQTtnapM2Jio6AY
@SaulBuilds
SaulBuilds dismissed stale reviews from Matr0xshka and BerryManifold via 3ddb4e2 November 28, 2026 21:01

@BerryManifold BerryManifold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Codex static review of 3ddb4e26a516b1982d10084f6e35e9ceb9b03ee6 is complete. Result: clean; details retained privately. Details and coverage limits are recorded in the project's private review log. No tests were executed by this reviewer. Both account submissions represent the same Codex review, not independent reviews.

@Matr0xshka Matr0xshka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Codex static review of 3ddb4e26a516b1982d10084f6e35e9ceb9b03ee6 is complete. Result: clean; details retained privately. Details and coverage limits are recorded in the project's private review log. No tests were executed by this reviewer. Both account submissions represent the same Codex review, not independent reviews.

@SaulBuilds SaulBuilds left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent agent review (sweeper D): APPROVE

Checked:

  • Diff is tests only: new tests/test_call_site_guard_pins.py. No changes under citrate_sdk/, and no version or dependency changes. The branch contains current main (0.9.0), so it is not superseded.
  • Ran in a scratch clone with Python 3.11: the new file has 5 passed. The suite minus the economics simulation has 877 passed, 50 skipped. The counts differ from the body only because main has moved since.
  • Nonce property: exchange_code has an up-front 'if not nonce' refusal. I neutralised it to 'if False'. Both parametrisations then go red (None and an empty string), so the pin is real. With None the token endpoint was otherwise reached and the ID token verified without nonce binding, which is the replay gap SPY-B-010 closes. The test also asserts that the authorization code is never redeemed (no token endpoint call). The positive control confirms the matching nonce still verifies and is carried in claims.
  • IPFS fail-closed: I replaced the raise in _upload_to_ipfs with a placeholder CID return, and test_deploy_model_aborts_when_the_ipfs_upload_fails goes red. The test also asserts that no eth_sendRawTransaction is sent. The positive control decodes the RLP payload and checks the real CID.
  • Fakes are in-process. No sockets. expected_genesis_hash=None is used only in the fixture, and the genesis guard is pinned elsewhere.
  • CI: all checks are green, including locked-env and python / test.

@SaulBuilds
SaulBuilds merged commit 07ce7b9 into main Nov 29, 2026
10 checks passed
@SaulBuilds
SaulBuilds deleted the test/call-site-guard-pins branch November 29, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants