Bug 2008554 - Add a linter for current policy JSON schema#910
Open
bsmth wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new mozlint linter (policies-json) that validates browser/components/enterprisepolicies/schemas/policies-schema.json against a new meta-schema describing the expected shape of each policy entry (requires x-category, description, type, examples, with description and x-category being non-empty). The linter is wired into Taskcluster and ships with a small Python unit test plus good/bad fixture files. Two pre-existing policy entries that failed the new schema are corrected.
Changes:
- New linter implementation, mozlint YAML config, meta-schema, and Taskcluster mozlint job.
- Unit test with
good.json/bad.jsonfixtures asserting one missing-x-categoryand one empty-descriptionerror. - Backfills
descriptionand the missingx-category/description/examplesfields onIPProtectionAvailableandDefaultSerialGuardSetting.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/lint/policies_json/init.py | New mozlint external linter that loads the meta-schema and reports Draft-7 validation errors with a best-effort line number. |
| tools/lint/policies-json.yml | Mozlint configuration declaring the linter, include path, and support files. |
| tools/lint/test/test_policies_json.py | Pytest verifying clean vs. error fixtures. |
| tools/lint/test/python.toml | Registers the new test module. |
| tools/lint/test/files/policies-json/good.json | Fixture passing schema validation. |
| tools/lint/test/files/policies-json/bad.json | Fixture intentionally violating two rules. |
| taskcluster/kinds/source-test/mozlint.yml | Adds the policies-json Taskcluster lint job and its files-changed triggers. |
| browser/components/enterprisepolicies/schemas/policies-schema.meta.json | Meta-schema describing required structure of policy entries. |
| browser/components/enterprisepolicies/schemas/policies-schema.json | Fills in description, x-category, and examples for two entries to satisfy the new linter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import json | ||
| import pathlib | ||
|
|
||
| import jsonschema |
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.
Description
Bugzilla: Bug-2008554
Supporting work in 2008554. This PR is a lint step that should help with incoming changes on the policies JSON. As we are working on extending the JSON artifact with additional members, we should validate it against a schema so that required fields are provided (compatibility, defaults, examples).
This already catches the following:
"")examplesAdditions:
browser/components/enterprisepolicies/schemas/policies-schema.meta.json: Described the shape of the current JSON file.The linter:
tools/lint/policies_json/__init__.pyTaskcluster changes in
taskcluster/kinds/source-test/mozlint.ymlTesting the linter:
tools/lint/test/test_policies_json.pychanges:
policies-schema.jsonbased on linter failures.Testing
Steps to verify changes:
./mach lint --linter policies-jsonbrowser/components/enterprisepolicies/schemas/policies-schema.jsonto make the JSON non-compliant (i.e., removex-categoryfor a given policy)./mach lint --linter policies-jsonExpected result:
There are lint failures detected.