@ref0/workspace 0.12.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
@@ -131,6 +131,29 @@ WSL2. `taskSources({ root, packages, apps })` gives `builtFrom(import.meta.url,
131
131
  the config's package and every workspace package it depends on, and `readsAll(command)`, keyed by
132
132
  every file. Each puts `env REF0_SOURCES=<hash>` before each command `&&` joins.
133
133
 
134
+ ## TypeScript
135
+
136
+ A repo's base `tsconfig` extends one preset, so an option the team adopts reaches every repo in the
137
+ release that adds it:
138
+
139
+ | Preset | What it holds |
140
+ | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
141
+ | `@ref0/workspace/tsconfig/base.json` | The strict options: `strict`, `exactOptionalPropertyTypes`, `noUncheckedIndexedAccess`, `verbatimModuleSyntax`, `isolatedModules`, the unused, fallthrough, return and override checks, and ES2023 |
142
+ | `@ref0/workspace/tsconfig/bundler.json` | The base, with `module: ESNext` and `moduleResolution: Bundler`, for code a bundler builds |
143
+ | `@ref0/workspace/tsconfig/node-next.json` | The base, with `module` and `moduleResolution` `NodeNext`, for code Node runs as it is |
144
+
145
+ ```jsonc
146
+ {
147
+ "extends": "@ref0/workspace/tsconfig/bundler.json",
148
+ "compilerOptions": {
149
+ "customConditions": ["@ref0/source"],
150
+ "plugins": [{ "name": "@effect/language-service" }],
151
+ },
152
+ }
153
+ ```
154
+
155
+ The repo keeps what's its own: `lib`, `types`, `paths`, `customConditions`, `noEmit`, its includes and references, and the Effect language service's options, since a config's `plugins` replaces the one it extends.
156
+
134
157
  ## Checks
135
158
 
136
159
  `ref0-workspace <check>`, from anywhere in the repo's checkout:
@@ -231,6 +254,25 @@ the repo's `.agents/repo/review.md` say. Its body names a tier on a `Merge risk:
231
254
  its floor, the highest tier its changed lines, the always-review list and its test code give it,
232
255
  and the gate checks the session comment or `Break:` lines that tier needs.
233
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
+
234
276
  - Bare, in CI: judges pull request `PR` of `GITHUB_REPOSITORY`, from `BASE` to `HEAD`, reading
235
277
  GitHub with `gh` and `GH_TOKEN`, and the history from the Git checkout it runs in, which holds
236
278
  both commits whole, blobs aside. It prints each reason it fails as an Actions `::error::`.
@@ -259,6 +301,8 @@ began with, and the file holds no other:
259
301
  | `testHelpers` | Shared test helpers, test code too whether `testCode` names them or not, whose change puts a pull request at medium (`*/testing/*`) |
260
302
  | `benchedPaths` | The bench list's path, whose `<case> <glob>` lines tie source to the bench cases that time it (none: no bench) |
261
303
  | `benchRuns` | Files under a `testing/` folder that a bench case runs all the same (none) |
304
+ | `sizeUncounted` | Generated files, as globs, whose lines the size floor leaves out, though the always-review list and the test code rules still read them; a list replaces the default, so name the lock in it too (`pnpm-lock.yaml`) |
305
+ | `botBranches` | Head branches, as globs, from which a bot's pull request in the repo itself, never a fork's, counts as from someone who may push, as a release's from `release/next` does, so a low one needs no session (none) |
262
306
 
263
307
  ```json
264
308
  { "benchedPaths": "bench/benched-paths.txt", "lowTierLines": 200 }
@@ -272,6 +316,13 @@ install of that version with no peers, which loads no peer, in a blobless clone
272
316
  the head, so a pull request can't change the gate that judges it:
273
317
 
274
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
275
326
  - name: Fetch review-record history
276
327
  id: fetch
277
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 alone, from the first `@@` line: GitHub leaves it out of a file
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. Its body names its tier on a `Merge risk:` line, at the floor or above, and the
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 whose first table counts 1 reviewer and 1 round. Its reviewer is a tests one
19
- * when the floor is from `testRisks`, and a tests one or a `Break:` line for each when it edits
20
- * test code otherwise.
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
@@ -47,8 +51,9 @@ import { env } from "node:process";
47
51
  *
48
52
  * A bot's comment doesn't count, and a session counts only from someone who may push to the repo,
49
53
  * since anyone may comment once it's public. A pull request whose author may not push needs a
50
- * session at any tier, as review.md says. It reads GitHub with `gh`, and the head's history with
51
- * `git` from the checkout that holds it, whole.
54
+ * session at any tier, as review.md says, unless it's a bot's from a branch the base's `botBranches`
55
+ * names in the repo itself. It reads GitHub with `gh`, and the head's history with `git` from the
56
+ * checkout that holds it, whole.
52
57
  */
53
58
  /** Net lines of production source from which a change is large and needs a code quality reviewer. */
54
59
  const largeChange = 1e3;
@@ -126,16 +131,49 @@ const breakLine = /^(?:[-*] )?(?:\*\*)?Break:(?:\*\*)?[ \t]*\S.*$/gm;
126
131
  const testRow = /^\s*(?:it|test|describe|bench)(?:\.\w+)*\s*\(/;
127
132
  /** A test's line that skips a row, or runs one alone, which skips the rest. */
128
133
  const skipping = /\.(?:skip|todo|only|skipIf|runIf)\b|\b(?:skipIf|runIf)\s*\(/;
129
- /** A test's line that sets a timeout or a retry, which may loosen it. */
130
- const loosening = /\b(?:timeout|testTimeout|hookTimeout|retry|retries)\b\s*[:=]/;
131
- /** A line that ends a call with a number, as `it(name, run, 60_000)` or `}, 60_000);` give a timeout. */
132
- const positional = /,\s*(\d[\d_]*)(\s*\)[\s;,]*)$/;
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 = /^[\]})]+$/;
133
159
  /** A line that `.each(` starts, whose cases a patch can't count. */
134
160
  const tableCall = /\.each\s*[(`]/;
