Dough Git

commit

Deny and close unsupported CNAME registrations

commit
3c78d648aaa69cee621035b8e2f1bbc88fbdad33
author
Clove Twilight <[email protected]>
date
2026-11-21 14:11
Add denial and incompatible-record labels, post a short explanation, and close approved unsupported-host pull requests. Upgrade JPCL to v2 for existing comment syntax and cover closure retries and legacy reviews.

Co-Authored-By: Sandrone <[email protected]>

diff --git a/README.md b/README.md
index e297118..0f30492 100644
--- a/README.md
+++ b/README.md
@@ -16,19 +16,20 @@ Without `DASHBOARD_PASSWORD`, moderation stays unavailable in production.
 
 It detects the violations below, pings you on Discord, and acts **only** when you press a button.
 
-| Violation                                                | Button          | What the button does                                 |
-| -------------------------------------------------------- | --------------- | ---------------------------------------------------- |
-| NS records from a first-time contributor                 | Close PR        | Posts the policy comment, then closes the PR         |
-| `CNAME` to an unsupported host                           | Request Changes | Submits a review with an inline comment on that line |
-| Vercel preview redirects to the Vercel login             | Request Changes | Submits a review explaining Deployment Protection    |
-| `owner.email` is a GitHub no-reply address               | Request Changes | Submits a review with an inline comment on that line |
-| `_vercel.www.alice.json` instead of `_vercel.alice.json` | Request Changes | Asks for the file to be renamed to the right name    |
-| `vc-domain-verify=` TXT inside `alice.json`              | Request Changes | Asks for it to move to `_vercel.alice.json`          |
+| Violation                                                | Button          | What the button does                                                           |
+| -------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------ |
+| NS records from a first-time contributor                 | Close PR        | Posts the policy comment, then closes the PR                                   |
+| `CNAME` to an unsupported host                           | Close PR        | Explains the unsupported host, labels denied/incompatible records, then closes |
+| Vercel preview redirects to the Vercel login             | Request Changes | Submits a review explaining Deployment Protection                              |
+| `owner.email` is a GitHub no-reply address               | Request Changes | Submits a review with an inline comment on that line                           |
+| `_vercel.www.alice.json` instead of `_vercel.alice.json` | Request Changes | Asks for the file to be renamed to the right name                              |
+| `vc-domain-verify=` TXT inside `alice.json`              | Request Changes | Asks for it to move to `_vercel.alice.json`                                    |
 
 Each pull request gets **one** Discord message and one dashboard card listing every issue on it,
 with one button for all of them:
 
-- With NS records on the PR, the button closes it, which settles every other issue too.
+- With NS records or an unsupported CNAME on the PR, the button closes it, settling every issue.
+- Unsupported CNAME closures add `status: denied` and `reason: incompatible records`.
 - Otherwise it submits one review: an inline comment per issue where GitHub allows one, the
   rest in the review body. That review is dismissed once every issue in it is fixed.
 - **Ignore** ignores every pending issue on the PR.
@@ -103,7 +104,9 @@ Once a contributor fixes a change request, the next scan dismisses that review w
 
 List hosts in `config/unsupportedCnames.jp` under `hosts`, for example
 `hosts: ["vercel.app", "example.com"]`. A CNAME matches an entry or any subdomain of it.
-Changes apply on the next scan. An empty list turns the rule off.
+Changes apply on the next scan. An empty list turns the rule off. Approving a finding posts
+a short unsupported-host explanation, adds `status: denied` and `reason: incompatible records`,
+and closes the PR instead of requesting changes.
 
 ## Vercel previews behind a login
 
diff --git a/config/messages.jp b/config/messages.jp
index 8ae10f3..6596c1f 100644
--- a/config/messages.jp
+++ b/config/messages.jp
@@ -7,6 +7,7 @@ closeComment: "Thanks for your interest in {service}!\n\nThis pull request reque
 reviewSummary: "This pull request has a few things to fix. Please see the comments below.\n<sub>This comment was sent with an [automated tool](https://doughmination.gay/automated), and approved by a human. I do not see replies.</sub>"
 
 [unsupportedCname]
