Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

CI: duplicate-PR check and a 'Changes a default' line (Refs #6439) (#6442)

bherbruck78de68790226
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 868b73f579..ba6bb80935 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -2,6 +2,12 @@
Describe the problem and resulting behavior. Link the issue when applicable.
+Changes a default: no
+
+<!-- Required line, replace "no" if this changes what a user gets out of the box (a default value, key binding, setting, tool behaviour):
+Changes a default: yes — <what>, old behaviour kept behind preference <name>
+Docs-only and bot PRs are exempt. -->
+
## Validation
What did you run, and what were the results? Include expected and measured values for geometry changes.
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c4427cf86d..097cece0c2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -295,7 +295,7 @@ jobs:
- name: Merge-of-main detection self-test
run: python3 -I scripts/ci/test_main_merge.py
- name: Claim, triage and kernel-paused bot tests
- run: node --test scripts/claim/*.test.js scripts/triage/*.test.js scripts/kernel-paused/*.test.js
+ run: node --test scripts/claim/*.test.js scripts/triage/*.test.js scripts/kernel-paused/*.test.js scripts/pr-checks/*.test.js
# Fast feedback for a pull request that has not been approved for the full CI yet.
quick-compile:
diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml
new file mode 100644
index 0000000000..9db8688271
--- /dev/null
+++ b/.github/workflows/pr-checks.yml
@@ -0,0 +1,69 @@
+# Two quick checks on every pull request (CONTRIBUTING.md, "Sending a change"): no second open PR
+# for an issue a lower-numbered one already closes, and the "Changes a default:" line is filled in.
+# Neither is a required status check. The logic is in scripts/pr-checks/pr-checks.js (tested in ci.yml).
+name: PR checks
+
+on:
+ # pull_request, never pull_request_target: nothing here checks out or runs the PR's code, and the
+ # token is read-only for fork PRs. Only scripts/pr-checks from the PR's own merge commit is run.
+ pull_request:
+ types: [opened, edited, synchronize, reopened, ready_for_review, labeled, unlabeled]
+
+permissions:
+ contents: read
+ pull-requests: read
+
+concurrency:
+ group: pr-checks-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+jobs:
+ duplicate:
+ name: Duplicate PR check
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ sparse-checkout: scripts/pr-checks
+ - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ with:
+ script: |
+ const checks = require('./scripts/pr-checks/pr-checks.js');
+ const r = await checks.checkDuplicate({ github, context, core });
+ core.info(JSON.stringify(r));
+
+ defaults:
+ name: Defaults line check
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ sparse-checkout: scripts/pr-checks
+ - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ with:
+ script: |
+ const checks = require('./scripts/pr-checks/pr-checks.js');
+ const r = await checks.checkDefaults({ github, context, core });
+ core.info(JSON.stringify(r));
+
+ # Labelling needs write access, which a fork PR's token never has, so it is its own job and best
+ # effort: a fork PR just doesn't get the `changes-default` label from here.
+ label:
+ name: Label changes-default
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ continue-on-error: true
+ permissions:
+ contents: read
+ pull-requests: write
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ sparse-checkout: scripts/pr-checks
+ - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ with:
+ script: |
+ const checks = require('./scripts/pr-checks/pr-checks.js');
+ await checks.syncDefaultLabel({ github, context, core });
diff --git a/AGENTS.md b/AGENTS.md
index 62d67958b7..24c1c11e59 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -156,6 +156,9 @@ People trust SolidCraft with their designs; a crash loses their work. **This out
- If someone already has it, comment on their PR or issue instead of opening a second one. Two
PRs for one change can't both land, and one of them is wasted work and CI.
+- Keep the `Changes a default:` line in the PR description filled in, and don't open a second PR for
+ an issue a lower-numbered open PR already closes; `pr-checks.yml` fails both (CONTRIBUTING.md, "Sending a change").
+
## Claim = a draft PR
- Before working on issue #N, check nobody has it: `gh pr list -R tangency-labs/solidcraft --state open --search "#N"`.
- If none, branch from the latest `origin/main`, `git commit --allow-empty -m "claim: #N"`, push,
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index eb5af6bee1..125fc8706f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -346,6 +346,10 @@ owning one area, with a human setting direction and reporting bugs. Their workin
[AGENTS.md](AGENTS.md). Human contributors are just as welcome. Use whatever tools you like, as
long as the change meets the rules above.
+Two quick checks run on every pull request (`.github/workflows/pr-checks.yml`, not required): it
+fails when a lower-numbered open PR by someone else already closes the same issue (the label
+`not-a-duplicate` skips it), or when the description lacks the `Changes a default: no` / `Changes a default: yes — <what>, old behaviour kept behind preference <name>` line (docs-only and bot PRs are exempt).
+
## Labels and triage
The triage bot labels every new issue and PR (`.github/workflows/triage.yml`). It only adds labels;
diff --git a/scripts/pr-checks/pr-checks.js b/scripts/pr-checks/pr-checks.js
new file mode 100644
index 0000000000..d1ed7aaccd
--- /dev/null
+++ b/scripts/pr-checks/pr-checks.js
@@ -0,0 +1,146 @@
+// Pull request checks for .github/workflows/pr-checks.yml (CONTRIBUTING.md, "Sending a change"):
+// 1. duplicate: fails when a lower-numbered open PR already closes the same issue;
+// 2. defaults: the template line `Changes a default: no | yes - <what>, old behaviour kept behind
+// preference <name>` must be present and well formed; `yes` earns the `changes-default` label.
+// The parsing is pure and tested in scripts/pr-checks/pr-checks.test.js; the functions that talk to
+// GitHub take the github-script `github` client and `context`, so the tests can pass fakes.
+'use strict';
+
+const SKIP_LABEL = 'not-a-duplicate';
+const DEFAULT_LABEL = 'changes-default';
+// PRs opened before this predate the template line; they pass the defaults check with a notice.
+const DEFAULTS_ENFORCED_FROM = Date.parse('2026-10-25T00:00:00Z');
+const BOT_LOGINS = new Set(['dependabot[bot]', 'github-actions[bot]', 'dependabot-preview[bot]']);
+
+// Template comments and code blocks hold examples, not claims.
+function stripNoise(body, { inlineCode = true } = {}) {
+ const text = String(body || '')
+ .replace(/<!--[\s\S]*?-->/g, '')
+ .replace(/```[\s\S]*?```/g, '')
+ .replace(/~~~[\s\S]*?~~~/g, '');
+ return inlineCode ? text.replace(/`[^`\n]*`/g, '') : text;
+}
+
+// Issue numbers after a closing keyword: Fixes #1, closes: #2, Resolved owner/repo#3.
+// A list ("Fixes #1, #2") counts every number; a URL to another repo does not.
+function parseClosing(body, repoFullName) {
+ const text = stripNoise(body);
+ const found = new Set();
+ const re = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\b:?[ \t]+((?:(?:[\w.-]+\/[\w.-]+)?#\d+(?:[ \t]*(?:,|and|&)[ \t]*)?)+)/gi;
+ for (const m of text.matchAll(re)) {
+ for (const ref of m[1].matchAll(/(?:([\w.-]+\/[\w.-]+))?#(\d+)/g)) {
+ if (ref[1] && repoFullName && ref[1].toLowerCase() !== repoFullName.toLowerCase()) continue;
+ found.add(Number(ref[2]));
+ }
+ }
+ return [...found].sort((a, b) => a - b);
+}
+
+// -> { status: 'missing' | 'malformed' | 'no' | 'yes', preference?, detail? }
+function parseDefaults(body) {
+ const m = stripNoise(body, { inlineCode: false }).replace(/\*\*/g, '').match(/^[ \t]*(?:[-*][ \t]+)?Changes a default:[ \t]*(.*?)[ \t]*$/im);
+ if (!m) return { status: 'missing' };
+ const value = m[1].replace(/\*\*/g, '').trim();
+ if (/^no\.?$/i.test(value)) return { status: 'no' };
+ const yes = value.match(/^yes\b[ \t]*(?:—|–|->|→|-{1,2}|:)[ \t]*(.+)$/i);
+ if (yes) {
+ const pref = yes[1].match(/^(.*?)[ ,;]*\bold (?:behaviou?r|value) kept behind (?:preference|pref|setting)[ \t]+`?([\w.:/-]+)`?\.?$/i);
+ if (pref && pref[1].trim() && !/^<.*>$/.test(pref[2])) {
+ return { status: 'yes', detail: pref[1].trim(), preference: pref[2] };
+ }
+ }
+ return { status: 'malformed', detail: value };
+}
+
+const DEFAULTS_HELP =
+ 'Add one line to the description: `Changes a default: no`, or ' +
+ '`Changes a default: yes — <what>, old behaviour kept behind preference <name>`.';
+
+function isBot(user) {
+ return !!user && (user.type === 'Bot' || BOT_LOGINS.has(user.login) || /\[bot\]$/.test(user.login || ''));
+}
+
+const DOC_FILE = /(^docs\/|\.md$|^LICENSE|^\.github\/ISSUE_TEMPLATE\/|^\.github\/pull_request_template\.md$)/;
+function isDocsOnly(files) {
+ return files.length > 0 && files.every((f) => DOC_FILE.test(f));
+}
+
+// Open PRs with a lower number than `number` that close one of `issues`, by someone else.
+// `pulls` is a list of REST pull objects.
+function findDuplicates({ number, author, issues, pulls, repoFullName }) {
+ const out = [];
+ for (const p of pulls) {
+ if (p.number >= number || p.state !== 'open') continue;
+ if (p.user && p.user.login === author) continue; // stacked work by the same author
+ if ((p.labels || []).some((l) => l.name === SKIP_LABEL)) continue;
+ const shared = parseClosing(p.body, repoFullName).filter((n) => issues.includes(n));
+ if (shared.length) out.push({ number: p.number, title: p.title, url: p.html_url, draft: !!p.draft, issues: shared });
+ }
+ return out.sort((a, b) => a.number - b.number);
+}
+
+function hasLabel(pull, name) {
+ return (pull.labels || []).some((l) => l.name === name);
+}
+
+async function checkDuplicate({ github, context, core }) {
+ const pull = context.payload.pull_request;
+ const repoFullName = `${context.repo.owner}/${context.repo.repo}`;
+ if (isBot(pull.user)) return { skipped: 'bot' };
+ if (hasLabel(pull, SKIP_LABEL)) return { skipped: SKIP_LABEL };
+ const issues = parseClosing(pull.body, repoFullName);
+ if (!issues.length) return { skipped: 'no closing keyword' };
+ const pulls = await github.paginate(github.rest.pulls.list, {
+ ...context.repo, state: 'open', per_page: 100,
+ });
+ const dups = findDuplicates({ number: pull.number, author: pull.user.login, issues, pulls, repoFullName });
+ if (!dups.length) return { dups };
+ const lines = dups.map(
+ (d) => ` #${d.number}${d.draft ? ' (draft)' : ''} ${d.title}\n ${d.url} (closes ${d.issues.map((n) => '#' + n).join(', ')})`,
+ );
+ core.setFailed(
+ `A lower-numbered open pull request already closes the same issue, and the lowest number wins:\n${lines.join('\n')}\n` +
+ `Close this one or help on that one. If this is not a duplicate (a different fix that happens to name the same issue), ` +
+ `change "Fixes" to "Refs" or ask a maintainer to add the \`${SKIP_LABEL}\` label.`,
+ );
+ return { dups };
+}
+
+async function checkDefaults({ github, context, core }) {
+ const pull = context.payload.pull_request;
+ if (isBot(pull.user)) return { skipped: 'bot' };
+ if (!(Date.parse(pull.created_at) >= DEFAULTS_ENFORCED_FROM)) {
+ core.notice('The "Changes a default:" line is only enforced on pull requests opened on or after 2026-10-25; this one predates it. Please add the line when you next push.');
+ return { skipped: 'opened before enforcement' };
+ }
+ const files = (await github.paginate(github.rest.pulls.listFiles, {
+ ...context.repo, pull_number: pull.number, per_page: 100,
+ })).map((f) => f.filename);
+ if (isDocsOnly(files)) return { skipped: 'docs only' };
+ const result = parseDefaults(pull.body);
+ if (result.status === 'missing') {
+ core.setFailed(`The description has no "Changes a default:" line. ${DEFAULTS_HELP}`);
+ } else if (result.status === 'malformed') {
+ core.setFailed(`Could not read "Changes a default: ${result.detail}". ${DEFAULTS_HELP}`);
+ }
+ return result;
+}
+
+// Separate job (it needs write access, which fork PRs don't get): best effort.
+async function syncDefaultLabel({ github, context, core }) {
+ const pull = context.payload.pull_request;
+ const { status } = parseDefaults(pull.body);
+ const has = hasLabel(pull, DEFAULT_LABEL);
+ const args = { ...context.repo, issue_number: pull.number };
+ if (status === 'yes' && !has) {
+ await github.rest.issues.addLabels({ ...args, labels: [DEFAULT_LABEL] });
+ } else if (status !== 'yes' && has) {
+ await github.rest.issues.removeLabel({ ...args, name: DEFAULT_LABEL });
+ }
+ core.info(`Defaults line: ${status}`);
+}
+
+module.exports = {
+ DEFAULTS_ENFORCED_FROM, SKIP_LABEL, DEFAULT_LABEL, stripNoise, parseClosing, parseDefaults, isBot, isDocsOnly,
+ findDuplicates, checkDuplicate, checkDefaults, syncDefaultLabel,
+};
diff --git a/scripts/pr-checks/pr-checks.test.js b/scripts/pr-checks/pr-checks.test.js
new file mode 100644
index 0000000000..7d47392dc7
--- /dev/null
+++ b/scripts/pr-checks/pr-checks.test.js
@@ -0,0 +1,148 @@
+'use strict';
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const pc = require('./pr-checks.js');
+
+const REPO = 'tangency-labs/solidcraft';
+
+test('parseClosing finds closing keywords only', () => {
+ assert.deepEqual(pc.parseClosing('Fixes #12', REPO), [12]);
+ assert.deepEqual(pc.parseClosing('closes: #3\nResolved #4', REPO), [3, 4]);
+ assert.deepEqual(pc.parseClosing('Fixes #5, #6 and #7', REPO), [5, 6, 7]);
+ assert.deepEqual(pc.parseClosing('Fix #8', REPO), [8]);
+ assert.deepEqual(pc.parseClosing('Refs #9\nSee #10\nrelated to #11', REPO), []);
+ assert.deepEqual(pc.parseClosing('Prefixes #1 and suffix fixes#2', REPO), []);
+ assert.deepEqual(pc.parseClosing(null, REPO), []);
+});
+
+test('parseClosing handles repo-qualified refs, comments and code', () => {
+ assert.deepEqual(pc.parseClosing(`Fixes ${REPO}#20`, REPO), [20]);
+ assert.deepEqual(pc.parseClosing('Fixes other/repo#21', REPO), []);
+ assert.deepEqual(pc.parseClosing('<!-- Fixes #22 -->', REPO), []);
+ assert.deepEqual(pc.parseClosing('```\nFixes #23\n```\nFixes #24', REPO), [24]);
+ assert.deepEqual(pc.parseClosing('say `Fixes #25` to close', REPO), []);
+});
+
+test('parseDefaults', () => {
+ assert.equal(pc.parseDefaults('x').status, 'missing');
+ assert.equal(pc.parseDefaults('<!-- Changes a default: no -->').status, 'missing');
+ assert.equal(pc.parseDefaults('Changes a default: no').status, 'no');
+ assert.equal(pc.parseDefaults('- Changes a default: No.\r\nmore').status, 'no');
+ assert.equal(pc.parseDefaults('**Changes a default:** no').status, 'no');
+ assert.equal(pc.parseDefaults('Changes a default: <no | yes — <what>, old behaviour kept behind preference <name>>').status, 'malformed');
+ assert.equal(pc.parseDefaults('Changes a default:').status, 'malformed');
+ assert.equal(pc.parseDefaults('Changes a default: maybe').status, 'malformed');
+ assert.equal(pc.parseDefaults('Changes a default: yes').status, 'malformed');
+ assert.equal(pc.parseDefaults('Changes a default: yes - faster zoom').status, 'malformed');
+});
+
+test('parseDefaults yes forms', () => {
+ for (const sep of ['—', '–', '-', '->', '→', ':']) {
+ const r = pc.parseDefaults(`Changes a default: yes ${sep} zoom speed doubled, old behaviour kept behind preference viewport.zoom_speed`);
+ assert.equal(r.status, 'yes', sep);
+ assert.equal(r.preference, 'viewport.zoom_speed');
+ assert.equal(r.detail, 'zoom speed doubled');
+ }
+ assert.equal(pc.parseDefaults('Changes a default: yes — x, old value kept behind preference `p`').status, 'yes');
+ assert.equal(pc.parseDefaults('Changes a default: yes — x, old behaviour kept behind preference <name>').status, 'malformed');
+});
+
+test('isBot and isDocsOnly', () => {
+ assert.ok(pc.isBot({ login: 'dependabot[bot]', type: 'Bot' }));
+ assert.ok(pc.isBot({ login: 'solidcraft-generated[bot]' }));
+ assert.ok(!pc.isBot({ login: 'alice', type: 'User' }));
+ assert.ok(pc.isDocsOnly(['README.md', 'docs/a.png']));
+ assert.ok(!pc.isDocsOnly(['README.md', 'crates/a.rs']));
+ assert.ok(!pc.isDocsOnly([]));
+});
+
+const mk = (number, login, body, extra = {}) => ({
+ number, state: 'open', user: { login }, body, title: `t${number}`,
+ html_url: `https://github.com/${REPO}/pull/${number}`, labels: [], ...extra,
+});
+
+test('findDuplicates: lower number, other author, same issue', () => {
+ const pulls = [
+ mk(10, 'bob', 'Fixes #5'),
+ mk(11, 'carol', 'Fixes #6'),
+ mk(12, 'alice', 'Fixes #5'),
+ mk(13, 'dan', 'Refs #5'),
+ mk(14, 'erin', 'Closes #5', { draft: true }),
+ mk(15, 'fay', 'Fixes #5', { labels: [{ name: 'not-a-duplicate' }] }),
+ mk(30, 'gus', 'Fixes #5'),
+ mk(16, 'hal', 'Fixes #5', { state: 'closed' }),
+ ];
+ const d = pc.findDuplicates({ number: 20, author: 'alice', issues: [5], pulls, repoFullName: REPO });
+ assert.deepEqual(d.map((x) => x.number), [10, 14]);
+ assert.ok(d[1].draft);
+});
+
+function fakes(pull, { pulls = [], files = [] } = {}) {
+ const calls = [];
+ const github = {
+ paginate: async (fn) => (fn === 'list' ? pulls : files),
+ rest: {
+ pulls: { list: 'list', listFiles: 'files' },
+ issues: {
+ addLabels: async (a) => calls.push(['add', a.labels]),
+ removeLabel: async (a) => calls.push(['remove', a.name]),
+ },
+ },
+ };
+ const failures = [];
+ const core = { setFailed: (m) => failures.push(m), info() {}, notice() {} };
+ const context = { repo: { owner: 'tangency-labs', repo: 'solidcraft' }, payload: { pull_request: pull } };
+ return { github, core, context, calls, failures };
+}
+
+test('checkDuplicate fails with links, skips on label and bots', async () => {
+ const me = mk(20, 'alice', 'Fixes #5');
+ let f = fakes(me, { pulls: [mk(10, 'bob', 'Fixes #5')] });
+ await pc.checkDuplicate(f);
+ assert.equal(f.failures.length, 1);
+ assert.match(f.failures[0], /pull\/10/);
+
+ f = fakes({ ...me, labels: [{ name: 'not-a-duplicate' }] }, { pulls: [mk(10, 'bob', 'Fixes #5')] });
+ await pc.checkDuplicate(f);
+ assert.equal(f.failures.length, 0);
+
+ f = fakes({ ...me, user: { login: 'dependabot[bot]', type: 'Bot' } }, { pulls: [mk(10, 'bob', 'Fixes #5')] });
+ await pc.checkDuplicate(f);
+ assert.equal(f.failures.length, 0);
+});
+
+test('checkDefaults fails when missing, passes docs-only and bots', async () => {
+ const me = mk(20, 'alice', 'Fixes #5', { created_at: '2026-10-25T00:00:00Z' });
+ let f = fakes(me, { files: [{ filename: 'crates/a.rs' }] });
+ await pc.checkDefaults(f);
+ assert.equal(f.failures.length, 1);
+
+ f = fakes(me, { files: [{ filename: 'docs/a.md' }] });
+ await pc.checkDefaults(f);
+ assert.equal(f.failures.length, 0);
+
+ f = fakes({ ...me, body: 'Changes a default: no' }, { files: [{ filename: 'crates/a.rs' }] });
+ await pc.checkDefaults(f);
+ assert.equal(f.failures.length, 0);
+});
+
+test('syncDefaultLabel adds and removes', async () => {
+ const yes = 'Changes a default: yes — a, old behaviour kept behind preference p';
+ let f = fakes(mk(1, 'a', yes));
+ await pc.syncDefaultLabel(f);
+ assert.deepEqual(f.calls, [['add', ['changes-default']]]);
+ f = fakes(mk(1, 'a', 'Changes a default: no', { labels: [{ name: 'changes-default' }] }));
+ await pc.syncDefaultLabel(f);
+ assert.deepEqual(f.calls, [['remove', 'changes-default']]);
+});
+
+test('checkDefaults only enforces from 2026-10-25', async () => {
+ const files = [{ filename: 'crates/a.rs' }];
+ const old = mk(20, 'alice', 'Fixes #5', { created_at: '2026-10-24T23:59:59Z' });
+ let f = fakes(old, { files });
+ assert.deepEqual(await pc.checkDefaults(f), { skipped: 'opened before enforcement' });
+ assert.equal(f.failures.length, 0);
+ f = fakes({ ...old, created_at: '2026-10-25T00:00:00Z' }, { files });
+ await pc.checkDefaults(f);
+ assert.equal(f.failures.length, 1);
+});