architecture-harness 0.25.1 → 0.27.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.
Files changed (155) hide show
  1. package/package.json +2 -18
  2. package/src/cli/ask.mjs +44 -0
  3. package/src/cli/ask.test.mjs +56 -0
  4. package/src/cli/bash-command-guard.mjs +37 -5
  5. package/src/cli/bash-command-guard.test.mjs +18 -0
  6. package/src/cli/check-commands.mjs +104 -7
  7. package/src/cli/check-commands.test.mjs +281 -7
  8. package/src/cli/check-full.test.mjs +153 -0
  9. package/src/cli/check.mjs +113 -0
  10. package/src/cli/check.test.mjs +45 -0
  11. package/src/cli/child-run.mjs +7 -2
  12. package/src/cli/child-run.test.mjs +17 -2
  13. package/src/cli/ci-failures.mjs +47 -9
  14. package/src/cli/ci-failures.test.mjs +116 -10
  15. package/src/cli/ci-preview.mjs +62 -0
  16. package/src/cli/ci-preview.test.mjs +85 -0
  17. package/src/cli/ci-state.mjs +2 -2
  18. package/src/cli/ci-state.test.mjs +8 -8
  19. package/src/cli/ci-template.test.mjs +115 -2
  20. package/src/cli/codex-implement.mjs +374 -44
  21. package/src/cli/codex-implement.test.mjs +868 -14
  22. package/src/cli/codex-limit.test.mjs +1 -1
  23. package/src/cli/codex-verify.mjs +230 -0
  24. package/src/cli/codex-verify.test.mjs +402 -0
  25. package/src/cli/comment-watch.mjs +391 -0
  26. package/src/cli/comment-watch.test.mjs +392 -0
  27. package/src/cli/commit-guard.mjs +3 -3
  28. package/src/cli/commit-guard.test.mjs +9 -3
  29. package/src/cli/commit-msg.mjs +4 -0
  30. package/src/cli/commit-msg.test.mjs +10 -0
  31. package/src/cli/diff-shape.mjs +162 -0
  32. package/src/cli/diff-shape.test.mjs +200 -0
  33. package/src/cli/dispatch-guard.test.mjs +7 -7
  34. package/src/cli/dispatch-reminder.mjs +18 -8
  35. package/src/cli/dispatch-reminder.test.mjs +46 -10
  36. package/src/cli/dispatch-slot.mjs +2 -2
  37. package/src/cli/dispatch-slot.test.mjs +18 -19
  38. package/src/cli/dispatch.test.mjs +3 -3
  39. package/src/cli/fleet-assign.mjs +46 -0
  40. package/src/cli/fleet-assign.test.mjs +114 -0
  41. package/src/cli/fleet-github.mjs +124 -0
  42. package/src/cli/fleet-github.test.mjs +243 -0
  43. package/src/cli/fleet-message.mjs +50 -0
  44. package/src/cli/fleet-message.test.mjs +72 -0
  45. package/src/cli/fleet-node.mjs +555 -0
  46. package/src/cli/fleet-node.test.mjs +1282 -0
  47. package/src/cli/fleet-platform.mjs +200 -0
  48. package/src/cli/fleet-platform.test.mjs +316 -0
  49. package/src/cli/fleet-state.mjs +75 -0
  50. package/src/cli/fleet-state.test.mjs +114 -0
  51. package/src/cli/fleet-talk.mjs +143 -0
  52. package/src/cli/fleet-talk.test.mjs +178 -0
  53. package/src/cli/fleet.mjs +309 -0
  54. package/src/cli/fleet.test.mjs +516 -0
  55. package/src/cli/gate-slot.mjs +2 -1
  56. package/src/cli/gh-merge-command.mjs +5 -3
  57. package/src/cli/gh-merge-command.test.mjs +4 -0
  58. package/src/cli/gh-run.mjs +50 -7
  59. package/src/cli/gh-run.test.mjs +35 -5
  60. package/src/cli/git-read.mjs +2 -1
  61. package/src/cli/integrate-tree.mjs +47 -0
  62. package/src/cli/integrate.mjs +35 -26
  63. package/src/cli/integration-lane.mjs +3 -5
  64. package/src/cli/integration-lane.test.mjs +2 -2
  65. package/src/cli/ledger.test.mjs +12 -3
  66. package/src/cli/legs.mjs +53 -0
  67. package/src/cli/legs.test.mjs +93 -0
  68. package/src/cli/locked-tests.mjs +134 -0
  69. package/src/cli/locked-tests.test.mjs +188 -0
  70. package/src/cli/merge-guard.mjs +103 -48
  71. package/src/cli/merge-guard.test.mjs +310 -111
  72. package/src/cli/metrics.mjs +53 -0
  73. package/src/cli/metrics.test.mjs +73 -0
  74. package/src/cli/milestone.mjs +297 -0
  75. package/src/cli/milestone.test.mjs +294 -0
  76. package/src/cli/mutate.mjs +203 -0
  77. package/src/cli/mutate.test.mjs +134 -0
  78. package/src/cli/overview.mjs +131 -0
  79. package/src/cli/overview.test.mjs +137 -0
  80. package/src/cli/platform-risk.mjs +140 -0
  81. package/src/cli/platform-risk.test.mjs +223 -0
  82. package/src/cli/pr-guard.mjs +128 -0
  83. package/src/cli/pr-guard.test.mjs +154 -0
  84. package/src/cli/qc.mjs +82 -20
  85. package/src/cli/qc.test.mjs +35 -1
  86. package/src/cli/repl-commands.mjs +168 -0
  87. package/src/cli/repl-commands.test.mjs +133 -0
  88. package/src/cli/retry-failed.mjs +3 -1
  89. package/src/cli/role-line.mjs +49 -0
  90. package/src/cli/role-line.test.mjs +55 -0
  91. package/src/cli/run-log.mjs +73 -0
  92. package/src/cli/run-log.test.mjs +121 -0
  93. package/src/cli/skill-length.test.mjs +8 -0
  94. package/src/cli/tools.mjs +49 -0
  95. package/src/cli/tools.test.mjs +89 -0
  96. package/src/cli/watch.mjs +56 -10
  97. package/src/cli/watch.test.mjs +151 -21
  98. package/src/cli/work-order-guard.mjs +2 -1
  99. package/src/cli/workflow-hooks.test.mjs +14 -5
  100. package/src/cli/workflow-settings.mjs +3 -2
  101. package/src/cli/workflow-settings.test.mjs +11 -1
  102. package/src/config.mjs +64 -2
  103. package/src/config.test.mjs +93 -20
  104. package/src/consumer-package.test.mjs +3 -18
  105. package/src/descriptions.mjs +1 -0
  106. package/src/eslint/index.mjs +2 -0
  107. package/src/eslint/preset.mjs +12 -1
  108. package/src/eslint/preset.test.mjs +1 -1
  109. package/src/eslint/rules/timeless-comment.mjs +92 -0
  110. package/src/eslint/rules.test.mjs +34 -0
  111. package/src/gates/plain-language.mjs +396 -0
  112. package/src/gates/plain-language.test.mjs +210 -0
  113. package/src/global-skills.test.mjs +0 -1
  114. package/templates/docs/enforcement.md +12 -2
  115. package/templates/github/workflows/ci.yml +51 -4
  116. package/src/cli/screens-discovery.mjs +0 -60
  117. package/src/cli/screens.mjs +0 -85
  118. package/src/cli/stack.mjs +0 -14
  119. package/src/cli/throwaway-db.mjs +0 -133
  120. package/src/cli/throwaway-db.test.mjs +0 -137
  121. package/src/screens/auth-context.test.mjs +0 -41
  122. package/src/screens/auth-run.test.mjs +0 -147
  123. package/src/screens/auth.mjs +0 -223
  124. package/src/screens/auth.test.mjs +0 -76
  125. package/src/screens/capture-idle.test.mjs +0 -27
  126. package/src/screens/capture.browser-test.mjs +0 -73
  127. package/src/screens/capture.mjs +0 -176
  128. package/src/screens/capture.test.mjs +0 -28
  129. package/src/screens/catalog.browser-test.mjs +0 -32
  130. package/src/screens/catalog.mjs +0 -72
  131. package/src/screens/catalog.test.mjs +0 -36
  132. package/src/screens/chrome.mjs +0 -21
  133. package/src/screens/compare.mjs +0 -41
  134. package/src/screens/compare.test.mjs +0 -30
  135. package/src/screens/discovery.browser-test.mjs +0 -29
  136. package/src/screens/discovery.mjs +0 -158
  137. package/src/screens/discovery.test.mjs +0 -27
  138. package/src/screens/inventory.mjs +0 -69
  139. package/src/screens/inventory.test.mjs +0 -10
  140. package/src/screens/map.mjs +0 -63
  141. package/src/screens/map.test.mjs +0 -35
  142. package/src/screens/open.browser-test.mjs +0 -50
  143. package/src/screens/regions.mjs +0 -138
  144. package/src/screens/regions.test.mjs +0 -38
  145. package/src/screens/session-files.mjs +0 -39
  146. package/src/screens/session-files.test.mjs +0 -39
  147. package/src/screens/setup.browser-test.mjs +0 -49
  148. package/src/screens/setup.mjs +0 -79
  149. package/src/screens/stack-auth.browser-test.mjs +0 -30
  150. package/src/screens/stack-auth.mjs +0 -107
  151. package/src/screens/stack-auth.test.mjs +0 -65
  152. package/src/screens/write-guard.mjs +0 -26
  153. package/src/stack/stack.mjs +0 -131
  154. package/src/stack/stack.test.mjs +0 -60
  155. package/src/stack/supervisor.mjs +0 -30
