Skip to content

test(crypto,client,ipfs,learning,release): pin envelope, list, invite, transport and release-gate guards at their entry points - #18

Merged
SaulBuilds merged 10 commits into
mainfrom
test/gap-guard-pins
Nov 29, 2026
Merged

SaulBuilds merged 10 commits into
mainfrom
test/gap-guard-pins

Conversation

@SaulBuilds

@SaulBuilds SaulBuilds commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Tests-only pins for guards whose removal the existing suite did not notice, one example fix, and one hygiene fix (MANIFEST.in no longer includes the removed requirements.txt). No version bump, nothing published, and no source changes under citrate_sdk/.

What is pinned

tests/test_gap_guard_pins.py (call-site tests, no network, fixed throwaway test keys):

  • decrypt_data: a well-formed envelope under any other scheme label is refused by the scheme check (the existing check used a malformed envelope, so a later step masked it). An envelope without kdf_salt is refused by name.
  • verify_model_integrity compares through hmac.compare_digest.
  • list_models unwraps the node's {"models": [...]} answer (the existing test fed a bare list).
  • ClassroomManager.create: the default invite secret comes from the OS CSPRNG and does not depend on the clock.
  • Transport gate: non-http(s) schemes are refused at the client constructors, on loopback and with allow_insecure_http=True.
  • IPFSClient: upload must send add and then object/stat for the CID add returned; upload, its verification stat, download and pin all carry the client timeout.

