feat: native contract coverage for MCP corruption corpus#196
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the contract validation system by introducing new invariant rules, specifically 'required_boundaries_preserved' and 'required_dependency_edges_preserved', and adding support for 'terminal_action' checks within ordering validation. Correspondingly, several contract fixtures were updated to use these new rules, and the test suite was adjusted to reflect increased validation coverage. Feedback from the reviewer focuses on improving the robustness of JSON parsing by ensuring that null or missing list fields are treated as empty lists and that 'RuntimeError' is raised for invalid types to maintain strictness, particularly for 'required_boundaries', 'capability_boundaries', and 'required_edges'.
Motivation
expected_failure_labeldeterministically.Description
ContractValidator: terminal-action checks for ordering contracts and three invariant rulesrequired_boundaries_preserved,required_dependency_edges_preserved, andrequired_action_order_preservedto detect missing boundaries, missing dependency edges, and action-order/terminal mismatches respectively (changes insrc/validation/contract_validator.py).failure_label_on_violationvalues (addedapproval_gate_preserved.jsonand editedcapability_boundary_respected.json,dependency_chain_preserved.json,recovery_path_available.json,tool_call_order_preserved.json,validation_before_unsafe_action.jsonunderfixtures/mcp_trace_replay_{degraded,mild,moderate}_v1/original/contracts).expected_failure_label; added focused unit tests exercising the new invariant rules (changes intests/test_mcp_trace_corruption_validation.pyandtests/test_contract_validator.py).APPROVAL_GATE_LOSS,TOOL_ORDER_VIOLATION,RECOVERY_PATH_INVALID,DEPENDENCY_CHAIN_BREAK,POLICY_ENFORCEMENT_GAP, andCAPABILITY_BOUNDARY_LOSS(no new taxonomy labels introduced).Testing
pytest -q tests/test_contract_validator.py— passed (unit tests for new rules added and existing ordering/reachability/causality/invariant tests pass).pytest -q tests/test_mcp_trace_corruption_validation.py— passed (all materialized MCP corruption entries now natively emit their manifestexpected_failure_label).pytest -q tests/test_mcp_trace_corruption_manifest.py tests/test_mcp_trace_corruption_materialization.py— passed (manifest and materialization checks unaffected).npm run check— targeted MCP-corruption tests pass, but fullnpm run checkruns the entire repository test/validation/build pipeline and surfaced unrelated broader fixture-manifest/artifact expectation mismatches caused by tightening contract definitions; these are out of scope for this narrow PR.Open a PR against
main.Codex Task