gentle-pi 4.6.0 → 4.7.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 (290) hide show
  1. package/README.md +10 -11
  2. package/assets/agents/gentle-ai-explore.md +1 -0
  3. package/assets/agents/gentle-ai-verify.md +5 -2
  4. package/assets/agents/gentle-ai-worker.md +3 -0
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +1 -0
  7. package/assets/agents/jd-judge-b.md +1 -0
  8. package/assets/design-canvas/canvas.css +13 -1
  9. package/assets/design-canvas/canvas.js +11 -2
  10. package/assets/install-wizard/wizard.js +1 -0
  11. package/assets/migrations/agent-body-history.json +16 -1
  12. package/assets/orchestrator-delegation-reference.md +4 -4
  13. package/assets/orchestrator-delegation.md +1 -1
  14. package/assets/orchestrator-full-delegation-card.md +65 -0
  15. package/assets/orchestrator-full-delegation.md +34 -0
  16. package/assets/orchestrator-memory.md +3 -3
  17. package/assets/orchestrator-prompts.md +1 -1
  18. package/assets/orchestrator-skills.md +1 -1
  19. package/assets/orchestrator-verification.md +7 -5
  20. package/assets/orchestrator.md +3 -3
  21. package/bin/gentle-shell.mjs +164 -56
  22. package/docs/agent-status.md +61 -0
  23. package/docs/bundled-install.md +7 -5
  24. package/docs/delegated-verification.md +29 -7
  25. package/docs/gentle-agents-activity.md +14 -0
  26. package/docs/gentle-shell.md +54 -16
  27. package/docs/install-wizard.md +1 -1
  28. package/docs/permission-modes.md +9 -4
  29. package/docs/readme-reference.md +75 -30
  30. package/docs/render-cache-performance.md +11 -1
  31. package/docs/review-coordinator.md +33 -0
  32. package/docs/review-request-context.md +19 -0
  33. package/docs/review-windows-acl.md +18 -0
  34. package/docs/voice.md +6 -3
  35. package/docs/yolo-mode.md +5 -5
  36. package/extensions/ask-user-choice.ts +1 -0
  37. package/extensions/ask-user-question.ts +1 -0
  38. package/extensions/child-safety.ts +3 -0
  39. package/extensions/gentle-agent-status.ts +99 -0
  40. package/extensions/gentle-agents.ts +326 -34
  41. package/extensions/gentle-ai.ts +1496 -454
  42. package/extensions/gentle-shell.ts +293 -63
  43. package/extensions/gentle-todo.ts +18 -2
  44. package/extensions/gentle-tps.ts +48 -0
  45. package/extensions/quiet-tools.ts +38 -8
  46. package/extensions/skill-registry.ts +175 -18
  47. package/extensions/startup-banner.ts +30 -3
  48. package/lib/agent-profile-pin.ts +3 -3
  49. package/lib/agent-profiles.ts +160 -2
  50. package/lib/agent-status.ts +105 -0
  51. package/lib/agents-config.ts +46 -0
  52. package/lib/agents-history.ts +24 -5
  53. package/lib/agents-messaging.ts +47 -5
  54. package/lib/agents-runner.ts +183 -12
  55. package/lib/auto-permission-runtime.ts +1 -1
  56. package/lib/bounded-writer-admission.ts +13 -1
  57. package/lib/card-content-policy.ts +8 -6
  58. package/lib/command-palette.ts +133 -17
  59. package/lib/context-backstop.ts +14 -5
  60. package/lib/destructive-command-guard.ts +48 -4
  61. package/lib/execution-surface-guard.ts +20 -0
  62. package/lib/exploration-budget.ts +4 -2
  63. package/lib/gentle-ai-binary.ts +1 -1
  64. package/lib/gentle-design.ts +3 -0
  65. package/lib/gentle-shell-bundled.ts +6 -19
  66. package/lib/gentle-shell-launcher.ts +43 -8
  67. package/lib/herdr-activity.ts +14 -2
  68. package/lib/herdr-busy.ts +45 -0
  69. package/lib/image-attachments.ts +33 -0
  70. package/lib/image-disk-cache.ts +137 -0
  71. package/lib/inprocess-reviewer.ts +270 -140
  72. package/lib/jobs-view.ts +198 -11
  73. package/lib/model-routing-authority.ts +22 -4
  74. package/lib/native-choice-list.ts +20 -2
  75. package/lib/native-review-cli.ts +96 -19
  76. package/lib/orchestrator-mode-policy.ts +105 -0
  77. package/lib/questionnaire/questionnaire-view.ts +105 -12
  78. package/lib/rdd-mode-control.ts +32 -0
  79. package/lib/reply-language-anchor.ts +104 -0
  80. package/lib/review-blocker.ts +92 -0
  81. package/lib/review-candidate-symlink-scan.ts +136 -0
  82. package/lib/review-candidate-view-owner.ts +81 -44
  83. package/lib/review-continuation-registry.ts +99 -0
  84. package/lib/review-coordinator.ts +163 -0
  85. package/lib/review-failure-facts.ts +49 -0
  86. package/lib/review-host-relay.ts +46 -10
  87. package/lib/review-integration-v2.ts +7 -1
  88. package/lib/review-relay-phase-timing.ts +45 -0
  89. package/lib/review-start-context.ts +17 -0
  90. package/lib/session-profile-freeze.ts +4 -2
  91. package/lib/shell-bar.ts +140 -58
  92. package/lib/shell-changes.ts +2 -0
  93. package/lib/shell-panel.ts +17 -3
  94. package/lib/shell-sidebar-layout.ts +112 -40
  95. package/lib/shell-sidebar.ts +7 -0
  96. package/lib/shell-todo.ts +10 -3
  97. package/lib/verifier-admission.ts +1 -1
  98. package/lib/visual-customization-policy.ts +36 -16
  99. package/lib/visual-customize-view.ts +216 -21
  100. package/lib/visual-layout-preview.ts +9 -5
  101. package/lib/visual-profiles.ts +2 -2
  102. package/lib/windows-session-transport.ts +53 -2
  103. package/lib/yolo-session-policy.ts +40 -15
  104. package/package.json +2 -1
  105. package/runtime/gentle-ai-binary.mjs +1 -1
  106. package/runtime/gentle-shell-bundled.mjs +6 -19
  107. package/runtime/gentle-shell-launcher.mjs +42 -7
  108. package/runtime/native-review-cli.mjs +93 -16
  109. package/runtime/review-integration-v2.mjs +7 -1
  110. package/scripts/build-full-delegation-card.mjs +175 -0
  111. package/scripts/bundled-install.mjs +38 -8
  112. package/scripts/download-progress.mjs +68 -0
  113. package/scripts/gentle-ai-installer.mjs +41 -18
  114. package/scripts/gentle-ai-proxy.mjs +294 -0
  115. package/scripts/install-gentle-ai.mjs +14 -1
  116. package/scripts/installer-preflight.mjs +5 -5
  117. package/scripts/installer-runner.mjs +27 -12
  118. package/scripts/installer-server.mjs +8 -7
  119. package/scripts/render-cache-host.mjs +72 -0
  120. package/scripts/render-cache-performance-worker.mjs +5 -4
  121. package/scripts/render-cache-performance.mjs +6 -1
  122. package/scripts/run-test-suite.mjs +40 -28
  123. package/scripts/verify-package-files.mjs +12 -2
  124. package/scripts/voice-worker.cjs +32 -6
  125. package/skills/design/SKILL.md +11 -8
  126. package/skills/gentle-ai/SKILL.md +2 -2
  127. package/skills/gentle-ui-design/SKILL.md +46 -0
  128. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  129. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  130. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  131. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  132. package/skills/skill-registry/SKILL.md +4 -2
  133. package/skills/work-unit-commits/SKILL.md +6 -7
  134. package/tests/agent-home.test.ts +28 -9
  135. package/tests/agent-profiles-workflow.test.ts +163 -0
  136. package/tests/agent-risk-escalation.test.ts +1 -1
  137. package/tests/agent-status.test.ts +143 -0
  138. package/tests/agents-config.test.ts +96 -0
  139. package/tests/agents-history.test.ts +31 -0
  140. package/tests/agents-jobs-frames.test.ts +93 -0
  141. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  142. package/tests/agents-runner-drain.test.ts +193 -0
  143. package/tests/agents-runner.test.ts +178 -2
  144. package/tests/append-system-prompt-route.test.ts +4 -1
  145. package/tests/ask-user-choice.test.ts +4 -3
  146. package/tests/ask-user-question.test.ts +97 -0
  147. package/tests/auto-permission-runtime.test.ts +1 -1
  148. package/tests/autonomous-guard.test.ts +346 -10
  149. package/tests/bounded-stop-contract.test.ts +43 -3
  150. package/tests/bridge-cost.test.ts +19 -4
  151. package/tests/bundled-install.test.ts +30 -5
  152. package/tests/card-content-policy.test.ts +3 -3
  153. package/tests/chained-pr-skill.test.ts +8 -6
  154. package/tests/child-safety.test.ts +11 -0
  155. package/tests/codegraph-tools.test.ts +11 -5
  156. package/tests/command-palette.test.ts +284 -1
  157. package/tests/delegate-for-reason-contract.test.ts +3 -3
  158. package/tests/design-canvas-assets.test.ts +185 -2
  159. package/tests/destructive-command-guard.test.ts +52 -0
  160. package/tests/download-progress.test.ts +71 -0
  161. package/tests/execution-surface-guard.test.ts +55 -0
  162. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
  163. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  164. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  165. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  166. package/tests/fixtures/session-profile-v1/replay.ts +53 -6
  167. package/tests/full-delegation-closure.test.ts +131 -0
  168. package/tests/full-delegation-notices.test.ts +76 -0
  169. package/tests/generic-agent-tools.test.ts +3 -3
  170. package/tests/gentle-agent-status.test.ts +74 -0
  171. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  172. package/tests/gentle-agents.test.ts +1070 -12
  173. package/tests/gentle-ai-binary.test.ts +3 -1
  174. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  175. package/tests/gentle-ai-exploration-budget.test.ts +18 -2
  176. package/tests/gentle-ai-installer.test.ts +134 -51
  177. package/tests/gentle-ai-proxy.test.ts +434 -0
  178. package/tests/gentle-ai.test.ts +113 -38
  179. package/tests/gentle-design.test.ts +21 -0
  180. package/tests/gentle-herdr-activity.test.ts +9 -6
  181. package/tests/gentle-shell-bin.test.ts +123 -0
  182. package/tests/gentle-shell-bundled.test.ts +207 -31
  183. package/tests/gentle-shell-launcher.test.ts +77 -10
  184. package/tests/gentle-shell.test.ts +899 -59
  185. package/tests/gentle-todo.test.ts +19 -2
  186. package/tests/gentle-tps.test.ts +123 -0
  187. package/tests/gentle-ui-design-skill.test.ts +59 -0
  188. package/tests/herdr-busy.test.ts +59 -0
  189. package/tests/herdr-task-summary-policy.test.ts +8 -4
  190. package/tests/image-disk-cache.test.ts +163 -0
  191. package/tests/independent-recovery-delivery.test.ts +83 -0
  192. package/tests/inprocess-reviewer.test.ts +176 -4
  193. package/tests/installer-posix-bootstrap.test.ts +1 -1
  194. package/tests/installer-preflight.test.ts +5 -4
  195. package/tests/installer-runner.test.ts +79 -44
  196. package/tests/installer-server.test.ts +14 -11
  197. package/tests/jobs-view.test.ts +260 -6
  198. package/tests/modal-mouse-boundaries.test.ts +136 -0
  199. package/tests/model-routing-authority.test.ts +178 -2
  200. package/tests/native-choice-list.test.ts +77 -2
  201. package/tests/native-review-capability-contract.test.ts +7 -1
  202. package/tests/native-review-cli.test.ts +269 -1
  203. package/tests/no-self-pause-contract.test.ts +4 -1
  204. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  205. package/tests/orchestrator-budget.test.ts +7 -2
  206. package/tests/orchestrator-delegation-mode.test.ts +153 -0
  207. package/tests/orchestrator-mode-policy.test.ts +175 -0
  208. package/tests/orchestrator-prompt-budget.test.ts +3 -1
  209. package/tests/orchestrator-rdd-ownership.test.ts +2 -2
  210. package/tests/package-manifest.test.ts +11 -9
  211. package/tests/permission-allowlist.test.ts +202 -0
  212. package/tests/pi-update-launcher.test.ts +8 -0
  213. package/tests/pnpm-workspace-config.test.ts +58 -0
  214. package/tests/primary-session-prompt.test.ts +13 -0
  215. package/tests/profile-pin.test.ts +29 -2
  216. package/tests/profile-tier-footer.test.ts +5 -0
  217. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  218. package/tests/questionnaire-view.test.ts +115 -0
  219. package/tests/quiet-bash-runtime.test.ts +1 -1
  220. package/tests/quiet-tool-rendering.test.ts +48 -0
  221. package/tests/rdd-aware-verification-contract.test.ts +16 -11
  222. package/tests/rdd-customize.test.ts +287 -0
  223. package/tests/rdd-mode-cache.test.ts +450 -0
  224. package/tests/rdd-mode-control.test.ts +407 -0
  225. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  226. package/tests/rdd-off-independent-regression.test.ts +69 -0
  227. package/tests/rdd-status-line.test.ts +18 -0
  228. package/tests/render-cache-performance.test.ts +171 -2
  229. package/tests/reply-language-anchor.test.ts +173 -0
  230. package/tests/review-agent-end-preflight.test.ts +1 -1
  231. package/tests/review-blocker.test.ts +193 -0
  232. package/tests/review-candidate-owner-retry.test.ts +1 -1
  233. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  234. package/tests/review-candidate-view.test.ts +1 -1
  235. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  236. package/tests/review-candidate-windows-probe.test.ts +63 -0
  237. package/tests/review-committed-restart-ack.test.ts +129 -0
  238. package/tests/review-continuation-registry.test.ts +76 -0
  239. package/tests/review-controller-native-routing.test.ts +261 -5
  240. package/tests/review-controller-workspace-root.test.ts +230 -3
  241. package/tests/review-controller.test.ts +96 -11
  242. package/tests/review-coordinator-runtime.test.ts +117 -0
  243. package/tests/review-coordinator.test.ts +195 -0
  244. package/tests/review-failure-facts.test.ts +87 -0
  245. package/tests/review-host-relay-routing.test.ts +258 -4
  246. package/tests/review-host-relay.test.ts +39 -0
  247. package/tests/review-integration-v2.test.ts +46 -3
  248. package/tests/review-json-arguments.test.ts +65 -10
  249. package/tests/review-last-event-closure.test.ts +68 -0
  250. package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
  251. package/tests/review-owner-identity.test.ts +60 -24
  252. package/tests/review-relay-phase-timing.test.ts +128 -0
  253. package/tests/review-relay-transport-agent.test.ts +12 -2
  254. package/tests/review-reviewer-evidence.test.ts +183 -0
  255. package/tests/review-risk-assessment.test.ts +74 -3
  256. package/tests/review-session-standing-permission-controller.test.ts +21 -1
  257. package/tests/review-start-context.test.ts +19 -0
  258. package/tests/review-tool-prose-budget.test.ts +121 -0
  259. package/tests/run-test-suite.test.ts +122 -1
  260. package/tests/runtime-harness.mjs +4 -1
  261. package/tests/sensitive-path-tools.test.ts +181 -5
  262. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  263. package/tests/session-profile-binding.test.ts +19 -1
  264. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  265. package/tests/session-profile-v1-compat.test.ts +35 -1
  266. package/tests/shell-bar.test.ts +186 -42
  267. package/tests/shell-panel.test.ts +50 -22
  268. package/tests/shell-sidebar-fullscreen.test.ts +5 -5
  269. package/tests/shell-sidebar-layout.test.ts +294 -23
  270. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  271. package/tests/shell-surface-transparent.test.ts +89 -0
  272. package/tests/shell-todo.test.ts +12 -0
  273. package/tests/skill-registry.test.ts +838 -5
  274. package/tests/startup-banner.test.ts +152 -1
  275. package/tests/startup-home-repo.test.ts +2 -0
  276. package/tests/support/review-coordinator-runtime.ts +69 -0
  277. package/tests/task-size-routing-contract.test.ts +5 -3
  278. package/tests/verifier-admission.test.ts +49 -0
  279. package/tests/verify-first-launch-contract.test.ts +78 -3
  280. package/tests/visual-customization-policy.test.ts +39 -6
  281. package/tests/visual-customize-view.test.ts +573 -9
  282. package/tests/visual-layout-preview.test.ts +15 -1
  283. package/tests/visual-profiles.test.ts +11 -0
  284. package/tests/voice-worker.test.ts +73 -2
  285. package/tests/windows-session-transport.test.ts +126 -0
  286. package/tests/work-continuity-contract.test.ts +28 -0
  287. package/tests/writer-feature-document-admission.test.ts +92 -0
  288. package/tests/yolo-customize.test.ts +27 -4
  289. package/tests/yolo-mode.test.ts +23 -18
  290. package/tests/yolo-session-policy.test.ts +270 -1