tests/test_release_artifact_pins.py (shipped examples and release workflows):

  • Examples: each example's main() is run up to client construction with CitrateClient replaced and no network. Without CITRATE_PRIVATE_KEY it must stop before building a signing client, and up to that point no 32-byte hex secret (generated or from the environment) may reach stdout or stderr at the file-descriptor level, or a log record. Past that point, an AST check requires every read of a name bound from a *PRIVATE_KEY* env var to be a truth test or the private_key= of CitrateClient. Examples may not call get_private_key() at all.
  • Encrypted calls (inference, encrypt_data) bind positional and keyword arguments to the public signatures; an encrypted call with an absent or literal-None recipient fails, as do */** arguments the check cannot bind. Negative fixtures pin each form.
  • Examples parse and never call purchase_model_access.
  • publish.yml is parsed as YAML (pyyaml and types-pyyaml added to the dev extra; uv.lock updated):
    • The publish job's if: is evaluated over a table of events, refs and versions against the policy: a release publishes; a manual run publishes only from main with a nonempty version. A small evaluator covers the expression subset in use and refuses anything else (for example always()).
    • The version-check step must run on every manual publish that reaches the job, sit before the PyPI upload, read WANT from inputs.publish_version, and its script is executed with bash against matching and mismatched dist/ fixtures.
    • test, build and publish are chained through needs. The test and build jobs and the pytest step carry no if:, and the pytest step adds only verbosity flags (no --co, -k or path). No job or step sets continue-on-error or runs || true.
    • Trusted Publishing: id-token: write, one pypa/gh-action-pypi-publish step, no password or token inputs.
  • Every workflow (*.yml and *.yaml) is parsed, and every job-level and step-level uses: (quoted and flow-style included) is pinned to a commit SHA.
  • The uv.lock cryptography version satisfies the pyproject range.
  • Every MANIFEST.in include names a file that exists. This was red on main and is fixed in caa4526.

Example fix

examples/basic_usage.py, run without CITRATE_PRIVATE_KEY, generated a key, printed it to stdout and signed with it. It now stops with the same message as encrypted_inference.py. The README notes the example takes its key from the environment.

Standard: met

  • Red first: 7ab37a0 adds the original tests and test_manifest_includes_only_files_that_exist fails against main; caa4526 is the fix. 74858a6 tightens the tests and is red on basic_usage.py (test_examples_never_print_a_private_key, test_examples_never_extract_a_private_key); 3b4944a fixes the example. 4c9df90 closes the gaps the independent review found (uses after client construction, fd-level output and logs, a narrowed pytest step).
  • Mutants (each applied to a copy, the two test files run, then reverted), all RED with this PR:
    • publish.yml: main-branch predicate dropped; nonempty-version predicate dropped; the job if: moved into a YAML comment; the version-check script stops failing on a mismatched artifact; the script exits 0 early; the version-check step if: narrowed to releases; the pytest step gains if: github.event_name != 'release'; the pytest step gains continue-on-error; the test job gains an if:; always() || prepended to the publish gate.
    • Pins: a quoted unpinned "uses" in publish.yml; a new extra.yaml with a flow-style unpinned uses.
    • Examples: encrypted inference with positional True and no recipient; positional None recipient; recipient_public_key=None; encrypt_data(data, None); the original basic_usage.py; a key generated with eth_account and printed without building a client; the env key printed before the client, printed after it, logged, or written with os.write; pytest -q --co in the pytest step.
    • IPFS: _verify_upload removed from upload_bytes; _verify_upload called with another CID.
  • Suite, frozen uv.lock environment (Python 3.11, uv sync --frozen --all-extras): pytest -q 1002 passed, 50 skipped. ruff check . and mypy . are clean. uv lock --check passes.
  • Tests touch no host state: in-process fakes for RPC and HTTP, no sockets; the version-check script runs in a pytest tmp dir.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FPJzHNqGLdTVoFzde3Sxbw

SaulBuilds and others added 3 commits October 22, 2026 17:29
…, transport and release-gate guards at their entry points (red)

The manifest check fails on main: MANIFEST.in includes requirements.txt,
which no longer exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGMeatV8UjtCB4CTbWuAv4
…s.txt

pyproject.toml is the single dependency declaration.

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 23, 2026 00:49

@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 07f8636b40133726f221adcf65acc76c638041e6 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 07f8636b40133726f221adcf65acc76c638041e6 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 previously approved these changes Oct 27, 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 a43ca38a1311fd225b48a10352e9ba82f2855fb7 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 27, 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 a43ca38a1311fd225b48a10352e9ba82f2855fb7 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 13:02
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 a pinned send; 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 ee718c5 November 28, 2026 21:04

@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 ee718c532ec32e71d9339558eb86cc8db4afa6c2 is complete. Result: blockers; 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 ee718c532ec32e71d9339558eb86cc8db4afa6c2 is complete. Result: blockers; 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:

  • The diff matches the body: two new test files and one MANIFEST.in line removed. No changes under citrate_sdk/, and no version bump. The branch contains current main (0.9.0).
  • MANIFEST.in: requirements.txt does not exist on main. It was removed in the pyproject-canonical modernization, and git history confirms it. I built an sdist with python -m build on main and on the PR head. main logs 'no files found matching requirements.txt' and the PR does not. The sdist file lists are identical, so the sdist is not broken and is not changed beyond the warning.
  • Ran in a scratch clone with Python 3.11: the 2 new files have 38 passed. The full suite minus the economics simulation has 910 passed, 50 skipped.
  • Envelope crypto property: decrypt_data refuses cleartext-key envelopes, then requires scheme == V2 exactly, then requires kdf_salt. I disabled the scheme check and 4 tests went red (v1 label, missing label, empty label, case/whitespace variant on an otherwise valid V2 envelope). I disabled the kdf_salt check and 1 went red. Both pins are therefore real.
  • Other mutations I reproduced: verify_model_integrity '==' in place of hmac.compare_digest turns 1 test red. A clock-derived invite secret in place of secrets.token_bytes turns 2 red. list_models unwrap, the transport scheme gate and the IPFS timeout pins were read and look sound.
  • The release-artifact tests are read-only text/AST checks on examples, publish.yml, workflow SHA pins, uv.lock and MANIFEST.in. They write nothing and use no network.
  • CI: all checks are green, including locked-env. The pip-audit note in the body now looks stale.

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_01FPJzHNqGLdTVoFzde3Sxbw

@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 9c040b117d4227d126e40c02237b704a196a1dd0 is complete. Result: blockers; 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 9c040b117d4227d126e40c02237b704a196a1dd0 is complete. Result: blockers; 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

Re-review after the main merge, reviewed head 9c040b1. This covers only the merge, since the content was approved at ee718c5. CI note: python / test, locked-env and ci were still in progress when I reviewed. The other checks are green.

Checked:

  • The merge commit 9c040b1 has parents ee718c5 (the previously reviewed head) and 07ce7b9 (current main, #17). It is SSH-signed.
  • git merge-tree --write-tree ee718c53 07ce7b9c gives tree 0c7d5404, the same as the merge commit's tree. The merge is a clean automatic merge with no manual edits.
  • From ee718c5 to the merge, the only file that changes is tests/test_call_site_guard_pins.py, which comes from main. From main to the merge, the only files that change are the PR's own three: MANIFEST.in and the two new test files. The merge adds nothing beyond main.
  • Ran in a scratch venv with Python 3.11: test_gap_guard_pins.py, test_release_artifact_pins.py and main's test_call_site_guard_pins.py together give 43 passed.
  • Note: the automated Codex reviews on ee718c5 and 9c040b1 report "blockers", with details in the private review log. I cannot see those details. Because the merge changes nothing beyond main, any such blocker would also apply to the content approved earlier or to main itself. The lead should look at that log before merging.

SaulBuilds and others added 2 commits November 28, 2026 17:36
…r key leaks

Tightens the release-artifact and IPFS pins after review found checks that
passed with the guard they name removed:

- Examples: a new run of each example's main() with the client replaced
  fails if, without CITRATE_PRIVATE_KEY, it builds a signing client or writes
  any 32-byte hex secret to stdout/stderr (and if it echoes an env key).
  Examples may not call get_private_key() at all. Red here on
  examples/basic_usage.py, which generates a key and prints it.
- Encrypted calls bind positional and keyword arguments to the public
  signatures and reject an absent or literal-None recipient.
- publish.yml is parsed as YAML. The publish job's if: is evaluated over a
  context table against the policy (release, or manual from main with a
  version); the version-check step must run on every manual publish before
  the upload, and its script is executed against matching and mismatched
  dist/ fixtures. The pytest step and the test/build jobs may not be
  conditional or continue-on-error.
- Workflow discovery covers *.yml and *.yaml; uses: pins are read from the
  parsed job and step mappings (quoted and flow-style included).
- The upload test requires add then object/stat, with the CID add returned.

Adds pyyaml and types-pyyaml to the dev extra (uv.lock updated).

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_01FPJzHNqGLdTVoFzde3Sxbw
Without CITRATE_PRIVATE_KEY the example generated a key, printed it to
stdout and signed with it. It now stops with the same message as
encrypted_inference.py. The README notes the key comes from the
environment. Turns test_examples_never_print_a_private_key and
test_examples_never_extract_a_private_key green.

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_01FPJzHNqGLdTVoFzde3Sxbw

@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 3b4944aad4e0c8f6e4f45993bec84804f6dd7691 is complete. Result: blockers; 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 3b4944aad4e0c8f6e4f45993bec84804f6dd7691 is complete. Result: blockers; 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 helper): APPROVE

Reviewed head 3b4944a (git diff origin/main...HEAD, PR body, examples/*.py, citrate_sdk/crypto.py KeyManager, citrate_sdk/ipfs.py upload path, all three workflows). Ran the two new test files from a scratch copy in the frozen uv.lock env (Python 3.11): 73 passed. CI locked-env (frozen sync, ruff, mypy, full pytest) and uv-lock-check are green on this head.

Prior findings, each checked with a mutant on a copy:

  1. basic_usage.py key print: closed. The example now exits without CITRATE_PRIVATE_KEY and no longer imports KeyManager. Restoring the main-branch basic_usage.py fails both test_examples_never_extract_a_private_key and test_examples_never_print_a_private_key. By inspection no shipped example prints a private key in any path, with or without the env var.
  2. Manual publish gate: closed. Replacing the main-ref predicate with true or with github.ref != '' fails; adding if: to the pytest step fails; the version-check script is executed against matching and mismatched dist fixtures.
  3. Workflow discovery and pin parsing: closed. A new extra.yaml with a flow-style unpinned uses fails; quoted and flow-style fixtures are covered.
  4. Encrypted-call check: closed. Positional encrypted flag, positional None recipient and recipient_public_key=None are all in the negative fixtures and refused.
  5. IPFS verification: closed. Removing the _verify_upload call, or passing a different CID to it, fails test_upload_and_its_verification_carry_the_timeout.

Deps: pyyaml was already in uv.lock as a transitive package, types-pyyaml is newly locked, both are added to the dev extra (the reusable CI installs .[dev], locked-env uses --all-extras). Lock is consistent (uv lock --check green in CI).

Non-blocking findings (test hardening, follow-up is fine):
a. The runtime key-leak check only exercises code before the first CitrateClient construction, because the stand-in client raises there. A print(PRIVATE_KEY) placed after the client is built passes the suite. The docstring wording (no run may write a 32-byte hex secret) is broader than what is exercised. Suggest a stand-in that returns an inert recorder so main() runs to completion, or narrow the docstring.
b. Output capture misses some channels: logging.warning(key) passes (pytest log capture intercepts it before stderr), and os.write(1, ...) passes (capsys, not capfd). Suggest capfd plus caplog.text in the scanned text.
c. Partial or reformatted keys pass: a 40-char prefix, a key split across two prints, and the bytes repr of Account.create().key all pass. The full-hex and uppercase forms, stderr, no-0x, and a key inside an exception message are caught.
d. The pytest step regex accepts any trailing arguments, so pytest --co or a narrowed test path still passes. Outside the five findings; consider pinning the exact command.
e. Pre-existing, not in this diff: encrypted_inference.py prints the first 8 bytes of the derived ECDH shared keys. Not a private key, but worth dropping in a later example pass.

None of these blocks merge: the shipped examples are clean today, and every finding the earlier review raised is closed with a test that goes red on the original regression.

…-suite pytest

From the independent review of 3b4944a:
- The runtime key test stops at client construction, so a print of the
  env key after it went unseen. A new AST check requires every read of a
  name bound from a *PRIVATE_KEY* env var to be a truth test or the
  private_key= of CitrateClient; fixtures pin print, logging, slicing and
  a pass-through call.
- The runtime test now reads capfd (fd 1/2, so os.write is seen) and
  caplog, and its docstring says what it covers.
- The pytest step may only add verbosity flags (-q, -v, -ra), so --co,
  -k or a path cannot narrow the release gate.

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_01FPJzHNqGLdTVoFzde3Sxbw

@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 4c9df907556abb380586d549c2d932e9efdadd76 is complete. Result: blockers; 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 4c9df907556abb380586d549c2d932e9efdadd76 is complete. Result: blockers; 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 helper, re-review of 4c9df90): APPROVE

Scope: git diff 3b4944a..4c9df90 plus the full PR diff vs origin/main. Ran tests/test_release_artifact_pins.py and tests/test_gap_guard_pins.py from a copy of 4c9df90 on Python 3.11 with the locked env: 80 passed. Then ran mutants against the copy.

The three claimed closures hold:

  1. Env key use after construction. The AST check flags every Load of an env-bound name that is not a bare truth test or the private_key= of CitrateClient. Caught: print(k) after k = PRIVATE_KEY (the alias read itself is flagged, so aliasing is covered), print(f'{PRIVATE_KEY[:10]}') after the client, logging.warning('%s', PRIVATE_KEY) after the client. No false positives on the three current examples. if/while bodies that merely test the name are correctly accepted.
  2. fd and log capture. os.write(1, key) and sys.stdout.write(key) before construction are now caught by capfd; caplog at DEBUG catches logging. Inline print of a freshly generated KeyManager key before the client is caught.
  3. pytest step. --co, a path, -k, -x, --deselect=, -p all fail the pin now; multi-line or chained commands also fail because every token must be in {-q, -v, -ra}.

SDK side: KeyManager/CitrateClient do not log or repr the key, and the construction errors do not echo it, so no example leaks the key through the SDK itself on the paths I checked.

Nothing blocking. Non-blocking nits (all hypothetical future examples, none present today):

  • _env_key_names only recognises ast.Assign of os.getenv / os.environ.get. Not recognised as a key source, verified to pass undetected after the client: os.environ['CITRATE_PRIVATE_KEY'] (Subscript), an inline print(os.getenv('CITRATE_PRIVATE_KEY')), an annotated K: str | None = os.getenv(...), and from os import getenv. Adding ast.AnnAssign and an os.environ[...] Subscript source is trivially closable; inline/aliased-import reads could be handled by flagging any getenv/environ access with a PRIVATE_KEY constant outside an Assign.
  • Key material not sourced from the env is only pinned up to the first CitrateClient: print(client.key_manager.account.key.hex()) after construction and print(sim_key) in the marketplace_demo simulation loop both pass. A static ban on .key.hex() / .account.key in examples would close it.
  • The publish pin does not look at PYTEST_ADDOPTS in workflow/job/step env or at addopts in pyproject, either of which could narrow the run without touching the run: line. Low risk since both are reviewed files.

No code was edited by this review.

@SaulBuilds
SaulBuilds merged commit 0e82174 into main Nov 29, 2026
10 checks passed
@SaulBuilds
SaulBuilds deleted the test/gap-guard-pins branch November 29, 2026 02:07
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