@@ -1,17 +1,97 @@
1
1
  import test from "node:test";
2
2
  import assert from "node:assert/strict";
3
3
  import { execFileSync, spawnSync } from "node:child_process";
4
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { defaults } from "../config.mjs";
9
+ import { testsCovering } from "./check-commands.mjs";
9
10
 
10
11
  const qc = fileURLToPath(new URL("./qc.mjs", import.meta.url));
11
- const node = (source) => `"${process.execPath}" -e '${source}'`;
12
- const record = node('require("node:fs").writeFileSync("args.json", JSON.stringify(process.argv.slice(1)))');
12
+ const scripts = mkdtempSync(path.join(tmpdir(), "qc-check-scripts-"));
13
+ test.after(() => rmSync(scripts, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
14
+ let scriptId = 0;
15
+ const node = (source) => {
16
+ const file = path.join(scripts, `${scriptId++}.cjs`);
17
+ writeFileSync(file, source);
18
+ return `"${process.execPath}" "${file}"`;
19
+ };
20
+ const record = node('require("node:fs").writeFileSync("args.json", JSON.stringify(process.argv.slice(2)))');
13
21
  const git = (root, ...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: "pipe" });
14
22
 
23
+ test("testsCovering finds sibling and reader-chain tests without basename-only matches for files and folders", async (t) => {
24
+ const root = fixture(t);
25
+ const base = "packages/qc-harness/src";
26
+ const source = `${base}/feature/source.mjs`;
27
+ const sibling = `${base}/feature/source.test.mjs`;
28
+ const reader = `${base}/reader.test.mjs`;
29
+ const named = `${base}/named.test.mjs`;
30
+ const data = `${base}/feature/data.json`;
31
+ const files = {
32
+ [source]: "export const value = 1;",
33
+ [sibling]: "export {};",
34
+ [`${base}/bridge.mjs`]: "export { value } from './feature/source.mjs';",
35
+ [reader]: "import './bridge.mjs';",
36
+ [named]: "// source.mjs and data.json are exercised by a command fixture",
37
+ [data]: "{}",
38
+ [`${base}/uncertain.test.mjs`]: "import(process.env.MODULE);",
39
+ "outside.test.mjs": "import './packages/qc-harness/src/feature/source.mjs';",
40
+ };
41
+ for (const [file, text] of Object.entries(files)) {
42
+ mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
43
+ writeFileSync(path.join(root, file), text);
44
+ }
45
+ git(root, "add", ".");
46
+ const expected = [sibling, reader].sort();
47
+ const covered = await testsCovering(root, [source, `${base}/feature/`]);
48
+ assert.deepEqual(covered.get(source), expected);
49
+ assert.deepEqual(covered.get(sibling), [sibling]);
50
+ assert.deepEqual(covered.get(data), []);
51
+ assert.deepEqual([...covered.keys()].sort(), [source, sibling, data].sort());
52
+ assert.deepEqual(await testsCovering(root, [`${base}/feature`]), covered);
53
+ assert.deepEqual(await testsCovering(root, [source.replace(/\//g, "\\")]), new Map([[source, expected]]));
54
+ assert.deepEqual(await testsCovering(root, [`${base}/feature/`.replace(/\//g, "\\")]), covered);
55
+ for (const entry of [".", "./"]) {
56
+ const all = await testsCovering(root, [entry]);
57
+ assert.ok(all.has(source));
58
+ assert.ok(all.has("committed.mjs"));
59
+ assert.ok(!all.has("."));
60
+ assert.deepEqual(all.get(source), expected);
61
+ }
62
+ assert.deepEqual(await testsCovering(root, [`${base}/missing.mjs`]), new Map([[`${base}/missing.mjs`, []]]));
63
+ });
64
+
65
+ for (const [kind, text] of [
66
+ ["regex apostrophe", "const apostrophe = /'/; import './source.mjs';"],
67
+ ["template substitution", 'export const module = `${await import("./source.mjs")}`;'],
68
+ ]) test(`testsCovering finds imports with a ${kind}`, async (t) => {
69
+ const root = fixture(t);
70
+ const base = "packages/qc-harness/src";
71
+ mkdirSync(path.join(root, base), { recursive: true });
72
+ writeFileSync(path.join(root, base, "source.mjs"), "export {};\n");
73
+ writeFileSync(path.join(root, base, "reader.test.mjs"), text);
74
+ git(root, "add", ".");
75
+ assert.deepEqual(await testsCovering(root, [`${base}/source.mjs`]), new Map([
76
+ [`${base}/source.mjs`, [`${base}/reader.test.mjs`]],
77
+ ]));
78
+ });
79
+
80
+ test("testsCovering normalizes config file and folder backslashes", async (t) => {
81
+ const root = fixture(t);
82
+ const source = "packages/qc-harness/src/config.mjs";
83
+ const sibling = "packages/qc-harness/src/config.test.mjs";
84
+ mkdirSync(path.dirname(path.join(root, source)), { recursive: true });
85
+ writeFileSync(path.join(root, source), "export {};\n");
86
+ writeFileSync(path.join(root, sibling), "export {};\n");
87
+ git(root, "add", ".");
88
+ for (const entry of [source, "packages/qc-harness/src/"]) {
89
+ const expected = await testsCovering(root, [entry]);
90
+ assert.deepEqual(expected.get(source), [sibling]);
91
+ assert.deepEqual(await testsCovering(root, [entry.replace(/\//g, "\\")]), expected);
92
+ }
93
+ });
94
+
15
95
  test("the e2e warning names qc e2e when the merge base is unavailable", (t) => {
16
96
  const root = fixture(t, { e2e: record, base: "missing-ref" });
17
97
  const run = spawnSync(process.execPath, [qc, "e2e"], { cwd: root, encoding: "utf8" });
@@ -37,7 +117,7 @@ test("an invalid feature switch pattern prints a config error without a stack tr
37
117
 
38
118
  function fixture(t, check = {}) {
39
119
  const root = mkdtempSync(path.join(tmpdir(), "qc-check-commands-"));
40
- t.after(() => rmSync(root, { recursive: true, force: true }));
120
+ t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
41
121
  git(root, "init", "-q", "-b", "main");
42
122
  git(root, "config", "user.name", "QC test");
43
123
  git(root, "config", "user.email", "qc@example.test");
@@ -56,14 +136,14 @@ function fixture(t, check = {}) {
56
136
  }
57
137
 
58
138
  function check(root, args = [], input, env = process.env) {
59
- return spawnSync(process.execPath, [qc, "check", ...args], { cwd: root, encoding: "utf8", input, env });
139
+ return spawnSync(process.execPath, [qc, "check", ...args], { cwd: root, encoding: "utf8", input, env: { ...env, NODE_TEST_CONTEXT: undefined } });
60
140
  }
61
141
 
62
142
  // Fixture fragment with commits before and after the push.
63
143
  function sincePushFixture(t, config, { push = true, changes = true } = {}) {
64
144
  const root = fixture(t, config);
65
145
  const origin = mkdtempSync(path.join(tmpdir(), "qc-check-origin-"));
66
- t.after(() => rmSync(origin, { recursive: true, force: true }));
146
+ t.after(() => rmSync(origin, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
67
147
  git(origin, "init", "-q", "--bare");
68
148
  git(root, "remote", "add", "origin", origin);
69
149
  writeFileSync(path.join(root, "early.mjs"), "export {};\n");
@@ -179,7 +259,7 @@ test("repository commands run in order and stop with the failing command's exit
179
259
 
180
260
  test("commands resolve PATH shims and preserve literal arguments and exit codes", (t) => {
181
261
  const bin = mkdtempSync(path.join(tmpdir(), "qc command shims "));
182
- t.after(() => rmSync(bin, { recursive: true, force: true }));
262
+ t.after(() => rmSync(bin, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
183
263
  const source = 'require("node:fs").writeFileSync("args.json", JSON.stringify(process.argv.slice(3))); console.log("shim output"); process.exit(Number(process.argv[2]));\n';
184
264
  if (process.platform === "win32") {
185
265
  writeFileSync(path.join(bin, "shim.cjs"), source);
@@ -268,3 +348,197 @@ test("related excludes staged deletions and receives the new path of a staged re
268
348
  assert.equal(run.status, 0, run.stderr);
269
349
  assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["renamed file.mjs"]);
270
350
  });
351
+
352
+
353
+ test("--affected runs a test that spawns a CLI importing the changed module", (t) => {
354
+ const root = fixture(t);
355
+ const dir = "packages/qc-harness/src/cli";
356
+ mkdirSync(path.join(root, dir), { recursive: true });
357
+ const put = (file, text) => writeFileSync(path.join(root, dir, file), text);
358
+ put("lib.mjs", "export const value = 1;\n");
359
+ put("tool.mjs", "import { value } from './lib.mjs'; console.log(value);\n");
360
+ put("tool-spawn.test.mjs", `import { spawnSync } from 'node:child_process';
361
+ import assert from 'node:assert/strict';
362
+ import { fileURLToPath } from 'node:url';
363
+ const run = spawnSync(process.execPath, [fileURLToPath(new URL('./tool.mjs', import.meta.url))], { encoding: 'utf8' });
364
+ assert.equal(run.status, 0, run.stderr);
365
+ assert.equal(run.stdout.trim(), '2');
366
+ console.log('SPAWN TEST RAN');
367
+ `);
368
+ put("unrelated.test.mjs", "throw Error('UNRELATED TEST RAN');\n");
369
+ writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
370
+ git(root, "add", "."); git(root, "commit", "-qm", "test: seed spawned CLI");
371
+ const base = git(root, "rev-parse", "HEAD").trim();
372
+ put("lib.mjs", "export const value = 2;\n");
373
+ git(root, "add", ".");
374
+ const run = check(root, ["--affected", "--base", base]);
375
+ assert.equal(run.status, 0, run.stdout + run.stderr);
376
+ assert.match(run.stdout, /tool-spawn\.test\.mjs/);
377
+ assert.match(run.stdout, /SPAWN TEST RAN/);
378
+ assert.doesNotMatch(run.stdout + run.stderr, /unrelated\.test\.mjs|UNRELATED TEST RAN|FULL SUITE/);
379
+ });
380
+
381
+ test("--affected runs a changed test and the wrapper that spawns it", (t) => {
382
+ const root = fixture(t);
383
+ const dir = "packages/qc-harness/src/cli";
384
+ mkdirSync(path.join(root, dir), { recursive: true });
385
+ const put = (file, text) => writeFileSync(path.join(root, dir, file), text);
386
+ put("child.test.mjs", "console.log('CHILD BEFORE');\n");
387
+ put("wrapper.test.mjs", `import { spawnSync } from 'node:child_process';
388
+ import assert from 'node:assert/strict';
389
+ import { fileURLToPath } from 'node:url';
390
+ const run = spawnSync(process.execPath, ['--test', fileURLToPath(new URL('./child.test.mjs', import.meta.url))], { encoding: 'utf8', env: { ...process.env, NODE_TEST_CONTEXT: undefined } });
391
+ assert.equal(run.status, 0, run.stderr);
392
+ assert.match(run.stdout, /CHILD AFTER/);
393
+ console.log('WRAPPER RAN');
394
+ `);
395
+ put("unrelated.test.mjs", "throw Error('UNRELATED TEST RAN');\n");
396
+ writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
397
+ git(root, "add", "."); git(root, "commit", "-qm", "test: seed spawned test");
398
+ const base = git(root, "rev-parse", "HEAD").trim();
399
+ put("child.test.mjs", "console.log('CHILD AFTER');\n");
400
+ git(root, "add", ".");
401
+ const run = check(root, ["--affected", "--base", base]);
402
+ assert.equal(run.status, 0, run.stdout + run.stderr);
403
+ assert.match(run.stdout, /child\.test\.mjs/);
404
+ assert.match(run.stdout, /CHILD AFTER/);
405
+ assert.match(run.stdout, /wrapper\.test\.mjs/);
406
+ assert.match(run.stdout, /WRAPPER RAN/);
407
+ assert.doesNotMatch(run.stdout + run.stderr, /unrelated\.test\.mjs|UNRELATED TEST RAN|FULL SUITE/);
408
+ });
409
+
410
+ test("--affected selects only tests included in the full suite", (t) => {
411
+ const root = fixture(t);
412
+ const dir = "packages/qc-harness/src/cli";
413
+ mkdirSync(path.join(root, dir), { recursive: true });
414
+ mkdirSync(path.join(root, "evals/agents/tasks/x"), { recursive: true });
415
+ writeFileSync(path.join(root, dir, "module.mjs"), "export const value = 1;\n");
416
+ writeFileSync(path.join(root, dir, "module.test.mjs"), "import './module.mjs'; console.log('SUITE TEST RAN');\n");
417
+ writeFileSync(path.join(root, "evals/agents/run.test.mjs"), "// module.mjs\nconsole.log('EVAL RUNNER RAN');\n");
418
+ writeFileSync(path.join(root, "evals/agents/tasks/x/hidden.test.ts"), "// module.mjs\nthrow Error('HIDDEN TEST RAN');\n");
419
+ writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
420
+ git(root, "add", "."); git(root, "commit", "-qm", "test: seed suite selection");
421
+ const base = git(root, "rev-parse", "HEAD").trim();
422
+ writeFileSync(path.join(root, dir, "module.mjs"), "export const value = 2;\n");
423
+ git(root, "add", ".");
424
+ const run = check(root, ["--affected", "--base", base]);
425
+ assert.equal(run.status, 0, run.stdout + run.stderr);
426
+ assert.match(run.stdout, /SUITE TEST RAN/);
427
+ assert.match(run.stdout, /EVAL RUNNER RAN/);
428
+ assert.doesNotMatch(run.stdout + run.stderr, /hidden\.test\.ts|HIDDEN TEST RAN|FULL SUITE/);
429
+ });
430
+
431
+ test("--affected with one changed gate file runs that gate's test file and not an unrelated one", (t) => {
432
+ const root = fixture(t);
433
+ const dir = "packages/qc-harness/src/cli";
434
+ mkdirSync(path.join(root, dir), { recursive: true });
435
+ const put = (file, text) => writeFileSync(path.join(root, dir, file), text);
436
+ const gates = path.join(root, "packages/qc-harness/src/gates");
437
+ mkdirSync(gates, { recursive: true });
438
+ writeFileSync(path.join(gates, "tree-scan.test.mjs"), "console.log('TREE SCAN');\n");
439
+ put("gate.mjs", "export const value = 1;\n");
440
+ put("bridge.mjs", "export { value, value as default } from './gate.mjs';\n");
441
+ for (const extension of ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"]) {
442
+ put(`reader.${extension}`, "export { value } from './gate.mjs';\n");
443
+ put(`reader-${extension}.test.mjs`, `if (false) import('./reader.${extension}'); console.log('GRAPH ${extension}');\n`);
444
+ }
445
+ const forms = [
446
+ "import value from './bridge.mjs';",
447
+ 'import { value }\nfrom "./bridge.mjs";',
448
+ "import * as values from './bridge.mjs';",
449
+ "export { value } from './bridge.mjs';",
450
+ 'export * from "./bridge.mjs";',
451
+ "import './bridge.mjs';",
452
+ 'await import("./bridge.mjs");',
453
+ "if (false) require('./bridge.mjs');",
454
+ "await import(`./bridge.mjs`);",
455
+ '// import "node:comment\nimport "./bridge.mjs";',
456
+ 'export { value } from /* comment */ "./gate.mjs";',
457
+ 'export const { value } = await import /* comment */ ("./gate.mjs");',
458
+ 'const target = "./" + "gate" + ".mjs"; export const { value } = await import /* comment */ (target);',
459
+ 'import /* comment */ "./bridge.mjs";',
460
+ 'export { value } from // comment\n "./bridge.mjs";',
461
+ 'await import // comment\n ( /* comment */ "./bridge.mjs" /* comment */ );',
462
+ 'if (false) require /* comment */ ( "./bridge.mjs" );',
463
+ 'const target = "./" + "bridge" + ".mjs"; if (false) require // comment\n (target);',
464
+ 'const url = "http://x"; await import("./bridge.mjs");',
465
+ "const text = '/* literal */'; await import('./bridge.mjs');",
466
+ 'const text = `http://x /* literal */`; await import("./bridge.mjs");',
467
+ 'const pattern = /[//]/; export { value } from "./gate.mjs";',
468
+ 'const text = `${`//`}`; export { value } from "./gate.mjs";',
469
+ 'const text = "escaped \\" // literal"; await import("./bridge.mjs");',
470
+ "const target = './bridge' + '.mjs'; await import(target);",
471
+ "const target = './bridge' + '.mjs'; if (false) require(target);",
472
+ "if (false) require('package');",
473
+ ];
474
+ for (const [index, source] of forms.entries()) {
475
+ put(`form-${index}.mjs`, source);
476
+ put(`form-${index}.test.mjs`, `import './form-${index}.mjs'; console.log('FORM ${index}');\n`);
477
+ }
478
+ for (const [name, source] of [["gate", ""], ["consumer", "import './bridge.mjs';"], ["unrelated", "throw Error('unrelated ran');"]]) {
479
+ put(`${name}.test.mjs`, `${source} console.log("${name}.test.mjs");\n`);
480
+ }
481
+ writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
482
+ git(root, "add", "."); git(root, "commit", "-qm", "test: seed affected graph");
483
+ const base = git(root, "rev-parse", "HEAD").trim();
484
+ put("gate.mjs", "export const value = 2;\n");
485
+ git(root, "add", "."); git(root, "commit", "-qm", "test: change gate");
486
+ let run = check(root, ["--affected", "--base", base]);
487
+ assert.equal(run.status, 0, run.stdout + run.stderr);
488
+ assert.match(run.stdout, /gate\.test\.mjs/);
489
+ assert.match(run.stdout, /consumer\.test\.mjs/);
490
+ assert.match(run.stdout, /TREE SCAN/);
491
+ assert.deepEqual([...forms.keys()].filter((index) => !new RegExp(`FORM ${index}\\b`).test(run.stdout)), [], run.stdout);
492
+ for (const extension of ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"]) assert.match(run.stdout, new RegExp(`GRAPH ${extension}\\b`));
493
+ assert.doesNotMatch(run.stdout, /unrelated\.test\.mjs|FULL SUITE/);
494
+ const omittedReaders = [
495
+ ["consumer.test.js", "import { value } from './gate.mjs'; if (value !== 1) throw Error('JS READER');"],
496
+ ["runtime.test.mjs", "import { spawnSync } from 'node:child_process'; const run = spawnSync(process.execPath, ['--input-type=module', '-e', `import { value } from ${JSON.stringify(new URL('./gate.mjs', import.meta.url).href)}; process.exit(value === 1 ? 0 : 1)`]); if (run.status !== 0) throw Error('RUNTIME READER');"],
497
+ ];
498
+ const omittedRuns = omittedReaders.map(([file, source]) => {
499
+ put(file, source);
500
+ const result = check(root, ["--affected", "--base", base]);
501
+ rmSync(path.join(root, dir, file), { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
502
+ return result;
503
+ });
504
+ assert.deepEqual(omittedRuns.map(({ status }) => status), [0, 1], omittedRuns.map(({ stdout, stderr }) => stdout + stderr).join("\n"));
505
+ assert.doesNotMatch(omittedRuns[0].stdout + omittedRuns[0].stderr, /consumer\.test\.js|JS READER/);
506
+ for (const result of omittedRuns) assert.doesNotMatch(result.stdout, /unrelated\.test\.mjs|FULL SUITE/);
507
+ put("dynamic.test.mjs", "const target = './' + 'gate' + '.mjs'; await import(target); if (false) require(target); console.log('DYNAMIC COVERED');\n");
508
+ git(root, "add", ".");
509
+ run = check(root, ["--affected", "--base", base]);
510
+ assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /DYNAMIC COVERED/);
511
+ git(root, "reset", "--hard", "HEAD");
512
+ for (const args of [["--affected", "--full"], ["--affected", "--since-push"], ["--affected", "--os", "linux"], ["--affected", "gate.mjs"], ["--affected", "--base"], ["--base", base]]) {
513
+ run = check(root, args);
514
+ assert.equal(run.status, 1, JSON.stringify(args));
515
+ assert.match(run.stderr, /qc check:/);
516
+ }
517
+ for (const file of ["shared.json", `${dir}/orphan.mjs`]) {
518
+ writeFileSync(path.join(root, file), "{}\n"); git(root, "add", file);
519
+ run = check(root, ["--affected", "--base", base]);
520
+ assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
521
+ git(root, "reset", "--hard", "HEAD");
522
+ }
523
+ git(root, "mv", `${dir}/gate.mjs`, `${dir}/renamed.mjs`);
524
+ run = check(root, ["--affected", "--base", base]);
525
+ assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
526
+ git(root, "reset", "--hard", "HEAD");
527
+ git(root, "rm", `${dir}/gate.mjs`);
528
+ run = check(root, ["--affected", "--base", base]);
529
+ assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
530
+ git(root, "reset", "--hard", "HEAD");
531
+ run = check(root, ["--affected", "--base", "missing-ref"]);
532
+ assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
533
+ const configFile = path.join(root, "qc.config.json");
534
+ const settings = JSON.parse(readFileSync(configFile, "utf8"));
535
+ settings.check.related = record;
536
+ writeFileSync(configFile, JSON.stringify(settings));
537
+ run = check(root, ["--affected", "--base", base]);
538
+ assert.equal(run.status, 0, run.stderr);
539
+ assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"))), [`${dir}/gate.mjs`]);
540
+ assert.doesNotMatch(run.stdout, /FULL SUITE/);
541
+ settings.check.related = node("process.exit(7)");
542
+ writeFileSync(configFile, JSON.stringify(settings));
543
+ assert.equal(check(root, ["--affected", "--base", base]).status, 7);
544
+ });
@@ -0,0 +1,153 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { execFileSync, spawnSync } from "node:child_process";
4
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { runAffectedCheck, runFullCheck } from "./check.mjs";
8
+
9
+ function fixture(overrides = {}) {
10
+ const records = [], calls = [];
11
+ const options = {
12
+ platform: 'win32', git: (...args) => args[0] === 'status' ? '' : 'head',
13
+ gates: async () => ({ problems: [], lines: [] }), commands: async () => 0,
14
+ suite: async () => 0, record: (_root, value) => records.push(value),
15
+ spawn: (cmd, args) => { calls.push([cmd, args]); return { status: 0 }; },
16
+ nodeMajor: () => '22', write: () => {}, ...overrides,
17
+ };
18
+ return { options, records, calls };
19
+ }
20
+ const config = { root: 'C:\\repo with space', check: {} };
21
+ test('full check runs gates, commands, and suite, then records the clean host head', async () => {
22
+ const order = [];
23
+ const { options, records } = fixture({
24
+ gates: async () => { order.push('gates'); return { problems: [], lines: [] }; },
25
+ commands: async () => { order.push('commands'); return 0; },
26
+ suite: async () => { order.push('suite'); return 0; },
27
+ });
28
+ assert.equal(await runFullCheck(config, [], options), 0);
29
+ assert.deepEqual(order, ['gates', 'commands', 'suite']);
30
+ assert.deepEqual(records, [{ type: 'leg', os: 'windows', head: 'head', source: 'local' }]);
31
+ });
32
+ for (const stage of ['gates', 'commands', 'suite', 'dirty', 'head changed']) {
33
+ test(`records no evidence for ${stage}`, async () => {
34
+ let heads = 0;
35
+ const { options, records } = fixture({
36
+ ...(stage === 'gates' ? { gates: async () => ({ problems: [{ path: 'a', rule: 'bad', detail: 'bad' }], lines: [] }) } : {}),
37
+ ...(stage === 'commands' ? { commands: async () => 1 } : {}),
38
+ ...(stage === 'suite' ? { suite: async () => 1 } : {}),
39
+ ...(stage === 'dirty' ? { git: (...args) => args[0] === 'status' ? ' M a' : 'head' } : {}),
40
+ ...(stage === 'head changed' ? { git: (...args) => args[0] === 'status' ? '' : String(heads++) } : {}),
41
+ });
42
+ await runFullCheck(config, [], options);
43
+ assert.deepEqual(records, []);
44
+ });
45
+ }
46
+ test('Windows uses Docker and engines Node major for a Linux leg', async () => {
47
+ const { options, calls, records } = fixture();
48
+ assert.equal(await runFullCheck(config, ['--os', 'linux'], options), 0);
49
+ assert.equal(calls[0][0], 'docker');
50
+ assert.ok(calls[1][1].includes('node:22'));
51
+ assert.ok(calls[1][1].includes('type=bind,source=C:\\repo with space,target=/workspace'));
52
+ assert.ok(calls[1][1].some((arg) => arg.startsWith('QC_PLATFORM_GIT_DIR=/qc-git')));
53
+ assert.ok(calls[1][1].every((arg) => !arg.startsWith('GIT_DIR=') && !arg.startsWith('GIT_WORK_TREE=')));
54
+ assert.match(calls[1][1].at(-1), /mktemp -d.*git -c core.autocrlf=false -c core.eol=lf --git-dir="\$QC_PLATFORM_GIT_DIR" archive --format=tar --output="\$qc_tree\/source.tar" 'head'/);
55
+ assert.doesNotMatch(calls[1][1].at(-1), /tar --exclude/);
56
+ assert.equal(records[0].os, 'linux');
57
+ });
58
+ test('Windows falls back to WSL when Docker is absent', async () => {
59
+ const { options, records, calls } = fixture();
60
+ options.spawn = (cmd, args) => { calls.push([cmd, args]); return cmd === 'docker' ? { error: new Error('absent') } : { status: 0, stdout: '/mnt/c/repo\n' }; };
61
+ assert.equal(await runFullCheck(config, ['--os', 'linux'], options), 0);
62
+ assert.equal(calls.at(-1)[0], 'wsl');
63
+ assert.ok(calls.at(-1)[1].includes('/mnt/c/repo'));
64
+ assert.ok(calls.at(-1)[1].every((arg) => !arg.startsWith('GIT_DIR=') && !arg.startsWith('GIT_WORK_TREE=')));
65
+ assert.doesNotMatch(calls.at(-1)[1].at(-1), /corepack enable/);
66
+ assert.match(calls.at(-1)[1].at(-1), /git -c core.autocrlf=false -c core.eol=lf --git-dir="\$QC_PLATFORM_GIT_DIR" archive --format=tar --output="\$qc_tree\/source.tar" 'head'/);
67
+ assert.equal(records[0].os, 'linux');
68
+ });
69
+
70
+ test('the Linux view uses the pinned head bytes despite a CRLF checkout and later edits', async (t) => {
71
+ const root = mkdtempSync(path.join(os.tmpdir(), 'qc-linux-bytes-'));
72
+ t.after(() => rmSync(root, { recursive: true, force: true }));
73
+ const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
74
+ git('init');
75
+ git('config', 'user.name', 'Fixture');
76
+ git('config', 'user.email', 'fixture@example.test');
77
+ git('config', 'core.autocrlf', 'true');
78
+ writeFileSync(path.join(root, 'source.sh'), 'echo stored\n');
79
+ git('add', 'source.sh');
80
+ git('commit', '-m', 'fixture');
81
+ rmSync(path.join(root, 'source.sh'));
82
+ git('checkout', '--', 'source.sh');
83
+ assert.equal(readFileSync(path.join(root, 'source.sh'), 'utf8'), 'echo stored\r\n');
84
+ const head = git('rev-parse', 'HEAD');
85
+ const { options, calls } = fixture({ git });
86
+ assert.equal(await runFullCheck({ root, check: {} }, ['--os', 'linux'], options), 0);
87
+ writeFileSync(path.join(root, 'source.sh'), 'echo edited\r\n');
88
+ writeFileSync(path.join(root, 'untracked.sh'), 'echo untracked\r\n');
89
+ git('add', 'source.sh');
90
+ git('commit', '-m', 'later fixture');
91
+ assert.notEqual(git('rev-parse', 'HEAD'), head);
92
+ const script = calls[1][1].at(-1).split('corepack enable && ')[0];
93
+ const bash = process.platform === 'win32' ? path.join(process.env.ProgramFiles, 'Git', 'bin', 'bash.exe') : 'sh';
94
+ assert.ok(process.platform !== 'win32' || existsSync(bash), 'Git Bash is required on Windows');
95
+ const result = spawnSync(bash, ['-xc', `${script}test "$(cat source.sh)" = 'echo stored' && test "$(wc -c < source.sh)" -eq 12 && test ! -e untracked.sh`], {
96
+ cwd: root, encoding: 'utf8', env: { ...process.env, QC_PLATFORM_GIT_DIR: git('rev-parse', '--absolute-git-dir') },
97
+ });
98
+ assert.equal(result.status, 0, result.stdout + result.stderr);
99
+ });
100
+ test('failed Docker run produces no leg and does not retry in WSL', async () => {
101
+ const { options, records, calls } = fixture();
102
+ options.spawn = (cmd, args) => { calls.push([cmd, args]); return { status: args[0] === 'info' ? 0 : 1 }; };
103
+ assert.equal(await runFullCheck(config, ['--os', 'linux'], options), 1);
104
+ assert.equal(calls.length, 2);
105
+ assert.deepEqual(records, []);
106
+ });
107
+ test('rejects unknown arguments and unsupported target hosts', async () => {
108
+ const { options, records } = fixture({ platform: 'linux' });
109
+ assert.equal(await runFullCheck(config, ['--os', 'windows'], options), 1);
110
+ assert.equal(await runFullCheck(config, ['a.mjs'], options), 1);
111
+ assert.deepEqual(records, []);
112
+ });
113
+
114
+ test('unavailable WSL records no Linux evidence', async () => {
115
+ const { options, records } = fixture({ spawn: () => ({ status: 1 }) });
116
+ assert.equal(await runFullCheck(config, ['--os', 'linux'], options), 1);
117
+ assert.deepEqual(records, []);
118
+ });
119
+
120
+ test('the parent records its temporary view without suppressing evidence in nested fixtures', async (t) => {
121
+ const previous = process.env.QC_PLATFORM_LEG_PARENT;
122
+ process.env.QC_PLATFORM_LEG_PARENT = config.root;
123
+ t.after(() => {
124
+ if (previous === undefined) delete process.env.QC_PLATFORM_LEG_PARENT;
125
+ else process.env.QC_PLATFORM_LEG_PARENT = previous;
126
+ });
127
+ const { options, records } = fixture();
128
+ assert.equal(await runFullCheck(config, [], options), 0);
129
+ assert.deepEqual(records, []);
130
+ assert.equal(await runFullCheck({ ...config, root: 'another-fixture' }, [], options), 0);
131
+ assert.equal(records.length, 1);
132
+ });
133
+
134
+
135
+ test('affected checks preserve gate and command failures and record only a clean unchanged supported head', async () => {
136
+ for (const stage of ['pass', 'darwin', 'gates', 'commands', 'gate error', 'command error', 'dirty', 'checkout dirtied', 'head changed', 'unsupported']) {
137
+ let heads = 0, statuses = 0;
138
+ const { options, records } = fixture({
139
+ ...(stage === 'gates' ? { gates: async () => ({ problems: [{ path: 'a', rule: 'bad', detail: 'bad' }], lines: [] }) } : {}),
140
+ ...(stage === 'commands' ? { commands: async () => 7 } : {}),
141
+ ...(stage === 'gate error' ? { gates: async () => { throw new Error('gate error'); } } : {}),
142
+ ...(stage === 'command error' ? { commands: async () => { throw new Error('command error'); } } : {}),
143
+ ...(stage === 'dirty' ? { git: (...args) => args[0] === 'status' ? ' M a' : 'head' } : {}),
144
+ ...(stage === 'checkout dirtied' ? { git: (...args) => args[0] === 'status' ? (statuses++ ? ' M a' : '') : 'head' } : {}),
145
+ ...(stage === 'head changed' ? { git: (...args) => args[0] === 'status' ? '' : String(heads++) } : {}),
146
+ ...(stage === 'darwin' ? { platform: 'darwin' } : {}),
147
+ ...(stage === 'unsupported' ? { platform: 'freebsd' } : {}),
148
+ });
149
+ const code = await runAffectedCheck(config, { base: 'main' }, options);
150
+ assert.equal(code, ['gates', 'gate error', 'command error', 'unsupported'].includes(stage) ? 1 : stage === 'commands' ? 7 : 0);
151
+ assert.deepEqual(records, ['pass', 'darwin'].includes(stage) ? [{ type: 'leg', os: stage === 'darwin' ? 'darwin' : 'windows', head: 'head', source: 'local' }] : []);
152
+ }
153
+ });
package/src/cli/check.mjs CHANGED
@@ -3,6 +3,11 @@
3
3
 
4
4
  import { readFile, stat } from "node:fs/promises";
5
5
  import path from "node:path";
6
+ import { spawnSync } from "node:child_process";
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { fileURLToPath } from "node:url";
9
+ import { appendLeg, gitText, hostOS } from "./legs.mjs";
10
+ import { runCheckCommands, runCommand } from "./check-commands.mjs";
6
11
  import { checkFeatureAnatomy, checkNoEmptyBlock } from "../gates/eight-blocks.mjs";
7
12
  import { checkCitations, checkDocPaths, checkSelfContained, definedIds } from "../gates/citations.mjs";
8
13
  import { checkAgreement, declaredValues } from "../gates/registry-agreement.mjs";
@@ -38,6 +43,7 @@ import { checkFrontendBoundaries } from "../gates/frontend-boundaries.mjs";
38
43
  import { checkTestMirror, mirrorFolders } from "../gates/test-mirror.mjs";
39
44
  import { checkCommentStyle } from "../gates/comment-style.mjs";
40
45
  import { checkEnglishFiles, checkEnglishSource, checkTranslationPairs } from "../gates/english-source.mjs";
46
+ import { checkPlainLanguage } from "../gates/plain-language.mjs";
41
47
  import { checkAdrFormat } from "../gates/adr-format.mjs";
42
48
  import { checkConfigFloor } from "../gates/config-floor.mjs";
43
49
  import { defaults } from "../config.mjs";
@@ -81,6 +87,99 @@ const PATHSPEC_BUDGET = 8_000;
81
87
 
82
88
  const read = (file) => readFile(file, "utf8").catch(() => null);
83
89
 
90
+ function nodeMajor(root) {
91
+ const engines = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")).engines?.node;
92
+ const major = /\d+/.exec(engines ?? "")?.[0];
93
+ if (!major) throw new Error("package.json engines.node must name a Node major");
94
+ return major;
95
+ }
96
+
97
+ function testSuite(root) {
98
+ const manager = existsSync(path.join(root, "pnpm-lock.yaml")) ? "pnpm" : existsSync(path.join(root, "yarn.lock")) ? "yarn" : "npm";
99
+ return runCommand(root, `${manager} test`);
100
+ }
101
+
102
+ const cleanHead = (git) => git("status", "--porcelain", "--untracked-files=all") === "";
103
+
104
+ async function checkGates(config, options, write) {
105
+ const { problems, lines } = await (options.gates ?? runCheck)(config);
106
+ for (const line of lines) write(line);
107
+ for (const problem of problems) write(`FAIL ${problem.feature ?? problem.path} ${problem.rule}: ${problem.detail}`);
108
+ return problems.length === 0;
109
+ }
110
+
111
+ function recordCleanLeg(config, git, head, clean, os, record = appendLeg) {
112
+ if (process.env.QC_PLATFORM_LEG_PARENT !== config.root && clean && git("rev-parse", "HEAD") === head && cleanHead(git)) {
113
+ record(config.root, { type: "leg", os, head, source: "local" });
114
+ }
115
+ }
116
+
117
+ export async function runFullCheck(config, args = [], options = {}) {
118
+ const write = options.write ?? console.log;
119
+ const git = options.git ?? ((...words) => gitText(config.root, ...words));
120
+ const spawn = options.spawn ?? spawnSync;
121
+ const record = options.record ?? appendLeg;
122
+ const host = hostOS(options.platform);
123
+ const target = args.length === 0 ? host : args.length === 2 && args[0] === "--os" ? args[1] : null;
124
+ if (!["linux", "windows"].includes(target) || (target !== host && !(host === "windows" && target === "linux"))) {
125
+ write("check --full accepts --os linux or --os windows; cross-platform runs need Windows and target Linux");
126
+ return 1;
127
+ }
128
+ try {
129
+ const head = git("rev-parse", "HEAD");
130
+ const clean = cleanHead(git);
131
+ let code;
132
+ if (target !== host) {
133
+ const major = (options.nodeMajor ?? nodeMajor)(config.root);
134
+ const opts = { cwd: config.root, stdio: "inherit", windowsHide: true };
135
+ const docker = spawn("docker", ["info"], { ...opts, stdio: "ignore" });
136
+ const cli = path.relative(config.root, fileURLToPath(new URL("./qc.mjs", import.meta.url))).split(path.sep).join("/");
137
+ const quotedCli = `'${cli.replace(/'/g, "'\\''")}'`;
138
+ const command = `if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile; else npm ci; fi && node ${quotedCli} check --full`;
139
+ // A temporary view gives Linux its own dependencies without exporting Git variables into test fixtures.
140
+ const linuxView = `qc_tree=$(mktemp -d /tmp/qc-platform.XXXXXX) && trap 'rm -rf "$qc_tree"' EXIT && git -c core.autocrlf=false -c core.eol=lf --git-dir="$QC_PLATFORM_GIT_DIR" archive --format=tar --output="$qc_tree/source.tar" '${head.replace(/'/g, "'\\''")}' && tar -xf "$qc_tree/source.tar" -C "$qc_tree" && rm "$qc_tree/source.tar" && printf 'gitdir: %s\\n' "$QC_PLATFORM_GIT_DIR" > "$qc_tree/.git" && cd "$qc_tree" && export QC_PLATFORM_LEG_PARENT="$qc_tree" && `;
141
+ const common = path.resolve(config.root, git("rev-parse", "--git-common-dir"));
142
+ const gitDir = path.resolve(config.root, git("rev-parse", "--absolute-git-dir"));
143
+ if (docker.status === 0) {
144
+ const containerGitDir = path.posix.join("/qc-git", path.relative(common, gitDir).split(path.sep).join("/"));
145
+ code = spawn("docker", ["run", "--rm", "--mount", `type=bind,source=${config.root},target=/workspace`, "--mount", `type=bind,source=${common},target=/qc-git`, "-e", `QC_PLATFORM_GIT_DIR=${containerGitDir}`, "-w", "/workspace", `node:${major}`, "sh", "-lc", `${linuxView}corepack enable && ${command}`], opts).status ?? 1;
146
+ } else {
147
+ const convert = (value) => {
148
+ const converted = spawn("wsl", ["--exec", "wslpath", "-u", value], { ...opts, stdio: "pipe", encoding: "utf8" });
149
+ if (converted.status !== 0 || !converted.stdout?.trim()) throw new Error("Linux check needs Docker or WSL");
150
+ return converted.stdout.trim();
151
+ };
152
+ const wslRoot = convert(config.root);
153
+ const wslGit = convert(gitDir);
154
+ const wslCommand = `test "$(node -p 'process.versions.node.split(String.fromCharCode(46))[0]')" = ${major} && ${command}`;
155
+ code = spawn("wsl", ["--cd", wslRoot, "--exec", "env", `QC_PLATFORM_GIT_DIR=${wslGit}`, "sh", "-lc", `${linuxView}${wslCommand}`], opts).status ?? 1;
156
+ }
157
+ } else {
158
+ if (!await checkGates(config, options, write)) return 1;
159
+ code = await (options.commands ?? runCheckCommands)(config);
160
+ if (code === 0) code = await (options.suite ?? testSuite)(config.root);
161
+ }
162
+ if (code !== 0) return code;
163
+ recordCleanLeg(config, git, head, clean, target, record);
164
+ return 0;
165
+ } catch (error) { write(`check --full: ${error.message}`); return 1; }
166
+ }
167
+
168
+ export async function runAffectedCheck(config, selection = {}, options = {}) {
169
+ const write = options.write ?? console.log;
170
+ const git = options.git ?? ((...words) => gitText(config.root, ...words));
171
+ const os = hostOS(options.platform);
172
+ try {
173
+ if (!["linux", "windows", "darwin"].includes(os)) throw new Error("unsupported platform");
174
+ const head = git("rev-parse", "HEAD"), clean = cleanHead(git);
175
+ if (!await checkGates(config, options, write)) return 1;
176
+ const code = await (options.commands ?? runCheckCommands)(config, { ...selection, affected: true });
177
+ if (code !== 0) return code;
178
+ recordCleanLeg(config, git, head, clean, os, options.record);
179
+ return 0;
180
+ } catch (error) { write(`qc check: ${error.message}`); return 1; }
181
+ }
182
+
84
183
  /** A problem names a path a reader can open — forward slashes always, since every gate splits on "/". */
85
184
  const relativeTo = (root) => (file) => (path.relative(root, file) || file).split(path.sep).join("/");
86
185
 
@@ -918,6 +1017,20 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
918
1017
  }
919
1018
  }
920
1019
 
1020
+ if (enabled(config.gates, "plain-language")) {
1021
+ // Its own roots and its own extensions: a language rule asks which language, this one asks how
1022
+ // plainly, and a repository answers the two questions over different parts of its tree.
1023
+ const { roots, extensions, exclude } = config.plainLanguage;
1024
+ const extension = new RegExp(`\\.(${extensions.join("|")})$`);
1025
+ const excluded = exclude.map((pattern) => new RegExp(pattern));
1026
+ const files = roots
1027
+ .flatMap((root) => tree.under(root))
1028
+ .filter((file) => extension.test(file) && !excluded.some((pattern) => pattern.test(file)));
1029
+ const prose = await readEach(config.root, files);
1030
+ problems.push(...checkPlainLanguage(prose, config.plainLanguage));
1031
+ lines.push(`OK prose ${prose.length} file(s) in short sentences, the active voice and the approved words`);
1032
+ }
1033
+
921
1034
  if (enabled(config.gates, "adr-format")) {
922
1035
  const records = await citableFiles(config, tree, [config.adr.root]);
923
1036
  const docs = records.filter((file) => file.path.endsWith(".md"));