@@ -0,0 +1,157 @@
1
+ import assert from "node:assert/strict";
2
+ import childProcess from "node:child_process";
3
+ import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
4
+ import { syncBuiltinESMExports } from "node:module";
5
+ import { tmpdir } from "node:os";
6
+ import { join, resolve } from "node:path";
7
+ import test from "node:test";
8
+ import { __testing } from "../extensions/gentle-ai.ts";
9
+ import { CandidateTreeSymlinkScanner } from "../lib/review-candidate-symlink-scan.ts";
10
+
11
+ function store(t: test.TestContext): string {
12
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "symlink-cache-")));
13
+ mkdirSync(join(root, "refs"));
14
+ writeFileSync(join(root, "config"), "[core]\nrepositoryformatversion = 0\n");
15
+ t.after(() => rmSync(root, { recursive: true, force: true }));
16
+ return root;
17
+ }
18
+
19
+ test("workspace identity and tree scans remove mixed-case Git overrides before dispatch", async () => {
20
+ const previousEnv = process.env, original = childProcess.execFileSync;
21
+ const seen: NodeJS.ProcessEnv[] = [];
22
+ const cwd = realpathSync(process.cwd());
23
+ process.env = { ...previousEnv, git_dir: "fixture-must-not-select-a-repository", GiT_WoRk_TrEe: "fixture-must-not-select-a-worktree" };
24
+ childProcess.execFileSync = ((_file, args, options) => {
25
+ assert.equal(args[0], "rev-parse");
26
+ seen.push(options.env);
27
+ return cwd + "\n";
28
+ }) as typeof childProcess.execFileSync;
29
+ syncBuiltinESMExports();
30
+ try {
31
+ const scanner = new CandidateTreeSymlinkScanner((_file, _args, options) => { seen.push(options.env); return ""; });
32
+ assert.equal(scanner.scan(cwd, "f".repeat(40)), "no-symlinks");
33
+ const result = await __testing.executeReviewControllerOperation({ operation: "status", workspaceRoot: cwd }, cwd, {} as any);
34
+ assert.equal(result.outcome, "native-status-unsupported");
35
+ assert.equal(seen.length, 3, "one tree scan and both workspace identity queries exercised");
36
+ for (const env of seen) assert.deepEqual(Object.keys(env).filter(key => /^git_/i.test(key)), []);
37
+ } finally { process.env = previousEnv; childProcess.execFileSync = original; syncBuiltinESMExports(); }
38
+ });
39
+
40
+ test("repeated inspect scans reuse an unchanged literal tree without launching another Git process", t => {
41
+ const common = store(t), original = childProcess.execFileSync;
42
+ let listings = 0;
43
+ childProcess.execFileSync = ((file, args) => {
44
+ assert.equal(file, "git"); assert.ok(args.includes("ls-tree")); listings++;
45
+ return "100644 blob " + "a".repeat(40) + "\tfile.txt\n";
46
+ }) as typeof childProcess.execFileSync;
47
+ syncBuiltinESMExports();
48
+ try {
49
+ for (let i = 0; i < 5; i++) assert.equal(__testing.scanCandidateTreeForSymlinks(process.cwd(), "1".repeat(40), common), "no-symlinks");
50
+ assert.equal(listings, 1);
51
+ } finally { childProcess.execFileSync = original; syncBuiltinESMExports(); }
52
+ });
53
+
54
+ test("active or malformed replacement refs bypass old cache entries without poisoning literal answers", t => {
55
+ const common = store(t);
56
+ let listing = "", listings = 0;
57
+ const argumentsSeen: string[][] = [];
58
+ const scanner = new CandidateTreeSymlinkScanner((_file, args) => { listings++; argumentsSeen.push([...args]); return listing; });
59
+ const scan = () => scanner.scan(process.cwd(), "2".repeat(40), common);
60
+ assert.equal(scan(), "no-symlinks");
61
+ mkdirSync(join(common, "refs", "replace"));
62
+ const replacement = join(common, "refs", "replace", "2".repeat(40));
63
+ writeFileSync(replacement, "3".repeat(40) + "\n");
64
+ listing = "120000 blob " + "a".repeat(40) + "\tlink\n";
65
+ assert.equal(scan(), "tracks-symlinks");
66
+ unlinkSync(replacement);
67
+ writeFileSync(join(common, "packed-refs"), "malformed refs\n");
68
+ assert.equal(scan(), "tracks-symlinks", "unknown eligibility does not borrow the cached negative");
69
+ unlinkSync(join(common, "packed-refs"));
70
+ assert.equal(scan(), "no-symlinks", "replacement answers never overwrite a literal tree entry");
71
+ assert.equal(listings, 3);
72
+ assert.ok(argumentsSeen[0].includes("--no-replace-objects"));
73
+ assert.ok(argumentsSeen.slice(1).every(args => !args.includes("--no-replace-objects")));
74
+ });
75
+
76
+ test("failed scans are retried, cache is bounded by LRU and trees remain isolated", t => {
77
+ const common = store(t);
78
+ let fail = true, listings = 0;
79
+ const scanner = new CandidateTreeSymlinkScanner(() => {
80
+ listings++; if (fail) throw new Error("output limit or timeout"); return "";
81
+ }, 2);
82
+ const scan = (id: string) => scanner.scan(process.cwd(), id.repeat(40), common);
83
+ assert.equal(scan("a"), "unconfirmed"); fail = false;
84
+ assert.equal(scan("a"), "no-symlinks"); assert.equal(scan("a"), "no-symlinks");
85
+ assert.equal(listings, 2);
86
+ scan("b"); scan("a"); scan("c"); scan("b");
87
+ assert.equal(listings, 5, "least recently used tree is scanned after eviction");
88
+ });
89
+
90
+ test("repository identity, unsupported refs and missing verified context never share cached scans", t => {
91
+ const a = store(t), b = store(t);
92
+ let listings = 0;
93
+ const scanner = new CandidateTreeSymlinkScanner(() => { listings++; return ""; });
94
+ const scan = (common?: string) => scanner.scan(process.cwd(), "d".repeat(40), common);
95
+ for (const common of [a, b, a, b]) assert.equal(scan(common), "no-symlinks");
96
+ assert.equal(listings, 2);
97
+ mkdirSync(join(a, "reftable"));
98
+ scan(a); scan(a); scan(); scan();
99
+ assert.equal(listings, 6, "unknown backend or context always scans afresh");
100
+ writeFileSync(join(b, "packed-refs"), "x".repeat(1024 * 1024 + 1));
101
+ scan(b); scan(b);
102
+ assert.equal(listings, 8, "oversized refs do not borrow cached classifications");
103
+ });
104
+
105
+ test("real Git loose and packed replacements are respected, including changes and removal", t => {
106
+ const cwd = store(t);
107
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith("GIT_")));
108
+ const git = (args: string[], input?: string) => childProcess.execFileSync("git", args, { cwd, env, encoding: "utf8", input, windowsHide: true }).trim();
109
+ git(["-c", "init.defaultRefFormat=files", "init", "--quiet"]);
110
+ const common = realpathSync(resolve(cwd, git(["rev-parse", "--git-common-dir"])));
111
+ const blob = git(["hash-object", "-w", "--stdin"], "fixture\n");
112
+ const regular = git(["mktree"], `100644 blob ${blob}\tfile.txt\n`);
113
+ const link = git(["mktree"], `120000 blob ${blob}\tlink\n`);
114
+ let listings = 0;
115
+ const scanner = new CandidateTreeSymlinkScanner((file, args, options) => { listings++; return childProcess.execFileSync(file, args, options); });
116
+ assert.equal(scanner.scan(cwd, regular, common), "no-symlinks");
117
+ assert.equal(scanner.scan(cwd, regular, common), "no-symlinks");
118
+ assert.equal(listings, 1, "the real-Git fixture must hit the cache before replacements");
119
+ git(["replace", regular, link]);
120
+ assert.equal(scanner.scan(cwd, regular, common), "tracks-symlinks");
121
+ git(["pack-refs", "--all"]);
122
+ assert.equal(scanner.scan(cwd, regular, common), "tracks-symlinks");
123
+ git(["replace", "-d", regular]);
124
+ assert.equal(scanner.scan(cwd, regular, common), "no-symlinks");
125
+ git(["replace", link, regular]);
126
+ assert.equal(scanner.scan(cwd, link, common), "no-symlinks");
127
+ git(["replace", "-d", link]);
128
+ assert.equal(scanner.scan(cwd, link, common), "tracks-symlinks");
129
+ const originalConfig = readFileSync(join(common, "config"), "utf8");
130
+ writeFileSync(join(common, "config"), originalConfig + "\n[core]\nrepositoryformatversion = 1\n[extensions]\nrefStorage = unknown-review-backend\n");
131
+ assert.equal(scanner.scan(cwd, regular, common), "unconfirmed", "unknown configured backend never borrows a warm answer");
132
+ writeFileSync(join(common, "config"), originalConfig);
133
+ assert.equal(scanner.scan(cwd, regular, common), "no-symlinks");
134
+ });
135
+
136
+ test("noncanonical packed refs never borrow a warm answer", t => {
137
+ const common = store(t), oid = "a".repeat(40);
138
+ const header = "# pack-refs with: peeled fully-peeled sorted \n";
139
+ let listing = "", listings = 0;
140
+ const scanner = new CandidateTreeSymlinkScanner(() => { listings++; return listing; });
141
+ const scan = () => scanner.scan(process.cwd(), "e".repeat(40), common);
142
+ assert.equal(scan(), "no-symlinks");
143
+ listing = `120000 blob ${oid}\tlink\n`;
144
+ const invalid = [
145
+ `^${oid}\n`, `${oid} refs/heads/x`, `${header}${oid} refs/heads/x\n# comment\n`, "# junk\n",
146
+ `${header}${oid} refs/tags/v1\n^${oid}\n^${oid}\n`,
147
+ `${header}${oid} refs/heads/z\n${oid} refs/heads/a\n`,
148
+ ];
149
+ for (const contents of invalid) {
150
+ writeFileSync(join(common, "packed-refs"), contents);
151
+ assert.equal(scan(), "tracks-symlinks", JSON.stringify(contents));
152
+ }
153
+ assert.equal(listings, 1 + invalid.length);
154
+ writeFileSync(join(common, "packed-refs"), `${header}${oid} refs/tags/v1.0\n^${oid}\n`);
155
+ assert.equal(scan(), "no-symlinks", "canonical peeled tag can reuse the literal tree");
156
+ assert.equal(listings, 1 + invalid.length);
157
+ });
@@ -268,7 +268,7 @@ test("private candidate owner ignores a spoofed SystemRoot when invoking Windows
268
268
  const execFile = childProcess.execFileSync;
269
269
  const aclExecutables: string[] = [];
270
270
  t.mock.method(childProcess, "execFileSync", (file, arguments_, options) => {
271
- if (typeof file === "string" && /\\(?:whoami|icacls)\.exe$/i.test(file)) {
271
+ if (typeof file === "string" && /\\(?:whoami|icacls|powershell)\.exe$/i.test(file)) {
272
272
  aclExecutables.push(file);
273
273
  assert.equal(file.toLowerCase().startsWith(spoofedSystemRoot.toLowerCase()), false);
274
274
  }
@@ -0,0 +1,131 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { randomUUID } from "node:crypto";
4
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+ import { tmpdir } from "node:os";
7
+ import test from "node:test";
8
+ import { CandidateViewRegistry } from "../lib/review-candidate-view.ts";
9
+ import { assertCandidateOwnerParent, removeCandidateOwner } from "../lib/review-candidate-view-owner.ts";
10
+
11
+ function fixture(t: test.TestContext) {
12
+ const parent = realpathSync(tmpdir());
13
+ const scratch = mkdtempSync(join(parent, "rdd-acl-ñ'漢-"));
14
+ const repo = join(scratch, "repo"); mkdirSync(repo);
15
+ const git = (...args: string[]) => execFileSync("git", args, { cwd: repo, encoding: "utf8", windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
16
+ git("init", "-q", "-b", "main"); git("config", "core.autocrlf", "false");
17
+ writeFileSync(join(repo, "tracked.txt"), "base\n"); git("add", ".");
18
+ git("-c", "user.name=ACL Boundary Lab", "-c", "user.email=acl@example.invalid", "commit", "-qm", "fixture");
19
+ const registry = new CandidateViewRegistry();
20
+ const view = registry.create({ contributorRoot: repo });
21
+ const marker = `${view.root}.owner.json`;
22
+ const owner = JSON.parse(readFileSync(marker, "utf8"));
23
+ const commonDir = join(repo, ".git");
24
+ t.after(() => {
25
+ registry.cleanupAll();
26
+ assert.equal(dirname(scratch), parent); assert.ok(scratch.startsWith(join(parent, "rdd-acl-ñ'漢-")));
27
+ assert.equal(realpathSync(scratch), scratch);
28
+ rmSync(scratch, { recursive: true, force: true });
29
+ });
30
+ const icacls = (path: string, ...args: string[]) => execFileSync(realpathSync.native("\\\\?\\GLOBALROOT\\SystemRoot\\System32\\icacls.exe"), [path, ...args], { encoding: "utf8", windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
31
+ const releaseOwnedLock = (token: string | undefined) => {
32
+ const lock = `${view.root}.reaper-lock`;
33
+ if (existsSync(lock)) { assert.ok(token); assert.equal(readFileSync(lock, "utf8"), token); unlinkSync(lock); }
34
+ };
35
+ return { repo, commonDir, registry, view, marker, owner, git, icacls, releaseOwnedLock };
36
+ }
37
+
38
+ test("real Windows ACL batches handle Unicode paths and re-read a changed ancestor DACL", { skip: process.platform !== "win32" }, t => {
39
+ const f = fixture(t);
40
+ assert.doesNotThrow(() => f.view.verify());
41
+ const parent = dirname(f.view.root);
42
+ try {
43
+ f.icacls(parent, "/grant", "*S-1-1-0:(OI)(CI)F");
44
+ assert.throws(() => assertCandidateOwnerParent(f.commonDir));
45
+ assert.throws(() => f.view.verify());
46
+ } finally { f.icacls(parent, "/remove:g", "*S-1-1-0"); }
47
+ assert.doesNotThrow(() => f.view.verify());
48
+ });
49
+
50
+ test("real Windows cleanup observes DACL changes made by the Git callback before further actions", { skip: process.platform !== "win32" }, t => {
51
+ const f = fixture(t);
52
+ const parent = dirname(f.view.root);
53
+ let changed = false; let writable = 0; let removals = 0; let lockToken: string | undefined;
54
+ try {
55
+ assert.throws(() => removeCandidateOwner(f.owner, args => {
56
+ if (args[0] === "worktree" && args[1] === "remove") removals++;
57
+ const output = f.git(...args);
58
+ if (!changed && args[0] === "worktree" && args[1] === "list") {
59
+ lockToken = readFileSync(`${f.view.root}.reaper-lock`, "utf8");
60
+ f.icacls(parent, "/grant", "*S-1-1-0:(OI)(CI)F"); changed = true;
61
+ }
62
+ return output;
63
+ }, () => { writable++; }));
64
+ assert.equal(changed, true); assert.equal(writable, 0); assert.equal(removals, 0);
65
+ assert.ok(existsSync(f.view.root)); assert.ok(existsSync(f.marker));
66
+ } finally {
67
+ if (changed) f.icacls(parent, "/remove:g", "*S-1-1-0");
68
+ f.releaseOwnedLock(lockToken);
69
+ }
70
+ });
71
+
72
+ test("real Windows cleanup rechecks marker and lock after makeWritable without deleting replacements", { skip: process.platform !== "win32" }, t => {
73
+ const f = fixture(t);
74
+ for (const change of ["marker", "lock"]) {
75
+ let removals = 0; let token: string | undefined;
76
+ const original = readFileSync(f.marker, "utf8");
77
+ try {
78
+ assert.throws(() => removeCandidateOwner(f.owner, args => {
79
+ if (args[0] === "worktree" && args[1] === "remove") removals++;
80
+ return f.git(...args);
81
+ }, () => {
82
+ token = readFileSync(`${f.view.root}.reaper-lock`, "utf8");
83
+ if (change === "marker") writeFileSync(f.marker, JSON.stringify({ ...f.owner, token: randomUUID() }));
84
+ else f.icacls(`${f.view.root}.reaper-lock`, "/grant", "*S-1-1-0:F");
85
+ }));
86
+ assert.equal(removals, 0); assert.ok(existsSync(f.view.root)); assert.ok(existsSync(f.marker));
87
+ if (change === "marker") assert.notEqual(readFileSync(f.marker, "utf8"), original);
88
+ else assert.ok(existsSync(`${f.view.root}.reaper-lock`));
89
+ } finally {
90
+ if (change === "marker") writeFileSync(f.marker, original);
91
+ else if (token !== undefined) f.icacls(`${f.view.root}.reaper-lock`, "/remove:g", "*S-1-1-0");
92
+ f.releaseOwnedLock(token);
93
+ }
94
+ }
95
+ });
96
+
97
+ test("real Windows cleanup preserves the worktree after Git failure and parent replacement", { skip: process.platform !== "win32" }, t => {
98
+ const f = fixture(t);
99
+ assert.throws(() => removeCandidateOwner(f.owner, args => {
100
+ if (args[0] === "worktree" && args[1] === "remove") throw new Error("controlled Git failure");
101
+ return f.git(...args);
102
+ }, () => {}), /controlled Git failure/);
103
+ assert.ok(existsSync(f.view.root)); assert.ok(existsSync(f.marker));
104
+ const parent = dirname(f.view.root); const saved = `${parent}.saved`;
105
+ const expectedParent = join(f.commonDir, "gentle-ai", "candidate-views");
106
+ let replacementLockToken: string | undefined;
107
+ let replacementRemovals = 0;
108
+ try {
109
+ assert.throws(() => removeCandidateOwner(f.owner, args => {
110
+ if (args[0] === "worktree" && args[1] === "remove") replacementRemovals++;
111
+ return f.git(...args);
112
+ }, () => {
113
+ assert.equal(realpathSync(parent), expectedParent);
114
+ assert.equal(dirname(saved), join(f.commonDir, "gentle-ai"));
115
+ assert.equal(existsSync(saved), false);
116
+ replacementLockToken = readFileSync(`${f.view.root}.reaper-lock`, "utf8");
117
+ renameSync(parent, saved); mkdirSync(parent);
118
+ }));
119
+ assert.ok(existsSync(saved));
120
+ assert.equal(replacementRemovals, 0);
121
+ } finally {
122
+ if (existsSync(saved)) {
123
+ assert.equal(realpathSync(parent), expectedParent);
124
+ assert.equal(realpathSync(saved), saved);
125
+ rmdirSync(parent); renameSync(saved, parent);
126
+ }
127
+ }
128
+ const lock = `${f.view.root}.reaper-lock`;
129
+ if (existsSync(lock)) f.releaseOwnedLock(replacementLockToken);
130
+ assert.ok(existsSync(f.view.root)); assert.ok(existsSync(f.marker));
131
+ });
@@ -0,0 +1,63 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import childProcess from "node:child_process";
4
+ import { syncBuiltinESMExports } from "node:module";
5
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { dirname, join } from "node:path";
8
+ import { assertCandidateOwnerParent, decodeWindowsAclProbe, WindowsOwnerValidationError } from "../lib/review-candidate-view-owner.ts";
9
+
10
+ const user = "S-1-5-21-1-2-3-1001";
11
+ const administrator = "S-1-5-21-1-2-3-500";
12
+ const dacl = `D:P(A;OICI;FA;;;${user})(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)`;
13
+ const response = () => ({ schema: "gentle-pi.windows-acl-probe/v1", user, localAdministrator: administrator,
14
+ entries: [{ index: 0, owner: user, dacl }, { index: 1, owner: "S-1-5-18", dacl }] });
15
+
16
+ test("Windows batch probe decodes ordered complete observations without path or SID diagnostics", () => {
17
+ const result = decodeWindowsAclProbe(JSON.stringify(response()), 2);
18
+ assert.equal(result.user, user);
19
+ assert.equal(result.localAdministrator, administrator);
20
+ assert.deepEqual(result.entries, response().entries);
21
+ });
22
+
23
+ test("Windows batch probe rejects partial, reordered, duplicated and unknown observations", () => {
24
+ for (const invalid of [
25
+ null, [], {}, { ...response(), extra: "unknown" }, { ...response(), schema: "other" },
26
+ { ...response(), user: "administrator" }, { ...response(), localAdministrator: "LA" },
27
+ { ...response(), entries: response().entries.slice(0, 1) },
28
+ { ...response(), entries: [...response().entries].reverse() },
29
+ { ...response(), entries: [response().entries[0], response().entries[0]] },
30
+ { ...response(), entries: [{ ...response().entries[0], owner: null }, response().entries[1]] },
31
+ { ...response(), entries: [{ ...response().entries[0], dacl: "" }, response().entries[1]] },
32
+ { ...response(), entries: [{ ...response().entries[0], path: "unrequested" }, response().entries[1]] },
33
+ ]) assert.throws(() => decodeWindowsAclProbe(JSON.stringify(invalid), 2), error => {
34
+ assert.ok(error instanceof Error);
35
+ assert.ok(!error.message.includes(user));
36
+ assert.ok(!error.message.includes(administrator));
37
+ return true;
38
+ });
39
+ for (const payload of ["", "{", JSON.stringify(response()).slice(0, -1)]) assert.throws(() => decodeWindowsAclProbe(payload, 2));
40
+ for (const count of [0, -1, 4, 1.5]) assert.throws(() => decodeWindowsAclProbe(JSON.stringify(response()), count));
41
+ });
42
+
43
+ test("Windows probe failures and foreign owners block without retrying invalid authority", { skip: process.platform !== "win32" }, t => {
44
+ const parent = realpathSync(tmpdir()); const root = mkdtempSync(join(parent, "rdd-probe-response-"));
45
+ mkdirSync(join(root, "gentle-ai", "candidate-views"), { recursive: true });
46
+ const original = childProcess.execFileSync;
47
+ let payload = "{"; let calls = 0;
48
+ t.mock.method(childProcess, "execFileSync", ((file: string, args: string[], options: unknown) => {
49
+ if (file.toLowerCase().endsWith("powershell.exe")) { calls++; return payload; }
50
+ return original(file, args, options as never);
51
+ }) as typeof childProcess.execFileSync);
52
+ syncBuiltinESMExports();
53
+ t.after(() => {
54
+ t.mock.restoreAll(); syncBuiltinESMExports();
55
+ assert.equal(dirname(root), parent); assert.ok(root.startsWith(join(parent, "rdd-probe-response-"))); assert.equal(realpathSync(root), root);
56
+ rmSync(root, { recursive: true, force: true });
57
+ });
58
+ assert.throws(() => assertCandidateOwnerParent(root, "win32"), /probe response is invalid/);
59
+ assert.equal(calls, 1);
60
+ payload = JSON.stringify({ ...response(), entries: [0, 1, 2].map(index => ({ index, owner: "S-1-5-21-9-8-7-1002", dacl })) });
61
+ assert.throws(() => assertCandidateOwnerParent(root, "win32"), WindowsOwnerValidationError);
62
+ assert.equal(calls, 2, "a valid transport response with untrusted authority is not retried");
63
+ });
@@ -0,0 +1,129 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import { pathToFileURL } from "node:url";
8
+
9
+ // Host regression for #2724: each step has a fresh module graph and empty
10
+ // CandidateViewRegistry. Provider durability is simulated through a file;
11
+ // this test makes no claim about the native engine, SDK session files or TUI.
12
+ // A real SDK/TUI + native process experiment separately established the flow.
13
+ const TARGET = `sha256:${"1".repeat(64)}`;
14
+ const REVISION = `sha256:${"2".repeat(64)}`;
15
+ const LINEAGE = "committed-restart-ack";
16
+
17
+ /** Build a fresh controller process with a file-backed, single-use provider fixture. */
18
+ function workerSource() {
19
+ const extension = pathToFileURL(join(import.meta.dirname, "../extensions/gentle-ai.ts")).href;
20
+ const registry = pathToFileURL(join(import.meta.dirname, "../lib/review-candidate-view.ts")).href;
21
+ return `
22
+ import assert from 'node:assert/strict';
23
+ import { readFileSync, writeFileSync } from 'node:fs';
24
+ const { __testing } = await import(${JSON.stringify(extension)});
25
+ const { CandidateViewRegistry } = await import(${JSON.stringify(registry)});
26
+ const [stateFile, mode, output] = process.argv.slice(-3);
27
+ const state = JSON.parse(readFileSync(stateFile, 'utf8'));
28
+ const { cwd, baseTree, candidateTree, baseCommit, target, revision, lineage, decoy } = state;
29
+ const requests = [];
30
+ const arguments_ = [
31
+ { name:'cwd',value:cwd,token:'--cwd='+cwd },
32
+ { name:'lineage',value:lineage,token:'--lineage='+lineage },
33
+ { name:'target',value:target,token:'--target='+target },
34
+ { name:'expected-revision',value:revision,token:'--expected-revision='+revision },
35
+ { name:'token',value:'provider-issued-once',token:'--token=provider-issued-once' },
36
+ ];
37
+ if(decoy) arguments_[2] = { name:'target',value:'sha256:'+'f'.repeat(64),token:'--target=sha256:'+'f'.repeat(64) };
38
+ const projection = {
39
+ schema:'gentle-ai.review-candidate-projection/v1',kind:'base-diff',projection:'workspace',
40
+ baseTree,initialReviewTree:candidateTree,currentCandidateTree:candidateTree,
41
+ pathsDigest:target,paths:['candidate.ts'],intendedUntracked:[],intendedUntrackedProof:target,
42
+ initialSnapshotIdentity:target,currentSnapshotIdentity:target,
43
+ };
44
+ const native = {
45
+ targetStatus:async request => {
46
+ requests.push(request);
47
+ assert.equal(request.cwd,cwd);
48
+ assert.equal(request.lineageId,lineage);
49
+ // Recovering the lineage must not require host memory of a base selector.
50
+ assert.equal(request.baseRef,undefined);
51
+ assert.equal(request.committedOnly,undefined);
52
+ return {
53
+ contract:'gentle-ai.review-integration/v2',applicability:state.burns?'unrelated':'current_target',
54
+ ...(state.burns?{}:{authority:{version:'compact-v2',lineageId:lineage,state:'approved',generation:1,revision}}),
55
+ receipt:{status:'none'},action:'stop',replayability:'not_replayable',targetIdentity:target,projection,candidates:[],
56
+ nextTransition:state.burns?{kind:'stop',reasonCode:'approved_acknowledged'}:{kind:'execute',reasonCode:'approved_acknowledgement_required',execute:{operation:'review.acknowledge-approved',command:'gentle-ai review acknowledge-approved --provider-vector',arguments:arguments_,preconditions:[{name:'state',value:'approved'}],binding:{lineageId:lineage,targetIdentity:target,revision}}},
57
+ raw:{schema:'gentle-ai.review-integration.status/v9',contract:'gentle-ai.review-integration/v2',lineage_id:lineage,target_identity:target,projection:{kind:'base-diff',base_tree:baseTree,paths:['candidate.ts']},...(state.burns?{}:{authority:{lineage_id:lineage,state:'approved'}})},
58
+ };
59
+ },
60
+ acknowledgeApproved:async request => {
61
+ assert.equal(state.burns,0,'No second native burn is permitted');
62
+ assert.deepEqual(request.argumentTokens,arguments_.map(a=>a.token));
63
+ assert.deepEqual(request.binding,{lineageId:lineage,targetIdentity:target,revision});
64
+ state.burns++;
65
+ writeFileSync(stateFile,JSON.stringify(state));
66
+ },
67
+ };
68
+ const views=new CandidateViewRegistry();
69
+ assert.equal(views.hasProjection(lineage,cwd),false);
70
+ const operation=mode==='inspect'?'status':'acknowledge-approved';
71
+ const result=await __testing.executeReviewControllerOperation({operation,lineageId:lineage,workspaceRoot:cwd},cwd,native,undefined,views);
72
+ writeFileSync(output,JSON.stringify({pid:process.pid,result,requests,burns:state.burns}));
73
+ `;
74
+ }
75
+
76
+ /** Create an isolated committed range and workers sharing only simulated provider state. */
77
+ function fixture(t: test.TestContext, decoy = false) {
78
+ const scratch = realpathSync(mkdtempSync(join(tmpdir(), "gentle-committed-restart-")));
79
+ t.after(() => rmSync(scratch, { recursive: true, force: true }));
80
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith("GIT_")));
81
+ const git = (...args: string[]) => execFileSync("git", ["-c", "core.hooksPath=", "-c", "commit.gpgSign=false", "-c", "core.autocrlf=false", ...args], { cwd: scratch, env, encoding: "utf8", windowsHide: true }).trim();
82
+ git("init", "-b", "main");
83
+ writeFileSync(join(scratch, "candidate.ts"), "export const value = 1;\n");
84
+ git("add", "candidate.ts");
85
+ git("-c", "user.name=Restart Fixture", "-c", "user.email=restart@example.invalid", "commit", "-qm", "base");
86
+ const baseCommit = git("rev-parse", "HEAD");
87
+ const baseTree = git("rev-parse", "HEAD^{tree}");
88
+ writeFileSync(join(scratch, "candidate.ts"), "export const value = 2;\n");
89
+ git("add", "candidate.ts");
90
+ git("-c", "user.name=Restart Fixture", "-c", "user.email=restart@example.invalid", "commit", "-qm", "committed correction");
91
+ const stateFile = join(scratch, "provider.json");
92
+ writeFileSync(stateFile, JSON.stringify({ cwd: scratch, baseCommit, baseTree, candidateTree: git("rev-parse", "HEAD^{tree}"), target: TARGET, revision: REVISION, lineage: LINEAGE, decoy, burns: 0 }));
93
+ const run = (mode: string) => {
94
+ const output = join(scratch, `${mode}.json`);
95
+ execFileSync(process.execPath, ["--experimental-strip-types", "--input-type=module", "--eval", workerSource(), stateFile, mode, output], { env, encoding: "utf8", timeout: 30_000, windowsHide: true });
96
+ return JSON.parse(readFileSync(output, "utf8"));
97
+ };
98
+ return { run, baseTree, stateFile };
99
+ }
100
+
101
+ test("fresh processes resume a committed approval and acknowledge it exactly once", (t) => {
102
+ const { run, baseTree } = fixture(t);
103
+ const inspected = run("inspect");
104
+ assert.equal(inspected.burns, 0);
105
+ assert.equal(inspected.result.result.authority.lineage_id, LINEAGE);
106
+ assert.equal(inspected.result.result.projection.base_tree, baseTree);
107
+ assert.deepEqual(inspected.result.result.projection.paths, ["candidate.ts"]);
108
+ assert.match(inspected.result.next_action, /acknowledge-approved/);
109
+ const acknowledged = run("ack");
110
+ assert.notEqual(acknowledged.pid, inspected.pid);
111
+ assert.equal(acknowledged.result.outcome, "native-approved-acknowledgement-completed");
112
+ assert.equal(acknowledged.result.authority, "burned");
113
+ assert.equal(acknowledged.result.target_identity, TARGET);
114
+ assert.equal(acknowledged.result.delivery, "ordinary-repository-policy");
115
+ assert.equal(acknowledged.burns, 1);
116
+ const replay = run("replay");
117
+ assert.notEqual(replay.pid, acknowledged.pid);
118
+ assert.equal(replay.result.outcome, "native-approved-acknowledgement-not-current");
119
+ assert.equal(replay.result.mutation_outcome, "none");
120
+ assert.equal(replay.burns, 1);
121
+ });
122
+
123
+ test("a fresh process refuses an acknowledgement vector for another target before burn", (t) => {
124
+ const { run, stateFile } = fixture(t, true);
125
+ const result = run("ack");
126
+ assert.equal(result.result.outcome, "native-operation-failed");
127
+ assert.equal(result.result.mutation_outcome, "none");
128
+ assert.equal(JSON.parse(readFileSync(stateFile, "utf8")).burns, 0);
129
+ });
@@ -0,0 +1,76 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { ReviewContinuationRegistry, type RetainedReviewContinuation } from "../lib/review-continuation-registry.ts";
4
+
5
+ const selection = { untrackedScope: "exclude" as const, expectedUntrackedInventory: "inventory", intendedUntracked: [] };
6
+ const preStart = { ...selection, targetIdentity: "target", candidateTree: "tree" };
7
+ const stop = { selectionBinding: "selection", targetIdentity: "target" };
8
+ const route = { workspaceRoot: "/repo", lineageId: "lineage", targetIdentity: "target" };
9
+
10
+ test("four continuation kinds share one capacity and replacement does not refresh insertion order", () => {
11
+ const registry = new ReviewContinuationRegistry();
12
+ registry.retainSelection("/repo", "first", selection);
13
+ registry.retainPreStart("/pre", preStart);
14
+ registry.retainStop("/stop", stop);
15
+ for (let index = 0; index < 61; index++) registry.retainCapture(`binding-${index}`, route);
16
+ assert.equal(registry.size, 64);
17
+ registry.retainSelection("/repo", "first", { ...selection, expectedUntrackedInventory: "replacement" });
18
+ registry.retainCapture("last", route);
19
+ assert.equal(registry.readSelection("/repo", "first"), undefined);
20
+ assert.equal(registry.readPreStart("/pre")?.candidateTree, "tree");
21
+ assert.equal(registry.readStop("/stop")?.selectionBinding, "selection");
22
+ assert.equal(registry.size, 64);
23
+ });
24
+
25
+ test("deleting and reinserting moves an entry behind older retained entries", () => {
26
+ const registry = new ReviewContinuationRegistry();
27
+ registry.retainSelection("/repo", "reinserted", selection);
28
+ registry.retainPreStart("/older", preStart);
29
+ registry.clearSelection("/repo", "reinserted");
30
+ registry.retainSelection("/repo", "reinserted", selection);
31
+ for (let index = 0; index < 63; index++) registry.retainCapture(`binding-${index}`, route);
32
+ assert.equal(registry.readPreStart("/older"), undefined);
33
+ assert.notEqual(registry.readSelection("/repo", "reinserted"), undefined);
34
+ });
35
+
36
+ test("pre-start entries replace stop entries but cannot be read as lineage selections", () => {
37
+ const registry = new ReviewContinuationRegistry();
38
+ registry.retainStop("/repo", stop);
39
+ assert.equal(registry.readPreStart("/repo"), undefined);
40
+ registry.retainPreStart("/repo", preStart);
41
+ assert.equal(registry.readStop("/repo"), undefined);
42
+ assert.equal(registry.readSelection("/repo", ""), undefined);
43
+ assert.equal(registry.size, 1);
44
+ });
45
+
46
+ test("capture cleanup keeps current bindings and other workspaces, lineages and sessions", () => {
47
+ const registry = new ReviewContinuationRegistry(), otherSession = new ReviewContinuationRegistry();
48
+ registry.retainCapture("keep", route);
49
+ registry.retainCapture("expired", route);
50
+ registry.retainCapture("other-root", { ...route, workspaceRoot: "/other" });
51
+ registry.retainCapture("other-lineage", { ...route, lineageId: "other" });
52
+ registry.retainSelection("/repo", "lineage", selection);
53
+ otherSession.retainCapture("expired", route);
54
+ registry.clearCaptureRoutes("/repo", "lineage", ["keep"]);
55
+ assert.equal(registry.readCapture("expired"), undefined);
56
+ for (const binding of ["keep", "other-root", "other-lineage"]) assert.notEqual(registry.readCapture(binding), undefined);
57
+ registry.clearCaptureRoutes("/repo", "lineage");
58
+ assert.equal(registry.readCapture("keep"), undefined);
59
+ assert.notEqual(registry.readSelection("/repo", "lineage"), undefined);
60
+ assert.notEqual(otherSession.readCapture("expired"), undefined);
61
+ assert.equal(registry.readSelection("/other", "lineage"), undefined);
62
+ });
63
+
64
+ test("Map test seam uses the same discriminated entries without copying retained state", () => {
65
+ const backing = new Map<string, RetainedReviewContinuation>();
66
+ const first = ReviewContinuationRegistry.from(backing), next = ReviewContinuationRegistry.from(backing);
67
+ first.retainSelection("/repo", "lineage", selection);
68
+ assert.equal(backing.size, 1);
69
+ assert.equal([...backing.values()][0].kind, "selection");
70
+ assert.notEqual(next.readSelection("/repo", "lineage"), undefined);
71
+ assert.equal("kind" in next.readSelection("/repo", "lineage")!, false, "internal tags never enter native requests");
72
+ first.retainCapture("binding", route);
73
+ assert.deepEqual(next.readCapture("binding"), route);
74
+ next.clearSelection("/repo", "lineage");
75
+ assert.equal(first.size, 1);
76
+ });