rungate 0.8.20 → 0.8.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/gates/.gate-salt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
36e88dc95acdd61bc72fdbbfffcae7a21722942437fbac2c5b2a5515cf2640ef
|
package/lib/ai-review-threads.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* two that only a live fork or a line outside a hunk would otherwise produce.
|
|
25
25
|
*/
|
|
26
26
|
import type { ThreadReading } from "./ai-review-rounds";
|
|
27
|
-
import { reviewThreadRequests, threadKeyFrom } from "./scaffold/ai-review-findings";
|
|
27
|
+
import { escapeAnnotation, reviewThreadRequests, threadKeyFrom } from "./scaffold/ai-review-findings";
|
|
28
28
|
import type { AiReviewFindingsReading, AiReviewThreadRequest } from "./scaffold/ai-review-findings";
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -254,6 +254,7 @@ export async function postReviewThreads(
|
|
|
254
254
|
reading: AiReviewFindingsReading,
|
|
255
255
|
post: AiReviewThreadPoster,
|
|
256
256
|
keyFor?: (finding: Record<string, unknown>) => string | null,
|
|
257
|
+
fork?: boolean | null,
|
|
257
258
|
): Promise<AiReviewThreadsResult> {
|
|
258
259
|
const detail: string[] = [];
|
|
259
260
|
|
|
@@ -306,10 +307,24 @@ export async function postReviewThreads(
|
|
|
306
307
|
continue;
|
|
307
308
|
}
|
|
308
309
|
if (answer.status === FORBIDDEN) {
|
|
310
|
+
// #1992: the fork excuse holds only for a fork. A same-repository run
|
|
311
|
+
// whose token lost write is a broken producer, and degrading it would
|
|
312
|
+
// hide that behind a reason that does not apply.
|
|
313
|
+
if (fork === false) {
|
|
314
|
+
failed += 1;
|
|
315
|
+
detail.push(
|
|
316
|
+
`${where}: 403 — this token cannot write pull-request comments, and this run is not a fork ` +
|
|
317
|
+
`(${AI_REVIEW_PR_IS_FORK_VAR}=false), so the read-only-token excuse does not apply.`,
|
|
318
|
+
);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
309
321
|
forbidden += 1;
|
|
310
322
|
detail.push(
|
|
311
323
|
`${where}: 403 — this token cannot write pull-request comments. A pull_request run from a ` +
|
|
312
|
-
`fork is handed a read-only token whatever the workflow declares
|
|
324
|
+
`fork is handed a read-only token whatever the workflow declares.` +
|
|
325
|
+
(fork === true
|
|
326
|
+
? ""
|
|
327
|
+
: ` Whether this run is a fork was not read (${AI_REVIEW_PR_IS_FORK_VAR} unset), so it is treated as one.`),
|
|
313
328
|
);
|
|
314
329
|
continue;
|
|
315
330
|
}
|
|
@@ -358,6 +373,35 @@ export function threadsLandedPhrase(result: AiReviewThreadsResult): string {
|
|
|
358
373
|
: `Only ${result.posted} of ${result.attempted} review threads were created`;
|
|
359
374
|
}
|
|
360
375
|
|
|
376
|
+
/**
|
|
377
|
+
* The environment variable the workflow sets to say whether this run is a
|
|
378
|
+
* fork (#1992; the generator half is #2203). An environment variable and not
|
|
379
|
+
* a flag on purpose: a published CLI that does not know a flag refuses it,
|
|
380
|
+
* while an unknown variable is ignored, so the workflow can set it before or
|
|
381
|
+
* after this reader ships without reddening anything.
|
|
382
|
+
*/
|
|
383
|
+
export const AI_REVIEW_PR_IS_FORK_VAR = "RUNGATE_PR_IS_FORK";
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Read exactly: `"true"` and `"false"` are readings, anything else is unread
|
|
387
|
+
* (`null`). The same rule `.claude/rules/config-access.md` applies to a switch
|
|
388
|
+
* that turns a refusal on — a loose reading turns it on by accident.
|
|
389
|
+
*/
|
|
390
|
+
export function prIsForkReading(raw: string | undefined): boolean | null {
|
|
391
|
+
return raw === "true" ? true : raw === "false" ? false : null;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Every line this command prints from a result's detail, escaped (#1992).
|
|
396
|
+
* Detail carries text the producer does not control — an API error message,
|
|
397
|
+
* a path a finding named — and a CR or LF printed raw starts a new line that
|
|
398
|
+
* the Actions runner reads as a workflow command. `escapeAnnotation` is the
|
|
399
|
+
* one escaper, so this does not grow a second.
|
|
400
|
+
*/
|
|
401
|
+
export function threadsDetailLines(result: AiReviewThreadsResult, command: string): string[] {
|
|
402
|
+
return result.detail.map(line => `${command}: ${escapeAnnotation(line)}`);
|
|
403
|
+
}
|
|
404
|
+
|
|
361
405
|
/** The exit code a round's outcome earns. Only `FAILED` refuses. */
|
|
362
406
|
export function aiReviewThreadsExitCode(result: AiReviewThreadsResult): number {
|
|
363
407
|
return result.outcome === "FAILED" ? AI_REVIEW_THREADS_REFUSAL : 0;
|
package/lib/board-intake-move.ts
CHANGED
|
@@ -47,6 +47,7 @@ export type MoveRefusal =
|
|
|
47
47
|
| "COLUMN_UNSEARCHABLE"
|
|
48
48
|
| "API_FAILED"
|
|
49
49
|
| "NULL_NODE"
|
|
50
|
+
| "WRONG_TYPE"
|
|
50
51
|
| "FIELDS_TRUNCATED"
|
|
51
52
|
| "NOT_RESOLVED"
|
|
52
53
|
| "VALUES_TRUNCATED"
|
|
@@ -142,6 +143,8 @@ interface ReadSite {
|
|
|
142
143
|
/** What the id names, and the input it came from, so the refusal blames the right one. */
|
|
143
144
|
names: "the project" | "the item";
|
|
144
145
|
input: "PROJECT_ID" | "ITEM_ID";
|
|
146
|
+
/** The type the query's inline fragment selects; any other type resolves with no connection. */
|
|
147
|
+
type: "ProjectV2" | "ProjectV2Item";
|
|
145
148
|
wrote: boolean;
|
|
146
149
|
}
|
|
147
150
|
|
|
@@ -153,6 +156,15 @@ interface ReadSite {
|
|
|
153
156
|
*/
|
|
154
157
|
function requireNode<T>(data: unknown, key: "fields" | "fieldValues" | "items", site: ReadSite): Page<T> {
|
|
155
158
|
const node = (data as { node?: Record<string, unknown> | null } | null | undefined)?.node;
|
|
159
|
+
// A node that RESOLVED but carries no connection is a different object
|
|
160
|
+
// type: the inline fragment did not apply. Said apart from a null node,
|
|
161
|
+
// which is an id that did not resolve (#2183, from PR #2194 round 6).
|
|
162
|
+
if (node !== null && node !== undefined && node[key] === undefined) {
|
|
163
|
+
throw new Refused(
|
|
164
|
+
"WRONG_TYPE",
|
|
165
|
+
`${site.what} is UNMEASURED and ${site.wrote ? "a write WAS sent before this read, so the board may already hold the new value" : "nothing was written"}: node(id: ${site.id}) resolved, but not to a ${site.type}, so ${site.input} names a different kind of object (an item id passed as the project, for example). This is NOT a stale id and NOT an empty board.`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
156
168
|
const page = node?.[key] as Page<T> | null | undefined;
|
|
157
169
|
if (!page) {
|
|
158
170
|
throw new Refused(
|
|
@@ -191,7 +203,7 @@ export async function moveToColumn(input: MoveInput, deps: MoveDeps): Promise<Mo
|
|
|
191
203
|
const fields = requireNode<{ id?: string; name?: string; options?: Array<{ id: string; name: string }> }>(
|
|
192
204
|
await call(deps, FIELDS_QUERY, { project: projectId }),
|
|
193
205
|
"fields",
|
|
194
|
-
{ what: "the project's field list", id: projectId, names: "the project", input: "PROJECT_ID", wrote: false },
|
|
206
|
+
{ what: "the project's field list", id: projectId, names: "the project", input: "PROJECT_ID", type: "ProjectV2", wrote: false },
|
|
195
207
|
);
|
|
196
208
|
const status = present(fields).find(f => f.name === "Status");
|
|
197
209
|
const fieldId = status?.id ?? "";
|
|
@@ -205,7 +217,7 @@ export async function moveToColumn(input: MoveInput, deps: MoveDeps): Promise<Mo
|
|
|
205
217
|
if (!fieldId || !optionId) {
|
|
206
218
|
throw new Refused(
|
|
207
219
|
"NOT_RESOLVED",
|
|
208
|
-
`Could not resolve the Status field or its '${column}' option on this project. ${fieldId ?
|
|
220
|
+
`Could not resolve the Status field or its '${column}' option on this project. ${fieldId ? `The Status field was found and its options were read in full${truncated(fields) ? " (the field list has more than one page, which does not affect its options)" : ""}, so this is not a truncated read` : "The whole field list was read, so this is not a truncated page"}. The item WAS added; only the transition failed. Someone renamed the field or the column — update COLUMN in this workflow to match the board.`,
|
|
209
221
|
);
|
|
210
222
|
}
|
|
211
223
|
|
|
@@ -218,7 +230,7 @@ export async function moveToColumn(input: MoveInput, deps: MoveDeps): Promise<Mo
|
|
|
218
230
|
const values = requireNode<{ name?: string; field?: { name?: string } }>(
|
|
219
231
|
await call(deps, VALUES_QUERY, { item: itemId }),
|
|
220
232
|
"fieldValues",
|
|
221
|
-
{ what: "the item's field values, read back after the write", id: itemId, names: "the item", input: "ITEM_ID", wrote: true },
|
|
233
|
+
{ what: "the item's field values, read back after the write", id: itemId, names: "the item", input: "ITEM_ID", type: "ProjectV2Item", wrote: true },
|
|
222
234
|
);
|
|
223
235
|
current = present(values).find(v => v.field?.name === "Status")?.name ?? "";
|
|
224
236
|
if (!current && truncated(values)) {
|
|
@@ -233,7 +245,7 @@ export async function moveToColumn(input: MoveInput, deps: MoveDeps): Promise<Mo
|
|
|
233
245
|
const index = requireNode<{ id?: string }>(
|
|
234
246
|
await call(deps, INDEX_QUERY, { project: projectId, q: `status:"${column}"` }),
|
|
235
247
|
"items",
|
|
236
|
-
{ what: `the search index for the '${column}' column`, id: projectId, names: "the project", input: "PROJECT_ID", wrote: true },
|
|
248
|
+
{ what: `the search index for the '${column}' column`, id: projectId, names: "the project", input: "PROJECT_ID", type: "ProjectV2", wrote: true },
|
|
237
249
|
);
|
|
238
250
|
const indexed = present(index).some(n => n.id === itemId);
|
|
239
251
|
if (!indexed && truncated(index)) {
|
|
@@ -1156,7 +1156,15 @@ export function reviewThreadRequests(
|
|
|
1156
1156
|
// posting less.
|
|
1157
1157
|
const scope = reading.scope;
|
|
1158
1158
|
let touched: ReadonlySet<string> | null = null;
|
|
1159
|
+
// The diff's own spelling of each changed file, keyed by the comparison
|
|
1160
|
+
// form. When a finding matches one, THAT spelling is sent: it is byte for
|
|
1161
|
+
// byte what the API resolves against (#1992).
|
|
1162
|
+
const diffSpelling = new Map<string, string>();
|
|
1159
1163
|
if (scope?.status === "MEASURED") {
|
|
1164
|
+
for (const entry of scope.files) {
|
|
1165
|
+
const spelt = repoPathSpelling(entry);
|
|
1166
|
+
if (spelt !== null) diffSpelling.set(spelt.toLowerCase(), spelt);
|
|
1167
|
+
}
|
|
1160
1168
|
// The same conversion `readPayload` makes, through the same function, so
|
|
1161
1169
|
// the skip here and the demotion there cannot disagree about one finding.
|
|
1162
1170
|
const { readable } = partitionChangedFiles(scope.files);
|
|
@@ -1176,13 +1184,17 @@ export function reviewThreadRequests(
|
|
|
1176
1184
|
if (findingPathScope(finding, touched) === "PRE_EXISTING") continue;
|
|
1177
1185
|
|
|
1178
1186
|
const raw = finding[f.file];
|
|
1179
|
-
//
|
|
1180
|
-
//
|
|
1181
|
-
//
|
|
1182
|
-
//
|
|
1183
|
-
|
|
1187
|
+
// The scope check above matched the NORMALISED spelling; the raw one —
|
|
1188
|
+
// `./lib/a.ts`, `lib//a.ts` — asks the API for a path it cannot resolve,
|
|
1189
|
+
// the file-level retry is refused the same way, and the round ends
|
|
1190
|
+
// FAILED over a finding that was correctly in the diff (#1992). So the
|
|
1191
|
+
// diff's own spelling is sent when the finding matched one, and the
|
|
1192
|
+
// finding's case-kept spelling otherwise. Both drop a `:line` suffix;
|
|
1193
|
+
// the number in it is still read below, as the only line given.
|
|
1194
|
+
const spelt = repoPathSpelling(raw);
|
|
1195
|
+
if (spelt === null) continue;
|
|
1196
|
+
const path = diffSpelling.get(spelt.toLowerCase()) ?? spelt;
|
|
1184
1197
|
const suffixed = String(raw).trim().replace(/\\/g, "/").match(/^(.*?):(\d+)(?::\d+)?$/);
|
|
1185
|
-
const path = suffixed ? suffixed[1]! : String(raw).trim().replace(/\\/g, "/");
|
|
1186
1198
|
|
|
1187
1199
|
const declared = finding[f.line];
|
|
1188
1200
|
const line =
|
|
@@ -2016,8 +2028,22 @@ function readPayload(
|
|
|
2016
2028
|
* deliberately `null` rather than unescaped here: decoding octal escapes to
|
|
2017
2029
|
* compare a path is a second parser, and the right repair is to produce the
|
|
2018
2030
|
* list with `-z` or `core.quotePath=false` in the first place.
|
|
2031
|
+
*
|
|
2032
|
+
* It is `repoPathSpelling` lowercased: the two share every rule but case,
|
|
2033
|
+
* because this one COMPARES and that one is SENT (#1992).
|
|
2019
2034
|
*/
|
|
2020
2035
|
export function normaliseRepoPath(value: unknown): string | null {
|
|
2036
|
+
return repoPathSpelling(value)?.toLowerCase() ?? null;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
/**
|
|
2040
|
+
* A path in the spelling the REST API can match: dot segments collapsed,
|
|
2041
|
+
* leading slashes, backslashes and a `:line` suffix removed, CASE KEPT. The
|
|
2042
|
+
* API matches the diff byte for byte, so the lowercased comparison form is
|
|
2043
|
+
* the predicate and never the value (#1992). `null` exactly where
|
|
2044
|
+
* `normaliseRepoPath` is `null`, because that one is this one lowercased.
|
|
2045
|
+
*/
|
|
2046
|
+
export function repoPathSpelling(value: unknown): string | null {
|
|
2021
2047
|
if (typeof value !== "string") return null;
|
|
2022
2048
|
let p = value.trim().replace(/\\/g, "/");
|
|
2023
2049
|
// git's C-quoted spelling. Not comparable without a second unescaper.
|
|
@@ -2053,7 +2079,7 @@ export function normaliseRepoPath(value: unknown): string | null {
|
|
|
2053
2079
|
p = out.join("/");
|
|
2054
2080
|
if (p === "") return null;
|
|
2055
2081
|
|
|
2056
|
-
return /^(?:[\w.@+-]+\/)*[\w.@+-]+$/.test(p) ? p
|
|
2082
|
+
return /^(?:[\w.@+-]+\/)*[\w.@+-]+$/.test(p) ? p : null;
|
|
2057
2083
|
}
|
|
2058
2084
|
|
|
2059
2085
|
/** What a changed-file list reduced to, split by whether it could be read. */
|
|
@@ -30,7 +30,12 @@
|
|
|
30
30
|
* add step with a warning and no item id, and the move step's `if:` skips on
|
|
31
31
|
* the empty id (`.claude/rules/config-access.md`). Any other failure stands.
|
|
32
32
|
*
|
|
33
|
-
* ## What the move step keeps
|
|
33
|
+
* ## What the move step keeps
|
|
34
|
+
*
|
|
35
|
+
* Since #2183 the step is one call to `rungate board-intake-move`
|
|
36
|
+
* (`lib/board-intake-move.ts`, #2193); the retry, the read-backs, the
|
|
37
|
+
* truncation and null-node refusals below are that code's, each tested in
|
|
38
|
+
* test/board-intake-move.test.ts. This file keeps the step's shape:
|
|
34
39
|
*
|
|
35
40
|
* - It owns only the opened -> In review edge. `merged -> Done` and
|
|
36
41
|
* `closed -> Done` stay with GitHub's built-in workflows, so each
|
|
@@ -38,13 +43,10 @@
|
|
|
38
43
|
* - Drafts are not moved (BI-2): Jason's call, 2026-11-04.
|
|
39
44
|
* - It keys off the item the add step created (BI-1), never a re-query, which
|
|
40
45
|
* would race the built-in "Item added to project" workflow.
|
|
41
|
-
* - Every call
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* and every `node(id:)` refuses a null node by naming the id (BI-11).
|
|
46
|
-
* - No `${{ }}` inside a `run:` block (BI-4), and the one scratch file is
|
|
47
|
-
* removed on exit (BI-12).
|
|
46
|
+
* - Every call is retried, every write is read back from the item AND from the
|
|
47
|
+
* project's search index, a full page is never read as absence, and a null
|
|
48
|
+
* or wrong-type node is refused by naming the id: in the command.
|
|
49
|
+
* - No `${{ }}` inside a `run:` block (BI-4), and no scratch file (BI-12).
|
|
48
50
|
* - The field and option are resolved by NAME at run time, so a renamed
|
|
49
51
|
* column fails loudly rather than writing a stale id.
|
|
50
52
|
*
|
|
@@ -113,278 +115,21 @@ echo "projectId=\${project}" >> "\${GITHUB_OUTPUT}"
|
|
|
113
115
|
`;
|
|
114
116
|
}
|
|
115
117
|
|
|
118
|
+
/** The CLI command the move step runs (#2193, #2183). */
|
|
119
|
+
export const BOARD_INTAKE_MOVE_COMMAND = "board-intake-move";
|
|
120
|
+
|
|
116
121
|
/**
|
|
117
|
-
* The move step's `run:` body
|
|
118
|
-
*
|
|
119
|
-
*
|
|
122
|
+
* The move step's `run:` body: one call to the tested command. Its 260 lines
|
|
123
|
+
* of shell are now `lib/board-intake-move.ts`, and each refusal is observed
|
|
124
|
+
* failing against a stub client in `test/board-intake-move.test.ts`. Values
|
|
125
|
+
* arrive through `env:`, never interpolated into this block (BI-4).
|
|
126
|
+
* Exported so a test reads THIS text.
|
|
120
127
|
*/
|
|
121
|
-
export
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# A bare \`gh api graphql\` that fails on a network blip, a secondary
|
|
125
|
-
# rate limit or a momentary 5xx aborts this step instantly with gh's
|
|
126
|
-
# raw error: the retry loop below is never reached and none of the
|
|
127
|
-
# diagnostics in this script ever print. The loop would then be
|
|
128
|
-
# guarding the race it was written for and nothing else.
|
|
129
|
-
#
|
|
130
|
-
# Three calls had that exposure, not the one that was reported —
|
|
131
|
-
# resolving the field, mutating, and reading back — so it is fixed
|
|
132
|
-
# as a population and \`test/board-intake.test.ts\` BI-7 asserts no
|
|
133
|
-
# bare \`gh api graphql\` survives anywhere in this step.
|
|
134
|
-
#
|
|
135
|
-
# STDERR GOES TO A FILE, NOT INTO THE RETURN VALUE. An earlier
|
|
136
|
-
# revision captured \`2>&1\`, which is right for the failure path —
|
|
137
|
-
# \${out} is quoted into the ::error — and wrong for the success
|
|
138
|
-
# path, because the same \${out} is what callers parse. \`gh\` writes
|
|
139
|
-
# to stderr on calls that SUCCEED: the update notifier, rate-limit
|
|
140
|
-
# warnings. Two of the three call sites treat the result as data,
|
|
141
|
-
# and the read-back is the dangerous one. A comparison against
|
|
142
|
-
# "\${COLUMN}" that is polluted by a one-line warning simply stops
|
|
143
|
-
# matching, so the loop logs "a concurrent write won" for a race
|
|
144
|
-
# that never happened and then blames a competing writer for a
|
|
145
|
-
# dirty capture — the right exit code reporting the wrong
|
|
146
|
-
# mechanism (\`.claude/rules/checks-must-be-able-to-fail.md\`, the
|
|
147
|
-
# sixth shape).
|
|
148
|
-
#
|
|
149
|
-
# Setting GH_NO_UPDATE_NOTIFIER would silence the one warning that
|
|
150
|
-
# was named and leave the class open, so it is not the fix.
|
|
151
|
-
err=$(mktemp)
|
|
152
|
-
# A trap, not a trailing \`rm\`. Every refusal below exits the step
|
|
153
|
-
# early, so a cleanup line at the bottom runs on exactly the path
|
|
154
|
-
# that did not need it. Asserted by BI-12.
|
|
155
|
-
trap 'rm -f "\${err}"' EXIT
|
|
156
|
-
gql() {
|
|
157
|
-
local out attempt
|
|
158
|
-
for attempt in 1 2 3; do
|
|
159
|
-
if out=$(gh api graphql "$@" 2>"\${err}"); then
|
|
160
|
-
printf '%s' "\${out}"
|
|
161
|
-
return 0
|
|
162
|
-
fi
|
|
163
|
-
sleep $(( attempt * 2 ))
|
|
164
|
-
done
|
|
165
|
-
echo "::error title=Board intake::GitHub's GraphQL API failed three times. The item may or may not be on the board and its Status is UNKNOWN — this run measured nothing. Last error: $(< "\${err}")" >&2
|
|
166
|
-
return 1
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
# \`node(id: ID!)\` IS NULLABLE, and a null node is an id that did not
|
|
170
|
-
# resolve rather than an empty reading. A stale id, a wrong
|
|
171
|
-
# PROJECT_ID, or a project this token lost access to returns
|
|
172
|
-
# \`{"data":{"node":null}}\` with NO GraphQL error, so \`gql\` exits 0
|
|
173
|
-
# and \`--jq '.data.node.X'\` prints the four bytes \`null\`.
|
|
174
|
-
#
|
|
175
|
-
# What that does downstream, measured:
|
|
176
|
-
#
|
|
177
|
-
# jq '.data.node.fields' on a null node -> null, exit 0
|
|
178
|
-
# jq -r '[.nodes[] | …]' on \`null\` -> exit 5
|
|
179
|
-
# jq -r '.pageInfo.hasNextPage' on \`null\` -> null, exit 0
|
|
180
|
-
#
|
|
181
|
-
# So \`set -euo pipefail\` does kill the job rather than write the
|
|
182
|
-
# wrong column — but it dies on jq's "Cannot iterate over null",
|
|
183
|
-
# naming jq and not the id, and the truncation guard above compares
|
|
184
|
-
# the string \`null\` against \`true\` and stays silent. Right exit
|
|
185
|
-
# code, unreadable cause, which is this workflow's own subject one
|
|
186
|
-
# layer down. BI-11 asserts it over all three reads.
|
|
187
|
-
require_node() {
|
|
188
|
-
if [ -z "$2" ] || [ "$2" = "null" ]; then
|
|
189
|
-
echo "::error title=Board intake::\${1} is UNMEASURED and nothing was written: node(id: \${3}) came back null, so that id did not resolve — it is stale, it names an object this token cannot see, or PROJECT_ID is wrong. This is NOT a missing field, NOT an unset column and NOT an empty board." >&2
|
|
190
|
-
exit 1
|
|
191
|
-
fi
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
# An empty item id means the add step did not produce one. Writing a
|
|
195
|
-
# field against "" returns a confusing NOT_FOUND about the project,
|
|
196
|
-
# so say which half actually failed.
|
|
197
|
-
if [ -z "\${ITEM_ID}" ]; then
|
|
198
|
-
echo "::error title=Board intake::The add step produced no itemId, so there is nothing to move. The item was NOT added and its Status is UNSET — this is not a board that merely missed a transition." >&2
|
|
199
|
-
exit 1
|
|
200
|
-
fi
|
|
201
|
-
|
|
202
|
-
# A TRUNCATED PAGE IS NOT AN ABSENT VALUE, and this step asked three
|
|
203
|
-
# connections for a FIRST page and then read "not in it" as "not
|
|
204
|
-
# there" at all three. Every one of them had the same consequence:
|
|
205
|
-
# a confident error message naming a cause that did not happen.
|
|
206
|
-
#
|
|
207
|
-
# Found in review round 8, reported at one site. It is a population
|
|
208
|
-
# — \`fields\`, \`fieldValues\` and the index \`items\` query — and the
|
|
209
|
-
# round that introduced it fixed the identical shape in the board
|
|
210
|
-
# sweep without carrying it across.
|
|
211
|
-
#
|
|
212
|
-
# THAT SWEEP IS NOT IN THIS TREE. It is \`scripts/board-status-sweep.ts\`
|
|
213
|
-
# on branch \`rg/board-sweep\`, open as PR #1754 and unmerged, so a
|
|
214
|
-
# reader of this file cannot resolve the path and review was right
|
|
215
|
-
# to say so. Naming the pull request instead: a cross-branch
|
|
216
|
-
# reference a reader can follow beats a path that 404s, and the
|
|
217
|
-
# citation is kept rather than deleted because the precedent is the
|
|
218
|
-
# reason this fix has the shape it does.
|
|
219
|
-
#
|
|
220
|
-
# The repair is NOT a bigger page. A bigger page has the same defect
|
|
221
|
-
# further out. Each connection now asks \`pageInfo { hasNextPage }\`,
|
|
222
|
-
# and "wanted value not found AND the page was full" is reported as
|
|
223
|
-
# UNMEASURED with its own message — the same treatment #1754 gives
|
|
224
|
-
# the same fact under the name \`statusUnread\`, so the two halves
|
|
225
|
-
# answer it the same way once both land.
|
|
226
|
-
# \`test/board-intake.test.ts\` BI-10 asserts the population rather
|
|
227
|
-
# than any one site.
|
|
228
|
-
fields=$(gql -f project="\${PROJECT_ID}" -f query='
|
|
229
|
-
query($project: ID!) {
|
|
230
|
-
node(id: $project) {
|
|
231
|
-
... on ProjectV2 {
|
|
232
|
-
fields(first: 50) {
|
|
233
|
-
pageInfo { hasNextPage }
|
|
234
|
-
nodes { ... on ProjectV2SingleSelectField { id name options { id name } } }
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}' --jq '.data.node.fields')
|
|
239
|
-
require_node "the project's field list" "\${fields}" "\${PROJECT_ID}"
|
|
240
|
-
|
|
241
|
-
status=$(printf '%s' "\${fields}" | jq -r '[.nodes[] | select(.name == "Status")] | first // empty')
|
|
242
|
-
field_id=$(printf '%s' "\${status}" | jq -r '.id // empty')
|
|
243
|
-
option_id=$(printf '%s' "\${status}" | jq -r --arg c "\${COLUMN}" '.options[]? | select(.name == $c) | .id')
|
|
244
|
-
|
|
245
|
-
if [ -z "\${field_id}" ] && [ "$(printf '%s' "\${fields}" | jq -r '.pageInfo.hasNextPage')" = "true" ]; then
|
|
246
|
-
echo "::error title=Board intake::The first 50 fields on this project do not include one named 'Status', AND there are more fields beyond that page — so this read is UNMEASURED, not a missing field. Nothing was written. Do not rename anything on the strength of this message; page the fields query instead." >&2
|
|
247
|
-
exit 1
|
|
248
|
-
fi
|
|
249
|
-
|
|
250
|
-
# Resolved by name on purpose, so a renamed field or column is a red
|
|
251
|
-
# job rather than a stale node id writing the wrong column quietly.
|
|
252
|
-
# Reachable only when the page was NOT truncated, so it can now say
|
|
253
|
-
# "renamed" and mean it.
|
|
254
|
-
if [ -z "\${field_id}" ] || [ -z "\${option_id}" ]; then
|
|
255
|
-
echo "::error title=Board intake::Could not resolve the Status field or its '\${COLUMN}' option on this project. The whole field list was read, so this is not a truncated page. The item WAS added; only the transition failed. Someone renamed the field or the column — update COLUMN in this workflow to match the board." >&2
|
|
256
|
-
exit 1
|
|
257
|
-
fi
|
|
258
|
-
|
|
259
|
-
# WRITE, THEN READ BACK. Keying off the add step's itemId settles
|
|
260
|
-
# WHICH item is written and says nothing about WHEN. This job and
|
|
261
|
-
# GitHub's built-in "Item added to project" automation fire off the
|
|
262
|
-
# same event and run concurrently, and this one is the slower of
|
|
263
|
-
# the two by construction: it resolves the field and the option
|
|
264
|
-
# first, which is two round trips the built-in does not make. If
|
|
265
|
-
# the built-in's "set to Backlog" lands after this step's write,
|
|
266
|
-
# the board reverts and the defect this workflow exists to fix
|
|
267
|
-
# returns non-deterministically.
|
|
268
|
-
#
|
|
269
|
-
# So the mutation's exit code is NOT a reading of the board. A
|
|
270
|
-
# write whose effect is never read is indistinguishable from one
|
|
271
|
-
# overwritten a millisecond later
|
|
272
|
-
# (\`.claude/rules/checks-must-be-able-to-fail.md\`, the sixth
|
|
273
|
-
# shape). Three attempts, each verified, and a loud refusal if the
|
|
274
|
-
# last one did not stick.
|
|
275
|
-
for attempt in 1 2 3; do
|
|
276
|
-
gql \\
|
|
277
|
-
-f project="\${PROJECT_ID}" -f item="\${ITEM_ID}" \\
|
|
278
|
-
-f field="\${field_id}" -f option="\${option_id}" -f query='
|
|
279
|
-
mutation($project: ID!, $item: ID!, $field: ID!, $option: String!) {
|
|
280
|
-
updateProjectV2ItemFieldValue(input: {
|
|
281
|
-
projectId: $project, itemId: $item, fieldId: $field,
|
|
282
|
-
value: { singleSelectOptionId: $option }
|
|
283
|
-
}) { projectV2Item { id } }
|
|
284
|
-
}' --jq '.data.updateProjectV2ItemFieldValue.projectV2Item.id' > /dev/null
|
|
285
|
-
|
|
286
|
-
# Give a concurrent built-in write time to land, so the read-back
|
|
287
|
-
# observes the SETTLED value rather than this step's own write
|
|
288
|
-
# racing ahead of it. Reading immediately would report success
|
|
289
|
-
# and then be overwritten, which is the exact failure being
|
|
290
|
-
# guarded against.
|
|
291
|
-
sleep 3
|
|
292
|
-
|
|
293
|
-
values=$(gql -f item="\${ITEM_ID}" -f query='
|
|
294
|
-
query($item: ID!) {
|
|
295
|
-
node(id: $item) {
|
|
296
|
-
... on ProjectV2Item {
|
|
297
|
-
fieldValues(first: 50) {
|
|
298
|
-
pageInfo { hasNextPage }
|
|
299
|
-
nodes {
|
|
300
|
-
... on ProjectV2ItemFieldSingleSelectValue {
|
|
301
|
-
name field { ... on ProjectV2FieldCommon { name } }
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}' --jq '.data.node.fieldValues')
|
|
308
|
-
require_node "the item's field values, read back after the write" "\${values}" "\${ITEM_ID}"
|
|
309
|
-
|
|
310
|
-
current=$(printf '%s' "\${values}" | jq -r '[.nodes[] | select(.field.name == "Status") | .name] | first // ""')
|
|
311
|
-
|
|
312
|
-
# The worst of the three, because its wrong diagnosis is the one
|
|
313
|
-
# a reader would act on: an item carrying more field values than
|
|
314
|
-
# the page holds reads back as "" and the loop below blames a
|
|
315
|
-
# competing writer for a race that never happened, three times,
|
|
316
|
-
# then fails a job whose write in fact succeeded.
|
|
317
|
-
if [ -z "\${current}" ] && [ "$(printf '%s' "\${values}" | jq -r '.pageInfo.hasNextPage')" = "true" ]; then
|
|
318
|
-
echo "::error title=Board intake::Status was not among this item's first 50 field values and there are more beyond that page, so the read-back is UNMEASURED — the write may well have worked. This is NOT a competing writer and NOT an unset column. Page the fieldValues query." >&2
|
|
319
|
-
exit 1
|
|
320
|
-
fi
|
|
321
|
-
|
|
322
|
-
# THE FIELD VALUE IS NOT WHAT THE BOARD DRAWS, AND THIS STEP USED
|
|
323
|
-
# TO STOP HERE. Projects serves a board view from a SEARCH INDEX
|
|
324
|
-
# that is separate from the item data, and the two can disagree.
|
|
325
|
-
#
|
|
326
|
-
# Measured on this project, 2026-11-04. Four pull requests held
|
|
327
|
-
# Status "In review" in the data; \`items(query: "status:...")\`
|
|
328
|
-
# returned two, and the board drew exactly those two. #1740 and
|
|
329
|
-
# #1747 were invisible on the board for over an hour while every
|
|
330
|
-
# field-value read said they were fine — which is precisely the
|
|
331
|
-
# read this loop was doing.
|
|
332
|
-
#
|
|
333
|
-
# So a read-back that only asks the data path CANNOT observe the
|
|
334
|
-
# failure it exists to catch: it returns "In review", the job
|
|
335
|
-
# reports success, and nobody sees the card. Right exit code,
|
|
336
|
-
# wrong mechanism (\`.claude/rules/checks-must-be-able-to-fail.md\`,
|
|
337
|
-
# the sixth shape).
|
|
338
|
-
#
|
|
339
|
-
# Both readings must agree before this job claims the move worked.
|
|
340
|
-
index_page=$(gql -f project="\${PROJECT_ID}" -f q="status:\\"\${COLUMN}\\"" -f query='
|
|
341
|
-
query($project: ID!, $q: String!) {
|
|
342
|
-
node(id: $project) {
|
|
343
|
-
... on ProjectV2 {
|
|
344
|
-
items(first: 100, query: $q) {
|
|
345
|
-
pageInfo { hasNextPage }
|
|
346
|
-
nodes { id }
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}' --jq '.data.node.items')
|
|
351
|
-
require_node "the search index for the '\${COLUMN}' column" "\${index_page}" "\${PROJECT_ID}"
|
|
352
|
-
|
|
353
|
-
# \`--arg\` rather than interpolating ITEM_ID into the jq program.
|
|
354
|
-
# The id is minted by GitHub so this is not a sanitisation fix; a
|
|
355
|
-
# value pasted into a program text is simply a different thing
|
|
356
|
-
# from a value passed to one, and only one of them stays a value.
|
|
357
|
-
indexed=$(printf '%s' "\${index_page}" | jq -r --arg id "\${ITEM_ID}" '[.nodes[].id] | index($id) // empty')
|
|
358
|
-
|
|
359
|
-
# The third site. A column holding more than 100 cards is not
|
|
360
|
-
# hypothetical on a 121-item board, and without this the job
|
|
361
|
-
# reports the card as absent from the index and tells a human to
|
|
362
|
-
# go and look at an index that is in fact correct.
|
|
363
|
-
if [ -z "\${indexed}" ] && [ "$(printf '%s' "\${index_page}" | jq -r '.pageInfo.hasNextPage')" = "true" ]; then
|
|
364
|
-
echo "::error title=Board intake::More than 100 items match '\${COLUMN}' in the project's search index and this item was not in the first page, so its membership is UNMEASURED — it may well be indexed and rendering. Do not read this as a missing card. Page the index query." >&2
|
|
365
|
-
exit 1
|
|
366
|
-
fi
|
|
367
|
-
|
|
368
|
-
if [ "\${current}" = "\${COLUMN}" ] && [ -n "\${indexed}" ]; then
|
|
369
|
-
echo "::notice title=Board intake::Moved to '\${COLUMN}' on attempt \${attempt}, confirmed in BOTH the item's field value and the project's search index — so the card will actually render. This workflow owns only the opened->In review edge; merged->Done and closed->Done remain GitHub's built-in project workflows, so exactly one decider writes each transition."
|
|
370
|
-
exit 0
|
|
371
|
-
fi
|
|
372
|
-
|
|
373
|
-
if [ "\${current}" = "\${COLUMN}" ]; then
|
|
374
|
-
echo "Attempt \${attempt}: the field value reads '\${COLUMN}' but the search index does not carry this item yet, so the board would not draw it. Re-writing to prompt a re-index."
|
|
375
|
-
else
|
|
376
|
-
echo "Attempt \${attempt}: wrote '\${COLUMN}', read back '\${current:-(nothing)}' — a concurrent write won. Retrying."
|
|
377
|
-
fi
|
|
378
|
-
done
|
|
379
|
-
|
|
380
|
-
if [ "\${current}" = "\${COLUMN}" ]; then
|
|
381
|
-
echo "::error title=Board intake::The Status field reads '\${COLUMN}' but after three attempts the project's SEARCH INDEX still does not list this item under it, and the board draws from the index. The data is right and the card is invisible — do not 'fix' the Status, it is already correct. Re-writing the same value is what repairs the index entry; if three did not take, the index is lagging and this needs a human to re-check later." >&2
|
|
382
|
-
exit 1
|
|
383
|
-
fi
|
|
384
|
-
|
|
385
|
-
echo "::error title=Board intake::Wrote '\${COLUMN}' three times and the board still reads '\${current:-(nothing)}'. Something else is writing this item's Status and winning: check the project's built-in workflows for a rule that also fires on a pull request being added. The item IS on the board; only its column is wrong. Not exiting 0 on this — a job that writes and does not check is how the column silently reverted before." >&2
|
|
386
|
-
exit 1
|
|
128
|
+
export function buildBoardIntakeMoveScript(version: string): string {
|
|
129
|
+
return `set -euo pipefail
|
|
130
|
+
bunx rungate@${version} ${BOARD_INTAKE_MOVE_COMMAND} --project "\${PROJECT_ID}" --item "\${ITEM_ID}" --column "\${COLUMN}"
|
|
387
131
|
`;
|
|
132
|
+
}
|
|
388
133
|
|
|
389
134
|
export interface BoardIntakeWorkflowOptions {
|
|
390
135
|
/** The `runs-on:` value, already JSON-quoted by the caller. */
|
|
@@ -464,6 +209,6 @@ ${indent(buildBoardIntakeAddScript(opts.version), " ")}
|
|
|
464
209
|
ITEM_ID: \${{ steps.add.outputs.itemId }}
|
|
465
210
|
COLUMN: In review
|
|
466
211
|
run: |
|
|
467
|
-
${indent(
|
|
212
|
+
${indent(buildBoardIntakeMoveScript(opts.version), " ")}
|
|
468
213
|
`;
|
|
469
214
|
}
|
package/package.json
CHANGED
|
@@ -32,13 +32,17 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { createGitHubClient } from "../lib/github";
|
|
34
34
|
import {
|
|
35
|
+
AI_REVIEW_PR_IS_FORK_VAR,
|
|
35
36
|
aiReviewThreadsExitCode,
|
|
36
37
|
postReviewThreads,
|
|
38
|
+
prIsForkReading,
|
|
39
|
+
threadsDetailLines,
|
|
37
40
|
threadsLandedPhrase,
|
|
38
41
|
type AiReviewThreadPoster,
|
|
39
42
|
type AiReviewThreadResponse,
|
|
40
43
|
} from "../lib/ai-review-threads";
|
|
41
44
|
import {
|
|
45
|
+
escapeAnnotation,
|
|
42
46
|
readAiReviewChangedFiles,
|
|
43
47
|
readAiReviewFindingsFile,
|
|
44
48
|
} from "../lib/scaffold/ai-review-findings";
|
|
@@ -113,7 +117,11 @@ if (!parsed.ok) {
|
|
|
113
117
|
// UNMEASURED, not a refusal. A step invoked wrongly has not discovered that
|
|
114
118
|
// a review produced no threads; it has not looked. Exiting non-zero here
|
|
115
119
|
// would red the job for a reason that says nothing about the review.
|
|
116
|
-
|
|
120
|
+
// Escaped: the error quotes the positionals, which are this process's argv
|
|
121
|
+
// (#1992).
|
|
122
|
+
console.log(
|
|
123
|
+
`::warning title=AI review threads::${COMMAND}: ${escapeAnnotation(parsed.error)} — UNMEASURED, nothing was posted`,
|
|
124
|
+
);
|
|
117
125
|
process.exit(0);
|
|
118
126
|
}
|
|
119
127
|
|
|
@@ -180,8 +188,12 @@ const post: AiReviewThreadPoster = async request => {
|
|
|
180
188
|
// every round would re-post every thread. `lineTextFor` comes off the SAME
|
|
181
189
|
// reader the gate above was built from, so it is the same cache and the same
|
|
182
190
|
// normalisation rather than a second one that happens to agree.
|
|
183
|
-
|
|
184
|
-
|
|
191
|
+
// #1992: whether this run is a fork, read exactly from the variable the
|
|
192
|
+
// workflow sets (#2203). Unset reads null, which keeps the fork degrade — so
|
|
193
|
+
// this CLI under a workflow that does not yet set it behaves as before.
|
|
194
|
+
const fork = prIsForkReading(process.env[AI_REVIEW_PR_IS_FORK_VAR]);
|
|
195
|
+
const result = await postReviewThreads(reading, post, f => carryKey(f, lineTextFor(f)), fork);
|
|
196
|
+
for (const line of threadsDetailLines(result, COMMAND)) console.log(line);
|
|
185
197
|
console.log(
|
|
186
198
|
`${COMMAND}: ${result.outcome} — attempted ${result.attempted}, posted ${result.posted}, ` +
|
|
187
199
|
`demoted ${result.demoted}`,
|