@ref0/workspace 0.13.0 → 0.14.0
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/README.md
CHANGED
|
@@ -254,6 +254,25 @@ the repo's `.agents/repo/review.md` say. Its body names a tier on a `Merge risk:
|
|
|
254
254
|
its floor, the highest tier its changed lines, the always-review list and its test code give it,
|
|
255
255
|
and the gate checks the session comment or `Break:` lines that tier needs.
|
|
256
256
|
|
|
257
|
+
- A file edited in place whose hunks change only whole-line comments, `//` in TypeScript or Rust
|
|
258
|
+
and `#` in YAML, shell or TOML, sets no floor from the list. Not when a comment is a directive,
|
|
259
|
+
such as `@ts-`, a lint rule's or `/// <reference`, when a line the patch shows may hide code, as a
|
|
260
|
+
block comment's mark, a backtick, a line that starts with `*` or a YAML block scalar may, or when
|
|
261
|
+
the file is under `verification/`. So a TSDoc edit counts as code.
|
|
262
|
+
- Test code is medium when it deletes, skips or adds a test, changes a shared helper, takes away
|
|
263
|
+
more test rows or assertion lines, `expect(` or `assert`, than it adds, swaps a matcher for a
|
|
264
|
+
less exact one, such as `toBeDefined()`, `toMatchObject` or a `.not.`, raises a test's timeout or
|
|
265
|
+
retry, in its options or a row's or hook's last argument, drops a table's case, or drops an
|
|
266
|
+
import whose names the file no longer holds. A moved, re-sourced, type-only or `node:` import
|
|
267
|
+
drops none.
|
|
268
|
+
- A session counts 1 to 3 rounds, and at medium at least 1 reviewer. It names each reviewer's
|
|
269
|
+
model, has a findings row for each finding its Raised cells count, and leaves every P0 or P1
|
|
270
|
+
finding fixed, filed or kept.
|
|
271
|
+
- A tests or code quality reviewer the tier needs counts only from a session fresh for what it
|
|
272
|
+
vouches for, the test code or the production source: its `Through:` commit is in the head's
|
|
273
|
+
history, and none of the pull request's commits after it changes those files, by either name of a
|
|
274
|
+
renamed one.
|
|
275
|
+
|
|
257
276
|
- Bare, in CI: judges pull request `PR` of `GITHUB_REPOSITORY`, from `BASE` to `HEAD`, reading
|
|
258
277
|
GitHub with `gh` and `GH_TOKEN`, and the history from the Git checkout it runs in, which holds
|
|
259
278
|
both commits whole, blobs aside. It prints each reason it fails as an Actions `::error::`.
|
|
@@ -297,6 +316,13 @@ install of that version with no peers, which loads no peer, in a blobless clone
|
|
|
297
316
|
the head, so a pull request can't change the gate that judges it:
|
|
298
317
|
|
|
299
318
|
```yaml
|
|
319
|
+
# The package declares node >=24, past the runner's own Node. No cache: the step restores and
|
|
320
|
+
# saves nothing.
|
|
321
|
+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
322
|
+
if: always() && github.event_name == 'pull_request'
|
|
323
|
+
with:
|
|
324
|
+
node-version: 24
|
|
325
|
+
package-manager-cache: false
|
|
300
326
|
- name: Fetch review-record history
|
|
301
327
|
id: fetch
|
|
302
328
|
if: always() && github.event_name == 'pull_request'
|
|
@@ -8,8 +8,8 @@ export interface Change {
|
|
|
8
8
|
/** GitHub's: `added`, `removed`, `modified`, `renamed` and the like. */
|
|
9
9
|
readonly status?: string;
|
|
10
10
|
/**
|
|
11
|
-
* Its hunks, kept for test code
|
|
12
|
-
* too big to show, and `testRisks` then reads the file as a risk.
|
|
11
|
+
* Its hunks, kept for test code and the files `patchRead` names, from the first `@@` line: GitHub
|
|
12
|
+
* leaves it out of a file too big to show, and `testRisks` then reads the file as a risk.
|
|
13
13
|
*/
|
|
14
14
|
readonly patch?: string;
|
|
15
15
|
}
|
|
@@ -11,22 +11,26 @@ import { env } from "node:process";
|
|
|
11
11
|
* The floor is the lowest tier the pull request may name, from its size and paths, as `floorOf`
|
|
12
12
|
* works it out: high past `highTierLines` changed lines, on the base's `review-paths.txt` at high
|
|
13
13
|
* or on a large change, medium past `lowTierLines` or on it at medium or on `testRisks`' list, and
|
|
14
|
-
* low otherwise.
|
|
15
|
-
* tier needs:
|
|
14
|
+
* low otherwise. A file whose hunks change only comments, as `commentOnly` reads them, is on no
|
|
15
|
+
* list. Its body names its tier on a `Merge risk:` line, at the floor or above, and the tier needs:
|
|
16
16
|
* - low: no session. Each test file it edits is named on a `Break:` line of the body, the break the
|
|
17
17
|
* builder ran, as test-audit's authoring gate asks.
|
|
18
|
-
* - medium: a session
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* - medium: a session, of 1 reviewer and 1 round at least. Its reviewer is a tests one when the
|
|
19
|
+
* floor is from `testRisks`, and a tests one or a `Break:` line for each when it edits test code
|
|
20
|
+
* otherwise.
|
|
21
21
|
* - high: a session, whose first table counts it at `high` with 1 to 4 reviewers.
|
|
22
22
|
* - Each session's reviewer table has a row for each reviewer its first table counts, each with
|
|
23
|
-
* one review type and its scope, since each reviewer is a Codex run of its own.
|
|
23
|
+
* one review type, its model and its scope, since each reviewer is a Codex run of its own.
|
|
24
24
|
* - On a pull request that changes a file a review covers, each session names every type in
|
|
25
25
|
* `consideredTypes` in its reviewer table or, with why, on its `Not run:` line.
|
|
26
26
|
* - A large change, 1,000 or more net lines of production source, needs a session with a code
|
|
27
27
|
* quality reviewer, which is why a large change's floor is high.
|
|
28
28
|
* - A pull request that changes test code, as `testCode` lists it, needs a session with a tests
|
|
29
29
|
* reviewer.
|
|
30
|
+
* - At any tier, each session counts 1 to 3 rounds and leaves no P0 or P1 finding unfixed, unfiled
|
|
31
|
+
* and unkept, as `readSession` reads it. A tests or code quality reviewer the tier needs counts
|
|
32
|
+
* only from a session fresh for what it vouches for, the test code or the production source, as
|
|
33
|
+
* `freshFor` says.
|
|
30
34
|
* - At any tier, a pull request that changes a file the base's `benchedPaths` list ties to a bench
|
|
31
35
|
* case holds a reading for each such case in its body's "Bench and cost" fold: a line that names
|
|
32
36
|
* the case with a run's link, or labelled local, as `benchReadings` reads it. A line that says the
|
|
@@ -127,16 +131,49 @@ const breakLine = /^(?:[-*] )?(?:\*\*)?Break:(?:\*\*)?[ \t]*\S.*$/gm;
|
|
|
127
131
|
const testRow = /^\s*(?:it|test|describe|bench)(?:\.\w+)*\s*\(/;
|
|
128
132
|
/** A test's line that skips a row, or runs one alone, which skips the rest. */
|
|
129
133
|
const skipping = /\.(?:skip|todo|only|skipIf|runIf)\b|\b(?:skipIf|runIf)\s*\(/;
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
+
/**
|
|
135
|
+
* Each timeout or retry a test's line sets, which may loosen it: its key, and its value, or none for
|
|
136
|
+
* a shorthand `{ timeout }`, whose value is out of sight. A shorthand that a pattern destructures,
|
|
137
|
+
* as `const { timeout } = options` or `({ timeout }: Opts) =>` do, sets none.
|
|
138
|
+
*/
|
|
139
|
+
const limitSettings = /\b(timeout|testTimeout|hookTimeout|teardownTimeout|retry|retries)\b(?:\s*[:=](?![=>])\s*([^,;)}\s][^,;)}]*)|(?=\s*[,}])(?![^}]*\}\s*(?:=(?![=>])|:|\)\s*=>)))/g;
|
|
140
|
+
/** A call whose options' timeout or retry is a test's: a row's, a hook's, or Vitest's config. */
|
|
141
|
+
const limitCall = /^(?:(?:it|test|describe|bench|suite)(?:\.\w+)*|(?:before|after)(?:All|Each)|vi\.setConfig|define(?:Config|Project|Workspace))$/;
|
|
142
|
+
/**
|
|
143
|
+
* A line's last argument, after its last comma, as a call of one argument, such as `seconds(60)`,
|
|
144
|
+
* or none, and the brackets that close its call.
|
|
145
|
+
*/
|
|
146
|
+
const lastArgument = /,\s*([\w$.]+\s*\([^(),]*\)|[^,(){}[\]'"`\s][^,(){}]*?)\s*(\)[\s;,]*)$/;
|
|
147
|
+
/** A duration's call of one number, such as `seconds(60)` or `Duration.millis(500)`. */
|
|
148
|
+
const durationCall = /^(?:[\w$]+\.)*([\w$]+)\s*\(\s*(\d[\d_]*)\s*\)$/;
|
|
149
|
+
/** A trailing `//` comment, after code. */
|
|
150
|
+
const trailingComment = /\s+\/\/.*$/;
|
|
151
|
+
/** Quoted text in a line, a string's or a template's. */
|
|
152
|
+
const quoted = /(['"`])(?:\\.|(?!\1).)*\1/g;
|
|
153
|
+
/** A call that starts a test's row, whose function comes before a timeout. */
|
|
154
|
+
const rowCall = /^(?:it|test|describe|bench|suite)(?:\.\w+)*\s*\(/;
|
|
155
|
+
/** A call that starts a hook, whose timeout comes straight after its function. */
|
|
156
|
+
const hookCall = /^(?:before|after)(?:All|Each)\s*\(/;
|
|
157
|
+
/** A line of only brackets, which may close a row or a hook before its timeout. */
|
|
158
|
+
const closing = /^[\]})]+$/;
|
|
134
159
|
/** A line that `.each(` starts, whose cases a patch can't count. */
|
|
135
160
|
const tableCall = /\.each\s*[(`]/;
|
|
136
161
|
/** A line shaped like a table's case: a string, tuple or object row, a bare number, or a spread. */
|
|
137
162
|
const tableCase = /^\s*(?:[[{].*[\]}]|(['"`]).*\1|-?\d[\d_.]*|\.\.\.[\w$.]+),?\s*$/;
|
|
138
|
-
/**
|
|
139
|
-
const
|
|
163
|
+
/** A line that holds only a string, which is a table's case only inside a list. */
|
|
164
|
+
const stringLine = /^\s*(['"`]).*\1,?\s*$/;
|
|
165
|
+
/** An import's first line, which may bring a table's cases in. */
|
|
166
|
+
const importStart = /^\s*import\b/;
|
|
167
|
+
/** An import statement's last line: the module it reads, or a side effect's. */
|
|
168
|
+
const importEnd = /(?:\bfrom\s*|^\s*import\s*)['"][^'"]*['"]/;
|
|
169
|
+
/** A multi-line import's last line, which names its module after its names. */
|
|
170
|
+
const importClose = /^\s*\}\s*from\s*['"]/;
|
|
171
|
+
/** An import of a module for its side effects, which binds no name. */
|
|
172
|
+
const sideEffect = /^\s*import\s*(?:\{\s*\}\s*from\s*)?['"]/;
|
|
173
|
+
/** A multi-line import's line of names, as ` b as c,`. */
|
|
174
|
+
const importNames = /^\s*(?:type\s+)?[\w$]+(?:\s+as\s+[\w$]+)?\s*,?\s*$/;
|
|
175
|
+
/** An import that brings no test's cases: types alone, or a Node module. */
|
|
176
|
+
const noCases = /^\s*import\s+type\s+(?!from\b|,)|['"]node:/;
|
|
140
177
|
const fixtures = /\/fixtures\//;
|
|
141
178
|
/**
|
|
142
179
|
* Whether a path is production source, as the review skill counts a large change: one the settings'
|
|
@@ -223,6 +260,10 @@ const filesIn = (changes, matches) => changes.flatMap((change) => {
|
|
|
223
260
|
lines
|
|
224
261
|
}] : [];
|
|
225
262
|
});
|
|
263
|
+
/** A change's paths: where it is, and where it was when it's a rename. */
|
|
264
|
+
const pathsOf = (change) => change.previous_filename === void 0 ? [change.filename] : [change.filename, change.previous_filename];
|
|
265
|
+
/** Each path of every change a list matches by either, since a commit may touch either name. */
|
|
266
|
+
const pathsIn = (changes, matches) => changes.flatMap((change) => pathsOf(change).some(matches) ? pathsOf(change) : []);
|
|
226
267
|
/**
|
|
227
268
|
* The test code a change touches, as `filesIn` reads it, with its changed lines: a test file moved
|
|
228
269
|
* with no edits is still one, at 0 lines, so it still needs a tests reviewer or a recorded break.
|
|
@@ -247,43 +288,302 @@ const hunksOf = (patch) => {
|
|
|
247
288
|
header: line,
|
|
248
289
|
kept: [],
|
|
249
290
|
added: [],
|
|
250
|
-
removed: []
|
|
291
|
+
removed: [],
|
|
292
|
+
before: [],
|
|
293
|
+
after: []
|
|
251
294
|
});
|
|
252
295
|
const hunk = hunks.at(-1);
|
|
253
296
|
if (hunk === void 0 || line.startsWith("@@")) continue;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
297
|
+
const text = line.slice(1);
|
|
298
|
+
if (line.startsWith("+")) {
|
|
299
|
+
hunk.added.push(text);
|
|
300
|
+
hunk.after.push({
|
|
301
|
+
line: text,
|
|
302
|
+
added: true
|
|
303
|
+
});
|
|
304
|
+
} else if (line.startsWith("-")) {
|
|
305
|
+
hunk.removed.push(text);
|
|
306
|
+
hunk.before.push({
|
|
307
|
+
line: text,
|
|
308
|
+
removed: true
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
hunk.kept.push(text);
|
|
312
|
+
hunk.before.push({
|
|
313
|
+
line: text,
|
|
314
|
+
removed: false
|
|
315
|
+
});
|
|
316
|
+
hunk.after.push({
|
|
317
|
+
line: text,
|
|
318
|
+
added: false
|
|
319
|
+
});
|
|
320
|
+
}
|
|
257
321
|
}
|
|
258
322
|
return hunks;
|
|
259
323
|
};
|
|
324
|
+
/** A timeout in milliseconds, where 0 is none at all, as Vitest reads it. */
|
|
325
|
+
const timeoutOf = (ms) => ms === 0 ? Infinity : ms;
|
|
260
326
|
/** A number as a test writes it, `60_000` among them. */
|
|
261
327
|
const numberOf = (digits) => Number(digits.replaceAll("_", ""));
|
|
328
|
+
/** Milliseconds in each unit a duration's string may name, as Effect's `'5 seconds'` does. */
|
|
329
|
+
const units = [
|
|
330
|
+
[/^(?:ms|millis|milliseconds?)?$/, 1],
|
|
331
|
+
[/^(?:s|seconds?)$/, 1e3],
|
|
332
|
+
[/^(?:m|minutes?)$/, 6e4],
|
|
333
|
+
[/^(?:h|hours?)$/, 36e5]
|
|
334
|
+
];
|
|
262
335
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
336
|
+
* A timeout's or a retry's value as a number to compare, or `undefined` when it isn't a literal:
|
|
337
|
+
* a timeout's milliseconds, from a number or a quoted duration, and a retry's count, `false` none.
|
|
265
338
|
*/
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
339
|
+
const limitOf = (key, value) => {
|
|
340
|
+
const text = value.trim();
|
|
341
|
+
if (/^retr/.test(key)) {
|
|
342
|
+
if (/^(?:false|null|undefined)$/.test(text)) return 0;
|
|
343
|
+
return /^\d[\d_]*$/.test(text) ? numberOf(text) : void 0;
|
|
344
|
+
}
|
|
345
|
+
const duration = /^(['"`]?)(\d[\d_]*(?:\.\d+)?)\s*([a-z]*)\1$/.exec(text);
|
|
346
|
+
const scale = units.find(([unit]) => unit.test(duration?.[3] ?? "-"))?.[1];
|
|
347
|
+
return duration === null || scale === void 0 ? void 0 : timeoutOf(numberOf(duration[2] ?? "0") * scale);
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* The innermost call still open at the end of `text`, past the brackets quoted text holds: its
|
|
351
|
+
* callee, `''` for a bracket no name calls, or `undefined` when none is open, or a quote is.
|
|
352
|
+
*/
|
|
353
|
+
const openCall = (text) => {
|
|
354
|
+
const open = [];
|
|
355
|
+
let quote;
|
|
356
|
+
for (let at = 0; at < text.length; at += 1) {
|
|
357
|
+
const char = text[at] ?? "";
|
|
358
|
+
if (quote !== void 0) {
|
|
359
|
+
if (char === "\\") at += 1;
|
|
360
|
+
else if (char === quote) quote = void 0;
|
|
361
|
+
} else if (char === "'" || char === "\"" || char === "`") quote = char;
|
|
362
|
+
else if (char === "(") open.push(/[\w$.]+\s*$/.exec(text.slice(0, at))?.[0].trim() ?? "");
|
|
363
|
+
else if (char === ")") open.pop();
|
|
364
|
+
}
|
|
365
|
+
return quote === void 0 ? open.at(-1) : void 0;
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* The timeouts and retries a line sets for a test, each by its key, with its value as `limitOf`
|
|
369
|
+
* reads it: none inside a call that isn't `limitCall`'s, as a client's own options are.
|
|
370
|
+
*/
|
|
371
|
+
const limitsIn = (line) => [...line.matchAll(limitSettings)].flatMap((match) => {
|
|
372
|
+
const callee = openCall(line.slice(0, match.index));
|
|
373
|
+
if (callee !== void 0 && callee !== "" && !limitCall.test(callee)) return [];
|
|
374
|
+
const [, key = "", value] = match;
|
|
375
|
+
return [{
|
|
376
|
+
key,
|
|
377
|
+
value: value === void 0 ? void 0 : limitOf(key, value)
|
|
378
|
+
}];
|
|
275
379
|
});
|
|
276
380
|
/**
|
|
277
|
-
* The
|
|
278
|
-
*
|
|
381
|
+
* The added lines that set a timeout or a retry higher than before: a key no removed line of the
|
|
382
|
+
* hunk set before, read against Vitest's default of no retry and a timeout it can't know, or a value
|
|
383
|
+
* above each it held. A value that isn't a literal counts, and a line removed the same elsewhere in
|
|
384
|
+
* the file, as a move, doesn't.
|
|
385
|
+
*/
|
|
386
|
+
const raisedLimits = (hunk, moved) => {
|
|
387
|
+
const held = /* @__PURE__ */ new Map();
|
|
388
|
+
for (const { key, value } of hunk.removed.flatMap(limitsIn)) held.set(key, [...held.get(key) ?? [], value]);
|
|
389
|
+
return hunk.added.filter((line) => !moved.has(line.trim()) && limitsIn(line).some(({ key, value }) => {
|
|
390
|
+
const was = held.get(key) ?? [/^retr/.test(key) ? 0 : void 0];
|
|
391
|
+
return value === void 0 || was.some((each) => each === void 0 || value > each);
|
|
392
|
+
}));
|
|
393
|
+
};
|
|
394
|
+
/** A timeout's value as a positional argument writes it: a number, or a duration's call of one. */
|
|
395
|
+
const positionalOf = (text) => {
|
|
396
|
+
if (/^\d[\d_]*$/.test(text)) return timeoutOf(numberOf(text));
|
|
397
|
+
const [, unit = "", digits = ""] = durationCall.exec(text) ?? [];
|
|
398
|
+
const scale = units.find(([each]) => unit !== "" && each.test(unit.toLowerCase()))?.[1];
|
|
399
|
+
return scale === void 0 ? void 0 : timeoutOf(numberOf(digits) * scale);
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* A line's positional timeout: the last argument of a row's call after its function, of a hook's,
|
|
403
|
+
* or of a line of only the brackets that close one, with the call before it and the brackets after.
|
|
404
|
+
* A row's own line, or a closing one, names one only as a number, a constant or a call of a number,
|
|
405
|
+
* since a row's function may come last, and only after its title and function.
|
|
406
|
+
*/
|
|
407
|
+
const timeoutIn = (line) => {
|
|
408
|
+
const code = line.replace(trailingComment, "");
|
|
409
|
+
const last = lastArgument.exec(code);
|
|
410
|
+
if (last === null || (last[1] ?? "").includes("=>")) return void 0;
|
|
411
|
+
const [, text = "", close = ""] = last;
|
|
412
|
+
const call = code.slice(0, last.index).trim();
|
|
413
|
+
const timeoutLike = /\d|^[A-Z][A-Z\d_]*$/.test(text);
|
|
414
|
+
if (!(rowCall.test(call) && call.replace(quoted, "''").includes(",") && timeoutLike) && !hookCall.test(call) && !(closing.test(call) && timeoutLike)) return void 0;
|
|
415
|
+
return {
|
|
416
|
+
call,
|
|
417
|
+
close,
|
|
418
|
+
value: positionalOf(text),
|
|
419
|
+
opens: !closing.test(call)
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* A line that opens a named call, as `setTimeout(() => {` or `await client.send(() => {` does, after
|
|
424
|
+
* an optional `await`, `return` or declaration, but not a function itself, as `async () => {` is.
|
|
425
|
+
*/
|
|
426
|
+
const namedCall = /^(?:(?:const|let|var)\s+[\w$]+\s*=\s*|return\s+|await\s+)*(?!(?:async|function)\b)[\w$][\w$.]*\s*\(/;
|
|
427
|
+
/**
|
|
428
|
+
* Whether the hunk shows that a line of closing brackets, at `at` in its lines after the change,
|
|
429
|
+
* closes a call that's neither a row nor a hook: the nearest line before it at its indent opens a
|
|
430
|
+
* named call that's neither. Anything else, as a row's function at that indent, closes a row.
|
|
431
|
+
*/
|
|
432
|
+
const closesOther = (after, at) => {
|
|
433
|
+
const indent = indentOf(after[at] ?? "");
|
|
434
|
+
const opener = after.slice(0, at).findLast((line) => line.trim() !== "" && indentOf(line) === indent)?.trim();
|
|
435
|
+
if (opener === void 0 || !namedCall.test(opener)) return false;
|
|
436
|
+
return !rowCall.test(opener) && !hookCall.test(opener);
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* The added lines that raise a positional timeout, as `timeoutIn` reads one: above the one a removed
|
|
440
|
+
* line of the same call held, where one wasn't, or past a value that isn't a literal. With none
|
|
441
|
+
* removed, a row's or a hook's line sets one, and so does a line of brackets that closes a row the
|
|
442
|
+
* hunk adds, at its indent. A line removed the same elsewhere in the file, as a move, doesn't.
|
|
443
|
+
*/
|
|
444
|
+
const raisedTimeouts = (hunk, moved) => {
|
|
445
|
+
const held = /* @__PURE__ */ new Map();
|
|
446
|
+
for (const line of hunk.removed) {
|
|
447
|
+
const was = timeoutIn(line);
|
|
448
|
+
if (was !== void 0) held.set(was.call, [...held.get(was.call) ?? [], was.value]);
|
|
449
|
+
}
|
|
450
|
+
const bare = new Set(hunk.removed.map((line) => line.trim()));
|
|
451
|
+
const indent = (line) => /^\s*/.exec(line)?.[0] ?? "";
|
|
452
|
+
const starts = new Set(hunk.added.flatMap((line) => rowCall.test(line.trim()) || hookCall.test(line.trim()) ? [indent(line)] : []));
|
|
453
|
+
const after = hunk.after.map((each) => each.line);
|
|
454
|
+
const raises = (line, at) => {
|
|
455
|
+
const now = timeoutIn(line);
|
|
456
|
+
if (now === void 0 || moved.has(line.trim())) return false;
|
|
457
|
+
if (!now.opens && closesOther(after, at)) return false;
|
|
458
|
+
const was = held.get(now.call);
|
|
459
|
+
const { value } = now;
|
|
460
|
+
if (was !== void 0) return value === void 0 || was.some((each) => each === void 0 || value > each);
|
|
461
|
+
return bare.has(`${now.call}${now.close}`.trim()) || now.opens || starts.has(indent(line));
|
|
462
|
+
};
|
|
463
|
+
return hunk.after.flatMap(({ line, added }, at) => added && raises(line, at) ? [line] : []);
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* The names an import's clause binds: `{ a, b as c }`, `* as d` and a default `e`, from its whole
|
|
467
|
+
* statement or the part of it a hunk shows, with or without its `import` and its `from`.
|
|
468
|
+
*/
|
|
469
|
+
const bindingsOf = (statement) => {
|
|
470
|
+
return statement.replace(/^\s*import\s+/, "").replace(/\bfrom\s*['"][\s\S]*$/, "").replace(quoted, " ").replace(/\btype\s+[\w$]+(?:\s+as\s+[\w$]+)?/g, " ").replace(/(?:[\w$]+|\*)\s+as\s+([\w$]+)/g, "$1").match(/[A-Za-z_$][\w$]*/g) ?? [];
|
|
471
|
+
};
|
|
472
|
+
/** Whether `text` names `name` whole, as a word of its own. */
|
|
473
|
+
const holdsName = (text, name) => new RegExp(`(?<![\\w$])${name.replace(/\$/g, "\\$")}(?![\\w$])`).test(text);
|
|
474
|
+
/**
|
|
475
|
+
* The import statements a hunk changes, each whole as one line from its `import` line to the line
|
|
476
|
+
* that names its module, kept and removed lines both: each with a removed line. A hunk that starts
|
|
477
|
+
* inside a multi-line import, its lines up to a `} from` line each names, holds that import's rest.
|
|
478
|
+
*/
|
|
479
|
+
const changedImports = (hunk) => {
|
|
480
|
+
const statements = [];
|
|
481
|
+
const close = hunk.before.findIndex(({ line }) => importEnd.test(line));
|
|
482
|
+
let open = close !== -1 && importClose.test(hunk.before[close]?.line ?? "") && hunk.before.slice(0, close).every(({ line }) => importNames.test(line) || line.trim() === "") ? [] : void 0;
|
|
483
|
+
for (const each of hunk.before) {
|
|
484
|
+
if (open === void 0 && importStart.test(each.line)) open = [];
|
|
485
|
+
if (open === void 0) continue;
|
|
486
|
+
open.push(each);
|
|
487
|
+
if (!importEnd.test(each.line) && !each.line.trimEnd().endsWith(";")) continue;
|
|
488
|
+
statements.push(open);
|
|
489
|
+
open = void 0;
|
|
490
|
+
}
|
|
491
|
+
return [...statements, ...open === void 0 ? [] : [open]].flatMap((lines) => lines.some((each) => each.removed) ? [lines.map((each) => each.line.trim()).join(" ")] : []);
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* The removed lines that may drop a test's case: a table's case, an `.each(` line, or an import whose
|
|
495
|
+
* names the lines after the change no longer hold, so a moved or re-sourced import drops none. Each
|
|
496
|
+
* with no identical line added back anywhere in the file, as a move within it adds one. A line of
|
|
497
|
+
* only a string is a case only inside a list: after a line that opens one, `.each(` or another case.
|
|
279
498
|
*/
|
|
280
499
|
const lostCases = (hunks) => {
|
|
281
500
|
const added = new Set(hunks.flatMap((hunk) => hunk.added).map((line) => line.trim()));
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
501
|
+
const after = hunks.flatMap((hunk) => [...hunk.kept, ...hunk.added]).join("\n");
|
|
502
|
+
const listed = (previous) => previous === void 0 || /\[\s*$/.test(previous) || tableCall.test(previous) || tableCase.test(previous);
|
|
503
|
+
const cases = hunks.flatMap((hunk) => hunk.before.flatMap(({ line, removed }, at) => {
|
|
504
|
+
if (!removed || !(tableCase.test(line) || tableCall.test(line))) return [];
|
|
505
|
+
return stringLine.test(line) && !listed(hunk.before[at - 1]?.line) ? [] : [line];
|
|
506
|
+
}));
|
|
507
|
+
const imports = hunks.flatMap(changedImports).filter((statement) => {
|
|
508
|
+
if (noCases.test(statement)) return false;
|
|
509
|
+
if (sideEffect.test(statement)) return true;
|
|
510
|
+
return bindingsOf(statement).some((name) => !holdsName(after, name));
|
|
511
|
+
});
|
|
512
|
+
return [...cases, ...imports].filter((line) => !added.has(line.trim()));
|
|
513
|
+
};
|
|
514
|
+
/** A line that asserts: `expect(`, `expect.soft(`, `expect.poll(`, `assert(` or `assert.<check>(`. */
|
|
515
|
+
const assertCall = /\bexpect(?:\.soft|\.poll)?\s*\(|(?<![\w$.])assert(?:\.\w+)?\s*\(/;
|
|
516
|
+
/**
|
|
517
|
+
* How exactly each matcher checks: 2 for a value exactly, or what an error says, 1 for part of one,
|
|
518
|
+
* and 0 for many values, as a negation, a bound or `toBeDefined()` passes.
|
|
519
|
+
*/
|
|
520
|
+
const strengths = [
|
|
521
|
+
[/\.not\.|\.(?:toBeDefined|toBeTruthy|toBeFalsy|toBeInstanceOf|toBeTypeOf|toBe(?:Greater|Less)Than(?:OrEqual)?)\s*\(|\.(?:toThrow(?:Error)?|toHaveBeenCalled|toBeCalled|toHaveReturned)\s*\(\s*\)|\bexpect\.(?:anything|any)\s*\(|(?<![\w$.])assert(?:\.ok|\.not\w*)?\s*\(/, 0],
|
|
522
|
+
[/\.(?:toMatchObject|toContain|toContainEqual|toHaveProperty)\s*\(|\bexpect\.(?:objectContaining|arrayContaining|stringContaining|stringMatching)\s*\(|\bassert\.(?:match|include)\w*\s*\(/, 1],
|
|
523
|
+
[/\.(?:toBe|toEqual|toStrictEqual|toMatch|toMatch\w*Snapshot|toHaveLength|toHaveBeen\w*CalledWith|toHaveBeenCalledTimes|toHaveReturnedWith|toBeNull|toBeUndefined|toBeNaN|toBeCloseTo)\s*\(|\.toThrow(?:Error)?\s*\(\s*\S|\bassert\.(?:(?:Deep)?(?:Strict)?Equal|deepStrictEqual|deepEqual|strictEqual|equal|throws|rejects)\s*\(/, 2]
|
|
524
|
+
];
|
|
525
|
+
/** How exactly a line asserts, as its weakest matcher checks, or `undefined` when it has none. */
|
|
526
|
+
const strengthOf = (line) => {
|
|
527
|
+
const found = strengths.flatMap(([matcher, strength]) => matcher.test(line) ? [strength] : []);
|
|
528
|
+
return found.length === 0 ? void 0 : Math.min(...found);
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* The added lines of a hunk that assert less exactly than its removed ones did: below a strength,
|
|
532
|
+
* as `strengthOf` ranks them, at or above which the hunk keeps fewer lines than it removes.
|
|
533
|
+
*/
|
|
534
|
+
const weakenedAssertions = (hunk) => {
|
|
535
|
+
const ranked = (lines) => lines.flatMap((line) => {
|
|
536
|
+
const strength = strengthOf(line);
|
|
537
|
+
return strength === void 0 ? [] : [{
|
|
538
|
+
line,
|
|
539
|
+
strength
|
|
540
|
+
}];
|
|
541
|
+
});
|
|
542
|
+
const before = ranked(hunk.removed);
|
|
543
|
+
const after = ranked(hunk.added);
|
|
544
|
+
const atLeast = (lines, strength) => lines.filter((each) => each.strength >= strength).length;
|
|
545
|
+
const lost = [1, 2].filter((strength) => atLeast(after, strength) < atLeast(before, strength));
|
|
546
|
+
return after.filter((each) => lost.some((strength) => each.strength < strength)).map((each) => each.line);
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Each kind of file whose comments a patch can tell: its extension, the mark a whole-line comment
|
|
550
|
+
* starts with, and what on any line of the patch may hide code from that reading, a block comment's
|
|
551
|
+
* mark, a backtick or a line that goes on with `*`, or a block scalar, heredoc or multi-line string.
|
|
552
|
+
*/
|
|
553
|
+
const commentStyles = [[
|
|
554
|
+
/\.(?:[cm]?ts|tsx|rs)$/,
|
|
555
|
+
/^\/\//,
|
|
556
|
+
/\/\*|\*\/|`|^\s*\*/
|
|
557
|
+
], [
|
|
558
|
+
/\.(?:ya?ml|sh|toml)$/,
|
|
559
|
+
/^#/,
|
|
560
|
+
/[|>][-+\d]*\s*(?:\s#.*)?$|<<|`|"""|'''/
|
|
561
|
+
]];
|
|
562
|
+
/** A comment that changes what a tool does: a compiler, lint or bundler directive, or a shebang. */
|
|
563
|
+
const directive = /@ts-|eslint-|oxlint-|biome-ignore|@effect-diagnostics|^\/\/\/\s*<|[@#]__(?:PURE|NO_SIDE_EFFECTS)__|@jsx|@vite-ignore|(?:c8|v8|istanbul) ignore|shellcheck|^#!/;
|
|
564
|
+
/**
|
|
565
|
+
* Whether `commentOnly` may read a change: a kind of file `commentStyles` names, edited in place,
|
|
566
|
+
* not added, removed or renamed, and never under a `verification/` folder, whose comments may be a
|
|
567
|
+
* model's rules.
|
|
568
|
+
*/
|
|
569
|
+
const commentReadable = (change) => commentStyles.some(([file]) => file.test(change.filename)) && change.previous_filename === void 0 && change.status !== "added" && change.status !== "removed" && !/(?:^|\/)verification\//.test(change.filename);
|
|
570
|
+
/**
|
|
571
|
+
* Whether a change edits only comments, as `commentReadable` allows it: its patch's added and removed
|
|
572
|
+
* lines are each blank or a whole-line comment, none a directive, and no line it shows, kept ones
|
|
573
|
+
* too, holds what `commentStyles` says may hide code.
|
|
574
|
+
*/
|
|
575
|
+
const commentOnly = (change) => {
|
|
576
|
+
const style = commentStyles.find(([file]) => file.test(change.filename));
|
|
577
|
+
if (style === void 0 || change.patch === void 0 || !commentReadable(change)) return false;
|
|
578
|
+
const [, comment, hides] = style;
|
|
579
|
+
const hunks = hunksOf(change.patch);
|
|
580
|
+
const changed = hunks.flatMap((hunk) => [...hunk.added, ...hunk.removed]).map((line) => line.trim());
|
|
581
|
+
const shown = hunks.flatMap((hunk) => [
|
|
582
|
+
...hunk.kept,
|
|
583
|
+
...hunk.added,
|
|
584
|
+
...hunk.removed
|
|
585
|
+
]);
|
|
586
|
+
return hunks.length > 0 && changed.every((line) => line === "" || comment.test(line) && !directive.test(line)) && !shown.some((line) => hides.test(line));
|
|
287
587
|
};
|
|
288
588
|
/** At most `count` of a list's items, then how many more. */
|
|
289
589
|
const some = (items, count = 3) => items.length <= count ? items.join(", ") : `${items.slice(0, count).join(", ")} and ${items.length - count} more`;
|
|
@@ -302,14 +602,17 @@ const riskyTests = (changes, settings) => {
|
|
|
302
602
|
const isHelper = matchesAny(settings.testHelpers);
|
|
303
603
|
const risks = [];
|
|
304
604
|
const rowFiles = [];
|
|
605
|
+
const expectFiles = [];
|
|
305
606
|
let rowsAdded = 0;
|
|
306
607
|
let rowsRemoved = 0;
|
|
608
|
+
let expectsAdded = 0;
|
|
609
|
+
let expectsRemoved = 0;
|
|
307
610
|
for (const change of changes) {
|
|
308
611
|
const from = change.previous_filename;
|
|
309
612
|
const file = change.filename;
|
|
310
613
|
if (!isTest(file) && (from === void 0 || !isTest(from))) continue;
|
|
311
614
|
const risk = (why) => risks.push({
|
|
312
|
-
files:
|
|
615
|
+
files: pathsOf(change),
|
|
313
616
|
why
|
|
314
617
|
});
|
|
315
618
|
if (change.status === "removed") risk(`it deletes the test file ${file}`);
|
|
@@ -323,20 +626,30 @@ const riskyTests = (changes, settings) => {
|
|
|
323
626
|
const hunks = hunksOf(change.patch);
|
|
324
627
|
const added = hunks.flatMap((hunk) => hunk.added);
|
|
325
628
|
const removed = hunks.flatMap((hunk) => hunk.removed);
|
|
629
|
+
const moved = new Set(removed.map((line) => line.trim()));
|
|
326
630
|
const skips = added.filter((line) => skipping.test(line));
|
|
327
|
-
const loosens =
|
|
631
|
+
const loosens = hunks.flatMap((hunk) => [...raisedLimits(hunk, moved), ...raisedTimeouts(hunk, moved)]);
|
|
328
632
|
if (skips.length > 0) risk(`it skips a test in ${file}: "${skips[0]?.trim()}"`);
|
|
329
|
-
if (loosens.length > 0) risk(`it
|
|
633
|
+
if (loosens.length > 0) risk(`it raises a timeout or a retry in ${file}: "${loosens[0]?.trim()}"`);
|
|
330
634
|
const lost = change.status === "added" ? [] : lostCases(hunks);
|
|
331
635
|
if (lost.length > 0) risk(`it may drop a case in ${file}: "${lost[0]?.trim()}"`);
|
|
636
|
+
const weakened = hunks.flatMap(weakenedAssertions);
|
|
637
|
+
if (weakened.length > 0) risk(`it weakens an assertion in ${file}: "${weakened[0]?.trim()}"`);
|
|
332
638
|
rowsAdded += added.filter((line) => testRow.test(line)).length;
|
|
333
639
|
rowsRemoved += removed.filter((line) => testRow.test(line)).length;
|
|
640
|
+
expectsAdded += added.filter((line) => assertCall.test(line)).length;
|
|
641
|
+
expectsRemoved += removed.filter((line) => assertCall.test(line)).length;
|
|
334
642
|
if (removed.some((line) => testRow.test(line))) rowFiles.push(file);
|
|
643
|
+
if (removed.some((line) => assertCall.test(line))) expectFiles.push(file);
|
|
335
644
|
}
|
|
336
645
|
if (rowsRemoved > rowsAdded) risks.push({
|
|
337
646
|
files: rowFiles,
|
|
338
647
|
why: `it takes away ${rowsRemoved - rowsAdded} more test rows than it adds`
|
|
339
648
|
});
|
|
649
|
+
if (expectsRemoved > expectsAdded) risks.push({
|
|
650
|
+
files: expectFiles,
|
|
651
|
+
why: `it takes away ${expectsRemoved - expectsAdded} more assertion lines than it adds`
|
|
652
|
+
});
|
|
340
653
|
return risks;
|
|
341
654
|
};
|
|
342
655
|
/**
|
|
@@ -351,7 +664,7 @@ const floorOf = (changes, list, net = 0, settings = defaults) => {
|
|
|
351
664
|
const isProduction = (path) => isProductionSource(path, settings);
|
|
352
665
|
const tierAt = list === void 0 ? (path) => isProduction(path) ? "high" : void 0 : tierOf(list);
|
|
353
666
|
const lines = changedLines(changes, settings);
|
|
354
|
-
const counted = changes.flatMap((change) => matchesAny(settings.sizeUncounted)(change.filename) ? [] :
|
|
667
|
+
const counted = changes.flatMap((change) => matchesAny(settings.sizeUncounted)(change.filename) ? [] : pathsOf(change));
|
|
355
668
|
const reasons = [];
|
|
356
669
|
if (net >= 1e3) reasons.push({
|
|
357
670
|
tier: "high",
|
|
@@ -368,12 +681,19 @@ const floorOf = (changes, list, net = 0, settings = defaults) => {
|
|
|
368
681
|
why: `${lines} changed lines, over ${lowTierLines}`,
|
|
369
682
|
files: counted
|
|
370
683
|
});
|
|
684
|
+
const listed = changes.flatMap((change) => {
|
|
685
|
+
const tier = highest(pathsOf(change).map(tierAt));
|
|
686
|
+
return tier === void 0 || commentOnly(change) ? [] : [{
|
|
687
|
+
change,
|
|
688
|
+
tier
|
|
689
|
+
}];
|
|
690
|
+
});
|
|
371
691
|
for (const tier of ["high", "medium"]) {
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
692
|
+
const at = listed.flatMap((each) => each.tier === tier ? [each.change] : []);
|
|
693
|
+
if (at.length > 0) reasons.push({
|
|
374
694
|
tier,
|
|
375
|
-
why: `${some(
|
|
376
|
-
files:
|
|
695
|
+
why: `${some(at.map((change) => change.previous_filename ?? change.filename))} on the base's review-paths.txt at ${tier}${list === void 0 ? ", which the base lacks, so every production file is" : ""}`,
|
|
696
|
+
files: at.flatMap(pathsOf)
|
|
377
697
|
});
|
|
378
698
|
}
|
|
379
699
|
for (const risk of riskyTests(changes, settings)) reasons.push({
|
|
@@ -697,6 +1017,50 @@ const refusal = (entry, label, form, settings) => {
|
|
|
697
1017
|
const unknown = unknownTypeOf(entry, settings);
|
|
698
1018
|
return unknown === void 0 ? void 0 : `the ${label} "${entry}" names the type "${unknown}", which isn't one this repo accepts: add it to reviewTypes in ${settingsPath}, or use one of ${settings.reviewTypes.join(", ")} as "${form}"`;
|
|
699
1019
|
};
|
|
1020
|
+
/** The most rounds a session runs: round 3 only for round 2's P0 and P1 fixes. */
|
|
1021
|
+
const maxRounds = 3;
|
|
1022
|
+
/** The columns of a session's findings table, which has a row for each finding. */
|
|
1023
|
+
const findingColumns = [
|
|
1024
|
+
"#",
|
|
1025
|
+
"Round",
|
|
1026
|
+
"Type",
|
|
1027
|
+
"Sev",
|
|
1028
|
+
"Finding",
|
|
1029
|
+
"Found by",
|
|
1030
|
+
"Design",
|
|
1031
|
+
"State"
|
|
1032
|
+
];
|
|
1033
|
+
/**
|
|
1034
|
+
* A finding's state that settles a P0 or a P1: fixed at a commit, filed as an issue, here or in a
|
|
1035
|
+
* repo it names, as a link or not, or kept.
|
|
1036
|
+
*/
|
|
1037
|
+
const settled = /^(?:Fixed in `?[0-9a-f]{7,40}\b|Filed \[?(?:[\w.-]+\/[\w.-]+)?#\d+\b|Kept: \S)/;
|
|
1038
|
+
/** A cell without the emphasis or code marks around it, as `**P1**` is `P1`. */
|
|
1039
|
+
const plain = (cell) => cell.replace(/^[*_`]+|[*_`]+$/g, "").trim();
|
|
1040
|
+
/**
|
|
1041
|
+
* What's wrong with a session's findings table, from line `from` to its first fold, outside code
|
|
1042
|
+
* blocks and HTML comments, so a folded review that quotes a table is no table: a table whose rows can't be read,
|
|
1043
|
+
* a count of rows other than `declared`, the reviewer table's sums of Raised and of Real, when it
|
|
1044
|
+
* has them, a row it can't read, or a P0 or P1 not fixed, filed or kept, as the review skill's
|
|
1045
|
+
* findings.md settles each.
|
|
1046
|
+
*/
|
|
1047
|
+
const openFindings = (lines, from, declared) => {
|
|
1048
|
+
const header = findingColumns.join("|");
|
|
1049
|
+
const shown = withoutHidden(lines.slice(from).join("\n")).split("\n");
|
|
1050
|
+
const fold = shown.findIndex((line) => /^\s*<details\b/i.test(line));
|
|
1051
|
+
const prose = fold === -1 ? shown : shown.slice(0, fold);
|
|
1052
|
+
const at = prose.findIndex((line) => line.startsWith("|") && cellsOf(line).join("|") === header);
|
|
1053
|
+
const table = at === -1 ? void 0 : tableAt(prose, findingColumns, at);
|
|
1054
|
+
if (at !== -1 && table === void 0) return [`its findings table has no rule of dashes under "| ${findingColumns.join(" | ")} |", so its rows can't be read`];
|
|
1055
|
+
const rows = table?.rows ?? [];
|
|
1056
|
+
const real = rows.filter((row) => !/^Dismissed\b/.test(plain(row.at(-1) ?? ""))).length;
|
|
1057
|
+
return [...declared === void 0 ? [] : [...declared.raised === rows.length ? [] : [`its reviewer table counts ${declared.raised} raised findings, where its findings table has ${rows.length} rows`], ...declared.real === real ? [] : [`its reviewer table counts ${declared.real} real findings, where its findings table has ${real} not dismissed`]], ...rows.flatMap((row) => {
|
|
1058
|
+
if (row.length !== findingColumns.length) return [`its finding row "| ${row.join(" | ")} |" has ${row.length} cells, where its table has ${findingColumns.length}: write a "|" inside a cell as "\\|"`];
|
|
1059
|
+
const [number = "", , , sev = "", , , , state = ""] = row;
|
|
1060
|
+
const severity = plain(sev).toUpperCase();
|
|
1061
|
+
return /^P[01]$/.test(severity) && !settled.test(plain(state)) ? [`its ${severity} finding ${number} is "${state}", where a P0 or P1 is fixed, filed or kept before merge`] : [];
|
|
1062
|
+
})];
|
|
1063
|
+
};
|
|
700
1064
|
/** A session comment's types run and not run, and what's wrong with its lines. */
|
|
701
1065
|
const readSession = (comment, covered, settings = defaults) => {
|
|
702
1066
|
const body = comment.replace(/\r/g, "");
|
|
@@ -705,8 +1069,12 @@ const readSession = (comment, covered, settings = defaults) => {
|
|
|
705
1069
|
const counts = countsOf(lines);
|
|
706
1070
|
const counted = counts?.counted ?? 0;
|
|
707
1071
|
const problems = [];
|
|
708
|
-
const
|
|
1072
|
+
const rounds = counts?.rounds ?? 0;
|
|
1073
|
+
if (rounds < 1 || rounds > maxRounds) problems.push(`its first table counts ${rounds} rounds, where a session runs 1 to ${maxRounds}, as the review skill's findings.md says`);
|
|
1074
|
+
const table = counts && tableAt(lines, reviewerColumns, counts.end);
|
|
1075
|
+
const rows = table?.rows ?? [];
|
|
709
1076
|
const reviewerEntries = rows.flatMap((row) => {
|
|
1077
|
+
if (row.length === reviewerColumns.length && (row[1] ?? "") === "") problems.push(`its reviewer "${row[0] ?? ""}" names no model in its Model cell`);
|
|
710
1078
|
if (row.length === reviewerColumns.length) return [`${row[0] ?? ""}: ${row[2] ?? ""}`];
|
|
711
1079
|
problems.push(`its reviewer row "| ${row.join(" | ")} |" has ${row.length} cells, where its table has ${reviewerColumns.length}: write a "|" inside a cell as "\\|"`);
|
|
712
1080
|
return [];
|
|
@@ -731,6 +1099,14 @@ const readSession = (comment, covered, settings = defaults) => {
|
|
|
731
1099
|
});
|
|
732
1100
|
const missing = covered ? settings.consideredTypes.filter((type) => !reviewers.includes(type) && !notRun.includes(type)) : [];
|
|
733
1101
|
if (missing.length > 0) problems.push(`it names neither as run nor, on its "Not run:" line with why, ${missing.join(", ")}`);
|
|
1102
|
+
const tallies = rows.filter((row) => row.length === reviewerColumns.length);
|
|
1103
|
+
const numbers = tallies.flatMap((row) => [row[3] ?? "", row[4] ?? ""]);
|
|
1104
|
+
if (!numbers.every((cell) => /^\d+$/.test(cell))) problems.push(`its reviewer table's Raised and Real cells aren't each a count`);
|
|
1105
|
+
const declared = numbers.every((cell) => /^\d+$/.test(cell)) ? {
|
|
1106
|
+
raised: tallies.reduce((sum, row) => sum + Number(row[3]), 0),
|
|
1107
|
+
real: tallies.reduce((sum, row) => sum + Number(row[4]), 0)
|
|
1108
|
+
} : void 0;
|
|
1109
|
+
problems.push(...openFindings(lines, table?.end ?? 0, declared));
|
|
734
1110
|
const throughs = body.split("\n").filter((line) => line.startsWith("Through:"));
|
|
735
1111
|
const through = throughs.length === 1 ? throughLine.exec(throughs[0] ?? "")?.[1] : void 0;
|
|
736
1112
|
if (throughs.length > 1) problems.push(`it has ${throughs.length} "Through:" lines, where one names its commit`);
|
|
@@ -739,7 +1115,7 @@ const readSession = (comment, covered, settings = defaults) => {
|
|
|
739
1115
|
head,
|
|
740
1116
|
sha: through ?? sessionLine.exec(head)?.[1] ?? "",
|
|
741
1117
|
counted,
|
|
742
|
-
rounds
|
|
1118
|
+
rounds,
|
|
743
1119
|
reviewers,
|
|
744
1120
|
notRun,
|
|
745
1121
|
problems
|
|
@@ -760,7 +1136,7 @@ const unreviewed = (record, sessions, covered, matches) => {
|
|
|
760
1136
|
if (since === void 0) return [`The session "${session.head}": its "Through:" commit, ${session.sha}, isn't in the repo's history, as after a force push, so nothing shows what it reviewed or what came after it. ${ways}`];
|
|
761
1137
|
if (!since.ancestor) continue;
|
|
762
1138
|
const changed = since.commits.flatMap((commit) => {
|
|
763
|
-
const files = commit.files.filter((file) => matches(file) && (covered.
|
|
1139
|
+
const files = commit.files.filter((file) => matches(file) && (covered.has(file) || !record.holds(file)));
|
|
764
1140
|
return files.length === 0 ? [] : [{
|
|
765
1141
|
commit,
|
|
766
1142
|
files
|
|
@@ -773,6 +1149,15 @@ const unreviewed = (record, sessions, covered, matches) => {
|
|
|
773
1149
|
}
|
|
774
1150
|
return [`No session's "Through:" commit is in the head's history, ${sessions.map((session) => session.sha).join(", ")}, as after a force push. ${ways}`];
|
|
775
1151
|
};
|
|
1152
|
+
/**
|
|
1153
|
+
* Whether a session's `Through:` commit covers `files`: it's in the head's history, and none of the
|
|
1154
|
+
* pull request's own commits after it changes one of them by hand.
|
|
1155
|
+
*/
|
|
1156
|
+
const freshFor = (record, session, files) => {
|
|
1157
|
+
const since = record.since(session.sha);
|
|
1158
|
+
const watched = new Set(files);
|
|
1159
|
+
return since?.ancestor === true && since.commits.every((commit) => !commit.files.some((file) => watched.has(file)));
|
|
1160
|
+
};
|
|
776
1161
|
/** A record's net lines of production source and its tier floor, as CI and each subcommand read them. */
|
|
777
1162
|
const recordFloor = (record) => {
|
|
778
1163
|
const settings = record.settings ?? defaults;
|
|
@@ -783,7 +1168,15 @@ const recordFloor = (record) => {
|
|
|
783
1168
|
};
|
|
784
1169
|
};
|
|
785
1170
|
/** Whether the review is on record: what passed it, or each reason it isn't. */
|
|
786
|
-
const verdict = (
|
|
1171
|
+
const verdict = (given) => {
|
|
1172
|
+
const known = /* @__PURE__ */ new Map();
|
|
1173
|
+
const record = {
|
|
1174
|
+
...given,
|
|
1175
|
+
since: (sha) => {
|
|
1176
|
+
if (!known.has(sha)) known.set(sha, given.since(sha));
|
|
1177
|
+
return known.get(sha);
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
787
1180
|
const settings = record.settings ?? defaults;
|
|
788
1181
|
const body = record.body.replace(/\r/g, "");
|
|
789
1182
|
const listed = record.changes.length;
|
|
@@ -838,20 +1231,23 @@ const verdict = (record) => {
|
|
|
838
1231
|
};
|
|
839
1232
|
}
|
|
840
1233
|
for (const session of sessions) for (const problem of session.problems) errors.push(`The session "${session.head}": ${problem}.`);
|
|
841
|
-
const vouched = [.../* @__PURE__ */ new Set([...
|
|
842
|
-
const fresh = vouched.length > 0 ? vouched : record.changes.map((change) => change.filename);
|
|
843
|
-
errors.push(...unreviewed(record, sessions, fresh, (path) => matches(path) || fresh.
|
|
844
|
-
const
|
|
1234
|
+
const vouched = [.../* @__PURE__ */ new Set([...pathsIn(record.changes, matches), ...floor.files])];
|
|
1235
|
+
const fresh = new Set(vouched.length > 0 ? vouched : record.changes.map((change) => change.filename));
|
|
1236
|
+
errors.push(...unreviewed(record, sessions, fresh, (path) => matches(path) || fresh.has(path)));
|
|
1237
|
+
const testFiles = tests.map((file) => file.file);
|
|
1238
|
+
const testPaths = pathsIn(record.changes, (path) => isTestCode(path, settings));
|
|
1239
|
+
const testsReviewed = sessions.some((session) => session.reviewers.includes("tests") && freshFor(record, session, testPaths));
|
|
1240
|
+
const stale = (type, files) => sessions.some((session) => session.reviewers.includes(type)) && !sessions.some((session) => session.reviewers.includes(type) && freshFor(record, session, files)) ? ` A session has a ${type} reviewer, but each such session's "Through:" commit is before a commit that changed ${some(files)}, or out of the head's history: run ${type} at the head.` : "";
|
|
845
1241
|
if (tier === "medium") {
|
|
846
|
-
for (const session of sessions.filter((each) => each.counted !== 1 || each.rounds !== 1)) errors.push(`The session "${session.head}": a medium pull request's session has 1 reviewer and 1 round, where it counts ${session.counted} and ${session.rounds}. Name "Merge risk: high" for the full session.`);
|
|
847
1242
|
const risks = testRisks(record.changes, settings);
|
|
848
|
-
if (risks.length > 0 && !testsReviewed) errors.push(`Its tests put it at medium or above, since ${some(risks)}, so its reviewer is a tests one: give a session's reviewer table a "tests" row
|
|
849
|
-
else if (missingBreaks.length > 0 && !testsReviewed) errors.push(`It changes test code with no tests reviewer and no break on record for ${some(missingBreaks)}. Make the session's reviewer a tests one, or add a "Break:" line to the body for each file
|
|
1243
|
+
if (risks.length > 0 && !testsReviewed) errors.push(`Its tests put it at medium or above, since ${some(risks)}, so its reviewer is a tests one: give a session's reviewer table a "tests" row.${stale("tests", testPaths)}`);
|
|
1244
|
+
else if (missingBreaks.length > 0 && !testsReviewed) errors.push(`It changes test code with no tests reviewer and no break on record for ${some(missingBreaks)}. Make the session's reviewer a tests one, or add a "Break:" line to the body for each file.${stale("tests", testPaths)}`);
|
|
850
1245
|
}
|
|
851
1246
|
if (tier === "low") errors.push(...lowBreaks);
|
|
852
1247
|
if (tier === "high") {
|
|
853
|
-
|
|
854
|
-
if (
|
|
1248
|
+
const production = pathsIn(record.changes, (path) => isProductionSource(path, settings));
|
|
1249
|
+
if (net >= 1e3 && !sessions.some((session) => session.reviewers.includes("code quality") && freshFor(record, session, production))) errors.push(`This change adds ${net} net lines of production source, ${largeChange} or more, so a session needs a code quality reviewer in its reviewer table.${stale("code quality", production)}`);
|
|
1250
|
+
if (tests.length > 0 && !testsReviewed) errors.push(`This pull request changes test code: ${some(testFiles)}. Add a tests reviewer to a session's reviewer table: a high pull request that changes test code needs one.${stale("tests", testPaths)}`);
|
|
855
1251
|
}
|
|
856
1252
|
if (errors.length > 0) return {
|
|
857
1253
|
ok: false,
|
|
@@ -895,6 +1291,14 @@ const changesOf = (numstat) => {
|
|
|
895
1291
|
}
|
|
896
1292
|
return changes;
|
|
897
1293
|
};
|
|
1294
|
+
/**
|
|
1295
|
+
* Whether the gate keeps a change's patch: test code, whose edits `testRisks` reads, and a file the
|
|
1296
|
+
* base's list covers, or production source with no list, that `commentOnly` may read as comments.
|
|
1297
|
+
*/
|
|
1298
|
+
const patchRead = (list, settings) => {
|
|
1299
|
+
const listed = list === void 0 ? (path) => isProductionSource(path, settings) : coveredBy(list);
|
|
1300
|
+
return (change) => pathsOf(change).some((path) => isTestCode(path, settings)) || commentReadable(change) && listed(change.filename);
|
|
1301
|
+
};
|
|
898
1302
|
/** GitHub's word for each status letter `git diff --name-status` prints. */
|
|
899
1303
|
const statuses = /* @__PURE__ */ new Map([
|
|
900
1304
|
["A", "added"],
|
|
@@ -906,9 +1310,10 @@ const statuses = /* @__PURE__ */ new Map([
|
|
|
906
1310
|
]);
|
|
907
1311
|
/**
|
|
908
1312
|
* A branch's changes between two commits, as `recordOf` reads them from GitHub: `changesOf`'s, each
|
|
909
|
-
* with its status, and its patch when
|
|
1313
|
+
* with its status, and its patch when `patchRead` keeps it, for `--count`.
|
|
910
1314
|
*/
|
|
911
|
-
const localChangesOf = (git, from, to, settings) => {
|
|
1315
|
+
const localChangesOf = (git, from, to, settings, list) => {
|
|
1316
|
+
const readsPatch = patchRead(list, settings);
|
|
912
1317
|
const fields = printed(git, [
|
|
913
1318
|
"diff",
|
|
914
1319
|
"--name-status",
|
|
@@ -935,7 +1340,10 @@ const localChangesOf = (git, from, to, settings) => {
|
|
|
935
1340
|
])).map((change) => {
|
|
936
1341
|
const status = statusOf.get(change.filename) ?? "modified";
|
|
937
1342
|
const paths = [change.previous_filename, change.filename].filter((path) => path !== void 0);
|
|
938
|
-
if (!
|
|
1343
|
+
if (!readsPatch({
|
|
1344
|
+
...change,
|
|
1345
|
+
status
|
|
1346
|
+
})) return {
|
|
939
1347
|
...change,
|
|
940
1348
|
status
|
|
941
1349
|
};
|
|
@@ -1259,7 +1667,9 @@ const contentsAt = (github, repo, path, ref) => github([
|
|
|
1259
1667
|
*/
|
|
1260
1668
|
const recordOf = (github, git, repo, pull, base, head) => {
|
|
1261
1669
|
const settings = settingsFrom(contentsAt(github, repo, settingsPath, base));
|
|
1670
|
+
const list = contentsAt(github, repo, listPath, base);
|
|
1262
1671
|
const isTest = (path) => isTestCode(path, settings);
|
|
1672
|
+
const readsPatch = patchRead(list, settings);
|
|
1263
1673
|
const login = found(github, [
|
|
1264
1674
|
`repos/${repo}/pulls/${pull}`,
|
|
1265
1675
|
"--jq",
|
|
@@ -1289,7 +1699,11 @@ const recordOf = (github, git, repo, pull, base, head) => {
|
|
|
1289
1699
|
]),
|
|
1290
1700
|
changes: items(github, `repos/${repo}/pulls/${pull}/files`, ".[] | {filename, additions, deletions, previous_filename, status, patch} | with_entries(select(.value != null)) | tojson").map(({ patch, ...change }) => {
|
|
1291
1701
|
const from = change.previous_filename;
|
|
1292
|
-
if (!
|
|
1702
|
+
if (!readsPatch(change)) return change;
|
|
1703
|
+
if (!isTest(change.filename) && (from === void 0 || !isTest(from))) return patch === void 0 ? change : {
|
|
1704
|
+
...change,
|
|
1705
|
+
patch
|
|
1706
|
+
};
|
|
1293
1707
|
return patch === void 0 && from !== void 0 && sameBlob(git, base, head, from, change.filename) ? {
|
|
1294
1708
|
...change,
|
|
1295
1709
|
patch: ""
|
|
@@ -1298,7 +1712,7 @@ const recordOf = (github, git, repo, pull, base, head) => {
|
|
|
1298
1712
|
patch
|
|
1299
1713
|
};
|
|
1300
1714
|
}),
|
|
1301
|
-
list
|
|
1715
|
+
list,
|
|
1302
1716
|
benched: settings.benchedPaths === void 0 ? void 0 : contentsAt(github, repo, settings.benchedPaths, base),
|
|
1303
1717
|
head,
|
|
1304
1718
|
pull: Number(pull),
|
|
@@ -1332,12 +1746,13 @@ const branchRecordOf = (git, comments = [], body = "") => {
|
|
|
1332
1746
|
`${tip}:${path}`
|
|
1333
1747
|
]) : void 0;
|
|
1334
1748
|
const settings = settingsFrom(atTip(settingsPath));
|
|
1749
|
+
const list = atTip(listPath);
|
|
1335
1750
|
return {
|
|
1336
1751
|
settings,
|
|
1337
1752
|
comments,
|
|
1338
1753
|
body,
|
|
1339
|
-
changes: localChangesOf(git, base, head, settings),
|
|
1340
|
-
list
|
|
1754
|
+
changes: localChangesOf(git, base, head, settings, list),
|
|
1755
|
+
list,
|
|
1341
1756
|
benched: settings.benchedPaths === void 0 ? void 0 : atTip(settings.benchedPaths),
|
|
1342
1757
|
head,
|
|
1343
1758
|
since: historyOf(git, tip, head),
|