Skip to content

Commit 623b2be

Browse files
committed
fix(ci): address Codex/Rabbit review on enforce-pr-target and issue-quality
Checkpoint ownership before mutations, keep active state when ready conversion fails, assert permissions without comment false-positives, and share unusable env stand-in detection for Version/OS.
1 parent 76f30bc commit 623b2be

5 files changed

Lines changed: 255 additions & 106 deletions

File tree

‎.github/scripts/enforce-pr-target.test.cjs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ describe("enforce-pr-target workflow", () => {
2121
it("grants contents:write so draft GraphQL mutations work with GITHUB_TOKEN", () => {
2222
// convertPullRequestToDraft / markPullRequestReadyForReview fail with
2323
// "Resource not accessible by integration" when contents stays unset/read
24-
// (seen on #626). Title + comment still use pull-requests:write.
25-
assert.match(workflow, /contents:\s*write/);
26-
assert.match(workflow, /pull-requests:\s*write/);
24+
// (seen on #626). Assert the real permissions block, not comment text
25+
// that also mentions these scopes.
26+
const permissionsBlock = workflow.match(/^permissions:\n((?:[ \t]+.+\n)+)/m);
27+
assert.ok(permissionsBlock, "workflow must declare a top-level permissions block");
28+
const lines = permissionsBlock[1]
29+
.split("\n")
30+
.map((line) => line.trim())
31+
.filter(Boolean)
32+
.sort();
33+
assert.deepEqual(lines, ["contents: write", "pull-requests: write"]);
2734
});
2835

2936
it("fails the required check on a wrong base even if draft conversion fails", () => {

‎.github/scripts/issue-quality.cjs‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,29 @@ function unwrapSingleEnclosingFence(text) {
2525
return match[2];
2626
}
2727

28-
function isPlaceholderOnlyValue(raw) {
29-
if (typeof raw !== "string") return false;
28+
/**
29+
* Shared strip/trim/unwrap used by placeholder and unusable-stand-in matchers.
30+
* Returns null when the value is absent after normalisation.
31+
*/
32+
function normalizeRawSectionValue(raw) {
33+
if (typeof raw !== "string") return null;
3034
let value = raw.replace(/<!--[\s\S]*?-->/g, "").trim();
31-
if (!value) return false;
35+
if (!value) return null;
3236

33-
// A lone fenced block whose entire body is a placeholder is still placeholder
34-
// text (e.g. ```text\nN/A\n```), not a real example.
37+
// A lone fenced block whose entire body is a stand-in is still a stand-in
38+
// (e.g. ```text\nN/A\n```), not a real example.
3539
const unwrapped = unwrapSingleEnclosingFence(value);
3640
if (unwrapped !== null) {
3741
value = unwrapped.trim();
38-
if (!value) return false;
42+
if (!value) return null;
3943
}
4044

45+
return value;
46+
}
47+
48+
function isPlaceholderOnlyValue(raw) {
49+
const value = normalizeRawSectionValue(raw);
50+
if (value === null) return false;
4151
return PLACEHOLDER_ONLY_RE.test(value);
4252
}
4353

@@ -407,14 +417,8 @@ const UNUSABLE_VERSION_RE =
407417
/^[\s_*~`]*(?:unknown|unkown|uknown|don'?t\s+know|do\s+not\s+know|idk|dunno|not\s+sure|unsure|\?+|모름|잘\s*모름|모르겠(?:습니다|음)?|不明|わからない|分からない|不知道|不清楚|keine\s+ahnung|wei[sß]{1,2}\s+nicht)[\s_*~`]*[.!?]*$/i;
408418

409419
function isUnusableVersion(raw) {
410-
if (typeof raw !== "string") return false;
411-
let value = raw.replace(/<!--[\s\S]*?-->/g, "").trim();
412-
if (!value) return false;
413-
const unwrapped = unwrapSingleEnclosingFence(value);
414-
if (unwrapped !== null) {
415-
value = unwrapped.trim();
416-
if (!value) return false;
417-
}
420+
const value = normalizeRawSectionValue(raw);
421+
if (value === null) return false;
418422
return UNUSABLE_VERSION_RE.test(value);
419423
}
420424

@@ -709,7 +713,10 @@ function validateIssue(issue) {
709713
guidance.push("Add your OpenCodex version so we can reproduce the environment.");
710714
}
711715

712-
if (
716+
if (!softPass && isNewBugForm && os !== null && isUnusableVersion(os)) {
717+
reasons.push("Operating system is missing or unknown.");
718+
guidance.push("Add your OS name and version (for example Windows 11 24H2).");
719+
} else if (
713720
!softPass &&
714721
isNewBugForm &&
715722
os !== null &&

‎.github/scripts/issue-quality.test.cjs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,33 @@ describe("validateIssue - bug", () => {
823823
assert.equal(result.valid, false);
824824
assert.ok(result.reasons.some((r) => /Reproduction/i.test(r) && /vague/i.test(r)));
825825
});
826+
827+
it("rejects unknown Operating system stand-ins on the new bug form", () => {
828+
const body = [
829+
"### Client or integration",
830+
"Codex CLI",
831+
"### Area",
832+
"CLI",
833+
"### Summary",
834+
"The OpenCodex proxy keeps dropping the Codex CLI connection mid-request.",
835+
"### Reproduction",
836+
"1. ocx start --port 10100",
837+
"2. Send any Codex CLI request through the proxy",
838+
"3. Observe the connection drop",
839+
"### Version",
840+
"2.7.42",
841+
"### Operating system",
842+
"Unknown",
843+
].join("\n");
844+
const result = validateIssue({
845+
title: "Unexpected interruption continues to occur",
846+
body,
847+
labels: ["bug"],
848+
});
849+
assert.equal(result.kind, "bug");
850+
assert.equal(result.valid, false);
851+
assert.ok(result.reasons.some((r) => /Operating system/i.test(r)));
852+
});
826853
});
827854

828855
// ---------------------------------------------------------------------------

‎.github/workflows/enforce-pr-target.yml‎

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
comment.user?.login === "github-actions[bot]" &&
6565
comment.body?.includes(COMMENT_MARKER)
6666
);
67+
let botCommentId = botComment?.id ?? null;
6768
6869
function parseState(body) {
6970
const match = body?.match(STATE_PATTERN);
@@ -96,23 +97,24 @@ jobs:
9697
}
9798
9899
async function upsertComment(body) {
99-
if (botComment) {
100+
if (botCommentId) {
100101
await github.rest.issues.updateComment({
101102
owner,
102103
repo,
103-
comment_id: botComment.id,
104+
comment_id: botCommentId,
104105
body
105106
});
106107
107108
return;
108109
}
109110
110-
await github.rest.issues.createComment({
111+
const created = await github.rest.issues.createComment({
111112
owner,
112113
repo,
113114
issue_number: pull_number,
114115
body
115116
});
117+
botCommentId = created.data.id;
116118
}
117119
118120
async function convertToDraft() {
@@ -169,6 +171,7 @@ jobs:
169171
// - fail the required check so merge stays blocked even if draft fails
170172
// - remember which changes were made by this workflow
171173
if (wrongBase) {
174+
const willPrefixTitle = !pr.title.startsWith(TITLE_PREFIX);
172175
const state = storedState?.active
173176
? { ...storedState }
174177
: {
@@ -178,10 +181,29 @@ jobs:
178181
titlePrefixedByBot: false
179182
};
180183
184+
// Claim title ownership before mutating so a crash after the
185+
// title write still records what the bot owns. Do not claim a
186+
// new draft here — only after convertToDraft succeeds.
187+
if (willPrefixTitle) {
188+
state.titlePrefixedByBot = true;
189+
}
190+
181191
let draftConversionFailed = false;
182192
183-
if (!pr.title.startsWith(TITLE_PREFIX)) {
184-
state.titlePrefixedByBot = true;
193+
await upsertComment(
194+
[
195+
COMMENT_MARKER,
196+
stateMarker(state),
197+
"",
198+
"⚠️ **Wrong target branch**",
199+
"",
200+
`This pull request currently targets ${inlineCode(pr.base.ref)}, but pull requests must target one of ${ALLOWED_BASES.map(inlineCode).join(" or ")}.`,
201+
"",
202+
"Recording ownership state before applying title/draft changes…"
203+
].join("\n")
204+
);
205+
206+
if (willPrefixTitle) {
185207
await github.rest.pulls.update({
186208
owner,
187209
repo,
@@ -194,6 +216,20 @@ jobs:
194216
try {
195217
await convertToDraft();
196218
state.autoDraftedByBot = true;
219+
// Checkpoint after a successful draft so ownership survives
220+
// if the final explanation write fails.
221+
await upsertComment(
222+
[
223+
COMMENT_MARKER,
224+
stateMarker(state),
225+
"",
226+
"⚠️ **Wrong target branch**",
227+
"",
228+
`This pull request currently targets ${inlineCode(pr.base.ref)}, but pull requests must target one of ${ALLOWED_BASES.map(inlineCode).join(" or ")}.`,
229+
"",
230+
"Draft conversion succeeded; finalising explanation…"
231+
].join("\n")
232+
);
197233
} catch (error) {
198234
draftConversionFailed = true;
199235
state.autoDraftedByBot = false;
@@ -272,12 +308,21 @@ jobs:
272308
}
273309
}
274310
275-
const completedState = {
276-
version: 1,
277-
active: false,
278-
autoDraftedByBot: false,
279-
titlePrefixedByBot: false
280-
};
311+
const completedState = readyConversionFailed
312+
? {
313+
// Keep ownership active so a later edited/reopened/
314+
// ready_for_review event retries markReadyForReview.
315+
version: 1,
316+
active: true,
317+
autoDraftedByBot: true,
318+
titlePrefixedByBot: false
319+
}
320+
: {
321+
version: 1,
322+
active: false,
323+
autoDraftedByBot: false,
324+
titlePrefixedByBot: false
325+
};
281326
282327
const titleResult = storedState.titlePrefixedByBot
283328
? `The ${inlineCode(TITLE_PREFIX.trim())} title prefix has been removed.`

0 commit comments

Comments
 (0)