135
161
  /** A line shaped like a table's case: a string, tuple or object row, a bare number, or a spread. */
136
162
  const tableCase = /^\s*(?:[[{].*[\]}]|(['"`]).*\1|-?\d[\d_.]*|\.\.\.[\w$.]+),?\s*$/;
137
- /** An import's first or last line, which may bring a table's cases in. */
138
- const importLine = /^\s*(?:import\b|\}\s*from\b)/;
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:/;
139
177
  const fixtures = /\/fixtures\//;
140
178
  /**
141
179
  * Whether a path is production source, as the review skill counts a large change: one the settings'
@@ -222,6 +260,10 @@ const filesIn = (changes, matches) => changes.flatMap((change) => {
222
260
  lines
223
261
  }] : [];
224
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) : []);
225
267
  /**
226
268
  * The test code a change touches, as `filesIn` reads it, with its changed lines: a test file moved
227
269
  * with no edits is still one, at 0 lines, so it still needs a tests reviewer or a recorded break.
@@ -233,10 +275,11 @@ const testChangesOf = (changes, settings) => {
233
275
  lines: files.reduce((sum, file) => sum + file.lines, 0)
234
276
  };
235
277
  };
236
- /** Generated files a pull request's size leaves out, though the always-review list may name them. */
237
- const uncounted = ["pnpm-lock.yaml"];
238
- /** A pull request's changed lines, additions plus deletions, as the tier limits count them. */
239
- const changedLines = (changes) => changes.filter((change) => !uncounted.includes(change.filename)).reduce((sum, change) => sum + change.additions + change.deletions, 0);
278
+ /**
279
+ * A pull request's changed lines, additions plus deletions, as the tier limits count them, without
280
+ * the generated files the settings' `sizeUncounted` names.
281
+ */
282
+ const changedLines = (changes, settings = defaults) => changes.filter((change) => !matchesAny(settings.sizeUncounted)(change.filename)).reduce((sum, change) => sum + change.additions + change.deletions, 0);
240
283
  /** A patch's hunks, from its first `@@` line, past any header a git diff prints. */
241
284
  const hunksOf = (patch) => {
242
285
  const hunks = [];
@@ -245,43 +288,302 @@ const hunksOf = (patch) => {
245
288
  header: line,
246
289
  kept: [],
247
290
  added: [],
248
- removed: []
291
+ removed: [],
292
+ before: [],
293
+ after: []
249
294
  });
250
295
  const hunk = hunks.at(-1);
251
296
  if (hunk === void 0 || line.startsWith("@@")) continue;
252
- if (line.startsWith("+")) hunk.added.push(line.slice(1));
253
- else if (line.startsWith("-")) hunk.removed.push(line.slice(1));
254
- else hunk.kept.push(line.slice(1));
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
+ }
255
321
  }
256
322
  return hunks;
257
323
  };
324
+ /** A timeout in milliseconds, where 0 is none at all, as Vitest reads it. */
325
+ const timeoutOf = (ms) => ms === 0 ? Infinity : ms;
258
326
  /** A number as a test writes it, `60_000` among them. */
259
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
+ ];
260
335
  /**
261
- * The added lines that raise a positional timeout, the number a call to `it`, `test` or `describe`
262
- * ends with: a removed line, the same but for its number, held a lower one or none.
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.
263
338
  */
264
- const raisedTimeouts = (hunk) => hunk.added.filter((line) => {
265
- const now = positional.exec(line);
266
- if (now === null) return false;
267
- const call = line.slice(0, now.index).trim();
268
- const after = numberOf(now[1] ?? "0");
269
- return hunk.removed.some((before) => {
270
- const was = positional.exec(before);
271
- return was === null ? before.trim() === `${call}${now[2] ?? ""}`.trim() : before.slice(0, was.index).trim() === call && numberOf(was[1] ?? "0") < after;
272
- });
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
+ }];
273
379
  });
274
380
  /**
275
- * The removed lines that may drop a test's case, a table's case, an `.each(` line or an import, with
276
- * no identical line added back anywhere in the file, as a move within it adds one.
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.
277
498
  */
278
499
  const lostCases = (hunks) => {
279
500
  const added = new Set(hunks.flatMap((hunk) => hunk.added).map((line) => line.trim()));
280
- return hunks.flatMap((hunk) => hunk.removed).filter((line) => [
281
- tableCase,
282
- tableCall,
283
- importLine
284
- ].some((pattern) => pattern.test(line)) && !added.has(line.trim()));
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));
285
587
  };
286
588
  /** At most `count` of a list's items, then how many more. */
287
589
  const some = (items, count = 3) => items.length <= count ? items.join(", ") : `${items.slice(0, count).join(", ")} and ${items.length - count} more`;
