Skip to content

Conversation

@caugner
Copy link
Contributor

@caugner caugner commented Aug 27, 2025

Summary

  1. Validates the built data.json against the schemas.
  2. Removes the maxProperties requirement for the browsers object from the browsers schema.

Test results and supporting details

This revealed two minor issues:

  1. The browsers schema was requiring a maximum of one browser defined in browsers. This requirement only applies to the individual browser/*.json files, not the built data.json, so this requirement was removed.
  2. The __meta object in the built data.json is not currently covered by the schema, so we cannot validate it.

Related issues

Fixes #27564.

@github-actions github-actions bot added schema Isses or pull requests regarding the JSON schema files used in this project. infra Infrastructure issues (npm, GitHub Actions, releases) of this project linter Issues or pull requests regarding the tests / linter of the JSON files. scripts Issues or pull requests regarding the scripts in scripts/. labels Aug 27, 2025
@caugner caugner changed the title enhance(build): validate data against schemas enhance(build): validate built data.json against schemas Aug 27, 2025
@caugner caugner requested review from Elchi3 and queengooborg August 27, 2025 09:23
@github-actions github-actions bot added the size:m [PR only] 25-100 LoC changed label Aug 27, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 27, 2025

Tip: Review these changes grouped by change (recommended for most PRs), or grouped by feature (for large PRs).

const writeData = async () => {
const dest = new URL('data.json', targetdir);
const data = await createDataBundle();
validate(data);
Copy link
Contributor Author

@caugner caugner Aug 27, 2025

Choose a reason for hiding this comment

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

Note

If validation fails, the validation errors are logged via console.error, but we don't bail out, to avoid disruption for contributors in the unlikely event that this ever happens on main. In either case, these errors won't get unnoticed, because they will appear on every npm install (via the prepare script).

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that a PR that breaks schema validation won't fail the build? I can kinda see the case for never failing during the prepare script, but it'd be nice if there were a test that does fail. I won't block on this though, as it would be a step up from what we have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about checking process.env.CI and failing if we're in CI?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would help for local development, but not pull request checks. Maybe check if GITHUB_REF is refs/heads/main and, if true, convert errors to warnings, else do nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In pull request checks, we always have CI=true in the environment, so we would notice it in a PR before merging. (In fact, the PR check would fail, preventing a merge.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's tackle this afterwards.

@ddbeck
Copy link
Contributor

ddbeck commented Aug 28, 2025

  • The __meta object in the built data.json is not currently covered by the schema, so we cannot validate it.

FWIW, I raised this as a concern in #17574 and got shot down on doing anything about it.

@caugner
Copy link
Contributor Author

caugner commented Aug 28, 2025

FWIW, I raised this as a concern in #17574 and got shot down on doing anything about it.

FWIW, here's the meta schema (isolated, like the other two):

{
  "$schema": "http://json-schema.org/schema",

  "definitions": {
    "meta_block": {
      "type": "object",
      "properties": {
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "version": {
          "type": "string"
        }
      },
      "required": ["timestamp", "version"],
      "additionalProperties": false
    }
  },

  "properties": {
    "__meta": {
      "$ref": "#/definitions/meta_block"
    }
  },

  "title": "MetaData",
  "type": "object",
  "required": ["__meta"],
  "additionalProperties": false,
  "maxProperties": 1,
  "minProperties": 1
}

Unfortunately, ajv gives me an error when validating the data:

TYPE must be string

  2 |   "__meta": {
  3 |     "version": "7.1.0",
> 4 |     "timestamp": "2025-08-28T14:30:46.924Z"
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ 👈🏽  type must be string
  5 |   }
  6 | }

That error doesn't make sense, but given this is not a priority, I would declare the scope of this PR to validate the built data against the existing schemas.

@caugner caugner requested a review from a team as a code owner September 16, 2025 13:38
@caugner caugner requested review from queengooborg and removed request for Elchi3 September 16, 2025 13:43
@caugner caugner force-pushed the 27564-validate-data-against-schema branch from b884975 to c046688 Compare October 7, 2025 12:32
@github-actions github-actions bot added data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API size:l [PR only] 101-1000 LoC changed and removed size:m [PR only] 25-100 LoC changed labels Oct 7, 2025
@caugner caugner force-pushed the 27564-validate-data-against-schema branch from c046688 to fabb4f2 Compare October 14, 2025 13:11
@github-actions github-actions bot added size:m [PR only] 25-100 LoC changed and removed data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API size:l [PR only] 101-1000 LoC changed labels Oct 14, 2025
@caugner
Copy link
Contributor Author

caugner commented Oct 17, 2025

@queengooborg If we can get this in, we can split up the schema into internal/public, and validate separately. Currently, it's a mix of both.

Copy link
Member

@Elchi3 Elchi3 left a comment

Choose a reason for hiding this comment

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

Approving the schema change 👍

@caugner caugner requested a review from a team as a code owner November 4, 2025 11:05
@caugner caugner requested a review from argl November 4, 2025 11:05
Copy link
Contributor

@ddbeck ddbeck left a comment

Choose a reason for hiding this comment

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

I've reviewed the code. Thank you!


for (const [key, value] of Object.entries(data)) {
if (key === '__meta') {
// Not covered by the schema.
Copy link
Contributor

Choose a reason for hiding this comment

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

See also 😒 #17574

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See also: #27685 (comment)

const writeData = async () => {
const dest = new URL('data.json', targetdir);
const data = await createDataBundle();
validate(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that a PR that breaks schema validation won't fail the build? I can kinda see the case for never failing during the prepare script, but it'd be nice if there were a test that does fail. I won't block on this though, as it would be a step up from what we have.

@caugner caugner merged commit 0dde3fe into main Nov 5, 2025
12 checks passed
@caugner caugner deleted the 27564-validate-data-against-schema branch November 5, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infra Infrastructure issues (npm, GitHub Actions, releases) of this project linter Issues or pull requests regarding the tests / linter of the JSON files. schema Isses or pull requests regarding the JSON schema files used in this project. scripts Issues or pull requests regarding the scripts in scripts/. size:m [PR only] 25-100 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The built package is not validated against the schema

5 participants