+closeComment: "This CNAME target is unsupported.\n\nDenied: incompatible records.\n<sub>This comment was sent with an [automated tool](https://doughmination.gay/automated), and approved by a human. I do not see replies.</sub>"
 reviewComment: "Your `CNAME` record points at a host that we do not support. Please point it at a supported host, or use another record type such as `A` or `AAAA`.\n\nIf you have requested a CloudFlare Worker, please use a legacy CloudFlare Pages project."
 reviewDismissal: "Thanks, the `CNAME` record is fixed. Dismissing the requested changes."
 reviewSummary: "Please see the inline comment on `CNAME`.\n<sub>This comment was sent with an [automated tool](https://doughmination.gay/automated), and approved by a human. I do not see replies.</sub>"
diff --git a/deno.lock b/deno.lock
index 7b65c27..7531e4f 100644
--- a/deno.lock
+++ b/deno.lock
@@ -11,7 +11,7 @@
     "npm:eslint-plugin-svelte@^3.24.1": "[email protected][email protected]",
     "npm:eslint@^10.15.0": "10.15.0",
     "npm:globals@^17.14.0": "17.14.0",
-    "npm:jpcl-lang@^1.2.0": "1.2.0",
+    "npm:jpcl-lang@2": "2.0.0",
     "npm:prettier-plugin-svelte@^4.2.0": "[email protected][email protected]",
     "npm:prettier@^3.10.1": "3.10.1",
     "npm:svelte-check@^4.7.8": "[email protected][email protected]",
@@ -867,8 +867,8 @@
     "[email protected]": {
       "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
     },