@@ -300,14 +602,17 @@ const riskyTests = (changes, settings) => {
300
602
  const isHelper = matchesAny(settings.testHelpers);
301
603
  const risks = [];
302
604
  const rowFiles = [];
605
+ const expectFiles = [];
303
606
  let rowsAdded = 0;
304
607
  let rowsRemoved = 0;
608
+ let expectsAdded = 0;
609
+ let expectsRemoved = 0;
305
610
  for (const change of changes) {
306
611
  const from = change.previous_filename;
307
612
  const file = change.filename;
308
613
  if (!isTest(file) && (from === void 0 || !isTest(from))) continue;
309
614
  const risk = (why) => risks.push({
310
- files: [file],
615
+ files: pathsOf(change),
311
616
  why
312
617
  });
313
618
  if (change.status === "removed") risk(`it deletes the test file ${file}`);
@@ -321,20 +626,30 @@ const riskyTests = (changes, settings) => {
321
626
  const hunks = hunksOf(change.patch);
322
627
  const added = hunks.flatMap((hunk) => hunk.added);
323
628
  const removed = hunks.flatMap((hunk) => hunk.removed);
629
+ const moved = new Set(removed.map((line) => line.trim()));
324
630
  const skips = added.filter((line) => skipping.test(line));
325
- const loosens = [...added.filter((line) => loosening.test(line)), ...hunks.flatMap(raisedTimeouts)];
631
+ const loosens = hunks.flatMap((hunk) => [...raisedLimits(hunk, moved), ...raisedTimeouts(hunk, moved)]);
326
632
  if (skips.length > 0) risk(`it skips a test in ${file}: "${skips[0]?.trim()}"`);
327
- if (loosens.length > 0) risk(`it sets a timeout or a retry in ${file}: "${loosens[0]?.trim()}"`);
633
+ if (loosens.length > 0) risk(`it raises a timeout or a retry in ${file}: "${loosens[0]?.trim()}"`);
328
634
  const lost = change.status === "added" ? [] : lostCases(hunks);
329
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()}"`);
330
638
  rowsAdded += added.filter((line) => testRow.test(line)).length;
331
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;
332
642
  if (removed.some((line) => testRow.test(line))) rowFiles.push(file);
643
+ if (removed.some((line) => assertCall.test(line))) expectFiles.push(file);
333
644
  }
334
645
  if (rowsRemoved > rowsAdded) risks.push({
335
646
  files: rowFiles,
336
647
  why: `it takes away ${rowsRemoved - rowsAdded} more test rows than it adds`
337
648
  });
649
+ if (expectsRemoved > expectsAdded) risks.push({
650
+ files: expectFiles,
651
+ why: `it takes away ${expectsRemoved - expectsAdded} more assertion lines than it adds`
652
+ });
338
653
  return risks;
339
654
  };
340
655
  /**
@@ -348,8 +663,8 @@ const floorOf = (changes, list, net = 0, settings = defaults) => {
348
663
  const { lowTierLines, highTierLines } = settings;
349
664
  const isProduction = (path) => isProductionSource(path, settings);
350
665
  const tierAt = list === void 0 ? (path) => isProduction(path) ? "high" : void 0 : tierOf(list);
351
- const lines = changedLines(changes);
352
- const counted = changes.flatMap((change) => uncounted.includes(change.filename) ? [] : [change.filename]);
666
+ const lines = changedLines(changes, settings);
667
+ const counted = changes.flatMap((change) => matchesAny(settings.sizeUncounted)(change.filename) ? [] : pathsOf(change));
353
668
  const reasons = [];
354
669
  if (net >= 1e3) reasons.push({
355
670
  tier: "high",
@@ -366,12 +681,19 @@ const floorOf = (changes, list, net = 0, settings = defaults) => {
366
681
  why: `${lines} changed lines, over ${lowTierLines}`,
367
682
  files: counted
368
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
+ });
369
691
  for (const tier of ["high", "medium"]) {
370
- const files = changes.flatMap((change) => highest([tierAt(change.filename), change.previous_filename === void 0 ? void 0 : tierAt(change.previous_filename)]) === tier ? [change.previous_filename ?? change.filename] : []);
371
- if (files.length > 0) reasons.push({
692
+ const at = listed.flatMap((each) => each.tier === tier ? [each.change] : []);
693
+ if (at.length > 0) reasons.push({
372
694
  tier,
373
- why: `${some(files)} on the base's review-paths.txt at ${tier}${list === void 0 ? ", which the base lacks, so every production file is" : ""}`,
374
- files: changes.flatMap((change) => files.includes(change.previous_filename ?? change.filename) ? [change.filename] : [])
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)
375
697
  });
376
698
  }
377
699
  for (const risk of riskyTests(changes, settings)) reasons.push({
@@ -440,6 +762,70 @@ const linkOf = (token) => {
440
762
  */
441
763
  const holdsReading = (line) => /\blocal\b/i.test(line) || line.split(/[\s|]+/).some((token) => runLink.test(linkOf(token)));
