Repository navigation
fix(policy): reject unknown keys and duplicate rule ids on load (#160) - #162
Open
RupeshMaster wants to merge 1 commit into
Open
RupeshMaster wants to merge 1 commit into
RupeshMaster wants to merge 1 commit into
Conversation
Policy models ignored keys they did not know, so a typo changed what a rule checked without any error: - a misspelled operator (`lt_eq: 500` next to a valid one) was dropped, weakening a require rule so real violations passed - `wen:` instead of `when:` made a conditional rule apply to every call - duplicate rule ids loaded, although hits, regressions and reports are keyed by rule id; empty id / tool loaded too PolicySet, PolicyRule and ArgConstraint now forbid extra keys, rule ids must be unique, and id / tool must be non-empty. Schema errors name the key's location and suggest the closest known key.
|
@RupeshMaster is attempting to deploy a commit to the priyanshu's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Summary
Fixes #160. Policy models ignored keys they did not know, so a typo in
policy.yamlchanged what a rule checked without any error.PolicySet,PolicyRuleandArgConstraintnow useextra="forbid": a misspelled operator (lt_eq), rule key (wen) or top-level key (ruels) fails loading instead of being dropped.idandtoolmust be non-empty.Behavior change to review
This is stricter than before: a policy that carries extra keys (for example a home-grown
severity:ornotes:field) will stop loading until they are removed. All policies shipped in the repo (examples/**, themutiny initscaffold, the demo harness) load unchanged, and a new test keeps it that way. If you prefer a softer rollout, I can turn unknown keys into a warning and keep only duplicate ids as an error.Files
mutiny_core/policy/models.py,mutiny_core/policy/constraints.py: strict models, unique ids.mutiny_core/policy/load.py: friendlier message for unknown keys.docs/SYSTEM_DESIGN.md,CHANGELOG.md(under Changed, since it can reject files that loaded before).tests/unit/test_policy_load.py.Type of change
Checklist
Fixes #N) or Discussion when applicableuv run pytest tests/unit -q)Test plan
uv run --locked ruff check→ all checks passeduv run pytest tests/unit tests/integration tests/reliability -q→ 861 passed. Run locally on Python 3.12 only (macOS,OPENAI_API_KEYunset); 3.11 is left for CI.examples/openai_support_agent,mutiny --help,mutiny init,mutiny runwithMUTINY_SAMPLE_OFFLINE=1and emptyOPENAI_API_KEY/FEATHERLESS_API_KEY→ violation found, regression saved.apps/webis not touched.tests/unit/test_package_release.pypassed as part of the unit run;./scripts/verify_release_artifacts.shnot run.Extra: 11 of the new tests fail on
main(ee7e898). Withwhen:changed towen:in the sample policy,mutiny runnow exits 2 with the message above. The existing suite needed no changes.Notes