oh-my-copilot 5.25.2 → 5.26.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 (257) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -0
  4. package/bridge/claude-md-coordinator.cjs +2 -2
  5. package/bridge/cli.cjs +9249 -4138
  6. package/bridge/mcp-server.cjs +4894 -1400
  7. package/bridge/runtime-cli.cjs +14 -9
  8. package/bridge/team-mcp.cjs +3 -2
  9. package/bridge/team.js +14 -9
  10. package/dist/cli/commands/factory-bench.d.ts +10 -0
  11. package/dist/cli/commands/factory-bench.d.ts.map +1 -0
  12. package/dist/cli/commands/factory-bench.js +122 -0
  13. package/dist/cli/commands/factory-bench.js.map +1 -0
  14. package/dist/cli/commands/factory-dashboard.d.ts +14 -0
  15. package/dist/cli/commands/factory-dashboard.d.ts.map +1 -0
  16. package/dist/cli/commands/factory-dashboard.js +51 -0
  17. package/dist/cli/commands/factory-dashboard.js.map +1 -0
  18. package/dist/cli/commands/factory.d.ts.map +1 -1
  19. package/dist/cli/commands/factory.js +10 -2
  20. package/dist/cli/commands/factory.js.map +1 -1
  21. package/dist/copilot-run/__tests__/job.fail-closed.test.d.ts +2 -0
  22. package/dist/copilot-run/__tests__/job.fail-closed.test.d.ts.map +1 -0
  23. package/dist/copilot-run/__tests__/job.fail-closed.test.js +64 -0
  24. package/dist/copilot-run/__tests__/job.fail-closed.test.js.map +1 -0
  25. package/dist/copilot-run/__tests__/job.large-tree.test.d.ts +2 -0
  26. package/dist/copilot-run/__tests__/job.large-tree.test.d.ts.map +1 -0
  27. package/dist/copilot-run/__tests__/job.large-tree.test.js +47 -0
  28. package/dist/copilot-run/__tests__/job.large-tree.test.js.map +1 -0
  29. package/dist/copilot-run/__tests__/sandbox.test.js +125 -1
  30. package/dist/copilot-run/__tests__/sandbox.test.js.map +1 -1
  31. package/dist/copilot-run/job.d.ts.map +1 -1
  32. package/dist/copilot-run/job.js +14 -3
  33. package/dist/copilot-run/job.js.map +1 -1
  34. package/dist/copilot-run/sandbox.d.ts +53 -0
  35. package/dist/copilot-run/sandbox.d.ts.map +1 -1
  36. package/dist/copilot-run/sandbox.js +176 -14
  37. package/dist/copilot-run/sandbox.js.map +1 -1
  38. package/dist/factory/bench/__tests__/bench.fake.test.d.ts +2 -0
  39. package/dist/factory/bench/__tests__/bench.fake.test.d.ts.map +1 -0
  40. package/dist/factory/bench/__tests__/bench.fake.test.js +87 -0
  41. package/dist/factory/bench/__tests__/bench.fake.test.js.map +1 -0
  42. package/dist/factory/bench/__tests__/bench.smoke.test.d.ts +2 -0
  43. package/dist/factory/bench/__tests__/bench.smoke.test.d.ts.map +1 -0
  44. package/dist/factory/bench/__tests__/bench.smoke.test.js +54 -0
  45. package/dist/factory/bench/__tests__/bench.smoke.test.js.map +1 -0
  46. package/dist/factory/bench/__tests__/bench.units.test.d.ts +2 -0
  47. package/dist/factory/bench/__tests__/bench.units.test.d.ts.map +1 -0
  48. package/dist/factory/bench/__tests__/bench.units.test.js +842 -0
  49. package/dist/factory/bench/__tests__/bench.units.test.js.map +1 -0
  50. package/dist/factory/bench/fake-lanes.d.ts +39 -0
  51. package/dist/factory/bench/fake-lanes.d.ts.map +1 -0
  52. package/dist/factory/bench/fake-lanes.js +127 -0
  53. package/dist/factory/bench/fake-lanes.js.map +1 -0
  54. package/dist/factory/bench/fixture.d.ts +55 -0
  55. package/dist/factory/bench/fixture.d.ts.map +1 -0
  56. package/dist/factory/bench/fixture.js +128 -0
  57. package/dist/factory/bench/fixture.js.map +1 -0
  58. package/dist/factory/bench/model-probe.d.ts +37 -0
  59. package/dist/factory/bench/model-probe.d.ts.map +1 -0
  60. package/dist/factory/bench/model-probe.js +148 -0
  61. package/dist/factory/bench/model-probe.js.map +1 -0
  62. package/dist/factory/bench/runner.d.ts +163 -0
  63. package/dist/factory/bench/runner.d.ts.map +1 -0
  64. package/dist/factory/bench/runner.js +687 -0
  65. package/dist/factory/bench/runner.js.map +1 -0
  66. package/dist/factory/bench/score.d.ts +211 -0
  67. package/dist/factory/bench/score.d.ts.map +1 -0
  68. package/dist/factory/bench/score.js +386 -0
  69. package/dist/factory/bench/score.js.map +1 -0
  70. package/dist/factory/bench/seed/issues.d.ts +51 -0
  71. package/dist/factory/bench/seed/issues.d.ts.map +1 -0
  72. package/dist/factory/bench/seed/issues.js +536 -0
  73. package/dist/factory/bench/seed/issues.js.map +1 -0
  74. package/dist/factory/bench/seed/project.d.ts +24 -0
  75. package/dist/factory/bench/seed/project.d.ts.map +1 -0
  76. package/dist/factory/bench/seed/project.js +216 -0
  77. package/dist/factory/bench/seed/project.js.map +1 -0
  78. package/dist/factory/check/__tests__/cli-local.test.js +17 -0
  79. package/dist/factory/check/__tests__/cli-local.test.js.map +1 -1
  80. package/dist/factory/check/cli.d.ts +14 -0
  81. package/dist/factory/check/cli.d.ts.map +1 -1
  82. package/dist/factory/check/cli.js +21 -0
  83. package/dist/factory/check/cli.js.map +1 -1
  84. package/dist/factory/dashboard/__tests__/dashboard.test.d.ts +2 -0
  85. package/dist/factory/dashboard/__tests__/dashboard.test.d.ts.map +1 -0
  86. package/dist/factory/dashboard/__tests__/dashboard.test.js +148 -0
  87. package/dist/factory/dashboard/__tests__/dashboard.test.js.map +1 -0
  88. package/dist/factory/dashboard/collect.d.ts +96 -0
  89. package/dist/factory/dashboard/collect.d.ts.map +1 -0
  90. package/dist/factory/dashboard/collect.js +234 -0
  91. package/dist/factory/dashboard/collect.js.map +1 -0
  92. package/dist/factory/dashboard/render.d.ts +11 -0
  93. package/dist/factory/dashboard/render.d.ts.map +1 -0
  94. package/dist/factory/dashboard/render.js +77 -0
  95. package/dist/factory/dashboard/render.js.map +1 -0
  96. package/dist/factory/poll.d.ts +2 -0
  97. package/dist/factory/poll.d.ts.map +1 -1
  98. package/dist/factory/poll.js +2 -2
  99. package/dist/factory/poll.js.map +1 -1
  100. package/dist/factory/run/__tests__/auto-merge-flaky.test.d.ts +2 -0
  101. package/dist/factory/run/__tests__/auto-merge-flaky.test.d.ts.map +1 -0
  102. package/dist/factory/run/__tests__/auto-merge-flaky.test.js +131 -0
  103. package/dist/factory/run/__tests__/auto-merge-flaky.test.js.map +1 -0
  104. package/dist/factory/run/__tests__/auto-merge.test.d.ts +2 -0
  105. package/dist/factory/run/__tests__/auto-merge.test.d.ts.map +1 -0
  106. package/dist/factory/run/__tests__/auto-merge.test.js +541 -0
  107. package/dist/factory/run/__tests__/auto-merge.test.js.map +1 -0
  108. package/dist/factory/run/__tests__/container-gate.test.d.ts +2 -0
  109. package/dist/factory/run/__tests__/container-gate.test.d.ts.map +1 -0
  110. package/dist/factory/run/__tests__/container-gate.test.js +733 -0
  111. package/dist/factory/run/__tests__/container-gate.test.js.map +1 -0
  112. package/dist/factory/run/__tests__/engine.auto-merge.github.test.d.ts +2 -0
  113. package/dist/factory/run/__tests__/engine.auto-merge.github.test.d.ts.map +1 -0
  114. package/dist/factory/run/__tests__/engine.auto-merge.github.test.js +142 -0
  115. package/dist/factory/run/__tests__/engine.auto-merge.github.test.js.map +1 -0
  116. package/dist/factory/run/__tests__/engine.gates-container.test.d.ts +2 -0
  117. package/dist/factory/run/__tests__/engine.gates-container.test.d.ts.map +1 -0
  118. package/dist/factory/run/__tests__/engine.gates-container.test.js +245 -0
  119. package/dist/factory/run/__tests__/engine.gates-container.test.js.map +1 -0
  120. package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.d.ts +2 -0
  121. package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.d.ts.map +1 -0
  122. package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.js +71 -0
  123. package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.js.map +1 -0
  124. package/dist/factory/run/__tests__/engine.gates-git-view.test.d.ts +2 -0
  125. package/dist/factory/run/__tests__/engine.gates-git-view.test.d.ts.map +1 -0
  126. package/dist/factory/run/__tests__/engine.gates-git-view.test.js +141 -0
  127. package/dist/factory/run/__tests__/engine.gates-git-view.test.js.map +1 -0
  128. package/dist/factory/run/__tests__/engine.gates-workspace.test.d.ts +2 -0
  129. package/dist/factory/run/__tests__/engine.gates-workspace.test.d.ts.map +1 -0
  130. package/dist/factory/run/__tests__/engine.gates-workspace.test.js +130 -0
  131. package/dist/factory/run/__tests__/engine.gates-workspace.test.js.map +1 -0
  132. package/dist/factory/run/__tests__/engine.human-review.test.js +4 -4
  133. package/dist/factory/run/__tests__/engine.human-review.test.js.map +1 -1
  134. package/dist/factory/run/__tests__/engine.local.auto-merge.test.d.ts +2 -0
  135. package/dist/factory/run/__tests__/engine.local.auto-merge.test.d.ts.map +1 -0
  136. package/dist/factory/run/__tests__/engine.local.auto-merge.test.js +196 -0
  137. package/dist/factory/run/__tests__/engine.local.auto-merge.test.js.map +1 -0
  138. package/dist/factory/run/__tests__/engine.private.test.js +17 -0
  139. package/dist/factory/run/__tests__/engine.private.test.js.map +1 -1
  140. package/dist/factory/run/__tests__/fake-lanes.d.ts +2 -0
  141. package/dist/factory/run/__tests__/fake-lanes.d.ts.map +1 -1
  142. package/dist/factory/run/__tests__/fake-lanes.js +6 -1
  143. package/dist/factory/run/__tests__/fake-lanes.js.map +1 -1
  144. package/dist/factory/run/__tests__/git-view.test.d.ts +2 -0
  145. package/dist/factory/run/__tests__/git-view.test.d.ts.map +1 -0
  146. package/dist/factory/run/__tests__/git-view.test.js +120 -0
  147. package/dist/factory/run/__tests__/git-view.test.js.map +1 -0
  148. package/dist/factory/run/__tests__/merge-policy.test.js +10 -0
  149. package/dist/factory/run/__tests__/merge-policy.test.js.map +1 -1
  150. package/dist/factory/run/__tests__/prepare-gates.gates-resume.test.js +2 -0
  151. package/dist/factory/run/__tests__/prepare-gates.gates-resume.test.js.map +1 -1
  152. package/dist/factory/run/__tests__/prepare-gates.moving-base.test.d.ts +2 -0
  153. package/dist/factory/run/__tests__/prepare-gates.moving-base.test.d.ts.map +1 -0
  154. package/dist/factory/run/__tests__/prepare-gates.moving-base.test.js +103 -0
  155. package/dist/factory/run/__tests__/prepare-gates.moving-base.test.js.map +1 -0
  156. package/dist/factory/run/__tests__/private-run.test.js +37 -1
  157. package/dist/factory/run/__tests__/private-run.test.js.map +1 -1
  158. package/dist/factory/run/__tests__/units.test.js +8 -1
  159. package/dist/factory/run/__tests__/units.test.js.map +1 -1
  160. package/dist/factory/run/__tests__/workspace-tree.test.d.ts +2 -0
  161. package/dist/factory/run/__tests__/workspace-tree.test.d.ts.map +1 -0
  162. package/dist/factory/run/__tests__/workspace-tree.test.js +325 -0
  163. package/dist/factory/run/__tests__/workspace-tree.test.js.map +1 -0
  164. package/dist/factory/run/auto-merge.d.ts +254 -0
  165. package/dist/factory/run/auto-merge.d.ts.map +1 -0
  166. package/dist/factory/run/auto-merge.js +785 -0
  167. package/dist/factory/run/auto-merge.js.map +1 -0
  168. package/dist/factory/run/budget.d.ts +14 -0
  169. package/dist/factory/run/budget.d.ts.map +1 -1
  170. package/dist/factory/run/budget.js +24 -0
  171. package/dist/factory/run/budget.js.map +1 -1
  172. package/dist/factory/run/clean.d.ts +3 -0
  173. package/dist/factory/run/clean.d.ts.map +1 -1
  174. package/dist/factory/run/clean.js +34 -0
  175. package/dist/factory/run/clean.js.map +1 -1
  176. package/dist/factory/run/container-gate.d.ts +230 -0
  177. package/dist/factory/run/container-gate.d.ts.map +1 -0
  178. package/dist/factory/run/container-gate.js +1076 -0
  179. package/dist/factory/run/container-gate.js.map +1 -0
  180. package/dist/factory/run/engine.d.ts +5 -1
  181. package/dist/factory/run/engine.d.ts.map +1 -1
  182. package/dist/factory/run/engine.js +582 -40
  183. package/dist/factory/run/engine.js.map +1 -1
  184. package/dist/factory/run/exec.d.ts +5 -0
  185. package/dist/factory/run/exec.d.ts.map +1 -1
  186. package/dist/factory/run/exec.js +17 -3
  187. package/dist/factory/run/exec.js.map +1 -1
  188. package/dist/factory/run/git-view.d.ts +39 -0
  189. package/dist/factory/run/git-view.d.ts.map +1 -0
  190. package/dist/factory/run/git-view.js +77 -0
  191. package/dist/factory/run/git-view.js.map +1 -0
  192. package/dist/factory/run/lane-commit.d.ts +2 -0
  193. package/dist/factory/run/lane-commit.d.ts.map +1 -1
  194. package/dist/factory/run/lane-commit.js +3 -1
  195. package/dist/factory/run/lane-commit.js.map +1 -1
  196. package/dist/factory/run/local-gate.d.ts +1 -0
  197. package/dist/factory/run/local-gate.d.ts.map +1 -1
  198. package/dist/factory/run/local-gate.js +2 -1
  199. package/dist/factory/run/local-gate.js.map +1 -1
  200. package/dist/factory/run/merge-policy.d.ts +24 -6
  201. package/dist/factory/run/merge-policy.d.ts.map +1 -1
  202. package/dist/factory/run/merge-policy.js +29 -7
  203. package/dist/factory/run/merge-policy.js.map +1 -1
  204. package/dist/factory/run/prepare.d.ts +27 -1
  205. package/dist/factory/run/prepare.d.ts.map +1 -1
  206. package/dist/factory/run/prepare.js +241 -28
  207. package/dist/factory/run/prepare.js.map +1 -1
  208. package/dist/factory/run/private-run.d.ts +7 -0
  209. package/dist/factory/run/private-run.d.ts.map +1 -1
  210. package/dist/factory/run/private-run.js +34 -3
  211. package/dist/factory/run/private-run.js.map +1 -1
  212. package/dist/factory/run/private-store.d.ts +2 -0
  213. package/dist/factory/run/private-store.d.ts.map +1 -1
  214. package/dist/factory/run/private-store.js +2 -1
  215. package/dist/factory/run/private-store.js.map +1 -1
  216. package/dist/factory/run/sandbox-exec.d.ts +22 -1
  217. package/dist/factory/run/sandbox-exec.d.ts.map +1 -1
  218. package/dist/factory/run/sandbox-exec.js +9 -0
  219. package/dist/factory/run/sandbox-exec.js.map +1 -1
  220. package/dist/factory/run/workspace-tree.d.ts +75 -0
  221. package/dist/factory/run/workspace-tree.d.ts.map +1 -0
  222. package/dist/factory/run/workspace-tree.js +299 -0
  223. package/dist/factory/run/workspace-tree.js.map +1 -0
  224. package/dist/forge/__tests__/gh-argv-baseline.factory.test.js +7 -5
  225. package/dist/forge/__tests__/gh-argv-baseline.factory.test.js.map +1 -1
  226. package/dist/forge/github/__tests__/required-checks.test.js +22 -1
  227. package/dist/forge/github/__tests__/required-checks.test.js.map +1 -1
  228. package/dist/forge/github/checks.d.ts +9 -0
  229. package/dist/forge/github/checks.d.ts.map +1 -1
  230. package/dist/forge/github/checks.js +26 -0
  231. package/dist/forge/github/checks.js.map +1 -1
  232. package/dist/forge/github/merge.d.ts +27 -0
  233. package/dist/forge/github/merge.d.ts.map +1 -1
  234. package/dist/forge/github/merge.js +44 -0
  235. package/dist/forge/github/merge.js.map +1 -1
  236. package/dist/forge/github/reviews.d.ts +2 -0
  237. package/dist/forge/github/reviews.d.ts.map +1 -1
  238. package/dist/forge/github/reviews.js.map +1 -1
  239. package/dist/smoke/copilot-factory-run-scenario.d.ts.map +1 -1
  240. package/dist/smoke/copilot-factory-run-scenario.js +4 -0
  241. package/dist/smoke/copilot-factory-run-scenario.js.map +1 -1
  242. package/dist/team/git-worktree.d.ts +8 -1
  243. package/dist/team/git-worktree.d.ts.map +1 -1
  244. package/dist/team/git-worktree.js +9 -2
  245. package/dist/team/git-worktree.js.map +1 -1
  246. package/dist/team/merge-coordinator.js +5 -5
  247. package/dist/team/merge-coordinator.js.map +1 -1
  248. package/dist/team/merge-orchestrator.d.ts.map +1 -1
  249. package/dist/team/merge-orchestrator.js +3 -1
  250. package/dist/team/merge-orchestrator.js.map +1 -1
  251. package/dist/team/runtime-v2.d.ts.map +1 -1
  252. package/dist/team/runtime-v2.js +2 -2
  253. package/dist/team/runtime-v2.js.map +1 -1
  254. package/docs/CLAUDE.md +1 -1
  255. package/docs/REFERENCE.md +133 -1
  256. package/package.json +2 -2
  257. package/plugin.json +1 -1
