diff --git a/.github/scripts/version-archive-review.cjs b/.github/scripts/version-archive-review.cjs index 9dbace9..9624293 100644 --- a/.github/scripts/version-archive-review.cjs +++ b/.github/scripts/version-archive-review.cjs @@ -3,6 +3,7 @@ const STATUS_CONTEXT = 'version-archives'; const POLICY_PATHS = new Set([ '.github/version_protection.md', + 'docs/bylaws.md', '.github/workflows/version-archive-review.yml', '.github/workflows/version-archive-review-signal.yml', '.github/scripts/version-archive-review.cjs', @@ -68,10 +69,10 @@ async function run({ github, context, core, pull_number }) { if (files.length >= 3000) throw new Error('PR has 3000+ files; cannot verify complete changes'); const paths = protectedFiles(files); if (!paths.length) { - await status('success', 'No archive approval required'); + await status('success', 'No protected-file approval required'); return; } - await status('pending', 'Checking approvals for archived documentation changes'); + await status('pending', 'Checking approvals for protected documentation changes'); const reviews = await github.paginate(github.rest.pulls.listReviews, { owner, repo, pull_number: prNumber, per_page: 100 }); @@ -83,14 +84,14 @@ async function run({ github, context, core, pull_number }) { if (['admin', 'write'].includes(data.permission)) eligible.push(reviewer); } if (eligible.length) { - await status('success', 'Archive changes approved by ' + eligible[0]); + await status('success', 'Protected changes approved by ' + eligible[0]); } else { - await status('failure', 'Archived documentation changes require approval'); + await status('failure', 'Protected documentation changes require approval'); core.setFailed('Changes to ' + paths.join(', ') + ' require a fresh APPROVED review from a different human with write/admin access on SHA ' + sha); } } catch (error) { - await status('failure', 'Unable to verify version archive approvals'); + await status('failure', 'Unable to verify protected-file approvals'); throw error; } } diff --git a/.github/scripts/version-archive-review.test.cjs b/.github/scripts/version-archive-review.test.cjs index 5183931..45706a6 100644 --- a/.github/scripts/version-archive-review.test.cjs +++ b/.github/scripts/version-archive-review.test.cjs @@ -7,6 +7,8 @@ const { run, protectedFiles, approvedReviewers } = require('./version-archive-re test('detects all protected version paths and historic rename sources', () => { assert.deepEqual(protectedFiles([ { filename: 'docs/intro.md' }, + { filename: 'docs/bylaws.md' }, + { filename: 'docs/renamed-bylaws.md', previous_filename: 'docs/bylaws.md' }, { filename: 'versions/archive-0.1.0/intro.md' }, { filename: 'new/location.md', previous_filename: 'versions/archive-0.1.0/old.md' }, { filename: 'versions/sidebars/version-0.1.0.json' }, @@ -17,6 +19,7 @@ test('detects all protected version paths and historic rename sources', () => { '.github/scripts/version-archive-review.cjs', '.github/version_protection.md', '.github/workflows/version-archive-review.yml', + 'docs/bylaws.md', 'versions/archive-0.1.0/intro.md', 'versions/archive-0.1.0/old.md', 'versions/sidebars/version-0.1.0.json' @@ -24,6 +27,19 @@ test('detects all protected version paths and historic rename sources', () => { assert.deepEqual(protectedFiles([{ filename: 'docs/intro.md' }]), []); }); +test('protects bylaws additions, edits, deletions, and both rename directions', () => { + for (const file of [ + { filename: 'docs/bylaws.md', status: 'added' }, + { filename: 'docs/bylaws.md', status: 'modified' }, + { filename: 'docs/bylaws.md', status: 'removed' }, + { filename: 'docs/relocated.md', previous_filename: 'docs/bylaws.md', status: 'renamed' }, + { filename: 'docs/bylaws.md', previous_filename: 'docs/old.md', status: 'renamed' } + ]) { + assert.ok(protectedFiles([file]).includes('docs/bylaws.md')); + } + assert.deepEqual(protectedFiles([{ filename: 'docs/bylaws-notes.md' }]), []); +}); + test('only most recent independent human approval on exact head counts', () => { assert.deepEqual(approvedReviewers([ { id: 1, user: { login: 'author', type: 'User' }, state: 'APPROVED', commit_id: 'new' }, @@ -85,7 +101,8 @@ test('unrelated docs changes pass automatically without fetching reviews', async for (const filename of [ 'versions/archive-0.1.0/intro.md', 'versions/sidebars/version-0.1.0.json', '.github/scripts/version-archive-review.cjs', - '.github/version_protection.md' + '.github/version_protection.md', + 'docs/bylaws.md' ]) { test('unapproved protected change fails: ' + filename, async () => { const gh = fake({ files: [{ filename }] }); @@ -104,14 +121,16 @@ test('renaming a file out of versions still requires approval', async () => { assert.equal(errors.length, 1); }); -test('fresh independent contributor approval passes', async () => { - const gh = fake({ - files: [{ filename: 'versions/sidebars/version-0.1.0.json' }], - reviews: [{ id: 1, user: { login: 'reviewer', type: 'User' }, state: 'APPROVED', commit_id: 'head' }] +for (const filename of ['versions/sidebars/version-0.1.0.json', 'docs/bylaws.md']) { + test('fresh independent contributor approval passes: ' + filename, async () => { + const gh = fake({ + files: [{ filename }], + reviews: [{ id: 1, user: { login: 'reviewer', type: 'User' }, state: 'APPROVED', commit_id: 'head' }] + }); + await run({ github: gh, context, core: { setFailed: () => { throw new Error('unexpected'); } } }); + assert.deepEqual(gh.statuses.map(x => x.state), ['pending', 'success']); }); - await run({ github: gh, context, core: { setFailed: () => { throw new Error('unexpected'); } } }); - assert.deepEqual(gh.statuses.map(x => x.state), ['pending', 'success']); -}); +} test('stale review, bot review, self approval, or read-only reviewer fail', async () => { for (const [reviewer, permission] of [ diff --git a/.github/version_protection.md b/.github/version_protection.md index 4bddc0b..9b91f21 100644 --- a/.github/version_protection.md +++ b/.github/version_protection.md @@ -11,6 +11,8 @@ The root manifest is ignored by Git. Do **not** create `versions/history.json`. Protected changes include: - All paths under `versions/`, including archived snapshots and sidebars. +- `docs/bylaws.md`, the governing bylaws path proposed in PR #56, including + additions, amendments, deletions, and renames to or from this path. - The version generation, staging and cleanup scripts under `scripts/`. - `package.json`, `.gitignore`, the version-protection policy, and the privileged verifier workflow and helper files to prevent unreviewed bypasses. @@ -45,7 +47,8 @@ create an active branch ruleset called **Version archive protection**: 4. Prohibit force pushes and deletions; do not configure bypass permissions. 5. Verify a test PR changing `versions/archive-0.1.0/` is blocked until another write/admin collaborator approves the current head SHA. - Confirm that a `docs/`-only PR passes without this approval. + Confirm that an unrelated `docs/`-only PR passes without this approval, + while a PR modifying `docs/bylaws.md` requires approval. After merging the workflow, open or update a PR to produce the first `version-archives` check if the ruleset UI does not yet list it.