3D engine that AI agents drive
Let a release branch through the protected file and change note gates
Nguyen Xuan An54f32e2650ba
diff --git a/scripts/check-change-note.mjs b/scripts/check-change-note.mjsindex ade4c494..061affca 100644--- a/scripts/check-change-note.mjs+++ b/scripts/check-change-note.mjs@@ -4,14 +4,14 @@import { spawnSync } from 'node:child_process';import { pathToFileURL } from 'node:url';import { resolve } from 'node:path';-import { planChecks } from './preflight.mjs';+import { isVersionBump, planChecks } from './preflight.mjs';import { pullRequestBaseOf } from './size-base.mjs';const gateNames = new Set(['protected files', 'change note']);// Returns the failing gates for a list of changed paths. Pure, so tests can call it without git.-export function failingGatesFor(changedPaths) {- return planChecks(changedPaths, { skipTests: true })+export function failingGatesFor(changedPaths, { release = false } = {}) {+ return planChecks(changedPaths, { skipTests: true, release }).filter(check => gateNames.has(check.name) && check.failure).map(check => ({ name: check.name, failure: check.failure, fix: check.fix }));}@@ -31,7 +31,9 @@ function baseRefFromArguments() {function main() {const baseRef = baseRefFromArguments();const changedPaths = git(['diff', '--name-only', baseRef, 'HEAD']).split('\n').filter(Boolean);- const failing = failingGatesFor(changedPaths);+ const release = isVersionBump(git(['show', `${baseRef}:package.json`]), git(['show', 'HEAD:package.json']));+ if (release) console.log('The package version changed, so this is a release: the protected file and change note gates do not apply.');+ const failing = failingGatesFor(changedPaths, { release });for (const gate of failing) {console.error(`FAIL ${gate.name}: ${gate.failure}\n Fix: ${gate.fix}`);}diff --git a/scripts/preflight.mjs b/scripts/preflight.mjsindex f8af1f4f..0d0d9c4c 100644--- a/scripts/preflight.mjs+++ b/scripts/preflight.mjs@@ -39,8 +39,16 @@ function isNewChangeNote(path) {return path.startsWith('changes/') && path.endsWith('.md') && path !== 'changes/README.md';}+const RELEASE_SKIP_REASON = 'a release: the version changed, so the notes are folded and the budgets reset (CONTRIBUTING.md#release)';++// True when the package version differs between two package.json texts. A release branch is the only change that bumps it.+export function isVersionBump(basePackageText, headPackageText) {+ if (!basePackageText || !headPackageText) return false;+ return JSON.parse(basePackageText).version !== JSON.parse(headPackageText).version;+}+// Decides which checks apply to a list of changed paths. Pure, so tests can call it without git.-export function planChecks(changedPaths, { skipTests = false } = {}) {+export function planChecks(changedPaths, { skipTests = false, release = false } = {}) {const paths = changedPaths.map(path => path.replace(/\\/g, '/'));const changesShippedCode = paths.some(path => shippedCodePattern.test(path));const changesToolCode = paths.some(path => toolCodePattern.test(path));@@ -50,16 +58,19 @@ export function planChecks(changedPaths, { skipTests = false } = {}) {checks.push({name: 'protected files',kind: 'inline',- failure: protectedEdits.length ? protectedEdits.map(path => `${path}: ${PROTECTED_FILES[path]}`).join('\n') : null,+ skipped: release ? RELEASE_SKIP_REASON : null,+ failure: !release && protectedEdits.length ? protectedEdits.map(path => `${path}: ${PROTECTED_FILES[path]}`).join('\n') : null,fix: 'Revert the edits named above: git checkout origin/main -- <file>',});- const needsNote = paths.some(path => userFacingPattern.test(path));+ const needsNote = !release && paths.some(path => userFacingPattern.test(path));const hasNote = paths.some(path => isNewChangeNote(path) && !path.endsWith('.size.md'));+ let noteSkipReason = needsNote ? null : 'no change under src/, bin/, packages/ or skills/';+ if (release) noteSkipReason = RELEASE_SKIP_REASON;checks.push({name: 'change note',kind: 'inline',- skipped: needsNote ? null : 'no change under src/, bin/, packages/ or skills/',+ skipped: noteSkipReason,failure: needsNote && !hasNote ? 'The branch changes shipped code but adds no changes/<issue>.md.' : null,fix: 'Add changes/<issue>.md with one bullet, such as "- `bar` takes a `foo` option (#123)" (changes/README.md).',});@@ -224,7 +235,8 @@ async function main(args) {const changedPaths = changedPathsSince(baseRef);console.log(`${changedPaths.length} files changed since ${baseRef}.`);- const checks = planChecks(changedPaths, { skipTests: args.includes('--skip-tests') });+ const release = isVersionBump(git(['show', `${baseRef}:package.json`]), readFileSync(join(root, 'package.json'), 'utf8'));+ const checks = planChecks(changedPaths, { skipTests: args.includes('--skip-tests'), release });const results = await runChecks(checks);const manualChecks = manualChecksFor(changedPaths);printSummary(results, manualChecks);diff --git a/tests/preflight.test.js b/tests/preflight.test.jsindex a9a7f196..e69348a8 100644--- a/tests/preflight.test.js+++ b/tests/preflight.test.js@@ -1,6 +1,6 @@import { test } from 'node:test';import assert from 'node:assert/strict';-import { manualChecksFor, planChecks } from '../scripts/preflight.mjs';+import { isVersionBump, manualChecksFor, planChecks } from '../scripts/preflight.mjs';function checkNamed(checks, name) {return checks.find(check => check.name === name);@@ -27,6 +27,19 @@ test('a size note alone does not count as a change note', () => {assert.equal(checkNamed(withNote, 'change note').failure, null);});+test('a release (version bump) may edit protected files and fold every change note', () => {+ const releasePaths = ['CHANGELOG.md', 'bench/size/budgets.json', 'bench/tool-cost-budgets.json', 'package.json', 'src/version.js', 'changes/700.md'];+ const checks = planChecks(releasePaths, { release: true });+ assert.equal(checkNamed(checks, 'protected files').failure, null);+ assert.match(checkNamed(checks, 'protected files').skipped, /release/);+ assert.equal(checkNamed(checks, 'change note').failure, null);+ assert.equal(isVersionBump('{"version":"0.18.0"}', '{"version":"0.19.0"}'), true);+ assert.equal(isVersionBump('{"version":"0.18.0"}', '{"version":"0.18.0","name":"x"}'), false);+ assert.equal(isVersionBump(null, '{"version":"0.19.0"}'), false);+ const notRelease = planChecks(releasePaths);+ assert.match(checkNamed(notRelease, 'protected files').failure, /CHANGELOG\.md/);+});+test('editing a protected file fails with the alternative', () => {const checks = planChecks(['CHANGELOG.md', 'bench/size/budgets.json']);const failure = checkNamed(checks, 'protected files').failure;