@@ -0,0 +1,733 @@
1
+ /**
2
+ * container-gate.ts with an injected fake runtime: the argv of every
3
+ * runtime call (no credential mount or env, network none in the run phase,
4
+ * labels, names, cleanup scope), the verdict mapping, the install plan, and
5
+ * the guarded copy back of a prepare check's writes. No container runs.
6
+ */
7
+ import { existsSync, linkSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
8
+ import { tmpdir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
11
+ import { defaultGateImage, resolveGateIsolation } from '../../../copilot-run/sandbox.js';
12
+ import { applyCopyBack, checkoutCopyProblem, cleanRunContainers, copyScript, linkTargetProblem, lockfileCachePolicy, NPM_FETCH_ENV, sizeBytes, containerArgv, containerRunLabel, defaultContainerExec, installPlan, mountArg, readTar, runContainerGate, safeRelPath, } from '../container-gate.js';
13
+ let dir;
14
+ beforeEach(() => { dir = mkdtempSync(join(tmpdir(), 'omg-container-gate-')); });
15
+ afterEach(() => rmSync(dir, { recursive: true, force: true }));
16
+ const settings = (over = {}) => ({ ...resolveGateIsolation({ user: { factory: { run: { sandbox: { isolation: 'container' } } } }, base: undefined }).container, ...over });
17
+ const ok = (over = {}) => ({ status: 0, tail: '', overflow: false, timedOut: false, ...over });
18
+ const IMAGE_ID = `sha256:${'c'.repeat(64)}`;
19
+ /** A fake runtime: `answer` per call (by the first argv words), every call recorded. */
20
+ function fake(answer = () => ok(), inspectAnswered = false) {
21
+ const calls = [];
22
+ const exec = async (bin, args, o) => {
23
+ calls.push({ bin, args: [...args], o });
24
+ // No cache volume yet unless a test answers the inspect itself.
25
+ if (args[0] === 'volume' && args[1] === 'inspect' && !inspectAnswered)
26
+ return ok({ status: 1, tail: 'no such volume' });
27
+ const r = await answer(args, o);
28
+ // A present image reports its id unless the test answers the inspect itself (an empty answer is "present").
29
+ return args[0] === 'image' && args[1] === 'inspect' && r.status === 0 && r.tail === '' ? { ...r, tail: `${IMAGE_ID}\n` } : r;
30
+ };
31
+ const runs = () => calls.filter((c) => c.args[0] === 'run');
32
+ const step = (suffix) => runs().find((c) => c.args[c.args.indexOf('--name') + 1].endsWith(suffix));
33
+ return { calls, exec, runs, step };
34
+ }
35
+ const LABEL = 'abc123-issue-7';
36
+ const request = (over = {}) => ({ purpose: 'gate', argv: ['npm', 'test'], exe: 'npm', args: ['test'], cwd: dir, commonGitDir: join(dir, '.git'), timeoutMs: 60_000, ...over });
37
+ const npmProject = () => {
38
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'p', devDependencies: { vitest: '1.0.0' } }));
39
+ writeFileSync(join(dir, 'package-lock.json'), '{"lockfileVersion":3}');
40
+ };
41
+ const nameOf = (args) => args[args.indexOf('--name') + 1];
42
+ const values = (args, flag) => args.flatMap((a, i) => (a === flag ? [args[i + 1]] : []));
43
+ /** A ustar/pax tar of `entries` (what `tar --format=posix -cf -` prints). */
44
+ function tarOf(entries) {
45
+ const blocks = [];
46
+ const header = (name, size, type, mode, link = '') => {
47
+ const h = Buffer.alloc(512);
48
+ h.write(name.slice(0, 100), 0, 'utf8');
49
+ h.write(`${mode.toString(8).padStart(7, '0')}\0`, 100);
50
+ h.write('0000000\0', 108);
51
+ h.write('0000000\0', 116);
52
+ h.write(`${size.toString(8).padStart(11, '0')}\0`, 124);
53
+ h.write('00000000000\0', 136);
54
+ h.write(' ', 148);
55
+ h.write(type, 156);
56
+ h.write(link.slice(0, 100), 157);
57
+ h.write('ustar\0', 257);
58
+ h.write('00', 263);
59
+ let sum = 0;
60
+ for (const b of h)
61
+ sum += b;
62
+ h.write(`${sum.toString(8).padStart(6, '0')}\0 `, 148);
63
+ return h;
64
+ };
65
+ const pad = (b) => Buffer.concat([b, Buffer.alloc((512 - (b.length % 512)) % 512)]);
66
+ for (const e of entries) {
67
+ const data = Buffer.from(e.data ?? '');
68
+ if (e.path.length > 100) {
69
+ const rec = (body) => { let len = body.length + 3; while (`${len} ${body}\n`.length !== len)
70
+ len = `${len} ${body}\n`.length; return `${len} ${body}\n`; };
71
+ const pax = Buffer.from(rec(`path=${e.path}`));
72
+ blocks.push(header('PaxHeader', pax.length, 'x', 0o644), pad(pax));
73
+ }
74
+ const type = e.type ?? '0';
75
+ blocks.push(header(e.path, type === '0' ? data.length : 0, type, e.mode ?? 0o644, e.link));
76
+ if (type === '0')
77
+ blocks.push(pad(data));
78
+ }
79
+ blocks.push(Buffer.alloc(1024));
80
+ return Buffer.concat(blocks);
81
+ }
82
+ describe('resolveGateIsolation (user config only)', () => {
83
+ it('defaults to copilot; container gets the host Node major image and sane limits', () => {
84
+ expect(resolveGateIsolation({ user: undefined, base: undefined })).toEqual({ isolation: 'copilot', ignoredBase: [] });
85
+ const r = resolveGateIsolation({ user: { factory: { run: { sandbox: { isolation: 'container' } } } }, base: undefined }, '22.4.1');
86
+ expect(r.container).toEqual({ runtime: 'docker', image: 'node:22-bookworm-slim', memory: '4g', cpus: 2, pidsLimit: 1024, installTimeoutMinutes: 15, diskLimit: '10g' });
87
+ expect(defaultGateImage('25.1.0')).toBe('node:25-bookworm-slim');
88
+ });
89
+ it('a committed value is never applied, only named for the notice', () => {
90
+ const base = { factory: { run: { sandbox: { isolation: 'container', container: { image: 'evil/x', runtime: 'podman' } } } } };
91
+ expect(resolveGateIsolation({ user: undefined, base })).toEqual({ isolation: 'copilot', ignoredBase: ['factory.run.sandbox.isolation', 'factory.run.sandbox.container'] });
92
+ const both = resolveGateIsolation({ user: { factory: { run: { sandbox: { isolation: 'container', container: { image: 'node@sha256:abc' } } } } }, base });
93
+ expect(both.container?.image).toBe('node@sha256:abc');
94
+ expect(both.container?.runtime).toBe('docker');
95
+ });
96
+ it('rejects malformed user values, an option-shaped image and unknown keys', () => {
97
+ const user = (sandbox) => ({ user: { factory: { run: { sandbox } } }, base: undefined });
98
+ expect(() => resolveGateIsolation(user({ isolation: 'wsl' }))).toThrow(/isolation must be "copilot" or "container"/);
99
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { image: '--privileged' } }))).toThrow(/container\.image/);
100
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { image: 'a b' } }))).toThrow(/container\.image/);
101
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { mounts: ['/'] } }))).toThrow(/got mounts/);
102
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { runtime: 'nerdctl' } }))).toThrow(/runtime/);
103
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { pidsLimit: 1 } }))).toThrow(/pidsLimit/);
104
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { memory: '4 g' } }))).toThrow(/memory/);
105
+ expect(() => resolveGateIsolation(user({ isolation: 'container', container: { diskLimit: '10t' } }))).toThrow(/diskLimit/);
106
+ expect(resolveGateIsolation(user({ isolation: 'container', container: { diskLimit: '800m' } })).container?.diskLimit).toBe('800m');
107
+ });
108
+ });
109
+ describe('runContainerGate argv', () => {
110
+ it('copy (read-only bind, no network), install (network, no credential), run (network none): hardened, labelled, cleaned up', async () => {
111
+ npmProject();
112
+ const f = fake((args) => (args[0] === 'run' && nameOf([...args]).endsWith('-1234abcd') ? ok({ tail: 'tests passed' }) : ok()));
113
+ const env = { ...process.env };
114
+ process.env.GH_TOKEN = ['gho', 'x'.repeat(36)].join('_');
115
+ let r;
116
+ try {
117
+ r = await runContainerGate(request(), settings(), LABEL, { exec: f.exec, id: () => '1234abcd', log: () => undefined });
118
+ }
119
+ finally {
120
+ process.env = env;
121
+ }
122
+ expect(r).toEqual({ ran: true, status: 0, output: 'tests passed', timedOut: false, imageId: IMAGE_ID });
123
+ const name = `omg-gate-${LABEL}-1234abcd`;
124
+ expect(f.calls.map((c) => c.args.slice(0, 2).join(' '))).toEqual([
125
+ 'version --format', 'image inspect', 'volume create', 'volume inspect', 'volume create', 'run --name',
126
+ 'network create', 'run --name', 'network rm', 'run --name', 'run --name',
127
+ 'rm -f', 'rm -f', 'rm -f', 'rm -f', 'volume rm',
128
+ ]);
129
+ expect(f.calls.every((c) => c.bin === 'docker')).toBe(true);
130
+ expect(f.calls[2].args).toEqual(['volume', 'create', '--label', `omg.run=${LABEL}`, '--label', 'omg.gate=1', name]);
131
+ expect(f.calls[4].args).toEqual(['volume', 'create', '--label', 'omg.gate=1', '--label', 'omg.cache=npm', expect.stringMatching(/^omg-gate-cache-[0-9a-f]{16}$/)]);
132
+ // Our own bridge for npm, labelled, inter-container traffic off; removed right after npm ci.
133
+ expect(f.calls[6].args).toEqual(['network', 'create', '--label', `omg.run=${LABEL}`, '--label', 'omg.gate=1', '--driver', 'bridge', '-o', 'com.docker.network.bridge.enable_icc=false', `${name}-net`]);
134
+ expect(f.calls[8].args).toEqual(['network', 'rm', `${name}-net`]);
135
+ expect(f.calls.filter((c) => c.args[0] === 'rm').map((c) => c.args[2])).toEqual([`${name}-copy`, `${name}-install`, `${name}-scripts`, name]);
136
+ expect(f.calls.at(-1).args).toEqual(['volume', 'rm', '-f', name]);
137
+ expect(f.runs().map((c) => nameOf(c.args))).toEqual([`${name}-copy`, `${name}-install`, `${name}-scripts`, name]);
138
+ for (const c of f.runs()) {
139
+ const a = c.args;
140
+ for (const flag of ['--rm', '--init', '--read-only'])
141
+ expect(a).toContain(flag);
142
+ expect(values(a, '--cap-drop')).toEqual(['ALL']);
143
+ expect(values(a, '--security-opt')).toEqual(['no-new-privileges']);
144
+ expect(values(a, '--pids-limit')).toEqual(['1024']);
145
+ expect(values(a, '--memory')).toEqual(['4g']);
146
+ expect(values(a, '--pull')).toEqual(['never']);
147
+ expect(values(a, '--label')).toEqual([`omg.run=${LABEL}`, 'omg.gate=1']);
148
+ // No -v, no socket, no privileged, no host env passthrough, no credential anywhere.
149
+ expect(a).not.toContain('-v');
150
+ expect(a).not.toContain('--privileged');
151
+ expect(a.join(' ')).not.toMatch(/docker\.sock|\.ssh|\.gitconfig|SSH_AUTH|GH_TOKEN|GITHUB_TOKEN|gho_/);
152
+ // .npmrc is named only by the fixed copy/scripts text (held aside, put back), never mounted or passed.
153
+ expect([...values(a, '--mount'), ...values(a, '-e')].join(' ')).not.toMatch(/\.npmrc/);
154
+ expect(values(a, '--log-driver')).toEqual(['none']);
155
+ expect(values(a, '-e').map((e) => e.split('=')[0]).filter((k) => !['PATH', 'HOME', 'CI', 'npm_config_update_notifier', 'npm_config_fund', 'npm_config_audit', 'npm_config_cache', ...Object.keys(NPM_FETCH_ENV)].includes(k))).toEqual([]);
156
+ expect(values(a, '--env')).toEqual([]);
157
+ // The container ends itself after its time even when the runtime's kill does not get through (M1).
158
+ expect(a.slice(a.indexOf(IMAGE_ID) + 1, a.indexOf(IMAGE_ID) + 4)).toEqual(['timeout', '-s', 'KILL']);
159
+ }
160
+ // The only host path mounted is the checkout, read-only, in the copy step (no PR code runs there).
161
+ const binds = f.runs().flatMap((c) => values(c.args, '--mount').filter((m) => m.includes('type=bind')));
162
+ expect(binds).toEqual([`type=bind,source=${dir},target=/in,readonly`]);
163
+ const copy = f.step('-copy').args;
164
+ expect(values(copy, '--network')).toEqual(['none']);
165
+ expect(copy.slice(-3, -1)).toEqual(['sh', '-c']);
166
+ expect(copy.at(-1)).not.toContain(dir);
167
+ // review-499b N2: the checkout's .npmrc is held outside the project while npm fetches.
168
+ expect(copy.at(-1)).toBe(copyScript(true));
169
+ expect(copy.at(-1)).toMatch(/; if \[ -e \/work\/src\/\.npmrc \] \|\| \[ -L \/work\/src\/\.npmrc \]; then mv \/work\/src\/\.npmrc \/work\/npmrc\.held; fi$/);
170
+ // npm itself: network (our bridge), the shared cache, no install script (H1/H2).
171
+ const install = f.step('-install').args;
172
+ expect(values(install, '--network')).toEqual([`${name}-net`]);
173
+ expect(values(install, '--user')).toEqual(['1000:1000']);
174
+ expect(install.slice(-3)).toEqual(['npm', 'ci', '--ignore-scripts']);
175
+ expect(values(install, '--mount').filter((m) => m.includes('target=/cache'))).toHaveLength(1);
176
+ expect(values(install, '-e')).toContain('npm_config_cache=/cache/npm');
177
+ expect(values(install, '-e')).toEqual(expect.arrayContaining(['npm_config_registry=https://registry.npmjs.org/', 'npm_config_proxy=null', 'npm_config_https_proxy=null', 'npm_config_strict_ssl=true', 'npm_config_replace_registry_host=npmjs']));
178
+ // The install scripts (the PR's code): no network, no shared cache.
179
+ const scripts = f.step('-scripts').args;
180
+ expect(values(scripts, '--network')).toEqual(['none']);
181
+ expect(values(scripts, '--mount').some((m) => m.includes('cache'))).toBe(false);
182
+ expect(values(scripts, '-e')).toContain('npm_config_cache=/work/home/.npm');
183
+ expect(scripts.slice(-2)[0]).toBe('-c');
184
+ expect(scripts.at(-1)).toBe('set -e; if [ -e /work/npmrc.held ] || [ -L /work/npmrc.held ]; then rm -rf /work/src/.npmrc; mv /work/npmrc.held /work/src/.npmrc; fi; npm rebuild --foreground-scripts; for s in preinstall install postinstall prepublish preprepare prepare postprepare; do npm run --if-present --ignore-scripts "$s"; done');
185
+ const run = f.step('-1234abcd').args;
186
+ expect(values(run, '--network')).toEqual(['none']);
187
+ expect(values(run, '--user')).toEqual(['1000:1000']);
188
+ expect(values(run, '--mount').some((m) => m.includes('cache'))).toBe(false);
189
+ expect(run.slice(-7)).toEqual([IMAGE_ID, 'timeout', '-s', 'KILL', '90s', 'npm', 'test']);
190
+ expect(values(run, '-w')).toEqual(['/work/src']);
191
+ });
192
+ it('a git view is bound read-only for the copy step only and copied in as the copy\'s .git', async () => {
193
+ const f = fake();
194
+ const view = join(dir, 'view-git');
195
+ const r = await runContainerGate(request({ argv: ['node', '--test'], exe: process.execPath, args: ['--test'], gitView: view }), settings(), LABEL, { exec: f.exec, id: () => 'eeeeeeee' });
196
+ expect(r.ran).toBe(true);
197
+ const binds = f.runs().map((c) => values(c.args, '--mount').filter((m) => m.includes('type=bind')));
198
+ expect(binds).toEqual([[`type=bind,source=${dir},target=/in,readonly`, `type=bind,source=${view},target=/in-git,readonly`], []]);
199
+ const script = f.step('-copy').args.at(-1);
200
+ expect(script).toBe(copyScript(false, true));
201
+ expect(script).not.toContain(view);
202
+ expect(script).toContain('tar -C /in --exclude=.git --exclude=node_modules -cf /work/in.tar .');
203
+ expect(script).toContain('mkdir /work/src/.git; tar -C /in-git -cf /work/git.tar .; tar -C /work/src/.git -xf /work/git.tar; rm -f /work/git.tar; chown -R 1000:1000 /work');
204
+ // Without a view: no second bind and no .git in the copy (as before).
205
+ expect(copyScript(false)).not.toContain('/in-git');
206
+ });
207
+ it('no package.json: no install, no cache volume; podman is called as podman', async () => {
208
+ const f = fake();
209
+ const r = await runContainerGate(request({ argv: ['node', '--test'], exe: process.execPath, args: ['--test'] }), settings({ runtime: 'podman' }), LABEL, { exec: f.exec, id: () => 'ffffffff' });
210
+ expect(r.ran).toBe(true);
211
+ expect(f.calls.every((c) => c.bin === 'podman')).toBe(true);
212
+ expect(f.runs().map((c) => nameOf(c.args))).toEqual([`omg-gate-${LABEL}-ffffffff-copy`, `omg-gate-${LABEL}-ffffffff`]);
213
+ expect(f.calls.filter((c) => c.args[0] === 'volume' && c.args[1] === 'create')).toHaveLength(1);
214
+ expect(f.runs()[1].args.slice(-2)).toEqual(['node', '--test']);
215
+ // No install: no network is made.
216
+ expect(f.calls.some((c) => c.args[0] === 'network')).toBe(false);
217
+ });
218
+ it('a missing runtime, a daemon that does not answer, or a failed pull is unavailable; nothing runs', async () => {
219
+ const missing = fake(() => ok({ status: null, spawnError: 'spawn docker ENOENT' }));
220
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: missing.exec })).toMatchObject({ ran: false, unavailable: true, reason: expect.stringContaining('isolation "copilot"') });
221
+ expect(missing.calls).toHaveLength(1);
222
+ const down = fake(() => ok({ status: 1, tail: 'Cannot connect to the Docker daemon' }));
223
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: down.exec })).toMatchObject({ ran: false, unavailable: true, reason: expect.stringContaining('Cannot connect to the Docker daemon') });
224
+ expect(down.runs()).toEqual([]);
225
+ const logs = [];
226
+ const nopull = fake((args) => (args[0] === 'image' || args[0] === 'pull' ? ok({ status: 1, tail: 'manifest unknown' }) : ok()));
227
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: nopull.exec, log: (l) => logs.push(l) })).toMatchObject({ ran: false, unavailable: true });
228
+ // The pull was announced before it started, never silent.
229
+ expect(logs).toEqual([expect.stringContaining(`pulling the gate image ${settings().image}`)]);
230
+ expect(nopull.runs()).toEqual([]);
231
+ });
232
+ it('a yarn or pnpm project, or dependencies without a lockfile, is unavailable before any container', async () => {
233
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ dependencies: { a: '1' } }));
234
+ writeFileSync(join(dir, 'yarn.lock'), '');
235
+ const f = fake();
236
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: f.exec })).toMatchObject({ ran: false, unavailable: true, reason: expect.stringContaining('yarn.lock') });
237
+ expect(f.runs()).toEqual([]);
238
+ expect(installPlan(dir)).toMatchObject({ kind: 'unsupported' });
239
+ rmSync(join(dir, 'yarn.lock'));
240
+ expect(installPlan(dir)).toMatchObject({ kind: 'unsupported', reason: expect.stringContaining('no package-lock.json') });
241
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ scripts: { test: 'node --test' } }));
242
+ expect(installPlan(dir)).toEqual({ kind: 'none' });
243
+ });
244
+ it('maps exit codes: failure, timeout (kills only our container), runtime error 125 and a signal give no verdict', async () => {
245
+ const main = (args) => args[0] === 'run' && nameOf([...args]) === `omg-gate-${LABEL}-00000001`;
246
+ const at = async (result) => {
247
+ const f = fake((args, o) => {
248
+ if (!main(args))
249
+ return ok();
250
+ if (result.timedOut)
251
+ void o.onTimeout?.();
252
+ return result;
253
+ });
254
+ return { r: await runContainerGate(request(), settings(), LABEL, { exec: f.exec, id: () => '00000001' }), f };
255
+ };
256
+ expect((await at(ok({ status: 1, tail: 'FAIL greet' }))).r).toEqual({ ran: true, status: 1, output: 'FAIL greet', timedOut: false, imageId: IMAGE_ID });
257
+ const t = await at(ok({ status: 137, timedOut: true, tail: 'running' }));
258
+ expect(t.r).toMatchObject({ ran: true, status: 124, timedOut: true });
259
+ expect(t.f.calls.filter((c) => c.args[0] === 'kill').map((c) => c.args)).toEqual([['kill', `omg-gate-${LABEL}-00000001`]]);
260
+ // After the kill, and again in the cleanup: rm -f of our own container by name, never anything else.
261
+ expect(t.f.calls.filter((c) => c.args[0] === 'rm').map((c) => c.args)).toEqual([['rm', '-f', `omg-gate-${LABEL}-00000001`], ['rm', '-f', `omg-gate-${LABEL}-00000001-copy`], ['rm', '-f', `omg-gate-${LABEL}-00000001`]]);
262
+ expect((await at(ok({ status: 125, tail: 'docker: Error response from daemon' }))).r).toMatchObject({ ran: false, started: true });
263
+ expect((await at(ok({ status: null }))).r).toMatchObject({ ran: false, started: true });
264
+ });
265
+ it('an install failure is the command\'s failure (calibrated on the base like any other); a copy failure gives no verdict', async () => {
266
+ npmProject();
267
+ const inst = fake((args) => (args[0] === 'run' && nameOf([...args]).endsWith('-install') ? ok({ status: 1, tail: 'npm ERR! git dep needs ssh' }) : ok()));
268
+ const r = await runContainerGate(request(), settings(), LABEL, { exec: inst.exec });
269
+ expect(r).toMatchObject({ ran: true, status: 1, timedOut: false });
270
+ expect(r.ran && r.output).toContain('the dependency install (npm ci) in the gate container failed (exit 1)');
271
+ expect(inst.runs()).toHaveLength(2);
272
+ const scr = fake((args) => (args[0] === 'run' && nameOf([...args]).endsWith('-scripts') ? ok({ status: 1, tail: 'postinstall: getaddrinfo EAI_AGAIN' }) : ok()));
273
+ const rs = await runContainerGate(request(), settings(), LABEL, { exec: scr.exec });
274
+ expect(rs).toMatchObject({ ran: true, status: 1 });
275
+ expect(rs.ran && rs.output).toContain("the install scripts (npm rebuild and the root's install scripts, no network)");
276
+ expect(scr.runs()).toHaveLength(3);
277
+ const copy = fake((args) => (args[0] === 'run' ? ok({ status: 2 }) : ok()));
278
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: copy.exec })).toMatchObject({ ran: false, started: true });
279
+ // The volume is removed even then.
280
+ expect(copy.calls.at(-1).args.slice(0, 2)).toEqual(['volume', 'rm']);
281
+ });
282
+ it('redacts token-shaped output and keeps a bounded tail', async () => {
283
+ const token = ['ghp', 'A'.repeat(36)].join('_');
284
+ const f = fake((args) => (args[0] === 'run' && !nameOf([...args]).endsWith('-copy') ? ok({ status: 1, tail: `${'y'.repeat(20_000)}\nleaked ${token}\n` }) : ok()));
285
+ const r = await runContainerGate(request(), settings(), LABEL, { exec: f.exec });
286
+ expect(r.ran && r.output).not.toContain(token);
287
+ expect(r.ran && r.output.length).toBeLessThanOrEqual(8_000);
288
+ });
289
+ it('purpose install needs no container: the gate container installs per command', async () => {
290
+ const f = fake();
291
+ expect(await runContainerGate(request({ purpose: 'install' }), settings(), LABEL, { exec: f.exec })).toMatchObject({ ran: true, status: 0 });
292
+ expect(f.calls).toEqual([]);
293
+ });
294
+ it('a prepare check that passed: its writes come back from the read-only export, guarded', async () => {
295
+ writeFileSync(join(dir, 'keep.txt'), 'same\n');
296
+ writeFileSync(join(dir, 'gone.txt'), 'old\n');
297
+ const tar = tarOf([{ path: './', type: '5' }, { path: './keep.txt', data: 'same\n' }, { path: './gen/', type: '5' }, { path: './gen/out.json', data: '{}\n' }]);
298
+ const f = fake((args, o) => (args[0] === 'run' && nameOf([...args]).endsWith('-export') ? ok({ stdout: o.full !== undefined ? tar : undefined }) : ok()));
299
+ const r = await runContainerGate(request({ purpose: 'prepare', argv: ['node', 'fmt.js'], exe: process.execPath, args: ['fmt.js'] }), settings(), LABEL, { exec: f.exec, platform: 'linux' });
300
+ expect(r).toMatchObject({ ran: true, status: 0 });
301
+ const exp = f.step('-export').args;
302
+ expect(values(exp, '--network')).toEqual(['none']);
303
+ expect(values(exp, '--mount')[0]).toMatch(/,readonly$/);
304
+ expect(readFileSync(join(dir, 'gen', 'out.json'), 'utf8')).toBe('{}\n');
305
+ expect(existsSync(join(dir, 'gone.txt'))).toBe(false);
306
+ // A failing prepare check is not copied back.
307
+ const failing = fake((args) => (args[0] === 'run' && !/-(copy|install)$/.test(nameOf([...args])) ? ok({ status: 1 }) : ok()));
308
+ await runContainerGate(request({ purpose: 'prepare' }), settings(), LABEL, { exec: failing.exec });
309
+ expect(failing.step('-export')).toBeUndefined();
310
+ });
311
+ });
312
+ describe('copy back', () => {
313
+ it('reads pax long names', () => {
314
+ const long = `${'d'.repeat(80)}/${'f'.repeat(80)}.txt`;
315
+ expect(readTar(tarOf([{ path: long, data: 'x' }]))).toEqual([{ path: long, type: 'file', mode: 0o644, data: Buffer.from('x') }]);
316
+ expect(() => readTar(Buffer.alloc(100))).toThrow();
317
+ });
318
+ it('refuses links, hardlinks, .. and absolute paths, and writes nothing then', () => {
319
+ writeFileSync(join(dir, 'a.txt'), 'a\n');
320
+ const cases = [
321
+ [{ path: './new-link', type: '2', link: '/home/node/.ssh/id_rsa' }],
322
+ [{ path: './hard', type: '1', link: 'a.txt' }],
323
+ [{ path: '../escape.txt', data: 'x' }],
324
+ [{ path: '/etc/passwd', data: 'x' }],
325
+ [{ path: './.git/config', data: '[core]' }],
326
+ ];
327
+ for (const entries of cases) {
328
+ const problem = applyCopyBack(dir, tarOf([{ path: './written.txt', data: 'w' }, { path: './a.txt', data: 'a\n' }, ...entries]), 'linux');
329
+ expect(problem, JSON.stringify(entries)).not.toBeNull();
330
+ expect(existsSync(join(dir, 'written.txt'))).toBe(false);
331
+ }
332
+ });
333
+ it('never writes through a host link (a junction or symlink to outside the checkout)', () => {
334
+ const outside = mkdtempSync(join(tmpdir(), 'omg-outside-'));
335
+ try {
336
+ symlinkSync(outside, join(dir, 'linked'), 'junction');
337
+ const problem = applyCopyBack(dir, tarOf([{ path: './linked/', type: '5' }, { path: './linked/planted.txt', data: 'p' }]), process.platform);
338
+ expect(problem).not.toBeNull();
339
+ expect(existsSync(join(outside, 'planted.txt'))).toBe(false);
340
+ }
341
+ finally {
342
+ unlinkSync(join(dir, 'linked'));
343
+ rmSync(outside, { recursive: true, force: true });
344
+ }
345
+ });
346
+ it('safeRelPath drops ./ and rejects Windows-reserved names on win32 only', () => {
347
+ expect(safeRelPath('./a/b.txt', 'linux')).toBe('a/b.txt');
348
+ expect(safeRelPath('./', 'linux')).toBe('');
349
+ expect(safeRelPath('a/con.txt', 'win32')).toBeNull();
350
+ expect(safeRelPath('a/b:c', 'win32')).toBeNull();
351
+ expect(safeRelPath('a/b:c', 'linux')).toBe('a/b:c');
352
+ expect(safeRelPath('a\\b', 'linux')).toBeNull();
353
+ expect(safeRelPath('x/node_modules/y', 'linux')).toBeNull();
354
+ });
355
+ });
356
+ describe('review-499 hardening', () => {
357
+ const linkOrSkip = (target, path) => {
358
+ try {
359
+ symlinkSync(target, path, 'junction');
360
+ return true;
361
+ }
362
+ catch {
363
+ return false;
364
+ }
365
+ };
366
+ it('C1: Node_Modules, NODE_M~1, .GIT and Unicode look-alikes are refused where names fold; nothing is written', () => {
367
+ for (const p of ['src/Node_Modules/vitest/vitest.mjs', 'NODE_MODULES/x', '.GIT/config', 'a/.Git', 'node_module\u017f/x']) {
368
+ expect(safeRelPath(p, 'win32'), p).toBeNull();
369
+ expect(safeRelPath(p, 'darwin'), p).toBeNull();
370
+ }
371
+ expect(safeRelPath('NODE_M~1/vitest/vitest.mjs', 'win32')).toBeNull();
372
+ expect(safeRelPath('GIT~1/config', 'win32')).toBeNull();
373
+ expect(safeRelPath('n\u200bode_modules/x', 'darwin')).toBeNull();
374
+ // Linux names do not fold: Node_Modules is just a directory there.
375
+ expect(safeRelPath('src/Node_Modules/x', 'linux')).toBe('src/Node_Modules/x');
376
+ writeFileSync(join(dir, 'a.txt'), 'a\n');
377
+ for (const path of ['./src/Node_Modules/vitest/vitest.mjs', './NODE_M~1/vitest/vitest.mjs', './.GIT']) {
378
+ expect(applyCopyBack(dir, tarOf([{ path: './written.txt', data: 'w' }, { path: './a.txt', data: 'a\n' }, { path, data: 'pwn' }]), 'win32'), path).not.toBeNull();
379
+ expect(existsSync(join(dir, 'written.txt'))).toBe(false);
380
+ }
381
+ });
382
+ it('C1: a write through a node_modules junction the engine left (any case) never reaches your node_modules', () => {
383
+ const userModules = mkdtempSync(join(tmpdir(), 'omg-user-nm-'));
384
+ mkdirSync(join(userModules, 'vitest'));
385
+ writeFileSync(join(userModules, 'vitest', 'vitest.mjs'), 'real\n');
386
+ try {
387
+ if (!linkOrSkip(userModules, join(dir, 'node_modules')))
388
+ return;
389
+ // Probed on the disk itself, whatever the platform argument says: case on a folding file system, links always.
390
+ const diskFolds = existsSync(join(dir, 'Node_Modules'));
391
+ for (const platform of ['win32', 'linux']) {
392
+ const problem = applyCopyBack(dir, tarOf([{ path: './Node_Modules/vitest/vitest.mjs', data: 'pwn' }]), platform);
393
+ if (platform === 'linux' && !diskFolds) {
394
+ // A case-sensitive disk: Node_Modules was a new real dir, never the junction.
395
+ expect(problem).toBeNull();
396
+ rmSync(join(dir, 'Node_Modules'), { recursive: true, force: true });
397
+ }
398
+ else
399
+ expect(problem, platform).not.toBeNull();
400
+ expect(readFileSync(join(userModules, 'vitest', 'vitest.mjs'), 'utf8')).toBe('real\n');
401
+ }
402
+ }
403
+ finally {
404
+ try {
405
+ unlinkSync(join(dir, 'node_modules'));
406
+ }
407
+ catch { /* not made */ }
408
+ rmSync(userModules, { recursive: true, force: true });
409
+ }
410
+ });
411
+ it('C1: DOCS/evil through a committed docs link is refused on the disk itself', () => {
412
+ const outside = mkdtempSync(join(tmpdir(), 'omg-outside-'));
413
+ try {
414
+ if (!linkOrSkip(outside, join(dir, 'docs')))
415
+ return;
416
+ const diskFolds = existsSync(join(dir, 'DOCS'));
417
+ for (const platform of ['win32', 'darwin', 'linux']) {
418
+ const problem = applyCopyBack(dir, tarOf([{ path: './docs', type: '2', link: outside }, { path: './DOCS/evil', data: 'p' }]), platform);
419
+ // A case-sensitive disk told "linux": DOCS is a new real dir next to the docs link, never through it.
420
+ if (platform === 'linux' && !diskFolds) {
421
+ expect(problem).toBeNull();
422
+ expect(readFileSync(join(dir, 'DOCS', 'evil'), 'utf8')).toBe('p');
423
+ }
424
+ else
425
+ expect(problem, platform).not.toBeNull();
426
+ expect(existsSync(join(outside, 'evil'))).toBe(false);
427
+ }
428
+ // And the scan before the copy refuses the checkout: a link that points outside it.
429
+ expect(checkoutCopyProblem(dir)).toMatch(/absolute target|points outside/);
430
+ }
431
+ finally {
432
+ unlinkSync(join(dir, 'docs'));
433
+ rmSync(outside, { recursive: true, force: true });
434
+ }
435
+ });
436
+ it('C1: two entries that are one file on a folding host are refused', () => {
437
+ expect(applyCopyBack(dir, tarOf([{ path: './README.md', data: 'a' }, { path: './readme.md', data: 'b' }]), 'win32')).toMatch(/same file/);
438
+ expect(existsSync(join(dir, 'README.md'))).toBe(false);
439
+ });
440
+ it('M3: a file with more than one hard link is never written through, and the checkout is refused before the copy', () => {
441
+ const outside = mkdtempSync(join(tmpdir(), 'omg-outside-'));
442
+ try {
443
+ writeFileSync(join(outside, 'npmrc'), 'token\n');
444
+ linkSync(join(outside, 'npmrc'), join(dir, 'cfg'));
445
+ expect(checkoutCopyProblem(dir)).toMatch(/hard link/);
446
+ expect(applyCopyBack(dir, tarOf([{ path: './cfg', data: 'overwritten\n' }]), process.platform)).not.toBeNull();
447
+ expect(readFileSync(join(outside, 'npmrc'), 'utf8')).toBe('token\n');
448
+ }
449
+ finally {
450
+ rmSync(outside, { recursive: true, force: true });
451
+ }
452
+ });
453
+ it('the scan: a plain checkout, an inside link and the excluded names pass', () => {
454
+ mkdirSync(join(dir, 'src'));
455
+ writeFileSync(join(dir, 'src', 'a.ts'), '');
456
+ mkdirSync(join(dir, '.git'));
457
+ const outside = mkdtempSync(join(tmpdir(), 'omg-outside-'));
458
+ try {
459
+ expect(checkoutCopyProblem(dir)).toBeNull();
460
+ if (linkOrSkip(outside, join(dir, 'node_modules')))
461
+ expect(checkoutCopyProblem(dir)).toBeNull();
462
+ // A relative link inside passes; a junction (always an absolute target) does not, even to inside (review-499b N5).
463
+ let rel = false;
464
+ try {
465
+ symlinkSync('src', join(dir, 'src-rel'), 'dir');
466
+ rel = true;
467
+ }
468
+ catch { /* no symlink privilege on this host */ }
469
+ if (rel)
470
+ expect(checkoutCopyProblem(dir)).toBeNull();
471
+ if (linkOrSkip(join(dir, 'src'), join(dir, 'src-link')))
472
+ expect(checkoutCopyProblem(dir)).toBe('the checkout has a link with an absolute target');
473
+ }
474
+ finally {
475
+ for (const l of ['node_modules', 'src-link', 'src-rel'])
476
+ try {
477
+ unlinkSync(join(dir, l));
478
+ }
479
+ catch { /* not made */ }
480
+ rmSync(outside, { recursive: true, force: true });
481
+ }
482
+ });
483
+ it('a checkout the scan refuses never reaches a container', async () => {
484
+ const outside = mkdtempSync(join(tmpdir(), 'omg-outside-'));
485
+ try {
486
+ if (!linkOrSkip(outside, join(dir, 'Node_Modules2')))
487
+ return;
488
+ const f = fake();
489
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: f.exec })).toMatchObject({ ran: false, started: true, reason: expect.stringMatching(/absolute target|points outside/) });
490
+ expect(f.runs()).toEqual([]);
491
+ expect(f.calls.some((c) => c.args[0] === 'volume')).toBe(false);
492
+ }
493
+ finally {
494
+ unlinkSync(join(dir, 'Node_Modules2'));
495
+ rmSync(outside, { recursive: true, force: true });
496
+ }
497
+ });
498
+ it('L1: a copied-back file replaces the old one by rename, leaving no temp file', () => {
499
+ writeFileSync(join(dir, 'a.txt'), 'old\n');
500
+ expect(applyCopyBack(dir, tarOf([{ path: './a.txt', data: 'new\n' }]), process.platform)).toBeNull();
501
+ expect(readFileSync(join(dir, 'a.txt'), 'utf8')).toBe('new\n');
502
+ expect(readdirSync(dir)).toEqual(['a.txt']);
503
+ });
504
+ it('H2: the shared cache only for registry packages with an integrity; else a fresh cache, or unavailable', async () => {
505
+ const reg = (name, extra = {}) => ({ version: '1.0.0', resolved: `https://registry.npmjs.org/${name}/-/${name}-1.0.0.tgz`, integrity: 'sha512-x', ...extra });
506
+ expect(lockfileCachePolicy({ lockfileVersion: 3, packages: { '': {}, 'node_modules/a': reg('a'), 'packages/w': { version: '1.0.0' }, 'node_modules/w': { resolved: 'packages/w', link: true } } })).toBe('shared');
507
+ expect(lockfileCachePolicy({ lockfileVersion: 3, packages: { 'node_modules/a': reg('a', { integrity: undefined }) } })).toBe('private');
508
+ expect(lockfileCachePolicy({ lockfileVersion: 3, packages: { 'node_modules/a': reg('a', { resolved: 'git+ssh://git@github.com/x/a.git#abc' }) } })).toMatchObject({ refuse: expect.any(String) });
509
+ expect(lockfileCachePolicy({ lockfileVersion: 3, packages: { 'node_modules/a': reg('a', { resolved: 'https://evil.example/a.tgz' }) } })).toMatchObject({ refuse: expect.any(String) });
510
+ expect(lockfileCachePolicy({ lockfileVersion: 1, dependencies: { a: { version: 'github:x/a', integrity: 'sha512-x' } } })).toMatchObject({ refuse: expect.any(String) });
511
+ expect(lockfileCachePolicy({ lockfileVersion: 1, dependencies: { a: { version: '1.0.0', resolved: 'https://registry.npmjs.org/a/-/a-1.0.0.tgz', integrity: 'sha512-x', dependencies: { b: { version: '1.0.0' } } } } })).toBe('private');
512
+ // A lockfile entry without an integrity: no shared cache volume anywhere; npm caches inside the command's own volume.
513
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ devDependencies: { a: '1' } }));
514
+ writeFileSync(join(dir, 'package-lock.json'), JSON.stringify({ lockfileVersion: 3, packages: { 'node_modules/a': reg('a', { integrity: undefined }) } }));
515
+ const f = fake();
516
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: f.exec })).toMatchObject({ ran: true });
517
+ expect(f.calls.some((c) => c.args.some((a) => a.includes('omg-gate-cache-')))).toBe(false);
518
+ expect(values(f.step('-install').args, '-e')).toContain('npm_config_cache=/work/home/.npm');
519
+ // One resolved from git: unavailable before any container.
520
+ writeFileSync(join(dir, 'package-lock.json'), JSON.stringify({ lockfileVersion: 3, packages: { 'node_modules/a': reg('a', { resolved: 'git+https://github.com/x/a.git' }) } }));
521
+ const g = fake();
522
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: g.exec })).toMatchObject({ ran: false, unavailable: true, reason: expect.stringContaining('npm registry') });
523
+ expect(g.runs()).toEqual([]);
524
+ });
525
+ it('H1/H2: no step that runs the PR\'s code has network or the shared cache', async () => {
526
+ npmProject();
527
+ const f = fake();
528
+ await runContainerGate(request({ purpose: 'prepare' }), settings(), LABEL, { exec: f.exec, id: () => 'cafe0001', platform: 'linux' });
529
+ const name = `omg-gate-${LABEL}-cafe0001`;
530
+ // Only the copy (no PR code) and npm ci --ignore-scripts see the cache; only npm ci has a network.
531
+ for (const c of f.runs()) {
532
+ const n = nameOf(c.args);
533
+ const cached = values(c.args, '--mount').some((m) => m.includes('omg-gate-cache-'));
534
+ expect(cached, n).toBe(n === `${name}-copy` || n === `${name}-install`);
535
+ expect(values(c.args, '--network'), n).toEqual([n === `${name}-install` ? `${name}-net` : 'none']);
536
+ }
537
+ expect(f.calls.find((c) => c.args[0] === 'run' && nameOf(c.args) === `${name}-install`).args).toContain('--ignore-scripts');
538
+ });
539
+ it('L4: an existing cache volume must carry our labels on the local driver with no options', async () => {
540
+ npmProject();
541
+ const inspect = (tail) => fake((args) => (args[0] === 'volume' && args[1] === 'inspect' ? ok({ tail }) : ok()), true);
542
+ const good = inspect('local|{"omg.cache":"npm","omg.gate":"1"}|{}\n');
543
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: good.exec })).toMatchObject({ ran: true });
544
+ expect(good.calls.filter((c) => c.args[0] === 'volume' && c.args[1] === 'create')).toHaveLength(1);
545
+ for (const tail of ['local|{"omg.cache":"npm"}|{}', 'local|{"omg.cache":"npm","omg.gate":"1"}|{"type":"none","o":"bind","device":"/Users/x"}', 'nfs|{"omg.cache":"npm","omg.gate":"1"}|null', 'garbage']) {
546
+ const bad = inspect(tail);
547
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: bad.exec }), tail).toMatchObject({ ran: false, unavailable: true });
548
+ expect(bad.runs(), tail).toEqual([]);
549
+ // Our own work volume is still removed; the foreign one never is.
550
+ expect(bad.calls.filter((c) => c.args[1] === 'rm').map((c) => c.args.at(-1))).toEqual([expect.stringMatching(/^omg-gate-abc123-issue-7-[0-9a-f]{8}$/)]);
551
+ }
552
+ });
553
+ it('M2: the disk watchdog kills only the step\'s own container when the work volume is over the limit', async () => {
554
+ const name = `omg-gate-${LABEL}-d15c0001`;
555
+ let release;
556
+ const f = fake((args) => {
557
+ if (args[0] === 'run' && nameOf([...args]) === `${name}-du-1`)
558
+ return ok({ tail: `${2 * 1024 * 1024}\t/work\n` });
559
+ if (args[0] === 'run' && nameOf([...args]) === name)
560
+ return new Promise((done) => { release = () => done(ok({ status: 137 })); });
561
+ if (args[0] === 'kill')
562
+ release?.();
563
+ return ok();
564
+ });
565
+ const r = await runContainerGate(request(), settings({ diskLimit: '1g' }), LABEL, { exec: f.exec, id: () => 'd15c0001', diskWatchMs: 5 });
566
+ expect(r).toMatchObject({ ran: true, status: 1, timedOut: false });
567
+ expect(r.ran && r.output).toContain('diskLimit (1g)');
568
+ expect(f.calls.filter((c) => c.args[0] === 'kill').map((c) => c.args)).toEqual([['kill', name]]);
569
+ const du = f.step('-du-1').args;
570
+ expect(values(du, '--mount')[0]).toMatch(/,readonly$/);
571
+ expect(values(du, '--network')).toEqual(['none']);
572
+ expect(values(du, '--cap-add')).toEqual(['DAC_READ_SEARCH']);
573
+ expect(values(du, '--log-driver')).toEqual(['none']);
574
+ expect(sizeBytes('10g')).toBe(10 * 1024 ** 3);
575
+ });
576
+ /** A run step that ends only when it is killed, and the du answers in order (the last repeats). */
577
+ const watchdog = async (duAnswers) => {
578
+ const name = `omg-gate-${LABEL}-d15c0002`;
579
+ let release;
580
+ let n = 0;
581
+ const f = fake((args) => {
582
+ if (args[0] === 'run' && nameOf([...args]).startsWith(`${name}-du-`))
583
+ return duAnswers[Math.min(n++, duAnswers.length - 1)];
584
+ if (args[0] === 'run' && nameOf([...args]) === name)
585
+ return new Promise((done) => { release = () => done(ok({ status: 137 })); });
586
+ if (args[0] === 'kill')
587
+ release?.();
588
+ return ok();
589
+ });
590
+ const r = await runContainerGate(request(), settings({ diskLimit: '1g' }), LABEL, { exec: f.exec, id: () => 'd15c0002', diskWatchMs: 5 });
591
+ return { r, f, name };
592
+ };
593
+ it('N1: du that exits 1 (entries vanished mid-walk) still counts its total: over the limit is killed', async () => {
594
+ const { r, f, name } = await watchdog([ok({ status: 1, tail: `du: cannot access '/work/src/t/x1': No such file or directory\n${2 * 1024 * 1024}\t/work\n` })]);
595
+ expect(r).toMatchObject({ ran: true, status: 1, timedOut: false });
596
+ expect(r.ran && r.output).toContain('used more than factory.run.sandbox.container.diskLimit (1g)');
597
+ expect(f.calls.filter((c) => c.args[0] === 'kill').map((c) => c.args)).toEqual([['kill', name]]);
598
+ });
599
+ it('N1: two checks in a row without a total kill the step (fail-closed); every du has its own name', async () => {
600
+ const { r, f, name } = await watchdog([ok({ status: 137, tail: '' }), ok({ status: 125, tail: 'Conflict. The container name is already in use' })]);
601
+ expect(r).toMatchObject({ ran: true, status: 1, timedOut: false });
602
+ expect(r.ran && r.output).toContain('could not be measured twice in a row');
603
+ expect(f.calls.filter((c) => c.args[0] === 'kill').map((c) => c.args)).toEqual([['kill', name]]);
604
+ const duNames = f.runs().map((c) => nameOf(c.args)).filter((n) => n.includes('-du-'));
605
+ expect(duNames).toEqual([`${name}-du-1`, `${name}-du-2`]);
606
+ // A du that did not end normally is removed by its own name right away.
607
+ expect(f.calls.filter((c) => c.args[0] === 'rm').map((c) => c.args[2])).toEqual(expect.arrayContaining([`${name}-du-1`, `${name}-du-2`]));
608
+ });
609
+ it('N1: one miss between totals under the limit does not kill', async () => {
610
+ const under = ok({ tail: `1024\t/work\n` });
611
+ const name = `omg-gate-${LABEL}-d15c0003`;
612
+ let n = 0;
613
+ const answers = [under, ok({ status: 137 }), under, ok({ status: 137 }), under];
614
+ const f = fake(async (args) => {
615
+ if (args[0] === 'run' && nameOf([...args]).startsWith(`${name}-du-`))
616
+ return answers[Math.min(n++, answers.length - 1)];
617
+ if (args[0] === 'run' && nameOf([...args]) === name) {
618
+ while (n < answers.length)
619
+ await new Promise((t) => setTimeout(t, 2));
620
+ return ok({ tail: 'done' });
621
+ }
622
+ return ok();
623
+ });
624
+ const r = await runContainerGate(request(), settings({ diskLimit: '1g' }), LABEL, { exec: f.exec, id: () => 'd15c0003', diskWatchMs: 1 });
625
+ expect(r).toMatchObject({ ran: true, status: 0, output: 'done' });
626
+ expect(f.calls.some((c) => c.args[0] === 'kill')).toBe(false);
627
+ });
628
+ it('N4: every container runs the inspected image id, not the tag', async () => {
629
+ npmProject();
630
+ const id = `sha256:${'b'.repeat(64)}`;
631
+ const f = fake((args) => (args[0] === 'image' ? ok({ tail: `${id}\n` }) : ok()));
632
+ await runContainerGate(request(), settings(), LABEL, { exec: f.exec });
633
+ expect(f.runs().length).toBeGreaterThan(0);
634
+ for (const c of f.runs()) {
635
+ expect(c.args).toContain(id);
636
+ expect(c.args).not.toContain(settings().image);
637
+ }
638
+ });
639
+ it('N5: link targets are checked as the container follows them: no absolute target, `..` only leading and inside', () => {
640
+ expect(linkTargetProblem('src', 0)).toBeNull();
641
+ expect(linkTargetProblem('./a/b', 0)).toBeNull();
642
+ expect(linkTargetProblem('../../..', 3)).toBeNull();
643
+ expect(linkTargetProblem('../README.md', 1)).toBeNull();
644
+ expect(linkTargetProblem('../x', 0)).toMatch(/points outside/);
645
+ expect(linkTargetProblem('..\\..\\x', 1)).toMatch(/points outside/);
646
+ // The review's chain: q -> e/f/g/p/../../../cache, where p -> ../../.. (the host resolves p by its own rules).
647
+ expect(linkTargetProblem('e/f/g/p/../../../cache', 0)).toMatch(/steps back/);
648
+ expect(linkTargetProblem('a\\..\\b', 0)).toMatch(/steps back/);
649
+ for (const abs of ['/etc/passwd', '\\\\?\\C:\\x', 'C:\\Users\\x', 'c:x', ''])
650
+ expect(linkTargetProblem(abs, 5), abs).toMatch(/absolute target/);
651
+ });
652
+ it('N5: the scan refuses a checkout link that steps back after a name', () => {
653
+ mkdirSync(join(dir, 'e'));
654
+ try {
655
+ symlinkSync('e/../e', join(dir, 'q'), 'dir');
656
+ }
657
+ catch {
658
+ return; /* no symlink privilege on this host */
659
+ }
660
+ try {
661
+ expect(checkoutCopyProblem(dir)).toBe('the checkout has a link whose target steps back (..) after a name');
662
+ }
663
+ finally {
664
+ unlinkSync(join(dir, 'q'));
665
+ }
666
+ });
667
+ it('N6: superscript COM/LPT device names are refused on win32', () => {
668
+ for (const p of ['a/COM\u00b9', 'lpt\u00b2.txt', 'com\u00b3.log'])
669
+ expect(safeRelPath(p, 'win32'), p).toBeNull();
670
+ expect(safeRelPath('a/COM\u00b9', 'linux')).toBe('a/COM\u00b9');
671
+ });
672
+ it('N6: a path component that cannot be checked (not missing) refuses the copy back; nothing is written', () => {
673
+ const long = 'a'.repeat(300);
674
+ const problem = applyCopyBack(dir, tarOf([{ path: `${long}/x.txt`, data: 'x' }]), process.platform);
675
+ expect(problem).not.toBeNull();
676
+ if (process.platform === 'linux')
677
+ expect(problem).toBe('a path could not be checked');
678
+ expect(readdirSync(dir)).toEqual([]);
679
+ });
680
+ it('L2: a ran result carries the image id', async () => {
681
+ const id = `sha256:${'a'.repeat(64)}`;
682
+ const f = fake((args) => (args[0] === 'image' ? ok({ tail: `${id}\n` }) : ok()));
683
+ expect(await runContainerGate(request(), settings(), LABEL, { exec: f.exec })).toMatchObject({ ran: true, imageId: id });
684
+ });
685
+ it('review-499c: an inspect without a sha256:<64 hex> id is unavailable; no container runs the tag', async () => {
686
+ npmProject();
687
+ for (const tail of ['node:22-bookworm-slim\n', 'sha256:abc\n', `sha256:${'A'.repeat(64)}\n`]) {
688
+ const f = fake((args) => (args[0] === 'image' ? ok({ tail }) : ok()));
689
+ const r = await runContainerGate(request(), settings(), LABEL, { exec: f.exec });
690
+ expect(r, tail).toMatchObject({ ran: false, unavailable: true });
691
+ expect(!r.ran && r.reason).toMatch(/could not read the image id of .* pin a digest/);
692
+ expect(f.runs()).toEqual([]);
693
+ }
694
+ });
695
+ });
696
+ describe('helpers', () => {
697
+ it('containerArgv: node scripts as `node <args>`, host paths in the checkout mapped, configured commands as configured', () => {
698
+ expect(containerArgv({ argv: [process.execPath, 'node_modules/vitest/vitest.mjs', 'run', 'a.test.ts'], exe: process.execPath, args: ['node_modules/vitest/vitest.mjs', 'run', 'a.test.ts'], cwd: dir })).toEqual(['node', 'node_modules/vitest/vitest.mjs', 'run', 'a.test.ts']);
699
+ expect(containerArgv({ argv: ['npm', 'test'], exe: process.execPath, args: [join(dir, 'npm-cli.js'), 'test'], cwd: dir })).toEqual(['npm', 'test']);
700
+ expect(containerArgv({ argv: ['node', join(dir, 'scripts', 'x.mjs')], exe: 'node', args: [join(dir, 'scripts', 'x.mjs')], cwd: dir })).toEqual(['node', '/work/src/scripts/x.mjs']);
701
+ });
702
+ it('mountArg quotes a field with a comma or a quote', () => {
703
+ expect(mountArg(['type=bind', 'source=C:\\a,b', 'target=/in'])).toBe('type=bind,"source=C:\\a,b",target=/in');
704
+ expect(mountArg(['source=x"y'])).toBe('"source=x""y"');
705
+ });
706
+ it('containerRunLabel is stable, per checkout and run, [a-z0-9-] only', () => {
707
+ expect(containerRunLabel(dir, 7)).toMatch(/^[0-9a-f]{10}-issue-7$/);
708
+ expect(containerRunLabel(dir, 7)).toBe(containerRunLabel(dir, 7));
709
+ expect(containerRunLabel(join(dir, 'other'), 7)).not.toBe(containerRunLabel(dir, 7));
710
+ expect(containerRunLabel(dir, 'heal-0123abcd')).toMatch(/-heal-0123abcd$/);
711
+ });
712
+ it('clean removes only this run\'s containers and volumes, by label and name prefix', () => {
713
+ const calls = [];
714
+ const out = {
715
+ ps: `omg-gate-${LABEL}-aa\nomg-gate-${LABEL}-aa-install\njaktis-runner\nomg-gate-other-issue-1-bb\n`,
716
+ volume: `omg-gate-${LABEL}-aa\nomg-gate-cache-0123456789abcdef\nsome-volume\n`,
717
+ };
718
+ out.network = `omg-gate-${LABEL}-aa-net\nbridge\njaktis_default\n`;
719
+ const r = cleanRunContainers('docker', LABEL, (bin, args) => { calls.push([bin, ...args]); return { status: 0, stdout: args[0] === 'ps' ? out.ps : args[1] === 'ls' ? out[args[0]] ?? '' : '' }; });
720
+ expect(r.removed).toEqual([`omg-gate-${LABEL}-aa`, `omg-gate-${LABEL}-aa-install`, `omg-gate-${LABEL}-aa-net`, `omg-gate-${LABEL}-aa`]);
721
+ expect(calls.filter((c) => c[1] === 'ps' || c[2] === 'ls').every((c) => c.includes(`label=omg.run=${LABEL}`))).toBe(true);
722
+ expect(calls.filter((c) => c.includes('rm')).map((c) => c.at(-1))).toEqual([`omg-gate-${LABEL}-aa`, `omg-gate-${LABEL}-aa-install`, `omg-gate-${LABEL}-aa-net`, `omg-gate-${LABEL}-aa`]);
723
+ expect(calls.some((c) => c.some((a) => /prune/.test(a)))).toBe(false);
724
+ const down = cleanRunContainers('docker', LABEL, () => ({ status: 1, stdout: '' }));
725
+ expect(down).toMatchObject({ removed: [], problem: expect.stringContaining('did not answer') });
726
+ });
727
+ it('defaultContainerExec: a runtime that is not installed is a spawn error, not a status', async () => {
728
+ const r = await defaultContainerExec(join(dir, 'no-such-runtime'), ['version'], { timeoutMs: 10_000 });
729
+ expect(r.status).toBeNull();
730
+ expect(r.spawnError).toBeDefined();
731
+ });
732
+ });
733
+ //# sourceMappingURL=container-gate.test.js.map