442
764
  /**
765
+ * A batch line's ending, after its case's name: the Coordinator's rule that a case with no local
766
+ * form goes unbenched on a pull request and is read in ci-bench's batch run on main.
767
+ */
768
+ const batchSkip = ": not run, read in the batch run on main (Coordinator)";
769
+ /** A batch line, whole: a case's name, in backticks or not, as a list item or not, then `batchSkip`. */
770
+ const batchLine = new RegExp(`^(?:[-*+] )?(\`?)([\\w.-]+)\\1${batchSkip.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`);
771
+ /** The case a line leaves to the batch run on main, as `batchLine` reads it, or `undefined`. */
772
+ const batchCaseOf = (line) => batchLine.exec(line.trim())?.[2];
773
+ /** The columns a line is indented by, a tab to the next stop of 4, as CommonMark counts them. */
774
+ const indentOf = (line) => {
775
+ let column = 0;
776
+ for (const char of line) if (char === " ") column += 1;
777
+ else if (char === " ") column += 4 - column % 4;
778
+ else break;
779
+ return column;
780
+ };
781
+ /** A list item's marker, and the spaces after it: its length from the line's indent is its content's. */
782
+ const listMarker = /^(?:[-*+]|\d{1,9}[.)])(?: +|$)/;
783
+ /** Text with its HTML comments and fenced code blocks taken out, as GitHub shows neither as prose. */
784
+ const withoutHidden = (text) => {
785
+ const shown = [];
786
+ let from = 0;
787
+ let at = 0;
788
+ while (at < text.length) {
789
+ fenceOpen.lastIndex = at;
790
+ const fence = at === 0 || text[at - 1] === "\n" ? fenceOpen.exec(text) : null;
791
+ const hidden = fence !== null ? pastFence(text, fenceOpen.lastIndex, fence[1] ?? "```") : text.startsWith("<!--", at) ? text.indexOf("-->", at + 4) : void 0;
792
+ if (hidden === void 0) {
793
+ at += 1;
794
+ continue;
795
+ }
796
+ shown.push(text.slice(from, at));
797
+ if (hidden === -1) return shown.join("");
798
+ at = fence !== null ? hidden : hidden + 3;
799
+ from = at;
800
+ }
801
+ shown.push(text.slice(from));
802
+ return shown.join("");
803
+ };
804
+ /**
805
+ * The lines of a body's fold that GitHub shows as prose: none inside an HTML comment or a code
806
+ * block, fenced or indented, so an example of a line never reads as the line itself. An indented
807
+ * block is 4 columns past the list item it's in, or past the margin outside any, after a blank line
808
+ * or another of its lines: a list item's own paragraphs, at 2, are prose.
809
+ */
810
+ const shownLines = (fold) => {
811
+ let content = 0;
812
+ let blank = true;
813
+ let code = false;
814
+ return withoutHidden(fold).split("\n").filter((line) => {
815
+ if (line.trim() === "") {
816
+ blank = true;
817
+ return false;
818
+ }
819
+ const indent = indentOf(line);
820
+ code = indent >= content + 4 && (blank || code);
821
+ const marker = code ? null : listMarker.exec(line.trimStart());
822
+ if (marker !== null) content = indent + marker[0].length;
823
+ else if (!code && blank && indent < content) content = 0;
824
+ blank = false;
825
+ return !code;
826
+ });
827
+ };
828
+ /**
443
829
  * Where the body's "Bench and cost" fold opens: a `<details>` tag whose summary reads so, in bold
444
830
  * or not. A tag's name ends at `>` or HTML's own whitespace, so `<details-fake>` or a non-breaking
445
831
  * space opens no fold.
@@ -561,20 +947,24 @@ const provenUnchanged = (line, record, lookup) => {
561
947
  /**
562
948
  * The bench cases the base's `benched-paths.txt` ties the changes to, and why the body's "Bench and
563
949
  * cost" fold doesn't hold a reading for each: a line there that names the case whole and holds a
564
- * run's link or the word local, or a "bundle unchanged" line a run proves, `provenUnchanged`. A
565
- * base with no list ties none.
950
+ * run's link or the word local, a "bundle unchanged" line a run proves, `provenUnchanged`, or the
951
+ * case's batch line, `batchCaseOf`, each of the fold's lines GitHub shows as prose, `shownLines`.
952
+ * `batched` names the cases a batch line carries and no reading does, so the batch run can be
953
+ * checked against what pull requests left to it. A base with no list ties none.
566
954
  */
567
955
  const benchReadings = (body, record, settings) => {
568
956
  if (record.benched === void 0) return {
569
957
  cases: [],
958
+ batched: [],
570
959
  errors: []
571
960
  };
572
961
  const { cases, files } = benchedCases(record.benched, record.changes, settings);
573
- const lines = benchFold(body).split("\n");
962
+ const lines = shownLines(benchFold(body));
574
963
  const claims = lines.filter((line) => unchangedClaim.test(line));
575
964
  const linked = new Set(claims.flatMap(runsOf));
576
965
  if (linked.size > 30) return {
577
966
  cases,
967
+ batched: [],
578
968
  errors: [`Its body's "bundle unchanged" lines link ${linked.size} runs, and review-record reads at most 30: link the one run that benched the set, ci-bench's \`pr\` dispatch.`]
579
969
  };
580
970
  const runs = /* @__PURE__ */ new Map();
@@ -584,10 +974,14 @@ const benchReadings = (body, record, settings) => {
584
974
  };
585
975
  const unproven = claims.filter((line) => !provenUnchanged(line, record, lookup));
586
976
  const readings = lines.filter((line) => (unchangedClaim.test(line) || holdsReading(line)) && !unproven.includes(line));
587
- const missing = cases.filter((name) => !readings.some((line) => names(line, name)));
977
+ const carried = new Set(lines.flatMap((line) => batchCaseOf(line) ?? []));
978
+ const read = (name) => readings.some((line) => names(line, name));
979
+ const batched = cases.filter((name) => carried.has(name) && !read(name));
980
+ const missing = cases.filter((name) => !carried.has(name) && !read(name));
588
981
  return {
589
982
  cases,
590
- errors: [...unproven.map((line) => `Its body's "${line.trim()}" says a bundle is unchanged, and no run it links is ci-bench's on main with a passed "${unchangedJob(unchangedClaim.exec(line)?.[1] ?? "", record.pull ?? 0, record.head)}" job: link the ci-bench run of this pull request that wrote it, \`pr\`'s.`), ...missing.length === 0 ? [] : [`It changes benched paths, ${some(files)}, so its body's "Bench and cost" fold holds a reading for each case ${settings.benchedPaths ?? "the bench list"} ties them to, and holds none for ${some(missing, 5)}. Add a line for each that names the case with its ci-bench run's link, or labelled local for a local pass, as .agents/repo/review.md says.`]]
983
+ batched,
984
+ errors: [...unproven.map((line) => `Its body's "${line.trim()}" says a bundle is unchanged, and no run it links is ci-bench's on main with a passed "${unchangedJob(unchangedClaim.exec(line)?.[1] ?? "", record.pull ?? 0, record.head)}" job: link the ci-bench run of this pull request that wrote it, \`pr\`'s.`), ...missing.length === 0 ? [] : [`It changes benched paths, ${some(files)}, so its body's "Bench and cost" fold holds a reading for each case ${settings.benchedPaths ?? "the bench list"} ties them to, and holds none for ${some(missing, 5)}. Add a line for each that names the case with its ci-bench run's link, labelled local for a local pass, or as \`<case>${batchSkip}\`, as .agents/repo/review.md says.`]]
591
985
  };
592
986
  };
