Skip to content

Bug 2008554 - Add a linter for current policy JSON schema#910

Open
bsmth wants to merge 2 commits into
mozilla:enterprise-mainfrom
bsmth:lint-policy-schema
Open

Bug 2008554 - Add a linter for current policy JSON schema#910
bsmth wants to merge 2 commits into
mozilla:enterprise-mainfrom
bsmth:lint-policy-schema

Conversation

@bsmth
Copy link
Copy Markdown

@bsmth bsmth commented May 18, 2026

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:

  • Empty description ("")
  • Missing examples

Additions:

  • browser/components/enterprisepolicies/schemas/policies-schema.meta.json: Described the shape of the current JSON file.

  • The linter: tools/lint/policies_json/__init__.py

  • Taskcluster changes in taskcluster/kinds/source-test/mozlint.yml

  • Testing the linter: tools/lint/test/test_policies_json.py

changes:

  • Updating the policies-schema.json based on linter failures.

Testing

  • Added tests
  • Manual testing performed

Steps to verify changes:

  1. run ./mach lint --linter policies-json
  2. edit browser/components/enterprisepolicies/schemas/policies-schema.json to make the JSON non-compliant (i.e., remove x-category for a given policy)
  3. run ./mach lint --linter policies-json

Expected result:

There are lint failures detected.

Copilot AI review requested due to automatic review settings May 18, 2026 12:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json fixtures asserting one missing-x-category and one empty-description error.
  • Backfills description and the missing x-category/description/examples fields on IPProtectionAvailable and DefaultSerialGuardSetting.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants