clearotron 0.6.0 → 0.7.0-beta.1

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.
Files changed (146) hide show
  1. package/INSTALL.md +7 -4
  2. package/QUICKSTART.md +1 -0
  3. package/README.md +5 -2
  4. package/THIRD-PARTY-NOTICES.md +1 -1
  5. package/bin/clearotron.mjs +4 -2
  6. package/bin/onboard.mjs +158 -29
  7. package/build-info.json +2 -2
  8. package/docs/CLIENT-MCP.md +3 -1
  9. package/docs/DELIVERY.md +6 -3
  10. package/docs/architecture/02-architecture.md +1 -1
  11. package/docs/architecture/04-configuration-reference.md +105 -8
  12. package/docs/branding.md +4 -4
  13. package/docs/report-data/clearance-1.schema.json +320 -0
  14. package/docs/report-data/knockout-1.schema.json +268 -0
  15. package/driver/CHANGELOG.md +77 -0
  16. package/driver/cancel.mjs +19 -0
  17. package/driver/connotation-search.mjs +1 -1
  18. package/driver/contract-e3-backlog.mjs +41 -41
  19. package/driver/contract-vocabulary.mjs +1 -1
  20. package/driver/coverage-ledger.mjs +18 -2
  21. package/driver/deferral-row.mjs +1 -1
  22. package/driver/degraded-parts.mjs +1 -0
  23. package/driver/driver.config.mjs +5 -5
  24. package/driver/effective-scope.mjs +3 -1
  25. package/driver/engagement-receipt.mjs +3 -3
  26. package/driver/engine/anthropic-agent.mjs +15 -1
  27. package/driver/engine/common.mjs +7 -0
  28. package/driver/engine/mcp/band-server.mjs +7 -16
  29. package/driver/engine/mcp/codex-config.mjs +3 -0
  30. package/driver/engine/mcp/recording-server.mjs +45 -34
  31. package/driver/engine/openai-agent.mjs +74 -7
  32. package/driver/engine/session-record.mjs +44 -2
  33. package/driver/findings-model.mjs +14 -2
  34. package/driver/follow-up-twins.mjs +86 -0
  35. package/driver/gateway.mjs +77 -12
  36. package/driver/jx-units.mjs +3 -1
  37. package/driver/jx.mjs +13 -5
  38. package/driver/manuals-inline.mjs +98 -0
  39. package/driver/manuals-seen.mjs +134 -0
  40. package/driver/mark-logos.mjs +174 -0
  41. package/driver/methodology-witness.mjs +2 -1
  42. package/driver/owner-use-check.mjs +8 -4
  43. package/driver/package.json +1 -1
  44. package/driver/pipeline-knockout.mjs +23 -4
  45. package/driver/pipeline.mjs +128 -15
  46. package/driver/portal-local-auth.mjs +6 -2
  47. package/driver/portal-report.mjs +45 -14
  48. package/driver/portal-routes/me.mjs +4 -1
  49. package/driver/portal-runs.mjs +19 -16
  50. package/driver/predelivery-lint.mjs +7 -5
  51. package/driver/profiles.mjs +4 -4
  52. package/driver/publish/README.md +9 -7
  53. package/driver/publish/email-conditions.mjs +22 -5
  54. package/driver/publish/evidence-words.mjs +21 -0
  55. package/driver/publish/index.mjs +304 -211
  56. package/driver/publish/knockout.mjs +297 -247
  57. package/driver/publish/office-record-links.mjs +11 -9
  58. package/driver/publish/page-shell.mjs +98 -0
  59. package/driver/publish/pool-admin.mjs +2 -2
  60. package/driver/publish/publish-inputs.mjs +4 -0
  61. package/driver/publish/regions.mjs +28 -3
  62. package/driver/publish/register-record-html.mjs +105 -0
  63. package/driver/publish/register-record.mjs +165 -0
  64. package/driver/publish/render-knockout.mjs +299 -671
  65. package/driver/publish/render.mjs +561 -492
  66. package/driver/publish/report-data.mjs +226 -13
  67. package/driver/publish/report-document.mjs +353 -0
  68. package/driver/publish/search-depth.mjs +88 -7
  69. package/driver/publish/shell.mjs +41 -1
  70. package/driver/publish/strings.mjs +810 -0
  71. package/driver/publish/templates/clearance-print.css +23 -0
  72. package/driver/publish/templates/knockout.css +224 -0
  73. package/driver/publish/templates/report.css +112 -53
  74. package/driver/publish/xlsx.mjs +158 -139
  75. package/driver/record-goods.mjs +42 -0
  76. package/driver/reference-score.mjs +4 -1
  77. package/driver/register-count.mjs +5 -1
  78. package/driver/register-reach.mjs +39 -0
  79. package/driver/registry-fidelity.mjs +155 -37
  80. package/driver/repair-composers.mjs +7 -3
  81. package/driver/repair-targets.mjs +4 -1
  82. package/driver/replay-archive.mjs +4 -3
  83. package/driver/run-delivered.mjs +14 -8
  84. package/driver/run-record.mjs +1 -0
  85. package/driver/runner.mjs +73 -29
  86. package/driver/scope-facts.mjs +27 -6
  87. package/driver/search-policy.mjs +9 -4
  88. package/driver/skills/clearance-search/report-prose.md +3 -0
  89. package/driver/skills/knockout-assess/SKILL.md +8 -0
  90. package/driver/stage-freshness.mjs +8 -5
  91. package/driver/stages.mjs +69 -43
  92. package/driver/steps/delivery.mjs +9 -5
  93. package/driver/steps/overview-and-cards.mjs +54 -15
  94. package/driver/steps/register-sweep.mjs +5 -4
  95. package/driver/steps/skeptic-and-follow-up.mjs +3 -2
  96. package/driver/steps/verdict-gate.mjs +35 -14
  97. package/driver/suite-census.json +579 -87
  98. package/driver/synthesis-record.mjs +4 -3
  99. package/driver/terminal-clamp.mjs +6 -1
  100. package/driver/withdrawn-rating.mjs +72 -0
  101. package/mcp-server/CHANGELOG.md +8 -0
  102. package/mcp-server/lib/audit-view.mjs +5 -2
  103. package/mcp-server/lib/brief.mjs +6 -2
  104. package/mcp-server/lib/evidence.mjs +94 -23
  105. package/mcp-server/lib/findings.mjs +19 -2
  106. package/mcp-server/lib/knockout.mjs +13 -4
  107. package/mcp-server/lib/scrub.mjs +1 -1
  108. package/mcp-server/package.json +1 -1
  109. package/mcp-server/server.mjs +22 -3
  110. package/package.json +4 -1
  111. package/portal-ui/dist/assets/{index-CYaO2ygd.js → index-BBlN4CYq.js} +238 -80
  112. package/portal-ui/dist/assets/{index-izLa9apq.css → index-CxAkJXIT.css} +25 -5
  113. package/portal-ui/dist/index.html +2 -2
  114. package/portal-ui/package.json +3 -3
  115. package/providers/_shared/ledger.mjs +30 -2
  116. package/providers/_shared/record-uri.mjs +15 -0
  117. package/providers/clarivate/src/adapter.js +11 -0
  118. package/providers/clarivate/src/core.js +17 -1
  119. package/providers/jx/src/core.js +4 -4
  120. package/providers/jx/src/judge.js +1 -3
  121. package/providers/jx/src/nativeread.js +1 -3
  122. package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
  123. package/providers/oauth-mcp-bridge/package.json +1 -1
  124. package/scripts/README.md +147 -3
  125. package/scripts/added-reference-check.mjs +35 -7
  126. package/scripts/e2e-first-time.mjs +4 -4
  127. package/scripts/env-audit.mjs +16 -9
  128. package/scripts/freeze-example-run.mjs +3 -3
  129. package/scripts/mint-public-residue.mjs +3 -3
  130. package/scripts/mint-search-level-tags.mjs +61 -0
  131. package/scripts/mint-source-pin-census.mjs +89 -0
  132. package/scripts/release-note-required.mjs +65 -6
  133. package/scripts/test-durations-reporter.mjs +25 -0
  134. package/scripts/test-full.mjs +72 -18
  135. package/scripts/test-run.mjs +18 -1
  136. package/shared/brand.mjs +93 -6
  137. package/shared/inline-markdown.mjs +53 -0
  138. package/shared/names-in-force.mjs +0 -1
  139. package/shared/portal-tokens.mjs +2 -1
  140. package/shared/reference-guard-classes.mjs +43 -2
  141. package/shared/register-selection.mjs +8 -3
  142. package/shared/search-level-tags.json +25 -0
  143. package/shared/source-spans.mjs +91 -0
  144. package/shared/tools/derive-band-pairs.mjs +10 -0
  145. package/driver/own-rights.mjs +0 -83
  146. package/driver/use-check.mjs +0 -85
@@ -15,8 +15,8 @@
15
15
  // written, and the surface has grown the whole time.
16
16
  //
17
17
  // A rule with no mechanism is not a weak rule, it is a rule that has stopped existing. This is the
18
- // mechanism half: it enumerates, it classifies, and `driver/test/env-governance.test.mjs` ratchets on
19
- // its output.
18
+ // mechanism half: it enumerates, it classifies, and
19
+ // `driver/test/every-setting-read-in-code-has-a-row-in-the-configuration-reference.test.mjs` ratchets on its output.
20
20
  //
21
21
  // ── THE CLASSIFICATION IS THE WHOLE VALUE ────────────────────────────────────────────────────────
22
22
  //
@@ -336,7 +336,8 @@ export function isProductFile(rel) {
336
336
  * The corpus is what git tracks — a walk would sweep build output and a contributor's scratch files
337
337
  * into a register an operator is supposed to read. Off a checkout there is nothing honest to
338
338
  * enumerate, so this returns null, shared/tracked-files.mjs says so by name in the log, and the
339
- * callers decide: the ratchet in driver/test/env-governance.test.mjs skips, and the CLI below
339
+ * callers decide: the ratchet in
340
+ * driver/test/every-setting-read-in-code-has-a-row-in-the-configuration-reference.test.mjs skips, and the CLI below
340
341
  * refuses. Neither reports an empty audit as a clean one.
341
342
  */
342
343
  /**
@@ -469,7 +470,9 @@ export function auditEnv(root = ROOT) {
469
470
  }
470
471
  }
471
472
 
472
- // Documented = named anywhere in either governance document, ON A NAME BOUNDARY.
473
+ // Documented = named in a row's first cell of the configuration reference, ON A NAME BOUNDARY. That page is the one a
474
+ // reader looking up a setting is sent to, so it is the catalogue; 05 is the governance view of the same
475
+ // names, and a name it alone carries is a name the reader does not find.
473
476
  //
474
477
  // Not a table parse — the register is prose with tables in it, and a stricter parser would report a
475
478
  // documented var as UNdocumented, which is the direction that gets a check switched off. But not a
@@ -478,7 +481,7 @@ export function auditEnv(root = ROOT) {
478
481
  // as system-owned, every `PORTAL_*`. A bare `includes` marks the SHORTER name documented the moment
479
482
  // the longer one is written down — the false-DOCUMENTED direction, which hides a real gap instead of
480
483
  // inventing a fake one.
481
- const docs = ["docs/architecture/05-config-governance.md", "docs/architecture/04-configuration-reference.md"]
484
+ const docs = ["docs/architecture/04-configuration-reference.md"]
482
485
  .map((p) => (existsSync(join(root, p)) ? readFileSync(join(root, p), "utf8") : ""));
483
486
  // step 2 — THE CATALOGUE IS A SET OF FILES, NOT ONE FILE.
484
487
  //
@@ -489,8 +492,7 @@ export function auditEnv(root = ROOT) {
489
492
  //
490
493
  // What the ratchet MEANS is that every product variable is written down where a reader can find it.
491
494
  // That meaning is preserved by reading the whole catalogue rather than one member of it. What it must
492
- // NOT become is weaker: a name with a row in NEITHER file still fails, and that is planted both ways
493
- // in driver/test/env-governance.test.mjs.
495
+ // NOT become is weaker: a name with a row in NEITHER file still fails.
494
496
  const example = [...CATALOGUE_FILES]
495
497
  .filter((f) => !f.endsWith(".json") && !f.endsWith(".txt")) // the inventories are contracts, not catalogues of rows
496
498
  .map((f) => (existsSync(join(root, f)) ? readFileSync(join(root, f), "utf8") : ""))
@@ -517,6 +519,11 @@ export function auditEnv(root = ROOT) {
517
519
  // NOT when either spelling does. A file carrying only the old row is a file teaching the old name,
518
520
  // which is a real defect and stays visible as one.
519
521
  const catalogued = (n) => isCatalogued(assigned, n);
522
+ // A ROW, NOT A MENTION: the name has to be in a table row's FIRST cell, where a reader looking it up
523
+ // finds it. A setting named only inside another row's meaning, or in prose, passed as documented while
524
+ // nobody searching the first column could find it. A first cell may name several settings that share a
525
+ // row. Cells are split on unescaped pipes, so a `\|` inside a cell does not end it.
526
+ const firstCells = docs.flatMap((d) => d.split("\n").filter((l) => /^\s*\|/.test(l)).map((l) => l.split(/(?<!\\)\|/)[1] ?? ""));
520
527
  const documented = (n) => {
521
528
  // step 4.0 — ANY SPELLING COUNTS. The governance documents are written in retired spellings,
522
529
  // so a read converted to the name in force read as documented NOWHERE and the ratchet fired on a
@@ -524,7 +531,7 @@ export function auditEnv(root = ROOT) {
524
531
  // `spellingsOf` returns only itself and the check is exactly what it was.
525
532
  return [n].some((sp) => {
526
533
  const re = new RegExp(`(?<![A-Z0-9_])${sp}(?![A-Z0-9_])`);
527
- return docs.some((d) => re.test(d));
534
+ return firstCells.some((c) => re.test(c));
528
535
  });
529
536
  };
530
537
 
@@ -829,7 +836,7 @@ if (isEntrypoint(import.meta.url)) {
829
836
  console.log(` ${a.total} distinct names read by code`);
830
837
  console.log(` ${a.product} read by product code — these need a governance row`);
831
838
  console.log(` ${a.harness} read ONLY by tests, mocks and dev scripts — these do not`);
832
- console.log(`\n ${a.undocumentedProduct.length} PRODUCT name(s) absent from both governance documents:`);
839
+ console.log(`\n ${a.undocumentedProduct.length} PRODUCT name(s) with no row in the configuration reference:`);
833
840
  for (const n of a.undocumentedProduct) {
834
841
  const r = a.rows.find((x) => x.name === n);
835
842
  console.log(` ${n.padEnd(38)} ${r.files[0]}${r.files.length > 1 ? ` (+${r.files.length - 1})` : ""}${r.inExample ? " [in .env.example]" : ""}`);
@@ -69,8 +69,8 @@ const FROZEN_FILES = [
69
69
  { path: "_driver/senior-rights.json", why: "publish/index.mjs:790 seniorRights" },
70
70
  { path: "_driver/verdict.json", why: "publish/index.mjs:811 verdictInfo" },
71
71
  { path: "_driver/framework.json", why: "publish/index.mjs, the frozen band vocabulary the run was rated under" },
72
- { path: "_driver/register-plan.json", why: "publish/index.mjs:919 scopeBasis" },
73
- { path: "_driver/instructed-scope.json", why: "publish/index.mjs:930 searchedJurisdictions, the fallback for register-plan" },
72
+ { path: "_driver/register-plan.json", why: "publish/index.mjs:914 scopeBasis" },
73
+ { path: "_driver/instructed-scope.json", why: "publish/index.mjs:915 searchedJurisdictions, the fallback for register-plan" },
74
74
  { path: "_driver/enforcer-signals.json", why: "`esPath` declared in index.mjs" },
75
75
  { path: "_driver/predelivery-lint.json", why: "publish/index.mjs:173 lintSink" },
76
76
  { path: "_driver/escalation-state.json", why: "publish/index.mjs:174 escSink" },
@@ -118,7 +118,7 @@ const KNOCKOUT_FILES = [
118
118
  // knockout report render empty (`buildKnockoutWorkbook` in publish/knockout.mjs). Named by `koPaths` in stages-knockout.mjs.
119
119
  { path: "_driver/register-counts.json", why: "buildKnockoutWorkbook in publish/knockout.mjs: counted figures + the Register column" },
120
120
  { path: "_driver/register-records.json", why: "koPaths in stages-knockout.mjs: the terms behind the close-variation axis" },
121
- { path: "_driver/instructed-scope.json", why: "publish/index.mjs:930 searchedJurisdictions, the fallback for register-plan" },
121
+ { path: "_driver/instructed-scope.json", why: "publish/index.mjs:915 searchedJurisdictions, the fallback for register-plan" },
122
122
  ];
123
123
 
124
124
  /** The allowlist for a template. One place, so a new template cannot half-exist. */
@@ -17,7 +17,7 @@
17
17
  import { readFileSync, writeFileSync } from "node:fs";
18
18
  import { join, dirname } from "node:path";
19
19
  import { fileURLToPath } from "node:url";
20
- import { CLASSES, censusOf, publishedOf, publishedReader } from "../shared/reference-guard-classes.mjs";
20
+ import { CENSUS_COLUMNS, censusOf, publishedOf, publishedReader } from "../shared/reference-guard-classes.mjs";
21
21
  import { trackedFiles, skipReason } from "../shared/tracked-files.mjs";
22
22
  import { isEntrypoint } from "../shared/is-entrypoint.mjs";
23
23
 
@@ -36,12 +36,12 @@ export function mint() {
36
36
  if (p.error) { console.error(`mint-public-residue: ${p.error}`); process.exit(2); }
37
37
  if (p.laid) console.log(`mint-public-residue: ${p.laid} tracked path(s) are not in HEAD — laid over this checkout, not published in it, and not counted`);
38
38
  const c = censusOf(p.files, publishedReader(ROOT, (f) => readFileSync(join(ROOT, f), "utf8")));
39
- return { classes: CLASSES.map((x) => x.id), total: c.total, files: c.files };
39
+ return { classes: CENSUS_COLUMNS, total: c.total, files: c.files };
40
40
  }
41
41
 
42
42
  /** Per-class totals, for a reader who wants to know WHICH number moved. */
43
43
  export const byClass = (table) =>
44
- CLASSES.map((c, i) => [c.id, Object.values(table.files).reduce((a, v) => a + v[i], 0)]);
44
+ CENSUS_COLUMNS.map((id, i) => [id, Object.values(table.files).reduce((a, v) => a + (v[i] ?? 0), 0)]);
45
45
 
46
46
  function main() {
47
47
  const apply = process.argv.includes("--apply");
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
4
+ //
5
+ // mint-search-level-tags.mjs — write the short name of each search the product sells, from the registry.
6
+ //
7
+ // The Clearances list prints a tag under each name, one per kind of search behind it, and offers the same
8
+ // tags as a filter: "KO", "Prelim", "Multi", "Full". Each tag lives on its product's own row in
9
+ // driver/search-policy.mjs (`report.tag`, beside the `identity` the report's masthead prints), so a product
10
+ // cannot ship without naming its own. The browser cannot import the registry, so this writes the part it
11
+ // needs, in the registry's order, to shared/search-level-tags.json, which the page imports.
12
+ //
13
+ // The page never keeps a list of its own. The portal once held its own table from product to label, and it
14
+ // listed only the retired products, so every new run showed a blank label. A retired product has no tag
15
+ // and is left out here: its runs show no tag and appear only under All.
16
+ //
17
+ // node scripts/mint-search-level-tags.mjs write the file
18
+ // node scripts/mint-search-level-tags.mjs --check exit 1 if the committed file disagrees with the registry
19
+
20
+ import { readFileSync, writeFileSync } from "node:fs";
21
+ import { dirname, join } from "node:path";
22
+ import { fileURLToPath } from "node:url";
23
+
24
+ const REPO = dirname(dirname(fileURLToPath(import.meta.url)));
25
+ const OUT = join(REPO, "shared", "search-level-tags.json");
26
+
27
+ /** The file's content, derived fresh: one `{product, tag, name}` per orderable product, in the registry's order. */
28
+ export async function deriveSearchLevelTags() {
29
+ const { PRODUCT_POLICIES, ORDERABLE_PRODUCTS } = await import("../driver/search-policy.mjs");
30
+ const levels = ORDERABLE_PRODUCTS.map((product) => {
31
+ const report = PRODUCT_POLICIES[product]?.report ?? {};
32
+ // Refuse rather than write a blank: a product with no tag would show nothing under its names and have no
33
+ // button, which reads as "no searches of this kind" rather than as a missing name.
34
+ if (typeof report.tag !== "string" || !report.tag.trim()) throw new Error(`${product}: the registry gives it no report.tag`);
35
+ if (typeof report.identity !== "string" || !report.identity.trim()) throw new Error(`${product}: the registry gives it no report.identity`);
36
+ return { product, tag: report.tag, name: report.identity };
37
+ });
38
+ return {
39
+ _generated: "by scripts/mint-search-level-tags.mjs from driver/search-policy.mjs PRODUCT_POLICIES — do not edit; re-mint",
40
+ levels,
41
+ };
42
+ }
43
+
44
+ const render = (doc) => JSON.stringify(doc, null, 2) + "\n";
45
+
46
+ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
47
+ const next = render(await deriveSearchLevelTags());
48
+ if (process.argv.includes("--check")) {
49
+ let current;
50
+ try { current = readFileSync(OUT, "utf8"); }
51
+ catch { console.error(`mint-search-level-tags: ${OUT} is missing — run without --check to mint it.`); process.exit(1); }
52
+ if (current === next) {
53
+ console.log(`search-level-tags: current, ${JSON.parse(current).levels.length} level(s).`);
54
+ process.exit(0);
55
+ }
56
+ console.error("search-level-tags: the committed file disagrees with the registry — re-mint: node scripts/mint-search-level-tags.mjs");
57
+ process.exit(1);
58
+ }
59
+ writeFileSync(OUT, next);
60
+ console.log(`search-level-tags: wrote ${JSON.parse(next).levels.length} level(s) to ${OUT}`);
61
+ }
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
4
+ //
5
+ // RE-MINT THE SOURCE-PIN CENSUS — which test files pin product source text, and how many pins each holds. A floor.
6
+ //
7
+ // node scripts/mint-source-pin-census.mjs # report the delta, change nothing
8
+ // node scripts/mint-source-pin-census.mjs --check # ... and exit 1 if the file is out of date
9
+ // node scripts/mint-source-pin-census.mjs --apply # write it
10
+ //
11
+ // WHY A COUNT. A test that asserts on a product file's TEXT goes red when that text moves, reflows or is renamed, though
12
+ // no run behaves differently, and every carve of a long function has to repoint such pins before it can land. About one
13
+ // test file in five pinned source on 2026-11-18 and nothing counted them, so the number could only grow unseen. Each pin is
14
+ // retired by the change that makes its behaviour reachable by a test; this records where they are so that can be seen.
15
+ //
16
+ // WHAT THE MATCHER SEES, said rather than found later. Two shapes, per test file under `driver/test` and `mcp-server/test`:
17
+ // - a call to `driverSource(` (driver/test/driver-source.mjs), the house helper for reading the driver's text;
18
+ // - a `readFileSync(` whose own argument names a product file by a path literal: a `../…` path outside any `test/`
19
+ // folder, a path under `driver/`, `bin/`, `shared/`, `scripts/`, `mcp-server/`, `providers/` or `portal-ui/`, or a
20
+ // `join(…, "<folder>", …, "<file>.mjs")`.
21
+ // A test that reads source through a variable holding the path is not seen, so the true count is at least this floor.
22
+ // Measured on 2026-11-18: 299 files (151 call `driverSource`, 148 read a product file by a literal path), against the
23
+ // 317 an audit counted by hand.
24
+ //
25
+ // THE ONLY REASON TO RUN `--apply` IS THAT THE NUMBER WENT DOWN. The floor arm in
26
+ // driver/test/the-tests-that-pin-source-are-a-floor.test.mjs reads the committed file and refuses a file that pins more
27
+ // than it is recorded with, so minting upward records a regression rather than absorbing it.
28
+ import { readFileSync, writeFileSync } from "node:fs";
29
+ import { join, dirname } from "node:path";
30
+ import { fileURLToPath } from "node:url";
31
+ import { publishedOf, publishedReader } from "../shared/reference-guard-classes.mjs";
32
+ import { trackedFiles, skipReason } from "../shared/tracked-files.mjs";
33
+ import { isEntrypoint } from "../shared/is-entrypoint.mjs";
34
+
35
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
36
+ export const FIXTURE = join(ROOT, "driver/test/fixtures/source-pin-census.json");
37
+ const GUARD = "source-pin-census";
38
+
39
+ const PRODUCT_PATH = new RegExp([
40
+ String.raw`["'\x60](?:\.\.\/)+(?![\w-]*\/?test\/)[\w./-]+\.(?:mjs|js|ts|tsx|css)["'\x60]`,
41
+ String.raw`["'\x60](?:driver|bin|shared|scripts|mcp-server|providers|portal-ui)\/(?![\w./-]*\btest\/)[\w./-]+\.(?:mjs|js|ts|tsx|css)["'\x60]`,
42
+ String.raw`join\([^)]*["'](?:driver|bin|shared|scripts|mcp-server|providers|portal-ui)["'][^)]*["'][\w.-]+\.(?:mjs|js|ts|tsx|css)["']\)`,
43
+ ].join("|"));
44
+
45
+ /** [driverSource calls, literal source reads] in one test file's text. PURE. */
46
+ export function pinsIn(text) {
47
+ const s = String(text ?? "");
48
+ const calls = (s.match(/\bdriverSource\(/g) ?? []).length;
49
+ let reads = 0;
50
+ for (const m of s.matchAll(/readFileSync\(([^;\n]{0,240})/g)) if (PRODUCT_PATH.test(m[1])) reads++;
51
+ return [calls, reads];
52
+ }
53
+
54
+ /** The tree's census: { total: files that pin, files: { path: [calls, reads] } }, or null outside a checkout. */
55
+ export function mint(root = ROOT) {
56
+ const tracked = trackedFiles(GUARD, { root, pathspec: ["driver/test", "mcp-server/test"] });
57
+ if (tracked === null) return null;
58
+ const p = publishedOf(tracked.filter((f) => f.endsWith(".test.mjs")), root);
59
+ if (p.error) throw new Error(`mint-source-pin-census: ${p.error}`);
60
+ // Test files the index carries and HEAD does not are laid over this checkout, not published in it: said, and not counted.
61
+ if (p.laid) console.log(`mint-source-pin-census: ${p.laid} tracked test file(s) are not in HEAD — laid over this checkout and not counted`);
62
+ const read = publishedReader(root, (f) => readFileSync(join(root, f), "utf8"));
63
+ const files = {};
64
+ for (const f of [...p.files].sort()) {
65
+ const counts = pinsIn(read(f));
66
+ if (counts[0] || counts[1]) files[f] = counts;
67
+ }
68
+ return { total: Object.keys(files).length, files };
69
+ }
70
+
71
+ function main() {
72
+ const apply = process.argv.includes("--apply");
73
+ const check = process.argv.includes("--check");
74
+ let now;
75
+ try { now = mint(); } catch (e) { console.error(e.message); process.exit(2); }
76
+ if (now === null) { console.error(`mint-source-pin-census: ${skipReason(GUARD)}`); process.exit(2); }
77
+ let was = null;
78
+ try { was = JSON.parse(readFileSync(FIXTURE, "utf8")); } catch { /* first mint */ }
79
+ const calls = Object.values(now.files).filter(([c]) => c).length;
80
+ console.log(`source pins: ${now.total} test file(s), ${calls} calling driverSource, ${now.total - calls} reading a product file by path`);
81
+ const next = JSON.stringify(now, null, 2) + "\n";
82
+ if (was && JSON.stringify(was, null, 2) + "\n" === next) { console.log("the census is current"); return; }
83
+ if (was) console.log(`total ${was.total} → ${now.total}`);
84
+ if (apply) { writeFileSync(FIXTURE, next); console.log("written"); return; }
85
+ console.log("re-run with --apply to write it");
86
+ if (check) process.exit(1);
87
+ }
88
+
89
+ if (isEntrypoint(import.meta.url)) main();
@@ -101,6 +101,23 @@
101
101
  // A deletion that gives no reason still refuses, and names the deleting commit as where the reason goes.
102
102
  // The move a pre-release makes — `.changeset/<name>.md` deleted and `.changeset/pre/<name>.md` added in
103
103
  // one commit — is not a withdrawal: the note still reaches a reader, and a version commit is that shape.
104
+ //
105
+ // ── A NOTE A RELEASE ALREADY PUBLISHED IS AN ANSWER ───────────────────────────────────────────────────
106
+ //
107
+ // A line branched from the previous line, not from main, carries that line's commits one by one across
108
+ // its stable release. Main holds them only as squashes, so none is reached by ancestry and every one is
109
+ // read again. Before the stable, each note a beta had consumed sat under `.changeset/pre/` at the head and
110
+ // answered by its name. The stable publishes them all and deletes them, the merge back carries the
111
+ // deletion, and the last deletion in the range, a commit removing copies an earlier merge had revived,
112
+ // read as a withdrawal that gave no reason. Measured on the 0.6.1 line, 2026-11-18: 35 commits whose notes
113
+ // shipped in 0.6.0 were charged as owing one, and the only fix offered was rewriting pushed history.
114
+ //
115
+ // So a note a VERSION COMMIT on main's own line deleted, at either path, has been published, and it
116
+ // answers for the commits that wrote or named it. The version commit is recognised as the placement check
117
+ // recognises it (`release-duplicate-notes.mjs`), by the pipeline's own author and subject. Not where that
118
+ // release is already in the commit's own history: a note written after the release merged back is a new
119
+ // note sharing a name, and it answers as any other note does. Every commit excused this way is printed
120
+ // with the release that published its note.
104
121
  // ── A LATER COMMIT MAY ANSWER A BARE `none` FOR ONE NAMED COMMIT ───────────────────────────────────────
105
122
  //
106
123
  // A commit carried `Release-note: none` with no reason and was merged into an integration branch before
@@ -145,6 +162,7 @@ import { readFileSync } from "node:fs";
145
162
  import { join, dirname } from "node:path";
146
163
  import { fileURLToPath } from "node:url";
147
164
  import { isEntrypoint } from "../shared/is-entrypoint.mjs";
165
+ import { cutCommitSubject, isVersionCommit } from "./release-duplicate-notes.mjs";
148
166
 
149
167
  const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
150
168
 
@@ -275,15 +293,18 @@ const shipped = (paths, files) => paths.filter((p) => !NEVER_A_NOTE.some((re) =>
275
293
  * @param {string[]} o.files the package's own `files` list
276
294
  * @param {string[]|null} [o.atHead] every path the head carries under `.changeset/`, when the caller read it
277
295
  * @param {((a:string, b:string) => boolean)|null} [o.isAncestor] git ancestry for `Release-note-for:` answers; range order without it
296
+ * @param {Map<string, {sha:string, subject:string}>|null} [o.released] note name → the version commit on main's
297
+ * line that published it, when the caller read it
278
298
  * @returns {{visible:string[], notes:string[], declined:Array<{sha:string, subject:string, reason:string}>,
279
299
  * withdrawals:Array<{sha:string, subject:string, note:string, by:string, reason:string}>,
300
+ * published:Array<{sha:string, subject:string, note:string, by:string, release:string}>,
280
301
  * answered:Array<{sha:string, subject:string, by:string, reason:string}>,
281
302
  * refusedAnswers:Array<{sha:string, subject:string, text:string, problem:string}>,
282
303
  * unneeded:Array<{sha:string, by:string, said:string}>,
283
304
  * owed:Array<{sha:string, subject:string, why:"no-note"|"prose"|"bare-none"|"names-a-missing-note"|"note-withdrawn-unsaid",
284
305
  * paths?:string[], text?:string, by?:string}>}}
285
306
  */
286
- export function commitVerdicts({ commits = [], files = [], atHead = null, isAncestor = null } = {}) {
307
+ export function commitVerdicts({ commits = [], files = [], atHead = null, isAncestor = null, released = null } = {}) {
287
308
  // `added` and `atHead` are what the command reads from git; a caller that passes neither keeps the older
288
309
  // reading of every changed path, which is what a pure table of paths means.
289
310
  // MATCHED ON THE NAME, NOT THE PATH, BECAUSE A PRE-RELEASE MOVES A NOTE IT CONSUMES.
@@ -331,7 +352,13 @@ export function commitVerdicts({ commits = [], files = [], atHead = null, isAnce
331
352
  });
332
353
  // AND A NAME THE HEAD STILL CARRIES WAS NEVER WITHDRAWN AT ALL: the release assembles what the head has.
333
354
  if (presentNames) for (const name of [...withdrawn.keys()]) if (presentNames.has(name)) withdrawn.delete(name);
334
- const declined = [], owed = [], withdrawals = [], answered = [], unneeded = [];
355
+ // THE RELEASE THAT PUBLISHED A NOTE OF THIS NAME (see the header), unless this commit's own history
356
+ // already holds that release, which makes its note a new one.
357
+ const publishedBy = (c, name) => {
358
+ const r = released?.get(name);
359
+ return r && !(isAncestor && isAncestor(r.sha, c.sha)) ? r : null;
360
+ };
361
+ const declined = [], owed = [], withdrawals = [], answered = [], unneeded = [], published = [];
335
362
  const { answers, refused: refusedAnswers } = readAnswers(commits, isAncestor);
336
363
  const used = new Set();
337
364
  for (const [i, c] of commits.entries()) {
@@ -342,13 +369,15 @@ export function commitVerdicts({ commits = [], files = [], atHead = null, isAnce
342
369
  const named = values.map((v) => NAMED_NOTE.exec(v)?.groups.name).filter(Boolean);
343
370
  const prose = values.filter((v) => !/^none\b/i.test(v) && !NAMED_NOTE.test(v));
344
371
  const at = { sha: c.sha, subject: c.subject };
372
+ const firstPublished = (names) => names.map((n) => [n, publishedBy(c, n)]).find(([, r]) => r);
373
+ const ownPublished = addsNote ? null : firstPublished((c.added ?? c.paths).filter(isNotePath).map(nameOf));
345
374
  // A LATER COMMIT'S ANSWER NAMING A NOTE: taken for a sentence line or a bare `none`, when the range adds it.
346
375
  const byNote = (answer) => {
347
376
  used.add(c.sha);
348
377
  if (!noteNames.has(answer.note)) { owed.push({ ...at, why: "names-a-missing-note", text: answer.note, by: answer.by }); return; }
349
378
  answered.push({ ...at, by: answer.by, note: answer.note, said: prose[0] ?? "none" });
350
379
  };
351
- if (prose.length && !addsNote) {
380
+ if (prose.length && !addsNote && !ownPublished) {
352
381
  const answer = answers.get(c.sha);
353
382
  if (answer?.note) byNote(answer);
354
383
  else owed.push({ ...at, why: "prose", text: prose[0] });
@@ -365,6 +394,12 @@ export function commitVerdicts({ commits = [], files = [], atHead = null, isAnce
365
394
  continue;
366
395
  }
367
396
  if (addsNote) continue; // it carries its own note
397
+ const releasedNote = ownPublished ?? firstPublished(named);
398
+ if (releasedNote) {
399
+ const [note, by] = releasedNote;
400
+ published.push({ ...at, note, by: by.sha, release: by.subject });
401
+ continue;
402
+ }
368
403
  // THE NOTE THIS COMMIT ANSWERED WITH, TAKEN BACK BY A LATER ONE. Only a later commit: a name deleted
369
404
  // before this commit named it was never this commit's answer.
370
405
  const addedNames = [...new Set((c.added ?? c.paths).filter(isNotePath).map(nameOf))];
@@ -395,7 +430,7 @@ export function commitVerdicts({ commits = [], files = [], atHead = null, isAnce
395
430
  : `names ${sha.slice(0, 7)}, which owes a note this line cannot give: an answer covers only a bare \`none\``)
396
431
  : `names ${sha.slice(0, 7)}, which owes no answer: it ships no code, carries a note, or gives its own reason` });
397
432
  }
398
- return { visible, notes, declined, withdrawals, owed, answered, refusedAnswers, unneeded };
433
+ return { visible, notes, declined, withdrawals, published, owed, answered, refusedAnswers, unneeded };
399
434
  }
400
435
 
401
436
  const argAfter = (flag) => {
@@ -415,6 +450,7 @@ function main() {
415
450
  const head = argAfter("--head") || "HEAD";
416
451
  const git = (...a) => execFileSync("git", a, { encoding: "utf8", maxBuffer: 1 << 28 });
417
452
  let changed, commits, atHead, onMainLine = [];
453
+ const released = new Map();
418
454
  try {
419
455
  changed = git("diff", "--name-only", `${base}...${head}`).split("\n").filter(Boolean);
420
456
  // THE BRANCH'S OWN COMMITS. On a pull request the range can reach commits main already carries, from
@@ -441,6 +477,24 @@ function main() {
441
477
  deleted: git("diff-tree", "--no-commit-id", "--name-only", "-r", "--root", "--diff-filter=D", sha).split("\n").filter(Boolean),
442
478
  }));
443
479
  atHead = git("ls-tree", "-r", "--name-only", head, "--", ".changeset/").split("\n").filter(Boolean);
480
+ // EVERY NOTE A RELEASE ON MAIN'S OWN LINE PUBLISHED (see the header): the names a version commit
481
+ // deleted, at either path. Newest first, so the first sighting of a name is the latest release.
482
+ if (mainKnown) {
483
+ const cutSubject = cutCommitSubject(ROOT);
484
+ let version = null;
485
+ const log = git("log", "--first-parent", "--no-renames", "--diff-filter=D", "--name-status",
486
+ "--format=@@%H%x00%an%x00%s", "origin/main", "--", ".changeset/");
487
+ for (const line of log.split("\n")) {
488
+ if (line.startsWith("@@")) {
489
+ const [sha, author, subject] = line.slice(2).split("\0");
490
+ version = isVersionCommit({ author, subject }, cutSubject) ? { sha, subject } : null;
491
+ continue;
492
+ }
493
+ const path = line.split("\t")[1] ?? "";
494
+ const name = path.split("/").pop();
495
+ if (version && isNotePath(path) && !released.has(name)) released.set(name, version);
496
+ }
497
+ }
444
498
  } catch (e) {
445
499
  // COULD NOT LOOK, never a pass — an unresolvable base is the shape this repository cares about.
446
500
  console.error(`release-note-required: cannot read the range against ${base}: ${e.message.split("\n")[0]}`);
@@ -462,11 +516,13 @@ function main() {
462
516
  }
463
517
  // ANCESTRY FROM GIT, NEVER TIMESTAMPS: an answer must come from a commit the named one is an ancestor of.
464
518
  const isAncestor = (a, b) => { try { git("merge-base", "--is-ancestor", a, b); return true; } catch { return false; } };
465
- const { visible, notes, declined, withdrawals, owed, answered, refusedAnswers, unneeded } = commitVerdicts({ commits, files, atHead, isAncestor });
519
+ const { visible, notes, declined, withdrawals, published, owed, answered, refusedAnswers, unneeded } =
520
+ commitVerdicts({ commits, files, atHead, isAncestor, released });
466
521
  console.log(`release-note-required: ${changed.length} changed file(s) against ${base}`
467
522
  + `${head === "HEAD" ? "" : ` (head ${head})`}; `
468
523
  + `${visible.length} ship as code; ${notes.length} release note(s) in the range; ${commits.length} commit(s) read`
469
- + `${withdrawals.length ? `; ${withdrawals.length} answered by a note the range withdrew` : ""}`);
524
+ + `${withdrawals.length ? `; ${withdrawals.length} answered by a note the range withdrew` : ""}`
525
+ + `${published.length ? `; ${published.length} answered by a note a release already published` : ""}`);
470
526
  // PER COMMIT, SAID AS PER COMMIT. "no note, declared on purpose" read as a verdict on the range, and beside
471
527
  // a range that carries a note it told a reader skimming the output that none went out. Found in review.
472
528
  if (onMainLine.length) {
@@ -481,6 +537,9 @@ function main() {
481
537
  for (const w of withdrawals) {
482
538
  console.log(` ${w.sha.slice(0, 7)} answered with ${w.note}, which ${w.by.slice(0, 7)} withdrew: ${w.reason}`);
483
539
  }
540
+ for (const p of published) {
541
+ console.log(` ${p.sha.slice(0, 7)} answered with ${p.note}, which ${p.by.slice(0, 7)} (${p.release}) published`);
542
+ }
484
543
  for (const a of answered) {
485
544
  console.log(a.note
486
545
  ? ` ${a.sha.slice(0, 7)} said ${a.said === "none" ? "a bare `none`" : `"${a.said}"`}, which ${a.by.slice(0, 7)} answers with ${a.note}`
@@ -0,0 +1,25 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ //
4
+ // test-durations-reporter.mjs — a `node --test` reporter that writes how long each test FILE took, one JSON line per
5
+ // file: `{"file":"driver/test/x.test.mjs","ms":1234}`, the path relative to the repository root.
6
+ //
7
+ // WHY A REPORTER. `node --test` runs a shard's files in parallel and its TAP names no file, so a file's cost cannot be
8
+ // read back from the suite's log. Every top-level test it reports does carry its file, so this sums their durations per
9
+ // file. That leaves out the time a file spends importing before its first test, the same few hundred milliseconds for
10
+ // most files, so the sums rank files as a shard pays for them. `scripts/test-run.mjs` adds it when `CT_DURATIONS_DIR` is
11
+ // set, beside the TAP stream, and CI keeps what it writes with each shard's log.
12
+ import { dirname, join, relative, sep } from "node:path";
13
+ import { fileURLToPath } from "node:url";
14
+
15
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
16
+
17
+ export default async function* durations(source) {
18
+ const perFile = new Map();
19
+ for await (const { type, data } of source) {
20
+ if ((type !== "test:pass" && type !== "test:fail") || data?.nesting !== 0 || !data.file) continue;
21
+ const file = relative(ROOT, data.file).split(sep).join("/");
22
+ perFile.set(file, (perFile.get(file) ?? 0) + (data.details?.duration_ms ?? 0));
23
+ }
24
+ for (const [file, ms] of perFile) yield `${JSON.stringify({ file, ms: Math.round(ms) })}\n`;
25
+ }
@@ -45,7 +45,7 @@ import { join, dirname } from "node:path";
45
45
  import { fileURLToPath } from "node:url";
46
46
  import { isEntrypoint } from "../shared/is-entrypoint.mjs";
47
47
 
48
- const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
48
+ export const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
49
49
 
50
50
  /**
51
51
  * Every `*.test.mjs` under `providers/`, at any depth, deduplicated and ordered.
@@ -175,12 +175,22 @@ export function plan(root = ROOT, { providerFiles } = {}) {
175
175
  * ~980 test files in the tree, executed in one serial job. Agents write faster than that gate opens, so
176
176
  * the gate — not the work — set the pace of the day.
177
177
  *
178
- * A shard is a SLICE OF THE SORTED FILE LIST TAKEN BY INDEX: shard i of n takes every file whose
179
- * position satisfies `index % n === i - 1`. That is exhaustive and disjoint by construction — every
180
- * index lands in exactly one shard, for any n — so the union of the shards is the whole list as a
181
- * property of the arithmetic, not as something a check has to confirm afterwards. Round-robin rather
182
- * than contiguous blocks because neighbouring files in a sorted list tend to be the same subsystem and
183
- * to cost the same; interleaving spreads the slow ones.
178
+ * A shard is DEALT BY MEASURED DURATION: the files go out longest first, each to the shard with the
179
+ * least time dealt so far, ties to the lower shard, from the table in `scripts/test-durations.json`.
180
+ * Every file is dealt exactly once, so the shards are exhaustive and disjoint by construction, for any
181
+ * n and any table — the union of the shards is the whole list as a property of the deal, not as
182
+ * something a check has to confirm afterwards. Every shard reads the same committed table, so every
183
+ * shard computes the same deal.
184
+ *
185
+ * It replaced a slice by index (`index % n`), which interleaved the sorted list and still left the
186
+ * longest shard about twice the shortest: measured over 38 green runs, 2026-11-11 to 2026-11-17, a
187
+ * median of 10.4 minutes against 5.3, while the four summed to 29.1. The required checks wait for the
188
+ * longest.
189
+ *
190
+ * A TABLE THAT IS STALE COSTS BALANCE, NEVER COVERAGE. A file the table does not name is dealt at the
191
+ * median of the files it does name, so it lands in exactly one shard like any other, and every shard's
192
+ * log says how many files that was. `scripts/measure-test-durations.mjs --run <id> --write` rebuilds the
193
+ * table from what a CI run measured.
184
194
  *
185
195
  * WHAT IS NOT SHARDED, and why that is stated rather than assumed. Only a corpus whose own test script
186
196
  * is the plain `node --test test/*.test.mjs` shape can be expressed as an explicit file list and cut up
@@ -191,10 +201,38 @@ export function plan(root = ROOT, { providerFiles } = {}) {
191
201
  */
192
202
  const PLAIN_GLOB = /^node \.\.\/scripts\/test-run\.mjs node --test test\/\*\.test\.mjs$/;
193
203
 
194
- export function shardSlice(list, i, n) {
195
- return list.filter((_, idx) => idx % n === i - 1);
204
+ export const DURATIONS_FILE = "scripts/test-durations.json";
205
+
206
+ /** The measured table (milliseconds per file), or an empty one: a missing table deals every file at one cost. */
207
+ export function readDurations(root = ROOT) {
208
+ try {
209
+ const table = JSON.parse(readFileSync(join(root, DURATIONS_FILE), "utf8"));
210
+ return { measured: table.measured ?? null, ms: table.ms ?? {} };
211
+ } catch { return { measured: null, ms: {} }; }
212
+ }
213
+
214
+ const timed = (ms, f) => Number.isFinite(ms[f]) && ms[f] >= 0;
215
+
216
+ /** Shard i of n of `list`, dealt by `ms` (see above). Returned in `list`'s own order. */
217
+ export function shardByDuration(list, i, n, ms = {}) {
218
+ const known = list.filter((f) => timed(ms, f)).map((f) => ms[f]).sort((a, b) => a - b);
219
+ const median = known.length ? known[Math.floor(known.length / 2)] : 1;
220
+ const deal = list.map((f, at) => ({ f, at, cost: timed(ms, f) ? ms[f] : median }))
221
+ .sort((a, b) => b.cost - a.cost || a.at - b.at);
222
+ const load = new Array(n).fill(0);
223
+ const owner = new Map();
224
+ for (const { f, cost } of deal) {
225
+ let k = 0;
226
+ for (let j = 1; j < n; j++) if (load[j] < load[k]) k = j;
227
+ load[k] += cost;
228
+ owner.set(f, k);
229
+ }
230
+ return list.filter((f) => owner.get(f) === i - 1);
196
231
  }
197
232
 
233
+ /** How many files of `list` the table does not name. */
234
+ export const untimedCount = (list, ms = {}) => list.filter((f) => !timed(ms, f)).length;
235
+
198
236
  function workspaceTestFiles(root, ws) {
199
237
  const dir = join(root, ws, "test");
200
238
  if (!existsSync(dir)) return [];
@@ -213,22 +251,28 @@ function isShardable(root, ws) {
213
251
  } catch { return false; }
214
252
  }
215
253
 
254
+ /** Every file the shards deal, corpus by corpus: what `measure-test-durations` needs a figure for. */
255
+ export function shardableFiles(corpora, root = ROOT) {
256
+ return corpora.flatMap((c) => (c.kind === "files" ? c.files
257
+ : c.kind === "workspace" && isShardable(root, c.name) ? workspaceTestFiles(root, c.name) : []));
258
+ }
259
+
216
260
  /**
217
261
  * Rewrite the plan for one shard. Every corpus stays in the list and is reported; what changes is how
218
- * many of its files THIS shard runs.
262
+ * many of its files THIS shard runs, and how many of them the table did not name.
219
263
  */
220
- export function applyShard(corpora, { i, n }, root = ROOT) {
264
+ export function applyShard(corpora, { i, n }, root = ROOT, ms = readDurations(root).ms) {
221
265
  return corpora.map((c) => {
222
266
  if (c.kind === "covered") return c;
223
267
  if (c.kind === "files") {
224
- const mine = shardSlice(c.files, i, n);
225
- return { ...c, files: mine, total: c.files.length,
268
+ const mine = shardByDuration(c.files, i, n, ms);
269
+ return { ...c, files: mine, total: c.files.length, untimed: untimedCount(c.files, ms),
226
270
  argv: ["node", "scripts/test-run.mjs", "node", "--test", ...mine] };
227
271
  }
228
272
  if (c.kind === "workspace" && isShardable(root, c.name)) {
229
273
  const all = workspaceTestFiles(root, c.name);
230
- const mine = shardSlice(all, i, n);
231
- return { ...c, kind: "files", files: mine, total: all.length,
274
+ const mine = shardByDuration(all, i, n, ms);
275
+ return { ...c, kind: "files", files: mine, total: all.length, untimed: untimedCount(all, ms),
232
276
  argv: ["node", "scripts/test-run.mjs", "node", "--test", ...mine] };
233
277
  }
234
278
  // Not expressible as a file list: run it whole, once, on shard 1.
@@ -249,7 +293,8 @@ function main() {
249
293
  return { i: a, n: b };
250
294
  })();
251
295
  const { corpora: full, faults } = plan();
252
- const corpora = shard ? applyShard(full, shard, ROOT) : full;
296
+ const durations = readDurations(ROOT);
297
+ const corpora = shard ? applyShard(full, shard, ROOT, durations.ms) : full;
253
298
 
254
299
  // FAULTS BEFORE ANYTHING RUNS. A missing corpus discovered after a green suite reads as an
255
300
  // afterthought; discovered first, it is the answer.
@@ -266,6 +311,17 @@ function main() {
266
311
  process.exit(2);
267
312
  }
268
313
 
314
+ // SAID BEFORE A LISTING TOO, so the deal and how much of it the table measured can be read without running a shard.
315
+ if (shard) {
316
+ const dealt = corpora.filter((c) => c.kind === "files");
317
+ const total = dealt.reduce((a, c) => a + c.total, 0);
318
+ const untimed = dealt.reduce((a, c) => a + c.untimed, 0);
319
+ console.log(`\ntest-full: shard ${shard.i} of ${shard.n} — files are dealt by measured duration, longest first to the `
320
+ + `shard with the least so far, so the shards are disjoint and their union is the whole list. `
321
+ + `${DURATIONS_FILE} (measured ${durations.measured ?? "never"}) names ${total - untimed} of the ${total} file(s); `
322
+ + `${untimed} have no recorded duration and were dealt at the median.`);
323
+ }
324
+
269
325
  if (listOnly) {
270
326
  for (const c of chosen) {
271
327
  console.log(c.kind === "covered"
@@ -275,8 +331,6 @@ function main() {
275
331
  return;
276
332
  }
277
333
 
278
- if (shard) console.log(`\ntest-full: shard ${shard.i} of ${shard.n} — slices are taken by index from the sorted file list, so the shards are disjoint and their union is the whole list.`);
279
-
280
334
  const ran = [];
281
335
  for (const c of chosen) {
282
336
  if (c.kind === "covered") { ran.push({ ...c, status: "covered" }); continue; }