593
987
  /**
@@ -623,6 +1017,50 @@ const refusal = (entry, label, form, settings) => {
623
1017
  const unknown = unknownTypeOf(entry, settings);
624
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}"`;
625
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
+ };
626
1064
  /** A session comment's types run and not run, and what's wrong with its lines. */
627
1065
  const readSession = (comment, covered, settings = defaults) => {
628
1066
  const body = comment.replace(/\r/g, "");
@@ -631,8 +1069,12 @@ const readSession = (comment, covered, settings = defaults) => {
631
1069
  const counts = countsOf(lines);
632
1070
  const counted = counts?.counted ?? 0;
633
1071
  const problems = [];
634
- const rows = (counts && tableAt(lines, reviewerColumns, counts.end)?.rows) ?? [];
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 ?? [];
635
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`);
636
1078
  if (row.length === reviewerColumns.length) return [`${row[0] ?? ""}: ${row[2] ?? ""}`];
637
1079
  problems.push(`its reviewer row "| ${row.join(" | ")} |" has ${row.length} cells, where its table has ${reviewerColumns.length}: write a "|" inside a cell as "\\|"`);
638
1080
  return [];
@@ -657,6 +1099,14 @@ const readSession = (comment, covered, settings = defaults) => {
657
1099
  });
658
1100
  const missing = covered ? settings.consideredTypes.filter((type) => !reviewers.includes(type) && !notRun.includes(type)) : [];
659
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));
660
1110
  const throughs = body.split("\n").filter((line) => line.startsWith("Through:"));
661
1111
  const through = throughs.length === 1 ? throughLine.exec(throughs[0] ?? "")?.[1] : void 0;
662
1112
  if (throughs.length > 1) problems.push(`it has ${throughs.length} "Through:" lines, where one names its commit`);
@@ -665,7 +1115,7 @@ const readSession = (comment, covered, settings = defaults) => {
665
1115
  head,
666
1116
  sha: through ?? sessionLine.exec(head)?.[1] ?? "",
667
1117
  counted,
668
- rounds: counts?.rounds ?? 0,
1118
+ rounds,
669
1119
  reviewers,
670
1120
  notRun,
671
1121
  problems
@@ -686,7 +1136,7 @@ const unreviewed = (record, sessions, covered, matches) => {
686
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}`];
687
1137
  if (!since.ancestor) continue;
688
1138
  const changed = since.commits.flatMap((commit) => {
689
- const files = commit.files.filter((file) => matches(file) && (covered.includes(file) || !record.holds(file)));
1139
+ const files = commit.files.filter((file) => matches(file) && (covered.has(file) || !record.holds(file)));
690
1140
  return files.length === 0 ? [] : [{
691
1141
  commit,
692
1142
  files
@@ -699,6 +1149,15 @@ const unreviewed = (record, sessions, covered, matches) => {
699
1149
  }
700
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}`];
701
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
+ };
702
1161
  /** A record's net lines of production source and its tier floor, as CI and each subcommand read them. */
703
1162
  const recordFloor = (record) => {
704
1163
  const settings = record.settings ?? defaults;
@@ -709,7 +1168,15 @@ const recordFloor = (record) => {
709
1168
  };
710
1169
  };
711
1170
  /** Whether the review is on record: what passed it, or each reason it isn't. */
712
- const verdict = (record) => {
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
+ };
713
1180
  const settings = record.settings ?? defaults;
714
1181
  const body = record.body.replace(/\r/g, "");
715
1182
  const listed = record.changes.length;
@@ -732,7 +1199,8 @@ const verdict = (record) => {
732
1199
  const { files: tests } = testChangesOf(record.changes, settings);
733
1200
  const missingBreaks = unbroken(body, record.changes, settings);
734
1201
  const bench = benchReadings(body, record, settings);
735
- const benched = bench.cases.length > 0 ? `, with a bench reading for each of ${bench.cases.length} cases` : "";
1202
+ const batched = bench.batched.length > 0 ? `; batch: ${bench.batched.length} cases, ${some(bench.batched, 10)}` : "";
1203
+ const benched = bench.cases.length > 0 ? `, with a bench reading for each of ${bench.cases.length} cases${batched}` : "";
736
1204
  const lowBreaks = missingBreaks.length > 0 ? [`This low-tier pull request changes test code with no break on record for ${some(missingBreaks)}. Add a "Break:" line to the body for each, naming its file, what you broke in the code and that the test failed, as test-audit's authoring gate asks.`] : [];
737
1205
  if (tier === "low" && record.outsider !== true) {
738
1206
  const errors = [...lowBreaks, ...bench.errors];
@@ -763,20 +1231,23 @@ const verdict = (record) => {
763
1231
  };
764
1232
  }
765
1233
  for (const session of sessions) for (const problem of session.problems) errors.push(`The session "${session.head}": ${problem}.`);
766
- const vouched = [.../* @__PURE__ */ new Set([...covered.map((file) => file.file), ...floor.files])];
767
- const fresh = vouched.length > 0 ? vouched : record.changes.map((change) => change.filename);
768
- errors.push(...unreviewed(record, sessions, fresh, (path) => matches(path) || fresh.includes(path)));
769
- const testsReviewed = sessions.some((session) => session.reviewers.includes("tests"));
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.` : "";
770
1241
  if (tier === "medium") {
771
- 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.`);
772
1242
  const risks = testRisks(record.changes, settings);
773
- 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.`);
774
- 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)}`);
775
1245
  }
776
1246
  if (tier === "low") errors.push(...lowBreaks);
777
1247
  if (tier === "high") {
778
- if (net >= 1e3 && !sessions.some((session) => session.reviewers.includes("code quality"))) 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.`);
779
- if (tests.length > 0 && !testsReviewed) errors.push(`This pull request changes test code: ${some(tests.map((file) => file.file))}. Add a tests reviewer to a session's reviewer table: a high pull request that changes test code needs one.`);
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)}`);
780
1251
  }
781
1252
  if (errors.length > 0) return {
782
1253
  ok: false,
@@ -820,6 +1291,14 @@ const changesOf = (numstat) => {
820
1291
  }
821
1292
  return changes;
822
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
+ };
823
1302
  /** GitHub's word for each status letter `git diff --name-status` prints. */
824
1303
  const statuses = /* @__PURE__ */ new Map([
825
1304
  ["A", "added"],
@@ -831,9 +1310,10 @@ const statuses = /* @__PURE__ */ new Map([
831
1310
  ]);
832
1311
  /**
833
1312
  * A branch's changes between two commits, as `recordOf` reads them from GitHub: `changesOf`'s, each
834
- * with its status, and its patch when it's test code, for `--count`.
1313
+ * with its status, and its patch when `patchRead` keeps it, for `--count`.
835
1314
  */
836
- const localChangesOf = (git, from, to, settings) => {
1315
+ const localChangesOf = (git, from, to, settings, list) => {
1316
+ const readsPatch = patchRead(list, settings);
837
1317
  const fields = printed(git, [
838
1318
  "diff",
839
1319
  "--name-status",
@@ -860,7 +1340,10 @@ const localChangesOf = (git, from, to, settings) => {
860
1340
  ])).map((change) => {
861
1341
  const status = statusOf.get(change.filename) ?? "modified";
862
1342
  const paths = [change.previous_filename, change.filename].filter((path) => path !== void 0);
863
- if (!paths.some((path) => isTestCode(path, settings))) return {
1343
+ if (!readsPatch({
1344
+ ...change,
1345
+ status
1346
+ })) return {
864
1347
  ...change,
865
1348
  status
866
1349
  };
@@ -1162,6 +1645,14 @@ const countedComments = (github, repo, pull) => {
1162
1645
  };
1163
1646
  /** The reason a session comment from someone who may not push doesn't count, when there is one. */
1164
1647
  const uncountedNote = (record) => record.uncounted === void 0 || record.uncounted.length === 0 ? "" : `: the sessions from ${record.uncounted.join(", ")} don't count, since they may not push to the repo`;
