Bug 2008554 - Add a linter for current policy JSON schema#910
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 |
|
We've decided to upstream this linter instead of adding here, so closing for now. |
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.