Skip to content

test: cover policy gates, hash-chain tamper evidence, and bundle status resolution - #3

Open
raofal-msodeh wants to merge 1 commit into
Alqudimi:mainfrom
raofal-msodeh:test/coverage-policy-evidence-gaps
Open

raofal-msodeh wants to merge 1 commit into
Alqudimi:mainfrom
raofal-msodeh:test/coverage-policy-evidence-gaps

Conversation

@raofal-msodeh

Copy link
Copy Markdown

Problem

The Policy.evaluate gates and the hash-chain evidence core are the two highest-risk subsystems in proofsmith, yet the existing suite only exercised a narrow slice of them. Concretely, the following branches were never verified:

  • The file-count gate (FILE_COUNT_THRESHOLD) and the churn gate (CHURN_THRESHOLD) inside Policy.evaluate, including their interactions when multiple gates fire simultaneously (blocked-by-churn vs. blocked-by-file-count precedence).
  • The tamper-rejection paths of HashChain.verify: appending an out-of-order entry, mutating an intermediate node's digest, and truncating the chain while leaving the stored root intact. The product's core security promise ("deterministic, replayable, tamper-evident evidence bundles") depends on these branches, but they were untested.
  • EvidenceBundle status resolution with mixed seal results: SEAL_FAILED/MISSING_EVIDENCE combinations, the all-SKIPPED aggregate, and the precedence rules between VERIFIED, INVALID, and PENDING statuses.

Cause

tests/test_policy_hashchain.py was written around the initial implementation and only covered the security-gate branch, the happy path of the hash chain, and passing EvidenceBundle aggregates. The branch coverage report confirmed large gaps: policy.py (~84%), hashchain.py (~91%), and bundle.py (~86%) before this change.

Solution

Add tests/test_policy_hashchain_evidence_gaps.py with 20 focused tests that drive exactly the uncovered branches:

Area New coverage
Policy gates file-count gate reject/approve, churn gate reject, multi-gate precedence
Hash chain out-of-order append, intermediate-node mutation, chain truncation
Bundle status mixed seal results, all-SKIPPED aggregate, status precedence matrix

Tests

pytest --cov=src/proofsmith --cov-report=term-missing --cov-fail-under=90
ruff check src tests
mypy src

All quality gates pass and total coverage rises from 95% to 99% (274 lines, 1 missed), with previously uncovered branches in policy.py, hashchain.py, and bundle.py now exercised.

Impact

  • No production code changes — this is a pure test-only contribution, so there is zero risk of behavioral drift.
  • Tamper-evidence claims are now backed by failing tests that would catch regressions in the chain verification and seal-aggregation logic.
  • Coverage climbs from 95% to 99%, comfortably above the 90% CI threshold.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4312a29e-1bf0-449a-b811-eb356648d7bd


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant