Repository navigation
test: cover policy decision matrix and tamper-rejecting hash chain (#1) - #2
Open
raofal-msodeh wants to merge 1 commit into
Open
raofal-msodeh wants to merge 1 commit into
raofal-msodeh wants to merge 1 commit into
Conversation
The baseline suite only exercised the security-gate branch of Policy.evaluate, the happy path of the hash chain, and the passing cases of EvidenceBundle.now. This adds 51 tests across four suites: - test_policy.py: full decision-matrix coverage, including boundary conditions at exactly the file (250) and churn (5000) limits, the generic BLOCKED/REVIEW propagation paths, and the block_on_security_failure=False override semantics. - test_hashchain.py: deterministic sorted canonical JSON, valid multi-bundle chains, and rejection of broken links, missing previous hashes, mutated payloads, mutated final_status, and extra fields. - test_models.py: aggregate status derivation for every composition, including the all-skipped -> SKIPPED branch (models.py line 76). - test_cli_errors.py: defensive CLI error contract (missing/unknown commands, invalid JSON, malformed payloads -> exit code 2). Total: 8 -> 59 tests, coverage 96% -> 99% (CI floor: 90%). No production code or dependency changes.
|
Important Review available on request
Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Closes #1
Problem
The baseline suite covered only 8 tests and exercised a narrow slice of the decision surface: the security-gate branch of
Policy.evaluate, the happy path of the hash chain, and the passing cases ofEvidenceBundle.now. The file-count gate, the churn gate, genericBLOCKED/REVIEWpaths, theSKIPPED-only aggregate status, and every tamper-rejection branch of the hash chain were completely unverified — yet tamper-evident chaining is the core security promise of the product ("deterministic, replayable evidence bundles").policy.pylines 22–43 had zero direct test evidence, so a future refactor could silently change user-facing decisions (pass/review/blocked).hashchain.pynever asserted that the chain rejects tampering — a broken link, a mutated payload, or a forgedcontent_hash/final_statusall went untested.models.pyline 76 (all-skipped → SKIPPED) and the CLI error contract (exit code2) were also unverified.Solution
51 new tests across four focused suites, testing only — no production-code or dependency changes, fully aligned with
CONTRIBUTING.md(test coverage for behavior, conventional commits, no new dependencies):tests/test_policy.py(16 tests) — full decision-matrix coverage, including boundary conditions at exactly the file limit (250) and churn limit (5000), the genericBLOCKED/REVIEWpropagation paths,BLOCKED-over-REVIEWprecedence, and theblock_on_security_failure=Falseoverride semantics.tests/test_hashchain.py(17 tests) — deterministic sorted canonical JSON (ASCII-safe UTF-8, whitespace/key-order independence), valid multi-bundle chains with JSON round-trip, and rejection of broken links, missing previous hashes, mutated payloads, mutatedfinal_status, and extra undocumented fields. Also provesprevious_hashis itself part of the digest (link repositioning attacks fail).tests/test_models.py(10 tests) — aggregate status derivation for every composition, including the all-skipped →SKIPPEDbranch (models.py line 76) and frozen-dataclass immutability.tests/test_cli_errors.py(8 tests) — defensive CLI error contract: missing/unknown commands, invalid JSON, malformed payloads, missing files → exit code2with actionable stderr.Tests
policy.pyhashchain.pymodels.pycli.pyAll 59 tests pass locally, plus
ruff check src tests(zero warnings) andmypy src(strict, zero issues), matching the CI pipeline exactly (pytest --cov-fail-under=90,ruff,mypy).Impact
A reviewer can now rely on the suite as evidence of the product's core invariants: any refactor of
Policy.evaluateor the hash-chain algorithm will be caught immediately, and the previously untested tamper-rejection branches are locked in as regression protection for the product's central security guarantee.