1648
+ /** The jq filter that reads the rest of a pull request's `PullAuthor`, beside its login. */
1649
+ const headFilter = "{type: .user.type, branch: .head.ref, from: (.head.repo.full_name // \"\")} | tojson";
1650
+ /**
1651
+ * Whether a pull request is a bot's from a branch the settings' `botBranches` names, in `repo`
1652
+ * itself and never a fork: only the repo's own workflows open one there, as a release's does, so its
1653
+ * author counts as one who may push. A bot's on any other branch is an outsider's.
1654
+ */
1655
+ const fromBotBranch = (author, repo, settings) => author.type === "Bot" && author.from.toLowerCase() === repo.toLowerCase() && matchesAny(settings.botBranches)(author.branch);
1165
1656
  /** A file at a commit, through GitHub's contents API, or `undefined` when the commit has none. */
1166
1657
  const contentsAt = (github, repo, path, ref) => github([
1167
1658
  "-H",
@@ -1176,7 +1667,22 @@ const contentsAt = (github, repo, path, ref) => github([
1176
1667
  */
1177
1668
  const recordOf = (github, git, repo, pull, base, head) => {
1178
1669
  const settings = settingsFrom(contentsAt(github, repo, settingsPath, base));
1670
+ const list = contentsAt(github, repo, listPath, base);
1179
1671
  const isTest = (path) => isTestCode(path, settings);
1672
+ const readsPatch = patchRead(list, settings);
1673
+ const login = found(github, [
1674
+ `repos/${repo}/pulls/${pull}`,
1675
+ "--jq",
1676
+ ".user.login"
1677
+ ]).trim();
1678
+ const fromBot = () => settings.botBranches.length > 0 && fromBotBranch({
1679
+ login,
1680
+ ...JSON.parse(found(github, [
1681
+ `repos/${repo}/pulls/${pull}`,
1682
+ "--jq",
1683
+ headFilter
1684
+ ]))
1685
+ }, repo, settings);
1180
1686
  return {
1181
1687
  settings,
1182
1688
  changedFiles: Number(found(github, [
@@ -1185,11 +1691,7 @@ const recordOf = (github, git, repo, pull, base, head) => {
1185
1691
  ".changed_files"
1186
1692
  ])),
1187
1693
  ...countedComments(github, repo, pull),
1188
- outsider: !mayPush(github, repo, found(github, [
1189
- `repos/${repo}/pulls/${pull}`,
1190
- "--jq",
1191
- ".user.login"
1192
- ]).trim()),
1694
+ outsider: !mayPush(github, repo, login) && !fromBot(),
1193
1695
  body: found(github, [
1194
1696
  `repos/${repo}/pulls/${pull}`,
1195
1697
  "--jq",
@@ -1197,7 +1699,11 @@ const recordOf = (github, git, repo, pull, base, head) => {
1197
1699
  ]),
1198
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 }) => {
1199
1701
  const from = change.previous_filename;
1200
- if (!isTest(change.filename) && (from === void 0 || !isTest(from))) return change;
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
+ };
1201
1707
  return patch === void 0 && from !== void 0 && sameBlob(git, base, head, from, change.filename) ? {
1202
1708
  ...change,
1203
1709
  patch: ""
@@ -1206,7 +1712,7 @@ const recordOf = (github, git, repo, pull, base, head) => {
1206
1712
  patch
1207
1713
  };
1208
1714
  }),
1209
- list: contentsAt(github, repo, listPath, base),
1715
+ list,
1210
1716
  benched: settings.benchedPaths === void 0 ? void 0 : contentsAt(github, repo, settings.benchedPaths, base),
1211
1717
  head,
1212
1718
  pull: Number(pull),
@@ -1240,12 +1746,13 @@ const branchRecordOf = (git, comments = [], body = "") => {
1240
1746
  `${tip}:${path}`
1241
1747
  ]) : void 0;
1242
1748
  const settings = settingsFrom(atTip(settingsPath));
1749
+ const list = atTip(listPath);
1243
1750
  return {
1244
1751
  settings,
1245
1752
  comments,
1246
1753
  body,
1247
- changes: localChangesOf(git, base, head, settings),
1248
- list: atTip(listPath),
1754
+ changes: localChangesOf(git, base, head, settings, list),
1755
+ list,
1249
1756
  benched: settings.benchedPaths === void 0 ? void 0 : atTip(settings.benchedPaths),
1250
1757
  head,
1251
1758
  since: historyOf(git, tip, head),
@@ -1253,4 +1760,4 @@ const branchRecordOf = (git, comments = [], body = "") => {
1253
1760
  lines: (path) => linesAt(git, head, path)
1254
1761
  };
1255
1762
  };
1256
- export { benchRunOf, benchWorkflow, benchedCases, branchRecordOf, changedLines, changesOf, countedComments, coveredBy, floorOf, gh, gitIn, githubFileCap, historyOf, isProductionSource, isTestCode, largeChange, netProductionLines, pullChangesOf, readSession, recordFloor, recordOf, testChangesOf, testRisks, testsOnly, tierOf, tiers, unchangedJob, verdict };
1763
+ export { benchRunOf, benchWorkflow, benchedCases, branchRecordOf, changedLines, changesOf, countedComments, coveredBy, floorOf, fromBotBranch, gh, gitIn, githubFileCap, historyOf, isProductionSource, isTestCode, largeChange, netProductionLines, pullChangesOf, readSession, recordFloor, recordOf, testChangesOf, testRisks, testsOnly, tierOf, tiers, unchangedJob, verdict };
@@ -35,6 +35,17 @@ export interface Settings {
35
35
  readonly benchedPaths: string | undefined;
36
36
  /** Files under a `testing/` folder that a bench case runs all the same, so a change to one owes its readings. */
37
37
  readonly benchRuns: ReadonlyArray<string>;
38
+ /**
39
+ * Generated files, as globs, whose lines a pull request's size leaves out, though the
40
+ * always-review list and the test code rules still read them.
41
+ */
42
+ readonly sizeUncounted: ReadonlyArray<string>;
43
+ /**
44
+ * Head branches, as globs, from which a bot's pull request in the repo itself, never a fork's,
45
+ * counts as one from someone who may push: only the repo's own workflows open one there, as a
46
+ * release's does.
47
+ */
48
+ readonly botBranches: ReadonlyArray<string>;
38
49
  }
39
50
  /** `settingsOf`'s settings, which throws on a problem, as the gate does on anything it can't read. */
40
51
  export declare const settingsFrom: (text: string | undefined) => Settings;
@@ -26,7 +26,9 @@ const File = Schema.Struct({
26
26
  testCode: Schema.optionalKey(Globs),
27
27
  testHelpers: Schema.optionalKey(Globs),
28
28
  benchedPaths: Schema.optionalKey(Schema.String),
29
- benchRuns: Schema.optionalKey(Schema.Array(Schema.String))
29
+ benchRuns: Schema.optionalKey(Schema.Array(Schema.String)),
30
+ sizeUncounted: Schema.optionalKey(Globs),
31
+ botBranches: Schema.optionalKey(Globs)
30
32
  });
31
33
  /** Each setting's value when the file leaves it out: ref-0/git's, where the gate began. */
32
34
  const defaults = {
@@ -74,7 +76,9 @@ const defaults = {
74
76
  ],
75
77
  testHelpers: ["*/testing/*"],
76
78
  benchedPaths: void 0,
77
- benchRuns: []
79
+ benchRuns: [],
80
+ sizeUncounted: ["pnpm-lock.yaml"],
81
+ botBranches: []
78
82
  };
79
83
  const decodeFile = Schema.decodeUnknownResult(Schema.fromJsonString(File), { onExcessProperty: "error" });
80
84
  /**
@@ -15,8 +15,8 @@ import { mkdir, readFile, readdir, rename, stat, unlink, utimes, writeFile } fro
15
15
  * A project's key hashes the contents of every file its program read, as tsrs's `--listFiles`
16
16
  * named them, except the packages under `node_modules/.pnpm/`, which the lockfile pins. It also
17
17
  * hashes what decides which files a program reads and how: the lockfile, `pnpm-workspace.yaml`,
18
- * every `package.json` and `tsconfig*.json` in the workspace and each file a config's `extends`
19
- * names, the path of every file a project includes, and tsrs's arguments. So an edit to any file
18
+ * every `package.json` and `tsconfig*.json` in the workspace and each file a config's chain of
19
+ * `extends` reaches, the path of every file a project includes, and tsrs's arguments. So an edit to any file
20
20
  * a program read moves that project's key, and adding, removing or renaming a project's file moves
21
21
  * every key. Contents are hashed rather than dated, since each worktree is a fresh checkout, and
22
22
  * every path is from the worktree's root, so two worktrees at the same contents share a key. A
@@ -37,30 +37,37 @@ const workspaceFiles = (root) => {
37
37
  return walk("");
38
38
  }
39
39
  };
40
+ /** The workspace files `file`'s `extends` names, from the root: those outside it, as a package's, aren't. */
41
+ const extendedBy = (root, file) => {
42
+ const text = (() => {
43
+ try {
44
+ return readFileSync(join(root, file), "utf8");
45
+ } catch {
46
+ return "";
47
+ }
48
+ })();
49
+ return [...(/"extends"\s*:\s*(\[[^\]]*\]|"[^"]*")/.exec(text)?.[1] ?? "").matchAll(/"(\.[^"]*)"/g)].flatMap(([, target = ""]) => {
50
+ const path = relative(root, resolve(root, dirname(file), target));
51
+ return path.startsWith("..") ? [] : [path];
52
+ });
53
+ };
40
54
  /**
41
55
  * The lockfile, the workspace's settings, every `package.json` and `tsconfig*.json` in `files`,
42
- * and each workspace file a config's `extends` names, from the root, sorted: what decides which
43
- * files a resolver reads and how it reads them.
56
+ * and each workspace file a config's chain of `extends` reaches, from the root, sorted: what
57
+ * decides which files a resolver reads and how it reads them.
44
58
  */
45
59
  const manifestInputs = (root, files) => {
46
60
  const manifests = files.filter((file) => {
47
61
  const name = basename(file);
48
62
  return name === "package.json" || /^tsconfig.*\.json$/.test(name);
49
63
  });
50
- const extended = manifests.flatMap((file) => {
51
- if (basename(file) === "package.json") return [];
52
- const text = (() => {
53
- try {
54
- return readFileSync(join(root, file), "utf8");
55
- } catch {
56
- return "";
57
- }
58
- })();
59
- return [...(/"extends"\s*:\s*(\[[^\]]*\]|"[^"]*")/.exec(text)?.[1] ?? "").matchAll(/"(\.[^"]*)"/g)].flatMap(([, target = ""]) => {
60
- const path = relative(root, resolve(root, dirname(file), target));
61
- return path.startsWith("..") ? [] : [path];
62
- });
63
- });
64
+ const extended = /* @__PURE__ */ new Set();
65
+ const toRead = manifests.filter((file) => basename(file) !== "package.json");
66
+ for (let file = toRead.pop(); file !== void 0; file = toRead.pop()) for (const target of extendedBy(root, file)) {
67
+ if (extended.has(target)) continue;
68
+ extended.add(target);
69
+ toRead.push(target);
70
+ }
64
71
  return [.../* @__PURE__ */ new Set([
65
72
  "pnpm-lock.yaml",
66
73
  "pnpm-workspace.yaml",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ref0/workspace",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "The lint and workspace checks every ref-0 repo shares",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -15,6 +15,7 @@
15
15
  "dist",
16
16
  "!dist/**/*.test.*",
17
17
  "!dist/**/fixtures",
18
+ "tsconfig",
18
19
  "README.md",
19
20
  "LICENSE"
20
21
  ],
@@ -40,7 +41,10 @@
40
41
  "./review-record": {
41
42
  "types": "./dist/review-record/index.d.mts",
42
43
  "import": "./dist/review-record/index.mjs"
43
- }
44
+ },
45
+ "./tsconfig/base.json": "./tsconfig/base.json",
46
+ "./tsconfig/bundler.json": "./tsconfig/bundler.json",
47
+ "./tsconfig/node-next.json": "./tsconfig/node-next.json"
44
48
  },
45
49
  "publishConfig": {
46
50
  "access": "public"
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "allowUnreachableCode": false,
5
+ "allowUnusedLabels": false,
6
+ "exactOptionalPropertyTypes": true,
7
+ "isolatedModules": true,
8
+ "moduleDetection": "force",
9
+ "noFallthroughCasesInSwitch": true,
10
+ "noImplicitOverride": true,
11
+ "noImplicitReturns": true,
12
+ "noUncheckedIndexedAccess": true,
13
+ "noUnusedLocals": true,
14
+ "noUnusedParameters": true,
15
+ "skipLibCheck": true,
16
+ "strict": true,
17
+ "target": "ES2023",
18
+ "verbatimModuleSyntax": true
19
+ }
20
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler"
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "module": "NodeNext",
6
+ "moduleResolution": "NodeNext"
7
+ }
8
+ }