From c7bbe57abfb221dd288cabbe7d9dce3d387f3cc1 Mon Sep 17 00:00:00 2001
From: frankx-eth <132689939+frankx-eth@users.noreply.github.com>
Date: Wed, 4 Nov 2026 05:04:06 +0100
Subject: [PATCH 1/3] fix(pr-gate): ignore hidden review metadata
Ignore HTML-comment metadata when reading findings or clean review text,
while retaining head association for visible bot-comment findings.
Intent: https://github.com/Starlight-Intelligence/.github/issues/7
---
pr-gate/decide.mjs | 9 ++++---
pr-gate/decide.test.mjs | 54 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/pr-gate/decide.mjs b/pr-gate/decide.mjs
index 6a80dbd..55f55c9 100644
--- a/pr-gate/decide.mjs
+++ b/pr-gate/decide.mjs
@@ -38,6 +38,8 @@ const MARKER_RE = /^\s*starlight-signoff:\s*harness=(\S+)\s+verdict=(\S+)\s+sha=
const CHECKER_RE = /^\s*Checker:\s*([a-z0-9_-]+?)(?:-cloud)?\s*[·|-]\s*head\s+([0-9a-fA-F]{7,40})\s*[·|-]\s*verdict\s+(PASS|FAIL|BLOCK)\b/i;
const CODEX_CLEAN_RE = /didn'?t find any major issues/i;
const SEVERE_RE = /\bp[01]\b|p[01] badge/i;
+// Reviewer metadata includes severity thresholds and summaries, not findings or signoffs.
+const reviewText = (body) => String(body || '').replace(//g, '');
// GitHub's own bot accounts are the only reviewer identity an agent cannot type its way into.
// Exact logins on purpose: a substring match would accept any app whose name contains "codex".
@@ -60,16 +62,17 @@ export function collectSignoffs({ comments = [], reviews = [], headSha }) {
}
// Bot comments are not sign-offs: they carry no commit id, and a "no major issues" line can sit
// beside a P1 in the same comment. Only commit-bound bot reviews pass. A bot comment that names
- // a P0/P1 against the head still blocks.
+ // a visible P0/P1 against the head still blocks, even if metadata names the head.
+ // That SHA can associate a block, but metadata can never turn a comment into a pass.
const h = botHarness(c.user);
- if (h && SEVERE_RE.test(c.body || '') && head.length >= 7 && String(c.body).toLowerCase().includes(head.slice(0, 7))) {
+ if (h && SEVERE_RE.test(reviewText(c.body)) && head.length >= 7 && String(c.body).toLowerCase().includes(head.slice(0, 7))) {
out.push({ harness: h, verdict: 'block', sha: head, via: 'bot-comment', trusted: true });
}
}
for (const r of reviews) {
const h = botHarness(r.user);
if (!h || r.state === 'DISMISSED' || r.state === 'PENDING') continue;
- const body = String(r.body || '');
+ const body = reviewText(r.body);
let verdict = null;
if (r.state === 'CHANGES_REQUESTED' || SEVERE_RE.test(body)) verdict = 'block';
else if (r.state === 'APPROVED' || CODEX_CLEAN_RE.test(body)) verdict = 'pass';
diff --git a/pr-gate/decide.test.mjs b/pr-gate/decide.test.mjs
index a440d77..18bc6c4 100644
--- a/pr-gate/decide.test.mjs
+++ b/pr-gate/decide.test.mjs
@@ -8,6 +8,10 @@ const claudeBot = { login: 'claude[bot]', type: 'Bot' };
const human = { login: 'frankxai', type: 'User' };
const greenCI = [{ name: 'test', status: 'completed', conclusion: 'success' }];
const cleanReview = { user: codexBot, commitId: HEAD, state: 'COMMENTED', body: "Codex Review: Didn't find any major issues." };
+const codexMetadata = (sha = HEAD) => [
+ '',
+ '',
+].join('\n');
const base = (over = {}) => ({
headRef: 'agent/claude/thing',
@@ -67,6 +71,56 @@ test('a human account or a look-alike bot claiming to be Codex signs nothing', (
assert.equal(decide(base({ reviews: [{ ...cleanReview, user: { login: 'my-codex-helper[bot]', type: 'Bot' } }] })).ok, false);
});
+test('Codex metadata does not block a summary comment or make it a signoff', () => {
+ const body = `${codexMetadata()}\nDidn't find any major issues. Reviewed ${HEAD.slice(0, 7)}`;
+ const d = decide(base({ reviews: [], comments: [{ user: codexBot, body }] }));
+ assert.deepEqual(d.reasons, []);
+ assert.equal(d.pending, true);
+ assert.equal(d.ok, false);
+ assert.deepEqual(d.signers, []);
+ assert.match(d.waiting.join(), /needs a review/);
+});
+
+test('a clean head review is not vetoed by metadata in its summary comment', () => {
+ const d = decide(base({ comments: [{ user: codexBot, body: `${codexMetadata()}\nCode review completed.` }] }));
+ assert.equal(d.ok, true, JSON.stringify(d));
+});
+
+test('metadata does not veto a clean review or replace its commit binding', () => {
+ for (const state of ['COMMENTED', 'APPROVED']) {
+ const review = { ...cleanReview, state, body: `${codexMetadata()}\nDidn't find any major issues.` };
+ assert.equal(decide(base({ reviews: [review] })).ok, true, state);
+ for (const commitId of ['', 'ffffffffffffffffffffffffffffffffffffffff']) {
+ assert.equal(decide(base({ reviews: [{ ...review, commitId }] })).ok, false, `${state}: ${commitId}`);
+ }
+ }
+});
+
+test('visible P0/P1 comments still block when only metadata identifies the head', () => {
+ for (const severity of ['P0', 'P1']) {
+ const body = `${codexMetadata()}\n${severity}: a real finding remains.`;
+ const d = decide(base({ comments: [{ user: codexBot, body }] }));
+ assert.equal(d.ok, false, severity);
+ assert.match(d.reasons.join(), /blocked on this commit by codex/);
+ }
+});
+
+test('visible P0/P1 findings still block reviews alongside metadata', () => {
+ for (const severity of ['P0', 'P1']) {
+ const body = `${codexMetadata()}\n${severity}: a real finding remains.`;
+ const d = decide(base({ reviews: [{ ...cleanReview, state: 'APPROVED', body }] }));
+ assert.equal(d.ok, false, severity);
+ assert.match(d.reasons.join(), /blocked on this commit by codex/);
+ }
+});
+
+test('a clean phrase hidden in metadata cannot sign off a commented review', () => {
+ const body = '';
+ const d = decide(base({ reviews: [{ ...cleanReview, body }] }));
+ assert.equal(d.ok, false);
+ assert.deepEqual(d.signers, []);
+});
+
// Codex review of 1404c37 reproduced the next two as false passes.
test('bot comments never sign off; a P0/P1 bot comment on the head blocks', () => {
const clean = decide(base({ reviews: [], comments: [{ user: codexBot, body: `Didn't find any major issues. Reviewed ${HEAD.slice(0, 10)}` }] }));
From 77b2ec651edf7d320b029d84542ba08531fcdde3 Mon Sep 17 00:00:00 2001
From: frankx-eth <132689939+frankx-eth@users.noreply.github.com>
Date: Wed, 4 Nov 2026 06:27:09 +0100
Subject: [PATCH 2/3] fix(pr-gate): preserve visible Markdown severity literals
---
pr-gate/decide.mjs | 60 +++++++++++++++++++++++++++++++++++++++--
pr-gate/decide.test.mjs | 51 +++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/pr-gate/decide.mjs b/pr-gate/decide.mjs
index 55f55c9..de41e78 100644
--- a/pr-gate/decide.mjs
+++ b/pr-gate/decide.mjs
@@ -38,8 +38,64 @@ const MARKER_RE = /^\s*starlight-signoff:\s*harness=(\S+)\s+verdict=(\S+)\s+sha=
const CHECKER_RE = /^\s*Checker:\s*([a-z0-9_-]+?)(?:-cloud)?\s*[·|-]\s*head\s+([0-9a-fA-F]{7,40})\s*[·|-]\s*verdict\s+(PASS|FAIL|BLOCK)\b/i;
const CODEX_CLEAN_RE = /didn'?t find any major issues/i;
const SEVERE_RE = /\bp[01]\b|p[01] badge/i;
-// Reviewer metadata includes severity thresholds and summaries, not findings or signoffs.
-const reviewText = (body) => String(body || '').replace(//g, '');
+// Reviewer metadata includes thresholds and summaries, not findings or signoffs.
+// Preserve comment-shaped text rendered literally in code or escaped Markdown.
+// This is a conservative visibility filter, not a Markdown renderer: uncertain
+// or unterminated constructs remain available to the severity check.
+function reviewText(body) {
+ const source = String(body || '');
+ let out = '', i = 0, fence = null;
+ while (i < source.length) {
+ if (i === 0 || source[i - 1] === '\n') {
+ const newline = source.indexOf('\n', i);
+ const end = newline < 0 ? source.length : newline + 1;
+ const line = source.slice(i, end).replace(/\r?\n$/, '');
+ // Recognize code fences inside the common quote/list containers too.
+ const quoted = line.replace(/^(?: {0,3}>[ \t]?)*/, '');
+ const content = quoted.replace(/^(?: {0,3}(?:[-+*]|\d+[.)])[ \t]+)?/, '');
+ const marker = /^[ \t]*(`{3,}|~{3,})(.*)$/.exec(content);
+ if (fence) {
+ // A deeply indented fence may itself be literal code; never let it
+ // close a surrounding block and hide the visible lines that follow.
+ const closing = /^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(content);
+ if (closing && closing[1][0] === fence.char && closing[1].length >= fence.length) fence = null;
+ out += source.slice(i, end); i = end; continue;
+ }
+ if (marker && (marker[1][0] !== '`' || !marker[2].includes('`'))) {
+ fence = { char: marker[1][0], length: marker[1].length };
+ out += source.slice(i, end); i = end; continue;
+ }
+ if (/^(?: {4}| {0,3}\t)/.test(content) || /^ {0,3}(?:[-+*]|\d+[.)])(?: {5}| {0,4}\t)/.test(quoted)) {
+ out += source.slice(i, end); i = end; continue;
+ }
+ }
+ if (source[i] === '\\') {
+ out += source.slice(i, i + 2); i += 2; continue;
+ }
+ if (source[i] === '`') {
+ let length = 1;
+ while (source[i + length] === '`') length++;
+ const delimiter = '`'.repeat(length);
+ let close = source.indexOf(delimiter, i + length);
+ while (close >= 0 && (source[close - 1] === '`' || source[close + length] === '`')) close = source.indexOf(delimiter, close + length);
+ if (close >= 0) {
+ out += source.slice(i, close + length); i = close + length; continue;
+ }
+ out += delimiter; i += length; continue;
+ }
+ if (source.startsWith('', i)) { i += 5; continue; }
+ if (source.startsWith('', i)) { i += 6; continue; }
+ const close = source.indexOf('-->', i + 4);
+ const ambiguous = source.indexOf('--!>', i + 4);
+ // Do not remove text across an ambiguous HTML-parser terminator.
+ if (ambiguous >= 0 && (close < 0 || ambiguous < close)) { out += source.slice(i); break; }
+ if (close >= 0) { i = close + 3; continue; }
+ }
+ out += source[i++];
+ }
+ return out;
+}
// GitHub's own bot accounts are the only reviewer identity an agent cannot type its way into.
// Exact logins on purpose: a substring match would accept any app whose name contains "codex".
diff --git a/pr-gate/decide.test.mjs b/pr-gate/decide.test.mjs
index 18bc6c4..9e884d3 100644
--- a/pr-gate/decide.test.mjs
+++ b/pr-gate/decide.test.mjs
@@ -121,6 +121,57 @@ test('a clean phrase hidden in metadata cannot sign off a commented review', ()
assert.deepEqual(d.signers, []);
});
+test('HTML-comment literals visible as Markdown code or escaped text still block', () => {
+ const literal = '';
+ const bodies = [
+ '`' + literal + '`',
+ '`` a ` ' + literal + ' ``',
+ '```html\n' + literal + '\n```',
+ '~~~html\n' + literal + '\n~~~~',
+ '```html\n' + literal,
+ ' ' + literal,
+ ' \t' + literal,
+ '- ' + literal,
+ '\\' + literal,
+ '> ```html\n> ' + literal + '\n> ```',
+ '- ```html\n ' + literal + '\n ```',
+ '- item\n\n ```html\n ' + literal + '\n ```',
+ '```html\n ```\n' + literal + '\n```',
+ ];
+ for (const visible of bodies) {
+ const body = `${codexMetadata()}\n${visible}`;
+ for (const facts of [
+ { comments: [{ user: codexBot, body }] },
+ { reviews: [{ ...cleanReview, state: 'APPROVED', body }] },
+ ]) {
+ const d = decide(base(facts));
+ assert.equal(d.ok, false, visible);
+ assert.match(d.reasons.join(), /blocked on this commit by codex/, visible);
+ }
+ }
+});
+
+test('backticks in hidden metadata stay hidden alongside visible ordinary code', () => {
+ const body = '\n`ordinary code`\nDidnt find any major issues.';
+ assert.equal(decide(base({ reviews: [{ ...cleanReview, body }] })).ok, true);
+ const fenced = '```js\nconst value = 1;\n```\n' + body;
+ assert.equal(decide(base({ reviews: [{ ...cleanReview, body: fenced }] })).ok, true);
+});
+
+test('short or ambiguous comment endings cannot swallow a later visible finding', () => {
+ for (const opening of ['', '', '']) {
+ const body = `${opening}\nP1: visible serious finding\n${codexMetadata()}`;
+ for (const facts of [
+ { comments: [{ user: codexBot, body }] },
+ { reviews: [{ ...cleanReview, state: 'APPROVED', body }] },
+ ]) {
+ const d = decide(base(facts));
+ assert.equal(d.ok, false, opening);
+ assert.match(d.reasons.join(), /blocked on this commit by codex/, opening);
+ }
+ }
+});
+
// Codex review of 1404c37 reproduced the next two as false passes.
test('bot comments never sign off; a P0/P1 bot comment on the head blocks', () => {
const clean = decide(base({ reviews: [], comments: [{ user: codexBot, body: `Didn't find any major issues. Reviewed ${HEAD.slice(0, 10)}` }] }));
From 7e29862b948d83f6177dc176fd95fbd4845543eb Mon Sep 17 00:00:00 2001
From: frankx-eth <132689939+frankx-eth@users.noreply.github.com>
Date: Wed, 4 Nov 2026 07:36:06 +0100
Subject: [PATCH 3/3] fix(pr-gate): use rendered review text and preserve badge
labels
---
pr-gate/decide.mjs | 89 ++++++------------
pr-gate/decide.test.mjs | 203 +++++++++++++++++++++++++++++++++++-----
pr-gate/run.mjs | 14 +--
3 files changed, 219 insertions(+), 87 deletions(-)
diff --git a/pr-gate/decide.mjs b/pr-gate/decide.mjs
index de41e78..3ddba6e 100644
--- a/pr-gate/decide.mjs
+++ b/pr-gate/decide.mjs
@@ -38,63 +38,27 @@ const MARKER_RE = /^\s*starlight-signoff:\s*harness=(\S+)\s+verdict=(\S+)\s+sha=
const CHECKER_RE = /^\s*Checker:\s*([a-z0-9_-]+?)(?:-cloud)?\s*[·|-]\s*head\s+([0-9a-fA-F]{7,40})\s*[·|-]\s*verdict\s+(PASS|FAIL|BLOCK)\b/i;
const CODEX_CLEAN_RE = /didn'?t find any major issues/i;
const SEVERE_RE = /\bp[01]\b|p[01] badge/i;
-// Reviewer metadata includes thresholds and summaries, not findings or signoffs.
-// Preserve comment-shaped text rendered literally in code or escaped Markdown.
-// This is a conservative visibility filter, not a Markdown renderer: uncertain
-// or unterminated constructs remain available to the severity check.
-function reviewText(body) {
- const source = String(body || '');
- let out = '', i = 0, fence = null;
- while (i < source.length) {
- if (i === 0 || source[i - 1] === '\n') {
- const newline = source.indexOf('\n', i);
- const end = newline < 0 ? source.length : newline + 1;
- const line = source.slice(i, end).replace(/\r?\n$/, '');
- // Recognize code fences inside the common quote/list containers too.
- const quoted = line.replace(/^(?: {0,3}>[ \t]?)*/, '');
- const content = quoted.replace(/^(?: {0,3}(?:[-+*]|\d+[.)])[ \t]+)?/, '');
- const marker = /^[ \t]*(`{3,}|~{3,})(.*)$/.exec(content);
- if (fence) {
- // A deeply indented fence may itself be literal code; never let it
- // close a surrounding block and hide the visible lines that follow.
- const closing = /^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(content);
- if (closing && closing[1][0] === fence.char && closing[1].length >= fence.length) fence = null;
- out += source.slice(i, end); i = end; continue;
- }
- if (marker && (marker[1][0] !== '`' || !marker[2].includes('`'))) {
- fence = { char: marker[1][0], length: marker[1].length };
- out += source.slice(i, end); i = end; continue;
- }
- if (/^(?: {4}| {0,3}\t)/.test(content) || /^ {0,3}(?:[-+*]|\d+[.)])(?: {5}| {0,4}\t)/.test(quoted)) {
- out += source.slice(i, end); i = end; continue;
- }
+// Full-media text excludes hidden metadata, but also omits image alt labels
+// (including real P1 badges). Recover alt text only from rendered image tags.
+// Tokenize comments and complete quoted tags so neither hidden images nor an
+// "alt" example inside another attribute can manufacture a finding.
+const HTML_TOKENS = /|--!>|$))|]*>|<\?[^>]*>|<\/?[A-Za-z](?:[^"'<>]|"[^"]*"|'[^']*')*>/g;
+const HTML_ATTRIBUTES = /([^\s"'<>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
+function reviewText(item) {
+ if (typeof item.bodyText !== 'string' || typeof item.bodyHTML !== 'string') return null;
+ const labels = [];
+ for (const [tag] of item.bodyHTML.matchAll(HTML_TOKENS)) {
+ if (!/^])/i.test(tag)) continue;
+ for (const attr of tag.slice(4, -1).matchAll(HTML_ATTRIBUTES)) {
+ if (attr[1].toLowerCase() !== 'alt') continue;
+ labels.push((attr[2] ?? attr[3] ?? attr[4] ?? '').replace(/(?:x([0-9a-f]+)|([0-9]+));/gi, (_, hex, dec) => {
+ const code = Number.parseInt(hex ?? dec, hex ? 16 : 10);
+ return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : '\ufffd';
+ }));
+ break; // HTML's first alt attribute wins.
}
- if (source[i] === '\\') {
- out += source.slice(i, i + 2); i += 2; continue;
- }
- if (source[i] === '`') {
- let length = 1;
- while (source[i + length] === '`') length++;
- const delimiter = '`'.repeat(length);
- let close = source.indexOf(delimiter, i + length);
- while (close >= 0 && (source[close - 1] === '`' || source[close + length] === '`')) close = source.indexOf(delimiter, close + length);
- if (close >= 0) {
- out += source.slice(i, close + length); i = close + length; continue;
- }
- out += delimiter; i += length; continue;
- }
- if (source.startsWith('', i)) { i += 5; continue; }
- if (source.startsWith('', i)) { i += 6; continue; }
- const close = source.indexOf('-->', i + 4);
- const ambiguous = source.indexOf('--!>', i + 4);
- // Do not remove text across an ambiguous HTML-parser terminator.
- if (ambiguous >= 0 && (close < 0 || ambiguous < close)) { out += source.slice(i); break; }
- if (close >= 0) { i = close + 3; continue; }
- }
- out += source[i++];
}
- return out;
+ return [item.bodyText, ...labels].join('\n');
}
// GitHub's own bot accounts are the only reviewer identity an agent cannot type its way into.
@@ -121,16 +85,21 @@ export function collectSignoffs({ comments = [], reviews = [], headSha }) {
// a visible P0/P1 against the head still blocks, even if metadata names the head.
// That SHA can associate a block, but metadata can never turn a comment into a pass.
const h = botHarness(c.user);
- if (h && SEVERE_RE.test(reviewText(c.body)) && head.length >= 7 && String(c.body).toLowerCase().includes(head.slice(0, 7))) {
- out.push({ harness: h, verdict: 'block', sha: head, via: 'bot-comment', trusted: true });
+ if (h && head.length >= 7 && String(c.body).toLowerCase().includes(head.slice(0, 7))) {
+ const body = reviewText(c);
+ if (body === null || SEVERE_RE.test(body)) {
+ out.push({ harness: h, verdict: body === null ? 'unreadable' : 'block', sha: head, via: 'bot-comment', trusted: true });
+ }
}
}
for (const r of reviews) {
const h = botHarness(r.user);
if (!h || r.state === 'DISMISSED' || r.state === 'PENDING') continue;
- const body = reviewText(r.body);
+ const body = reviewText(r);
let verdict = null;
- if (r.state === 'CHANGES_REQUESTED' || SEVERE_RE.test(body)) verdict = 'block';
+ if (r.state === 'CHANGES_REQUESTED') verdict = 'block';
+ else if (body === null) verdict = 'unreadable';
+ else if (SEVERE_RE.test(body)) verdict = 'block';
else if (r.state === 'APPROVED' || CODEX_CLEAN_RE.test(body)) verdict = 'pass';
// A COMMENTED review that neither approves nor says it is clean is not a verdict either way;
// its inline findings surface as unresolved threads.
@@ -207,6 +176,8 @@ export function decide(f) {
reasons.push('no linked intent: reference the issue, board item or ruling this PR serves');
}
+ const unreadable = signoffs.filter((s) => s.verdict === 'unreadable' && onHead(s));
+ if (unreadable.length) reasons.push(`review text unavailable on this commit from ${[...new Set(unreadable.map((s) => s.harness))].join(', ')}`);
const blocks = signoffs.filter((s) => (s.verdict === 'block' || s.verdict === 'fail') && onHead(s) && s.harness !== author);
const valid = signoffs.filter((s) => s.verdict === 'pass' && onHead(s) && s.harness !== author);
if (blocks.length) reasons.push(`blocked on this commit by ${[...new Set(blocks.map((b) => b.harness))].join(', ')}`);
diff --git a/pr-gate/decide.test.mjs b/pr-gate/decide.test.mjs
index 9e884d3..c0b849b 100644
--- a/pr-gate/decide.test.mjs
+++ b/pr-gate/decide.test.mjs
@@ -1,5 +1,10 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
+import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { basename, dirname, join } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { fileURLToPath, pathToFileURL } from 'node:url';
import { decide, harnessOfBranch, shaMatches, protectedReasons, ciState } from './decide.mjs';
const HEAD = 'a1b2c3d4e5f60718293a4b5c6d7e8f9012345678';
@@ -7,13 +12,14 @@ const codexBot = { login: 'chatgpt-codex-connector[bot]', type: 'Bot' };
const claudeBot = { login: 'claude[bot]', type: 'Bot' };
const human = { login: 'frankxai', type: 'User' };
const greenCI = [{ name: 'test', status: 'completed', conclusion: 'success' }];
-const cleanReview = { user: codexBot, commitId: HEAD, state: 'COMMENTED', body: "Codex Review: Didn't find any major issues." };
+const cleanReview = { user: codexBot, commitId: HEAD, state: 'COMMENTED', body: "Codex Review: Didn't find any major issues.", bodyText: "Codex Review: Didn't find any major issues." };
const codexMetadata = (sha = HEAD) => [
'',
'',
].join('\n');
-const base = (over = {}) => ({
+const base = (over = {}) => {
+ const facts = {
headRef: 'agent/claude/thing',
headSha: HEAD,
draft: false,
@@ -27,7 +33,11 @@ const base = (over = {}) => ({
requiredChecks: ['test'],
unresolvedThreads: 0,
...over,
-});
+ };
+ // Plain-text fixtures contain no images unless explicitly supplied. Do not
+ // fabricate rendered Markdown; bodyText is always explicit in each fixture.
+ return { ...facts, comments: facts.comments.map(c => ({bodyHTML:'',...c})), reviews: facts.reviews.map(r => ({bodyHTML:'',...r})) };
+};
test('clean Claude PR with a clean Codex bot review on head passes', () => {
const d = decide(base());
@@ -61,8 +71,8 @@ test('dismissed and pending bot reviews do not count', () => {
});
test('a bot review that is neither approval nor clean is not a pass; P0/P1 text blocks', () => {
- assert.equal(decide(base({ reviews: [{ user: codexBot, commitId: HEAD, state: 'COMMENTED', body: 'Critical security issue' }] })).ok, false);
- const d = decide(base({ reviews: [{ user: codexBot, commitId: HEAD, state: 'COMMENTED', body: '![P1 Badge] token leaks' }] }));
+ assert.equal(decide(base({ reviews: [{ user: codexBot, commitId: HEAD, state: 'COMMENTED', body: 'Critical security issue', bodyText: 'Critical security issue' }] })).ok, false);
+ const d = decide(base({ reviews: [{ user: codexBot, commitId: HEAD, state: 'COMMENTED', body: '![P1 Badge] token leaks', bodyText: 'P1 Badge token leaks' }] }));
assert.match(d.reasons.join(), /blocked on this commit by codex/);
});
@@ -73,7 +83,7 @@ test('a human account or a look-alike bot claiming to be Codex signs nothing', (
test('Codex metadata does not block a summary comment or make it a signoff', () => {
const body = `${codexMetadata()}\nDidn't find any major issues. Reviewed ${HEAD.slice(0, 7)}`;
- const d = decide(base({ reviews: [], comments: [{ user: codexBot, body }] }));
+ const d = decide(base({ reviews: [], comments: [{ user: codexBot, body, bodyText: `Didn't find any major issues. Reviewed ${HEAD.slice(0, 7)}` }] }));
assert.deepEqual(d.reasons, []);
assert.equal(d.pending, true);
assert.equal(d.ok, false);
@@ -82,13 +92,13 @@ test('Codex metadata does not block a summary comment or make it a signoff', ()
});
test('a clean head review is not vetoed by metadata in its summary comment', () => {
- const d = decide(base({ comments: [{ user: codexBot, body: `${codexMetadata()}\nCode review completed.` }] }));
+ const d = decide(base({ comments: [{ user: codexBot, body: `${codexMetadata()}\nCode review completed.`, bodyText: 'Code review completed.' }] }));
assert.equal(d.ok, true, JSON.stringify(d));
});
test('metadata does not veto a clean review or replace its commit binding', () => {
for (const state of ['COMMENTED', 'APPROVED']) {
- const review = { ...cleanReview, state, body: `${codexMetadata()}\nDidn't find any major issues.` };
+ const review = { ...cleanReview, state, body: `${codexMetadata()}\nDidn't find any major issues.`, bodyText: "Didn't find any major issues." };
assert.equal(decide(base({ reviews: [review] })).ok, true, state);
for (const commitId of ['', 'ffffffffffffffffffffffffffffffffffffffff']) {
assert.equal(decide(base({ reviews: [{ ...review, commitId }] })).ok, false, `${state}: ${commitId}`);
@@ -99,7 +109,7 @@ test('metadata does not veto a clean review or replace its commit binding', () =
test('visible P0/P1 comments still block when only metadata identifies the head', () => {
for (const severity of ['P0', 'P1']) {
const body = `${codexMetadata()}\n${severity}: a real finding remains.`;
- const d = decide(base({ comments: [{ user: codexBot, body }] }));
+ const d = decide(base({ comments: [{ user: codexBot, body, bodyText: `${severity}: a real finding remains.` }] }));
assert.equal(d.ok, false, severity);
assert.match(d.reasons.join(), /blocked on this commit by codex/);
}
@@ -108,7 +118,7 @@ test('visible P0/P1 comments still block when only metadata identifies the head'
test('visible P0/P1 findings still block reviews alongside metadata', () => {
for (const severity of ['P0', 'P1']) {
const body = `${codexMetadata()}\n${severity}: a real finding remains.`;
- const d = decide(base({ reviews: [{ ...cleanReview, state: 'APPROVED', body }] }));
+ const d = decide(base({ reviews: [{ ...cleanReview, state: 'APPROVED', body, bodyText: `${severity}: a real finding remains.` }] }));
assert.equal(d.ok, false, severity);
assert.match(d.reasons.join(), /blocked on this commit by codex/);
}
@@ -116,7 +126,7 @@ test('visible P0/P1 findings still block reviews alongside metadata', () => {
test('a clean phrase hidden in metadata cannot sign off a commented review', () => {
const body = '';
- const d = decide(base({ reviews: [{ ...cleanReview, body }] }));
+ const d = decide(base({ reviews: [{ ...cleanReview, body, bodyText: '' }] }));
assert.equal(d.ok, false);
assert.deepEqual(d.signers, []);
});
@@ -141,8 +151,8 @@ test('HTML-comment literals visible as Markdown code or escaped text still block
for (const visible of bodies) {
const body = `${codexMetadata()}\n${visible}`;
for (const facts of [
- { comments: [{ user: codexBot, body }] },
- { reviews: [{ ...cleanReview, state: 'APPROVED', body }] },
+ { comments: [{ user: codexBot, body, bodyText: literal }] },
+ { reviews: [{ ...cleanReview, state: 'APPROVED', body, bodyText: literal }] },
]) {
const d = decide(base(facts));
assert.equal(d.ok, false, visible);
@@ -153,17 +163,17 @@ test('HTML-comment literals visible as Markdown code or escaped text still block
test('backticks in hidden metadata stay hidden alongside visible ordinary code', () => {
const body = '\n`ordinary code`\nDidnt find any major issues.';
- assert.equal(decide(base({ reviews: [{ ...cleanReview, body }] })).ok, true);
+ assert.equal(decide(base({ reviews: [{ ...cleanReview, body, bodyText: 'ordinary code\nDidnt find any major issues.' }] })).ok, true);
const fenced = '```js\nconst value = 1;\n```\n' + body;
- assert.equal(decide(base({ reviews: [{ ...cleanReview, body: fenced }] })).ok, true);
+ assert.equal(decide(base({ reviews: [{ ...cleanReview, body: fenced, bodyText: 'const value = 1;\nordinary code\nDidnt find any major issues.' }] })).ok, true);
});
test('short or ambiguous comment endings cannot swallow a later visible finding', () => {
for (const opening of ['', '', '']) {
const body = `${opening}\nP1: visible serious finding\n${codexMetadata()}`;
for (const facts of [
- { comments: [{ user: codexBot, body }] },
- { reviews: [{ ...cleanReview, state: 'APPROVED', body }] },
+ { comments: [{ user: codexBot, body, bodyText: 'P1: visible serious finding' }] },
+ { reviews: [{ ...cleanReview, state: 'APPROVED', body, bodyText: 'P1: visible serious finding' }] },
]) {
const d = decide(base(facts));
assert.equal(d.ok, false, opening);
@@ -174,11 +184,11 @@ test('short or ambiguous comment endings cannot swallow a later visible finding'
// Codex review of 1404c37 reproduced the next two as false passes.
test('bot comments never sign off; a P0/P1 bot comment on the head blocks', () => {
- const clean = decide(base({ reviews: [], comments: [{ user: codexBot, body: `Didn't find any major issues. Reviewed ${HEAD.slice(0, 10)}` }] }));
+ const clean = decide(base({ reviews: [], comments: [{ user: codexBot, body: `Didn't find any major issues. Reviewed ${HEAD.slice(0, 10)}`, bodyText: `Didn't find any major issues. Reviewed ${HEAD.slice(0, 10)}` }] }));
assert.equal(clean.ok, false);
- const mixed = decide(base({ comments: [{ user: codexBot, body: `Didnt find any major issues on ${HEAD.slice(0, 7)}. P1: auth bypass remains.` }] }));
+ const mixed = decide(base({ comments: [{ user: codexBot, body: `Didnt find any major issues on ${HEAD.slice(0, 7)}. P1: auth bypass remains.`, bodyText: `Didnt find any major issues on ${HEAD.slice(0, 7)}. P1: auth bypass remains.` }] }));
assert.match(mixed.reasons.join(), /blocked on this commit by codex/);
- assert.equal(decide(base({ reviews: [{ user: codexBot, commitId: HEAD, state: 'COMMENTED', body: 'p1 regression' }] })).ok, false);
+ assert.equal(decide(base({ reviews: [{ user: codexBot, commitId: HEAD, state: 'COMMENTED', body: 'p1 regression', bodyText: 'p1 regression' }] })).ok, false);
});
test('renames are judged on both ends', () => {
@@ -189,7 +199,7 @@ test('renames are judged on both ends', () => {
});
test('Claude bot approval signs a Codex PR on the exact head', () => {
- const d = decide(base({ headRef: 'codex/x', reviews: [{ user: claudeBot, commitId: HEAD, state: 'APPROVED', body: '' }] }));
+ const d = decide(base({ headRef: 'codex/x', reviews: [{ user: claudeBot, commitId: HEAD, state: 'APPROVED', body: '', bodyText: '' }] }));
assert.equal(d.ok, true, JSON.stringify(d));
assert.equal(shaMatches(HEAD, 'a1b2'), false);
});
@@ -241,3 +251,154 @@ test('branch prefixes map to harnesses, Foreman and cloud sessions count as Clau
assert.equal(harnessOfBranch('sentinel-fix-timing'), 'gemini');
assert.equal(harnessOfBranch('dependabot/npm_and_yarn/x'), 'dependabot');
});
+
+test('GitHub-rendered text prevents an indented-code metadata false block', () => {
+ const body = ' ```\n ordinary code\n ```\n\n\n';
+ // Authenticated GitHub GFM rendering observed on 2026-11-04. The comment is
+ // hidden after an indented code block; its threshold is not a finding.
+ const bodyText = '```\nordinary code\n```\n\n';
+ const d = decide(base({ reviews: [{ ...cleanReview, state: 'APPROVED', body, bodyText }] }));
+ assert.equal(d.ok, true, JSON.stringify(d));
+});
+
+test('missing rendered text holds current bot evidence instead of guessing visibility', () => {
+ for (const facts of [
+ { reviews: [{ ...cleanReview, state: 'APPROVED', bodyText: undefined }] },
+ { comments: [{ user: codexBot, body: codexMetadata() }] },
+ ]) {
+ const d = decide(base(facts));
+ assert.equal(d.ok, false);
+ assert.match(d.reasons.join(), /review text unavailable/);
+ assert.doesNotMatch(d.reasons.join(), /blocked on this commit/);
+ }
+});
+
+// Execute the real producer with an in-process fake server. Every request is
+// intercepted, including report writes; this never calls or changes GitHub.
+function runProducer(data) {
+ const parent = realpathSync(tmpdir());
+ const dir = mkdtempSync(join(parent, 'starlight-prgate-render-'));
+ const receipt = join(dir, 'requests.json');
+ const hook = join(dir, 'mock.mjs');
+ const source = `
+ import { writeFileSync } from 'node:fs';
+ const data = JSON.parse(process.env.FIXTURE_JSON), calls = [];
+ process.on('exit', () => writeFileSync(process.env.FIXTURE_RECEIPT, JSON.stringify(calls)));
+ globalThis.fetch = async (url, init = {}) => {
+ const u = new URL(url), method = init.method || 'GET';
+ if (u.origin !== 'https://api.github.com') throw new Error('Unexpected server');
+ calls.push({ path: u.pathname, page: u.searchParams.get('page'), method, accept: init.headers?.accept });
+ const rendered = (rows, media) => init.headers?.accept === media ? rows : rows.map(({body_text, ...raw}) => raw);
+ let value;
+ if (u.pathname === '/graphql' && method === 'POST') value = {data:{repository:{pullRequest:{reviewThreads:{nodes:[],pageInfo:{hasNextPage:false,endCursor:null}}}}}};
+ else if (u.pathname.endsWith('/pulls/1') && method === 'GET') value = {head:{sha:'${HEAD}',ref:'agent/claude/example'},body:'Serves #7',labels:[],state:'open',draft:false,changed_files:1};
+ else if (u.pathname.endsWith('/files') && method === 'GET') value = [{filename:'src/lib/x.ts',status:'modified'}];
+ else if (u.pathname.endsWith('/reviews') && method === 'GET') value = rendered(data.reviews, 'application/vnd.github-commitcomment.full+json');
+ else if (u.pathname.endsWith('/check-runs') && method === 'GET') value = {check_runs:[{name:'test',status:'completed',conclusion:'success'}]};
+ else if (u.pathname.endsWith('/comments') && method === 'GET') {
+ const page = Number(u.searchParams.get('page') || 1);
+ value = rendered(data.commentPages?.[page-1] ?? (page === 1 ? data.comments : []), 'application/vnd.github.full+json');
+ } else if (u.pathname.endsWith('/comments') && method === 'POST') value = {id:1000};
+ else throw new Error('Unexpected request: '+method+' '+u.pathname);
+ return new Response(JSON.stringify(value), {status:200});
+ };
+ `;
+ writeFileSync(hook, source);
+ const env = Object.fromEntries(['PATH', 'Path', 'SystemRoot', 'WINDIR', 'TEMP', 'TMP'].filter(k => process.env[k]).map(k => [k, process.env[k]]));
+ Object.assign(env, { GITHUB_TOKEN: 'test-only-token', GITHUB_REPOSITORY: 'example/repo', PR_NUMBER: '1', PR_GATE_MERGE: 'false', PR_GATE_WAIT_MINUTES: '0', PR_GATE_REQUIRED_CHECKS: 'test', FIXTURE_JSON: JSON.stringify(data), FIXTURE_RECEIPT: receipt });
+ try {
+ const result = spawnSync(process.execPath, ['--import', pathToFileURL(hook).href, fileURLToPath(new URL('./run.mjs', import.meta.url))], {env,encoding:'utf8',timeout:10_000});
+ assert.equal(result.error, undefined, result.error?.message);
+ return { ...result, calls: JSON.parse(readFileSync(receipt, 'utf8')) };
+ } finally {
+ const target = realpathSync(dir);
+ assert.equal(dirname(target), parent);
+ assert.ok(basename(target).startsWith('starlight-prgate-render-'));
+ rmSync(target, {recursive:true,force:true});
+ }
+}
+const restReview = (over = {}) => ({user:codexBot,commit_id:HEAD,state:'APPROVED',body:'Reviewed.',body_text:'Reviewed.',body_html:'
Reviewed.
',...over}); +const restComment = {user:codexBot,body:codexMetadata(),body_text:'',body_html:codexMetadata()}; + +test('producer requests and preserves raw plus rendered comment/review representations', () => { + const r = runProducer({reviews:[restReview()],comments:[restComment]}); + assert.equal(r.status, 0, r.stdout + r.stderr); + assert.ok(r.calls.some(c => c.path.endsWith('/reviews') && c.accept === 'application/vnd.github-commitcomment.full+json')); + assert.ok(r.calls.some(c => c.path.endsWith('/comments') && c.method === 'GET' && c.accept === 'application/vnd.github.full+json')); +}); + +test('producer uses rendered text for the actual indented-code regression', () => { + const r = runProducer({reviews:[restReview({body:' ```\n ordinary code\n ```\n\n',body_text:'```\nordinary code\n```\n'})],comments:[]}); + assert.equal(r.status, 0, r.stdout + r.stderr); + assert.doesNotMatch(r.stdout, /blocked on this commit/); +}); + +test('producer preserves visible comment literals and metadata-only head association', () => { + const r = runProducer({reviews:[restReview()],comments:[{user:codexBot,body:codexMetadata()+'\n``',body_text:'',body_html:'<!-- P1: real finding -->
ordinary note
'})); + const r = runProducer({reviews:[restReview()],comments:[],commentPages:[page,[restComment]]}); + assert.equal(r.status, 0, r.stdout + r.stderr); + const reads = r.calls.filter(c => c.path.endsWith('/comments') && c.method === 'GET'); + assert.ok(reads.some(c => c.page === '2')); + assert.ok(reads.every(c => c.accept === 'application/vnd.github.full+json')); +}); + +test('producer retains severity badge labels omitted from GitHub plain text', () => { + // Real full-media review comments observed on 2026-11-04 omit the image's + // alt label from body_text while body_html retains alt="P1 Badge". + const r = runProducer({reviews:[restReview()],comments:[{ + user:codexBot,body:codexMetadata()+'\n Fix the issue.', + body_text:'Fix the issue.',body_html:' Fix the issue.
Fix it.