-    "[email protected]": {
-      "integrity": "sha512-ChlK4ZdPq8Tp/+TQazJqE+HztDIiPS98h5F4EvNns662lt3/r7754ye7cthypODvsAketUcaTthUHgzm1OWrlw==",
+    "[email protected]": {
+      "integrity": "sha512-n99Fj10ntxhu83lcnhgIZ/PAMwSgs4zpamOM73Uy5gtCQlvBYIkEnGFIxwTGGRo+zvh+oY4W7RNFErNxF9uuAQ==",
       "bin": true
     },
     "[email protected]": {
@@ -1351,7 +1351,7 @@
         "npm:eslint-plugin-svelte@^3.24.1",
         "npm:eslint@^10.15.0",
         "npm:globals@^17.14.0",
-        "npm:jpcl-lang@^1.2.0",
+        "npm:jpcl-lang@2",
         "npm:prettier-plugin-svelte@^4.2.0",
         "npm:prettier@^3.10.1",
         "npm:svelte-check@^4.7.8",
diff --git a/package.json b/package.json
index 39c2f1b..dc4a502 100644
--- a/package.json
+++ b/package.json
@@ -23,7 +23,7 @@
 	},
 	"dependencies": {
 		"discord.js": "^14.28.1",
-		"jpcl-lang": "^1.2.0"
+		"jpcl-lang": "^2.0.0"
 	},
 	"devDependencies": {
 		"@eslint/js": "^10.0.1",
diff --git a/src/lib/server/github/pullRequests.ts b/src/lib/server/github/pullRequests.ts
index 4cf3b80..c53c792 100644
--- a/src/lib/server/github/pullRequests.ts
+++ b/src/lib/server/github/pullRequests.ts
@@ -209,6 +209,19 @@ export async function createIssueComment(
 	return response.data;
 }
 
+export async function addIssueLabels(
+	repo: string,
+	number: number,
+	labels: string[]
+): Promise<void> {
+	await githubRequest({
+		method: 'POST',
+		path: `${getRepoPath(repo)}/issues/${number}/labels`,
+		body: { labels },
+		priority: true
+	});
+}
+
 export async function closePullRequest(repo: string, number: number): Promise<void> {
 	await githubRequest({
 		method: 'PATCH',
diff --git a/src/lib/server/messages.ts b/src/lib/server/messages.ts
index c3d32de..5e16417 100644
--- a/src/lib/server/messages.ts
+++ b/src/lib/server/messages.ts
@@ -24,7 +24,7 @@ export type ModerationMessages = {
 	combined: {
 		reviewSummary: string;
 	};
-	unsupportedCname: ReviewMessages;
+	unsupportedCname: ReviewMessages & { closeComment: string };
 	noReplyEmail: ReviewMessages;
 	vercelLogin: ReviewMessages;
 	vercelFileName: ReviewMessages;
diff --git a/src/lib/server/moderation/actions.ts b/src/lib/server/moderation/actions.ts
index 2975559..c05d464 100644
--- a/src/lib/server/moderation/actions.ts
+++ b/src/lib/server/moderation/actions.ts
@@ -39,7 +39,7 @@ interface Resolution {
 }
 
 function chooseAction(findings: FindingRow[]): Exclude<ActionType, 'ignore'> {
-	// NS closes the PR, which settles every other issue with it
+	// A closure settles every other issue on the PR
 	return findings.some((finding) => getRule(finding.ruleId).actionType === 'closePr')
 		? 'closePr'
 		: 'requestChanges';
diff --git a/src/lib/server/moderation/executors.ts b/src/lib/server/moderation/executors.ts
index 91fbbdb..3dca0b7 100644
--- a/src/lib/server/moderation/executors.ts
+++ b/src/lib/server/moderation/executors.ts
@@ -10,6 +10,7 @@ import { emitFindingEvent } from '../events.ts';
 import { getCommentableLines } from '../github/diff.ts';
 import { GitHubError } from '../github/client.ts';
 import {
+	addIssueLabels,
 	closePullRequest,
 	createChangesRequestedReview,
 	createIssueComment,
@@ -53,21 +54,35 @@ function findingKey(item: { ruleId: string; filePath: string }): string {
 async function closeWithPolicyComment(input: ExecutorInput): Promise<ActionOutcome> {
 	const { pullRequest, findings } = input;
 	const { repo, number } = pullRequest;
-	const nsFinding = findings.find((finding) => getRule(finding.ruleId).actionType === 'closePr');
+	const closingFinding =
+		findings.find((finding) => finding.ruleId === 'unsupportedCname') ??
+		findings.find((finding) => getRule(finding.ruleId).actionType === 'closePr');
 
-	if (!nsFinding) {
+	if (!closingFinding) {
 		throw new Error('Closing needs a closePr finding.');
 	}
 
+	const unsupported = closingFinding.ruleId === 'unsupportedCname';
+
+	if (unsupported) {
+		await addIssueLabels(repo, number, ['status: denied', 'reason: incompatible records']);
+	}
+
 	// A stored comment id means an earlier attempt already explained; never explain twice
-	if (nsFinding.commentId === null) {
+	if (closingFinding.commentId === null) {
 		const comment = await createIssueComment(
 			repo,
 			number,
-			fillWording(getMessages().nsRecords.closeComment, repo, nsFinding.filePath)
+			fillWording(
+				unsupported
+					? getMessages().unsupportedCname.closeComment
+					: getMessages().nsRecords.closeComment,
+				repo,
+				closingFinding.filePath
+			)
 		);
 
-		setFindingComment(nsFinding.id, comment.id);
+		setFindingComment(closingFinding.id, comment.id);
 	}
 
 	await closePullRequest(repo, number);
@@ -80,7 +95,9 @@ async function closeWithPolicyComment(input: ExecutorInput): Promise<ActionOutco
 	return {
 		status: 'success',
 		summary:
-			`Closed #${number} with the NS policy explanation` +
+			(unsupported
+				? `Closed #${number}: denied, incompatible records (unsupported host)`
+				: `Closed #${number} with the NS policy explanation`) +
 			(others > 0 ? `, settling ${others} other issue(s) with it.` : '.'),
 		githubUrl: pullRequest.url
 	};
@@ -230,7 +247,9 @@ export async function dismissFixedChangeRequests(
 	const fixed = listFindingsForPullRequest(repo, number).filter(
 		(finding) =>
 			finding.status === 'actioned' &&
-			getRule(finding.ruleId).actionType === 'requestChanges' &&
+			// Older unsupported-host findings may still have a change-request review.
+			(getRule(finding.ruleId).actionType === 'requestChanges' ||
+				finding.ruleId === 'unsupportedCname') &&
 			!stillViolated.has(findingKey(finding))
 	);
 
diff --git a/src/lib/server/moderation/pipeline.test.ts b/src/lib/server/moderation/pipeline.test.ts
index 169210c..01d3221 100644
--- a/src/lib/server/moderation/pipeline.test.ts
+++ b/src/lib/server/moderation/pipeline.test.ts
@@ -14,7 +14,7 @@ const repo = 'is-a-dev/register';
 
 import { getConfig } from '../config.ts';
 import { getModerationStats, searchActions } from '../db/auditLog.ts';
-import { listFindingsForPullRequest } from '../db/findings.ts';
+import { listFindingsForPullRequest, setFindingStatus } from '../db/findings.ts';
 import { performModerationAction } from './actions.ts';
 import { scanOnce } from './scanner.ts';
 import { executors } from './executors.ts';
@@ -36,6 +36,7 @@ interface RecordedWrite {
 	path: string;
 	body: {
 		state?: string;
+		labels?: string[];
 		event?: string;
 		body?: string;
 		commit_id?: string;
@@ -69,6 +70,7 @@ const noReplyJson = {
 
 const fakePullRequests = new Map<number, FakePullRequest>();
 const writes: RecordedWrite[] = [];
+let failNextWritePath: string | null = null;
 
 function addPullRequest(pullRequest: FakePullRequest): void {
 	fakePullRequests.set(pullRequest.number, pullRequest);
@@ -111,6 +113,11 @@ async function fakeGitHub(input: string | URL | Request, init?: RequestInit): Pr
 			body: JSON.parse(String(init?.body))
 		});
 
+		if (path === failNextWritePath) {
+			failNextWritePath = null;
+			return new Response('{"message":"Permission denied"}', { status: 403 });
+		}
+
 		if (method === 'PATCH' && pullRequest) {
 			pullRequest.state = 'closed';
 		}
@@ -191,6 +198,28 @@ function findingFor(prNumber: number) {
 	return listFindingsForPullRequest(repo, prNumber)[0];
 }
 
+async function addUnsupportedPullRequest(number: number) {
+	addPullRequest({
+		number,
+		author: `unsupported-${number}`,
+		association: 'CONTRIBUTOR',
+		sha: `unsupported-sha-${number}`,
+		state: 'open',
+		updatedAt: `2026-11-06T00:00:${number}Z`,
+		fileName: `domains/unsupported-${number}.json`,
+		json: {
+			owner: noReplyJson.owner,
+			records: { CNAME: 'site.workers.dev' }
+		}
+	});
+
+	await scanOnce(repo);
+
+	return listFindingsForPullRequest(repo, number).find(
+		(finding) => finding.ruleId === 'unsupportedCname'
+	)!;
+}
+
 before(() => {
 	globalThis.fetch = fakeGitHub as typeof fetch;
 
@@ -570,4 +599,166 @@ describe('moderation pipeline', () => {
 			writes.pop();
 		}
 	});
+
+	test('unsupported hosts close with denial labels and a short explanation, even from another finding', async () => {
+		await addUnsupportedPullRequest(10);
+		const findings = listFindingsForPullRequest(repo, 10);
+		const other = findings.find((finding) => finding.ruleId === 'noReplyEmail')!;
+		const writesBefore = writes.length;
+
+		const outcome = await performModerationAction({
+			findingId: other.id,
+			decision: 'approve',
+			source: 'dashboard'
+		});
+
+		const sent = writes.slice(writesBefore);
+
+		assert.equal(outcome.status, 'success');
+		assert.deepEqual(
+			sent.map((write) => `${write.method} ${write.path}`),
+			['POST /issues/10/labels', 'POST /issues/10/comments', 'PATCH /pulls/10']
+		);
+		assert.deepEqual(sent[0].body.labels, ['status: denied', 'reason: incompatible records']);
+		assert.ok(sent[1].body.body?.startsWith('This CNAME target is unsupported.'));
+		assert.ok(sent[1].body.body?.includes('Denied: incompatible records.'));
+		assert.equal(sent[1].body.body?.includes('Please point'), false);
+		assert.equal(fakePullRequests.get(10)?.state, 'closed');
+		assert.ok(
+			listFindingsForPullRequest(repo, 10).every((finding) => finding.status === 'actioned')
+		);
+	});
+
+	test('dry-running unsupported closures sends no labels, comments, or closures', async () => {
+		const finding = await addUnsupportedPullRequest(11);
+		const writesBefore = writes.length;
+		getConfig().dryRun = true;
+
+		try {
+			const outcome = await performModerationAction({
+				findingId: finding.id,
+				decision: 'approve',
+				source: 'discord'
+			});
+
+			assert.equal(outcome.status, 'dryRun');
+			assert.ok(outcome.summary.includes('Close PR'));
+			assert.equal(writes.length, writesBefore);
+			assert.equal(fakePullRequests.get(11)?.state, 'open');
+		} finally {
+			getConfig().dryRun = false;
+		}
+	});
+
+	test('an unsupported host fixed before approval is not denied or closed', async () => {
+		const finding = await addUnsupportedPullRequest(12);
+		const pullRequest = fakePullRequests.get(12)!;
+		pullRequest.sha = 'supported-now';
+		pullRequest.json = {
+			owner: { username: 'fixed' },
+			records: { CNAME: 'site.github.io' }
+		};
+		const writesBefore = writes.length;
+
+		const outcome = await performModerationAction({
+			findingId: finding.id,
+			decision: 'approve',
+			source: 'dashboard'
+		});
+
+		assert.equal(outcome.status, 'skipped');
+		assert.equal(writes.length, writesBefore);
+		assert.equal(pullRequest.state, 'open');
+	});
+
+	test('a labeling failure leaves the PR open and its findings retryable', async () => {
+		const finding = await addUnsupportedPullRequest(13);
+		failNextWritePath = '/issues/13/labels';
+		const writesBefore = writes.length;
+
+		const outcome = await performModerationAction({
+			findingId: finding.id,
+			decision: 'approve',
+			source: 'discord'
+		});
+
+		assert.equal(outcome.status, 'failure');
+		assert.equal(writes.length, writesBefore + 1);
+		assert.equal(fakePullRequests.get(13)?.state, 'open');
+		assert.ok(listFindingsForPullRequest(repo, 13).every((member) => member.status === 'pending'));
+	});
+
+	test('retrying a failed closure does not duplicate its explanation', async () => {
+		const finding = await addUnsupportedPullRequest(14);
+		failNextWritePath = '/pulls/14';
+
+		const decision = {
+			findingId: finding.id,
+			decision: 'approve' as const,
+			source: 'dashboard' as const
+		};
+
+		assert.equal((await performModerationAction(decision)).status, 'failure');
+		assert.equal(fakePullRequests.get(14)?.state, 'open');
+		assert.equal((await performModerationAction(decision)).status, 'success');
+		assert.equal(writes.filter((write) => write.path === '/issues/14/comments').length, 1);
+		assert.equal(fakePullRequests.get(14)?.state, 'closed');
+	});
+
+	test('unsupported targets receive denial labels even when NS findings lead the PR', async () => {
+		const finding = await addUnsupportedPullRequest(15);
+		const pullRequest = fakePullRequests.get(15)!;
+		pullRequest.association = 'NONE';
+		pullRequest.json = {
+			owner: { username: 'unsupported' },
+			records: {
+				NS: ['ns1.example.com'],
+				CNAME: 'site.workers.dev'
+			}
+		};
+		await scanOnce(repo);
+		assert.ok(listFindingsForPullRequest(repo, 15).some((member) => member.ruleId === 'nsRecords'));
+		const writesBefore = writes.length;
+
+		const outcome = await performModerationAction({
+			findingId: finding.id,
+			decision: 'approve',
+			source: 'dashboard'
+		});
+
+		assert.equal(outcome.status, 'success');
+		assert.deepEqual(writes[writesBefore].body.labels, [
+			'status: denied',
+			'reason: incompatible records'
+		]);
+	});
+
+	test('old unsupported-host change requests are still dismissed when fixed', async () => {
+		const finding = await addUnsupportedPullRequest(16);
+		const pullRequest = fakePullRequests.get(16)!;
+		setFindingStatus(finding.id, 'actioned');
+		writes.push({
+			method: 'POST',
+			path: '/pulls/16/reviews',
+			body: {
+				commit_id: pullRequest.sha,
+				body: `<!-- isATracker:unsupportedCname:${finding.filePath} -->`
+			}
+		});
+		pullRequest.sha = 'legacy-review-fixed';
+		pullRequest.json = {
+			owner: { username: 'fixed' },
+			records: { CNAME: 'site.github.io' }
+		};
+
+		await scanOnce(repo);
+
+		assert.ok(
+			writes.some((write) => write.method === 'PUT' && write.path.startsWith('/pulls/16/reviews/'))
+		);
+		assert.equal(
+			listFindingsForPullRequest(repo, 16).find((member) => member.id === finding.id)?.status,
+			'resolved'
+		);
+	});
 });
diff --git a/src/lib/server/rules/unsupportedCname.ts b/src/lib/server/rules/unsupportedCname.ts
index e462340..8eda08d 100644
--- a/src/lib/server/rules/unsupportedCname.ts
+++ b/src/lib/server/rules/unsupportedCname.ts
@@ -81,8 +81,8 @@ export const unsupportedCnameRule: Rule = {
 	id: 'unsupportedCname',
 	title: 'CNAME to an unsupported host',
 	severity: 2,
-	actionType: 'requestChanges',
-	actionLabel: 'Request Changes',
+	actionType: 'closePr',
+	actionLabel: 'Close PR',
 
 	findLine: (file: DomainFile) => findCnameLine(file.content),