From cd162ec1fe7e78edd260d3e80582918581de2fb5 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 7 Oct 2026 06:08:40 +0000 Subject: [PATCH] Add docs drift prevention and docs-triggered Pages deployment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/docs-drift.mjs maps code areas to the documents that describe them and fails when a change touches such an area without updating one of its documents, unless it declares "Docs-Impact: none – ". - Runs on every pull request (Docs drift workflow) and as a Claude Code PreToolUse hook that blocks git push and PR creation while drift is open. - CONTRIBUTING.md defines the threshold: a change needs docs when it alters what a document states, not when it is large. - pages.yml also deploys when docs/, site/ or design/ change on main. The app is always built from a release tag; automatic deployments are skipped while main has unreleased app changes. BUILD.txt records both refs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0198cQvPKzb7BqcEw7VLBWvu --- .claude/settings.json | 15 +++ .github/workflows/docs-drift.yml | 28 +++++ .github/workflows/pages.yml | 72 ++++++++++- CLAUDE.md | 7 ++ CONTRIBUTING.md | 40 ++++++ README.md | 6 +- docs/SETUP.md | 13 +- scripts/docs-drift.mjs | 209 +++++++++++++++++++++++++++++++ scripts/docs-drift.test.mjs | 57 +++++++++ 9 files changed, 439 insertions(+), 8 deletions(-) create mode 100644 .claude/settings.json create mode 100644 .github/workflows/docs-drift.yml create mode 100644 CLAUDE.md create mode 100644 CONTRIBUTING.md create mode 100644 scripts/docs-drift.mjs create mode 100644 scripts/docs-drift.test.mjs diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..22734cd --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PreToolUse": [ + { + "matcher": "Bash|mcp__github__create_pull_request", + "hooks": [ + { + "type": "command", + "command": "node \"$CLAUDE_PROJECT_DIR/scripts/docs-drift.mjs\" --hook" + } + ] + } + ] + } +} diff --git a/.github/workflows/docs-drift.yml b/.github/workflows/docs-drift.yml new file mode 100644 index 0000000..134dd45 --- /dev/null +++ b/.github/workflows/docs-drift.yml @@ -0,0 +1,28 @@ +name: Docs drift + +# Separate from CI because it also re-runs when the PR description is edited +# (that is where "Docs-Impact: none – " may be declared). +on: + pull_request: + types: [opened, synchronize, reopened, edited] + +permissions: + contents: read + +jobs: + docs-drift: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: node --test scripts/docs-drift.test.mjs + - name: Check that documented behaviour changes come with documentation + run: node scripts/docs-drift.mjs --base "$BASE_SHA" --head "$HEAD_SHA" + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_BODY: ${{ github.event.pull_request.body }} diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 50fd8a2..c4d528f 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -1,8 +1,21 @@ name: Deploy to GitHub Pages +# The web app (/app/) is always built from a release tag, so every deployed app can be +# verified against a tag. The documentation site is built from the triggering ref: +# - tag v*: site and app from that tag +# - push to main: site from main when site inputs changed, app from the latest release tag; +# skipped while main has unreleased app changes, so the published docs never +# describe an app that is not deployed (they go live with the next tag) +# - manual run: site from the chosen ref, app from the latest release tag (no skip) on: push: - tags: ['v*'] + tags: ['v*'] # path filters do not apply to tag pushes + branches: [main] + paths: + - 'docs/**' + - 'site/**' + - 'design/**' + - '.github/workflows/pages.yml' workflow_dispatch: permissions: @@ -17,43 +30,94 @@ concurrency: jobs: build: runs-on: ubuntu-latest + outputs: + deploy: ${{ steps.release.outputs.deploy }} steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Resolve the app release + id: release + run: | + if [[ "$GITHUB_REF_TYPE" == tag ]]; then + tag="$GITHUB_REF_NAME" + else + tag=$(git tag --list 'v*' --sort=-v:refname | head -n 1) + fi + if [[ -z "$tag" ]]; then + echo "::error::No release tag v* exists. Tag a release (e.g. v0.1.0) to deploy the app." + exit 1 + fi + deploy=true + if ! git diff --quiet "$tag" HEAD -- web ':(exclude)web/tests' ':(exclude)web/e2e'; then + if [[ "$GITHUB_EVENT_NAME" == push ]]; then + deploy=false + echo "::notice::$GITHUB_REF_NAME has app changes not released in $tag. The documentation goes live with the next release tag, or run this workflow manually." + else + echo "::warning::Deploying documentation from $GITHUB_SHA with the app from $tag; the documentation may describe unreleased app changes." + fi + fi + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "deploy=$deploy" >> "$GITHUB_OUTPUT" + { + echo "| | Ref | Commit |" + echo "|---|---|---|" + echo "| Site | \`$GITHUB_REF_NAME\` | \`$GITHUB_SHA\` |" + echo "| App | \`$tag\` | \`$(git rev-parse "$tag^{commit}")\` |" + echo + echo "Deploy: **$deploy**" + } >> "$GITHUB_STEP_SUMMARY" - uses: actions/setup-node@v4 + if: steps.release.outputs.deploy == 'true' with: node-version: 22 cache: npm cache-dependency-path: | web/package-lock.json site/package-lock.json - - name: Build web app - working-directory: web + - name: Build web app from the release tag + if: steps.release.outputs.deploy == 'true' run: | + git worktree add --detach "$RUNNER_TEMP/release" "$TAG" + cd "$RUNNER_TEMP/release/web" npm ci npm test npm run build env: + TAG: ${{ steps.release.outputs.tag }} VITE_GOOGLE_CLIENT_ID: ${{ vars.GOOGLE_CLIENT_ID }} VITE_GOOGLE_API_KEY: ${{ vars.GOOGLE_API_KEY }} VITE_GOOGLE_APP_ID: ${{ vars.GOOGLE_APP_ID }} - name: Build documentation site (app under /app/) + if: steps.release.outputs.deploy == 'true' working-directory: site run: | npm ci - node build.mjs --out ../_site --app ../web/dist + node build.mjs --out ../_site --app "$RUNNER_TEMP/release/web/dist" node check.mjs --dir ../_site + - name: Record what the deployment was built from + if: steps.release.outputs.deploy == 'true' + run: | + printf 'site %s %s\napp %s %s\n' \ + "$GITHUB_REF_NAME" "$GITHUB_SHA" "$TAG" "$(git rev-parse "$TAG^{commit}")" > _site/BUILD.txt + env: + TAG: ${{ steps.release.outputs.tag }} - name: Checksums of every published file + if: steps.release.outputs.deploy == 'true' run: node web/scripts/checksums.mjs _site - uses: actions/upload-artifact@v4 + if: steps.release.outputs.deploy == 'true' with: name: SHA256SUMS path: _site/SHA256SUMS.txt - uses: actions/upload-pages-artifact@v3 + if: steps.release.outputs.deploy == 'true' with: path: _site deploy: needs: build + if: needs.build.outputs.deploy == 'true' runs-on: ubuntu-latest environment: name: github-pages diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..370c30d --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,7 @@ +# unpassword + +Overview, layout and commands: [README.md](README.md). + +## Documentation + +Update documentation in the same change as the code it describes. The threshold and the code-to-document map are in [CONTRIBUTING.md](CONTRIBUTING.md#documentation) and `scripts/docs-drift.mjs`. A `PreToolUse` hook blocks `git push` and PR creation while drift is open. If a change really does not alter what the named documents state, add `Docs-Impact: none – ` as a commit trailer instead of editing documents for the sake of the check. Never edit `docs/PRIVACY.md`, `docs/TERMS.md` or `docs/IMPRINT.md` without saying so explicitly in the PR description: they are legal texts the maintainer approves. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..dda2781 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +Development commands are in the [README](README.md#development). Pull requests run CI (lint, typecheck, unit and E2E tests, site build) and the docs drift check described below. + +## Documentation + +Documentation is part of the change that makes it necessary, not a follow-up. + +### When a change needs a documentation update + +The threshold is not the size of a change but whether it alters something a document states. A change needs a documentation update when it changes: + +- **what users can do or observe:** supported formats and protections, flows, messages, result file names (README, landing page, SUPPORT) +- **security and anti-misuse guarantees** or how they are enforced (README Guardrails, SECURITY) +- **what data goes where:** OAuth scopes, contacted hosts, CSP, storage (SECURITY, PRIVACY) +- **how to build, configure, deploy or verify** unpassword (README, SETUP) +- **the bundled third-party components** (THIRD_PARTY_NOTICES) + +It does not need one for refactors, tests, styling, tooling or dependency updates that leave all of the above unchanged. + +Privacy policy, terms and imprint are legal texts: changes to them are proposed in a pull request and approved by the maintainer, never published unreviewed. + +### How it is enforced + +[`scripts/docs-drift.mjs`](scripts/docs-drift.mjs) maps code areas to the documents that describe them (`RULES`). When a change touches such an area without touching one of its documents, the check fails and names the rule, the files and the documents to update. Then either update the documentation, or declare that the change does not alter what those documents describe: + +``` +Docs-Impact: none – +``` + +as a commit message trailer or in the pull request description. A reason is required. The check only makes sure the decision is taken explicitly; whether it is right is decided in review. + +- **CI:** the *Docs drift* workflow runs on every pull request, and again when its description is edited. +- **Claude Code:** a `PreToolUse` hook in [`.claude/settings.json`](.claude/settings.json) blocks `git push` and pull request creation while drift is open, so the agent updates the documentation within the same change. At push time there is no pull request description yet, so an opt-out has to be a commit trailer. + +Keep the map current: a new code area or document gets a rule. A rule that mostly produces opt-outs is too broad and should be narrowed (the `dependencies` rule, for example, fires only when runtime dependencies are added or removed, not on version bumps). + +### Publishing + +The documentation site deploys automatically when `docs/`, `site/` or `design/` change on `main`. The web app under `/app/` is always built from the latest release tag. While `main` contains app changes that are not released yet, the automatic deployment is skipped, so the site never describes an app that is not deployed; the documentation then goes live with the next release tag. Details are in the [setup guide](docs/SETUP.md#5-deploy-the-site-and-the-web-app). diff --git a/README.md b/README.md index bfe0e10..44deb4a 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ web/ static web app (Vite + TypeScript, no UI framework) gmail-addon/ Apps Script Gmail launcher (never decrypts) site/ documentation site for GitHub Pages: renders docs/ and the landing page, no JavaScript design/ Nullthrone Design System tokens and fonts (self-hosted), the unpassword mark and its PNG renderings -scripts/ fixture generator, cross-check, brand asset renderer +scripts/ fixture generator, cross-check, brand asset renderer, docs drift check docs/ security model, privacy policy, terms, support, imprint, deployment setup ``` @@ -94,11 +94,13 @@ node check.mjs # CSP, no external resources, no broken links Brand assets (icons, banner, Marketplace screenshots) are rendered by `node scripts/render-brand-assets.mjs` after `npm run build` in `web/`. +Changes that alter documented behaviour update the documentation in the same pull request; the *Docs drift* check enforces this. See [CONTRIBUTING.md](CONTRIBUTING.md#documentation). + Drive integration needs `VITE_GOOGLE_CLIENT_ID`, `VITE_GOOGLE_API_KEY` and `VITE_GOOGLE_APP_ID` (see [docs/SETUP.md](docs/SETUP.md)). Without them the app runs in local mode only. ## Verifying a deployment -The Pages workflow builds from a tagged commit and publishes `SHA256SUMS.txt` at the site root. Build the same tag locally with the same public Google identifiers and compare the checksums. +The Pages workflow builds the web app from a release tag and publishes `BUILD.txt` and `SHA256SUMS.txt` at the site root. `BUILD.txt` names the release tag the app under `/app/` was built from and the commit the documentation site was built from (the same commit for a release; a later commit on `main` after a documentation-only deployment). Build the app from that tag with the same public Google identifiers, and the site from that commit, and compare the checksums. ## License diff --git a/docs/SETUP.md b/docs/SETUP.md index da9c1de..fb7f7a2 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -73,12 +73,21 @@ None of these values is secret. They end up in the public JavaScript bundle by d ## 5. Deploy the site and the web app -Push a tag `v*` (e.g. `v0.1.0`), or run *Actions* → *Deploy to GitHub Pages* → *Run workflow*. `.github/workflows/pages.yml` builds the web app and the documentation site, then deploys both: +`.github/workflows/pages.yml` builds the web app and the documentation site, then deploys both: - `/` – documentation site (`site/`, rendered from `docs/`) -- `/app/` – the web app (`web/`) +- `/app/` – the web app (`web/`), always built from a release tag +- `/BUILD.txt` – the release tag of the app and the commit of the site - `/SHA256SUMS.txt` – checksums of every published file, also attached to the workflow run +It runs when: + +- **a tag `v*` is pushed** (e.g. `v0.1.0`): site and app from that tag. This is how a release is published, and the first deployment needs one. +- **`docs/`, `site/` or `design/` change on `main`**: site from `main`, app from the latest release tag. Skipped while `main` contains app changes that are not released yet, so the site never describes an app that is not deployed; the documentation then goes live with the next tag. +- **started manually** (*Actions* → *Deploy to GitHub Pages* → *Run workflow*): site from the chosen branch or tag, app from that tag or else the latest release tag, without the skip. Use it to publish an urgent documentation fix (e.g. the privacy policy) ahead of a release. + +The `github-pages` environment must allow deployments from `main` and from `v*` tags (*Settings* → *Environments* → *github-pages* → *Deployment branches and tags*). + Then check the deployment: - **Local mode:** drop a protected file and unlock it. In the browser's network panel, verify that no request leaves the page's origin. diff --git a/scripts/docs-drift.mjs b/scripts/docs-drift.mjs new file mode 100644 index 0000000..0da3541 --- /dev/null +++ b/scripts/docs-drift.mjs @@ -0,0 +1,209 @@ +// Docs drift check: fails when a change touches documented behaviour without updating the +// documents that describe it, unless the change declares that it has no documentation impact. +// +// node scripts/docs-drift.mjs --base [--head ] CI and manual runs +// node scripts/docs-drift.mjs --hook Claude Code PreToolUse hook (stdin) +// +// Opt-out, with a reason, in a commit message or the pull request description (env PR_BODY): +// Docs-Impact: none – +// The threshold behind RULES is described in CONTRIBUTING.md#documentation. +import { execFileSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; +import { parseArgs } from 'node:util'; + +/** + * Code areas whose behaviour a document describes. A rule fires when a changed file matches + * `when` (and `test`, if present); it is satisfied when any file in `docs` changed as well. + */ +export const RULES = [ + { + id: 'formats', + when: ['web/src/core/**'], + docs: ['README.md', 'docs/SECURITY.md', 'site/index.html'], + why: 'supported formats, protection handling and results (README, landing page, SECURITY)', + }, + { + id: 'guardrails', + when: [ + 'web/src/core/guard.ts', + 'web/src/core/session.ts', + 'web/tests/guardrails.test.ts', + 'web/eslint.config.js', + ], + docs: ['README.md', 'docs/SECURITY.md', 'site/index.html'], + why: 'anti-misuse guarantees and their enforcement (README Guardrails, SECURITY)', + }, + { + id: 'trust-boundaries', + when: ['web/src/google/**', 'web/src/worker.ts', 'web/vite.config.ts', 'web/index.html'], + docs: ['docs/SECURITY.md', 'docs/PRIVACY.md'], + why: 'data flows, CSP, OAuth scopes and worker isolation (SECURITY, PRIVACY)', + }, + { + id: 'user-flows', + when: ['web/src/ui/**', 'web/src/i18n.ts', 'web/src/files.ts', 'web/src/unlocker.ts'], + docs: ['README.md', 'docs/SUPPORT.md'], + why: 'user-visible flows, messages and result file names (README How it works, SUPPORT)', + }, + { + id: 'gmail-addon', + when: ['gmail-addon/Code.js', 'gmail-addon/appsscript.json'], + docs: ['README.md', 'docs/PRIVACY.md', 'docs/SETUP.md'], + why: 'add-on behaviour, scopes and deployment (README, PRIVACY, SETUP)', + }, + { + id: 'deployment', + when: ['.github/workflows/pages.yml', 'web/scripts/checksums.mjs', 'web/src/google/config.ts'], + docs: ['README.md', 'docs/SETUP.md'], + why: 'build variables, deployment and verification (README, SETUP)', + }, + { + id: 'dependencies', + when: ['web/package.json'], + docs: ['THIRD_PARTY_NOTICES.md'], + why: 'bundled third-party components and their licenses (THIRD_PARTY_NOTICES)', + // only runtime dependencies are bundled; version bumps and dev tooling change no document + test: (ctx) => keysChanged(ctx, 'web/package.json', 'dependencies'), + }, +]; + +const OPT_OUT = /^[ \t>*-]*Docs-Impact:[ \t]*none\b[ \t:,;–—-]*(.*)$/gim; + +/** Glob subset: `**` spans directories, `*` stays within one path segment. */ +export function matches(pattern, file) { + const re = pattern + .split('**') + .map((part) => + part + .split('*') + .map((s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')) + .join('[^/]*'), + ) + .join('.*'); + return new RegExp(`^${re}$`).test(file); +} + +/** Opt-out declared in commit messages or the PR description: { reason } or { missingReason }. */ +export function optOut(texts) { + let missingReason = false; + for (const text of texts) { + for (const m of (text ?? '').matchAll(OPT_OUT)) { + const reason = m[1].trim(); + if (reason) return { reason }; + missingReason = true; + } + } + return missingReason ? { missingReason } : null; +} + +function keysChanged(ctx, path, field) { + const keys = (ref) => { + try { + return Object.keys(JSON.parse(ctx.show(ref, path))[field] ?? {}).sort().join('\n'); + } catch { + return ''; // file absent on this side + } + }; + return keys(ctx.base) !== keys(ctx.head); +} + +/** Rules that fire for `changed` and are not satisfied by a documentation change. */ +export function evaluate(changed, ctx = {}, rules = RULES) { + return rules.flatMap((rule) => { + const files = changed.filter((f) => rule.when.some((p) => matches(p, f))); + if (!files.length || (rule.test && !rule.test(ctx))) return []; + if (changed.some((f) => rule.docs.includes(f))) return []; + return [{ rule, files }]; + }); +} + +export function report(drift, opt) { + const lines = [ + 'Docs drift: this change touches documented behaviour without updating its documentation.', + '', + ]; + for (const { rule, files } of drift) { + lines.push(` ${rule.id}: ${rule.why}`); + lines.push(` changed: ${files.join(', ')}`); + lines.push(` update one of: ${rule.docs.join(', ')}`); + } + lines.push( + '', + 'Update the documentation in this change. If the change does not alter what those', + 'documents describe, say so with a reason, as a commit message trailer or in the pull', + 'request description:', + '', + ' Docs-Impact: none – ', + '', + 'Threshold: CONTRIBUTING.md#documentation', + ); + if (opt?.missingReason) lines.push('', 'Found "Docs-Impact: none" without a reason; add one.'); + return lines.join('\n'); +} + +const git = (...args) => + execFileSync('git', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }); + +/** Runs the check for base...head. Returns the report, or null when there is no drift. */ +export function check({ base, head = 'HEAD', prBody = '' }) { + const changed = git('diff', '--name-only', `${base}...${head}`).split('\n').filter(Boolean); + const messages = git('log', '--format=%B%x00', `${base}..${head}`).split('\0'); + const opt = optOut([prBody, ...messages]); + if (opt?.reason) return null; + const ctx = { + base: git('merge-base', base, head).trim(), + head, + show: (ref, p) => git('show', `${ref}:${p}`), + }; + const drift = evaluate(changed, ctx); + return drift.length ? report(drift, opt) : null; +} + +function mergeBase(ref) { + try { + return git('merge-base', 'HEAD', ref).trim(); + } catch { + return ''; + } +} + +/** Claude Code PreToolUse hook: blocks `git push` and PR creation while docs drift. */ +function hook() { + const input = JSON.parse(readFileSync(0, 'utf8')); + const tool = input.tool_name ?? ''; + const args = input.tool_input ?? {}; + let prBody = ''; + if (tool === 'Bash') { + if (!/\bgit\b[^;&|\n]*\spush\b/.test(args.command ?? '')) return 0; + } else if (/create_pull_request$/.test(tool)) { + prBody = args.body ?? ''; + } else { + return 0; + } + if (input.cwd) process.chdir(input.cwd); + const base = ['origin/HEAD', 'origin/main'].map(mergeBase).find(Boolean); + if (!base) return 0; // no default branch to compare against; CI still enforces the check + const result = check({ base, prBody }); + if (!result) return 0; + process.stderr.write(`${result}\n`); + return 2; // blocks the tool call and hands the report to Claude +} + +function main() { + const { values } = parseArgs({ + options: { base: { type: 'string' }, head: { type: 'string' }, hook: { type: 'boolean' } }, + }); + if (values.hook) return hook(); + if (!values.base) throw new Error('--base is required'); + const result = check({ base: values.base, head: values.head, prBody: process.env.PR_BODY }); + if (!result) { + console.log('No docs drift.'); + return 0; + } + console.log(result); + if (process.env.GITHUB_ACTIONS) + console.log('::error title=Docs drift::Documentation not updated, see log'); + return 1; +} + +if (import.meta.url === `file://${process.argv[1]}`) process.exitCode = main(); diff --git a/scripts/docs-drift.test.mjs b/scripts/docs-drift.test.mjs new file mode 100644 index 0000000..c67b3df --- /dev/null +++ b/scripts/docs-drift.test.mjs @@ -0,0 +1,57 @@ +// Unit tests for the docs drift check (node --test scripts/docs-drift.test.mjs). +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { evaluate, matches, optOut, RULES } from './docs-drift.mjs'; + +const ids = (drift) => drift.map((d) => d.rule.id); + +test('glob subset', () => { + assert.ok(matches('web/src/core/**', 'web/src/core/pdf/index.ts')); + assert.ok(matches('web/src/*.ts', 'web/src/i18n.ts')); + assert.ok(!matches('web/src/*.ts', 'web/src/ui/app.ts')); + assert.ok(!matches('web/index.html', 'web/indexXhtml')); +}); + +test('code change without docs drifts', () => { + assert.deepEqual(ids(evaluate(['web/src/core/pdf/index.ts'])), ['formats']); + assert.deepEqual(ids(evaluate(['web/src/core/guard.ts'])), ['formats', 'guardrails']); +}); + +test('any listed document satisfies a rule', () => { + assert.deepEqual(evaluate(['web/src/core/pdf/index.ts', 'docs/SECURITY.md']), []); + assert.deepEqual(ids(evaluate(['web/src/google/drive.ts', 'README.md'])), ['trust-boundaries']); +}); + +test('changes outside documented areas pass', () => { + const changed = ['web/tests/pdf.test.ts', 'web/src/styles.css', 'scripts/gen-fixtures.py']; + assert.deepEqual(evaluate(changed), []); +}); + +test('dependency rule fires only when runtime dependencies are added or removed', () => { + const pkg = (deps) => JSON.stringify({ dependencies: deps, devDependencies: { vite: '1' } }); + const ctx = (before, after) => ({ + base: 'b', + head: 'h', + show: (ref) => (ref === 'b' ? pkg(before) : pkg(after)), + }); + const changed = ['web/package.json']; + assert.deepEqual(evaluate(changed, ctx({ a: '^1' }, { a: '^2' })), []); + const added = ctx({ a: '^1' }, { a: '^1', b: '^1' }); + assert.deepEqual(ids(evaluate(changed, added)), ['dependencies']); +}); + +test('opt-out needs a reason', () => { + assert.deepEqual(optOut(['Fix typo\n\nDocs-Impact: none – internal refactor']), { + reason: 'internal refactor', + }); + assert.deepEqual(optOut(['', '- Docs-Impact: none (tests only)']), { reason: '(tests only)' }); + assert.deepEqual(optOut(['Docs-Impact: none']), { missingReason: true }); + assert.equal(optOut(['Docs-Impact: README updated', undefined]), null); +}); + +test('every rule names existing documents', async () => { + const { existsSync } = await import('node:fs'); + const { join } = await import('node:path'); + for (const rule of RULES) + for (const doc of rule.docs) assert.ok(existsSync(join(import.meta.dirname, '..', doc)), doc); +});