-
Notifications
You must be signed in to change notification settings - Fork 61
Block breaking changes to the dev schema at pull-request time #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gudge (MGudgin)
wants to merge
2
commits into
user/gudge/versioning_phase7c_detector_lib
from
user/gudge/versioning_phase7d_dev_schema_gate
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env node | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // Dev-schema compatibility gate. | ||
| // | ||
| // Every other breaking-change guard in this directory compares RELEASED stable | ||
| // schemas, and only at release time. That leaves the surface a pull request | ||
| // actually edits -- the dev schema -- unguarded: a PR can delete a stable field, | ||
| // regenerate the schema and the SDK types, migrate the fixtures, and merge | ||
| // green. PR #676 did exactly that. | ||
| // | ||
| // This gate closes that hole by comparing the dev schema at the pull request | ||
| // base against the dev schema at HEAD and blocking any structural restriction | ||
| // of the accepted instance set. | ||
| // | ||
| // There is deliberately no per-field escape hatch. A field may not simply | ||
| // disappear: the supported-version window is what allows surface to end, so | ||
| // until a change moves that window the only correct answer is to keep accepting | ||
| // what the base accepted. | ||
| // | ||
| // node scripts/versioning/check-dev-schema-compat.js | ||
| // node scripts/versioning/check-dev-schema-compat.js --base-ref origin/main | ||
|
|
||
| const { resolve } = require("path"); | ||
| const { readFileAtCommit, resolveBaseCommit } = require("./lib/git-base"); | ||
| const { detectBreaking } = require("./lib/schema-compatibility"); | ||
|
|
||
| const repoRoot = resolve(__dirname, "..", ".."); | ||
|
|
||
| function fail(lines) { | ||
| console.error("Dev schema compatibility FAILED:"); | ||
| for (const line of lines) console.error(` - ${line}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| function jsonAtCommit(commit, path) { | ||
| const content = readFileAtCommit(repoRoot, commit, path); | ||
| if (content === null) return null; | ||
| try { | ||
| return JSON.parse(content); | ||
| } catch (error) { | ||
| fail([`${path} at ${commit} is not valid JSON: ${error.message}`]); | ||
| } | ||
| } | ||
|
|
||
| let base; | ||
| try { | ||
| base = resolveBaseCommit(repoRoot); | ||
| } catch (error) { | ||
| fail([error.message]); | ||
| } | ||
|
|
||
| const devSchemaPath = (versions) => | ||
| `schemas/dev/mxc-config.schema.${versions.devSchemaFile}.json`; | ||
|
|
||
| const baseVersions = jsonAtCommit(base.commit, "schemas/schema-version.json"); | ||
| const headVersions = jsonAtCommit("HEAD", "schemas/schema-version.json"); | ||
| if (!baseVersions || !headVersions) { | ||
| fail(["schemas/schema-version.json is missing at the base or at HEAD"]); | ||
| } | ||
| for (const [label, versions] of [ | ||
| [base.ref, baseVersions], | ||
| ["HEAD", headVersions], | ||
| ]) { | ||
| if (typeof versions.devSchemaFile !== "string" || !versions.devSchemaFile) { | ||
| fail([`schemas/schema-version.json at ${label} has no devSchemaFile`]); | ||
| } | ||
| } | ||
|
|
||
| // Each side is read at its own declared dev line. Opening a new dev line copies | ||
| // the outgoing one, so the two documents stay the same lineage and the | ||
| // structural comparison remains meaningful across that transition. Skipping the | ||
| // comparison when the line moves -- or resolving both sides at the base path -- | ||
| // would let a pull request escape the gate by editing one line of | ||
| // schemas/schema-version.json. | ||
| const basePath = devSchemaPath(baseVersions); | ||
| const headPath = devSchemaPath(headVersions); | ||
| const baseSchema = jsonAtCommit(base.commit, basePath); | ||
| const headSchema = jsonAtCommit("HEAD", headPath); | ||
| if (!baseSchema) fail([`${basePath} is missing at ${base.ref}`]); | ||
| if (!headSchema) fail([`${headPath} is missing at HEAD`]); | ||
|
|
||
| const moved = | ||
| baseVersions.devSchemaFile === headVersions.devSchemaFile | ||
| ? "" | ||
| : ` (dev line moved ${baseVersions.devSchemaFile} -> ${headVersions.devSchemaFile})`; | ||
|
|
||
| const findings = detectBreaking(baseSchema, headSchema); | ||
|
|
||
| if (findings.length > 0) { | ||
| fail([ | ||
| `the dev schema removes or restricts surface that callers may already ` + | ||
| `depend on, compared against ${base.ref} ` + | ||
| `${base.commit.slice(0, 8)}${moved}:`, | ||
| ...findings, | ||
| `Configs declaring an already-supported version must keep parsing. Add ` + | ||
| `surface instead of removing it, or move the supported-version window ` + | ||
| `in the same change.`, | ||
| ]); | ||
| } | ||
|
|
||
| console.log( | ||
| `Dev schema compatibility OK against ${base.ref} ` + | ||
| `(${base.commit.slice(0, 8)})${moved}: no breaking change.` | ||
| ); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bot's comment seems legit? A removed field is blocked unconditionally even though the PR raises min?
Shall we address this before checking in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this to #738 since it introduces the x-mxc-since/x-mxc-until availability metadata- https://github.com/microsoft/mxc/pull/738/changes#r3737807652