Bound context scans and bind audit-event content - #42
Conversation
📝 WalkthroughWalkthroughThe change adds bounded context-policy loading and regex scanning. It also replaces path-only audit-event references with profile-bound canonical JSON digests, secure artifact handling, producer integration, consumer verification, schemas, documentation, and expanded platform and contract tests. ChangesAudit-event content binding
Bounded context-policy scanning
Test environment isolation
Estimated code review effort: 4 (Complex) | ~60 minutes Mergeability Score: 🟡 Moderate · up to Invalid context-policy values can currently fall back to default scanning instead of failing closed, while published evidence contracts and documentation can disagree with packaged validation for audit-event bundles. This can produce inconsistent repository scanning and event-binding behavior, so the PR needs fixes or explicit owner acceptance before merge. Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96269a0e9d
ℹ️ 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.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Around line 359-361: Align both documentation sites with the conditional
behavior of _validate_evidence_bundle: update README.md lines 359-361 and
docs/quickstart-existing-repo.md lines 280-284 to state that the standalone
manifest is required only if present, rather than unconditionally required. No
consumer code change is needed.
In `@src/agent_guard/consumer/_bindings.py`:
- Around line 36-66: Add a concise docstring to
validate_agent_policy_audit_event_files documenting that each paths[i] is
positionally paired with the i-th manifest artifact whose role is
agent-policy-audit-event, preserving the required ordering contract at the API
boundary.
In `@src/agent_guard/context_guard.py`:
- Around line 349-354: Update the YAML loading flow around load_bounded_yaml in
the context-policy scan so only a None result is replaced with an empty mapping.
Validate all other loaded values, including falsy non-mappings such as lists,
false, zero, and empty strings, with the existing isinstance(loaded, dict) check
so they raise BoundedYamlInvalidError and preserve ERROR_CONTEXT_POLICY_INVALID
behavior.
In `@src/agent_guard/schemas/agent-guard.evidence_pack_manifest.v1.schema.json`:
- Around line 77-103: Require content_binding for artifacts whose role is
agent-policy-audit-event by adding the same role-based allOf conditional to the
artifact item schemas at
src/agent_guard/schemas/agent-guard.evidence_pack_manifest.v1.schema.json lines
77-103 and src/agent_guard/schemas/agent-guard.report_evidence.v1.schema.json
lines 309-336; leave report artifacts unaffected.
In `@tests/test_evidence_consumer.py`:
- Around line 103-106: Update the anchored match patterns in the pytest.raises
calls near the existing ValueError assertions, including both occurrences, to
use raw string literals while preserving the exact ^...$ patterns and error
text.
In `@tests/test_evidence_contract_examples.py`:
- Around line 478-479: Add an assertion in the missing-event/missing-metadata
test case that missing_event_result.stdout is empty, matching the negative-path
assertions for wrong-profile and replaced-content cases while preserving the
existing returncode and stderr checks.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: a68faf1f-8cb9-45eb-ba2a-378139738ff1
📒 Files selected for processing (28)
.github/workflows/ci.ymlCHANGELOG.mdREADME.mddocs/compatibility.mddocs/evidence-contracts.mddocs/evidence-samples/agent-guard-report.jsondocs/quickstart-existing-repo.mdscripts/check_wheel_contract.pysrc/agent_guard/cli/evidence_pack.pysrc/agent_guard/cli/report.pysrc/agent_guard/consumer/__init__.pysrc/agent_guard/consumer/_bindings.pysrc/agent_guard/consumer/_bundle.pysrc/agent_guard/consumer/_cli.pysrc/agent_guard/consumer/_sections.pysrc/agent_guard/context_guard.pysrc/agent_guard/evidence_pack.pysrc/agent_guard/schemas/agent-guard.evidence_pack_manifest.v1.schema.jsonsrc/agent_guard/schemas/agent-guard.report_evidence.v1.schema.jsontests/cli/test_evidence_pack.pytests/cli/test_report_output.pytests/test_context_guard.pytests/test_contract_stability.pytests/test_docs_contract.pytests/test_evidence_consumer.pytests/test_evidence_contract_examples.pytests/test_windows_file_boundaries.pytests/test_workflow_hardening.py
Summary
agent-policyaudit events by canonical JSON content, an explicit profile, and a public-safe portable digestVerification
Boundary check
Scope
This does not add runtime MCP or OAuth validation, semantic
agent-policyaudit-event schema validation, generic secret scanning, or producer authentication.