@warpgogol/forge 9.4.0 → 9.5.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 (167) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +4 -2
  3. package/README.uk.md +10 -8
  4. package/bin/cli.ts +152 -11
  5. package/dist/bin/cli.js +125 -5
  6. package/dist/bin/cli.js.map +1 -1
  7. package/dist/os/flow/dirty-classify.d.ts +11 -1
  8. package/dist/os/flow/dirty-classify.d.ts.map +1 -1
  9. package/dist/os/flow/dirty-classify.js +13 -0
  10. package/dist/os/flow/dirty-classify.js.map +1 -1
  11. package/dist/os/flow/flow.module.d.ts.map +1 -1
  12. package/dist/os/flow/flow.module.js +29 -3
  13. package/dist/os/flow/flow.module.js.map +1 -1
  14. package/dist/os/flow/handlers/flow-check.d.ts.map +1 -1
  15. package/dist/os/flow/handlers/flow-check.js +9 -9
  16. package/dist/os/flow/handlers/flow-check.js.map +1 -1
  17. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  18. package/dist/os/flow/handlers/flow-cut.js +22 -8
  19. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  20. package/dist/os/flow/handlers/flow-integrate.d.ts +6 -0
  21. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  22. package/dist/os/flow/handlers/flow-integrate.js +155 -44
  23. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  24. package/dist/os/flow/handlers/flow-open.d.ts.map +1 -1
  25. package/dist/os/flow/handlers/flow-open.js +14 -19
  26. package/dist/os/flow/handlers/flow-open.js.map +1 -1
  27. package/dist/os/flow/handlers/flow-peers.d.ts +24 -0
  28. package/dist/os/flow/handlers/flow-peers.d.ts.map +1 -0
  29. package/dist/os/flow/handlers/flow-peers.js +99 -0
  30. package/dist/os/flow/handlers/flow-peers.js.map +1 -0
  31. package/dist/os/flow/index.d.ts +3 -0
  32. package/dist/os/flow/index.d.ts.map +1 -1
  33. package/dist/os/flow/index.js +9 -4
  34. package/dist/os/flow/index.js.map +1 -1
  35. package/dist/os/flow/ops-registry.d.ts +33 -0
  36. package/dist/os/flow/ops-registry.d.ts.map +1 -0
  37. package/dist/os/flow/ops-registry.js +177 -0
  38. package/dist/os/flow/ops-registry.js.map +1 -0
  39. package/dist/os/flow/preflight.d.ts +70 -3
  40. package/dist/os/flow/preflight.d.ts.map +1 -1
  41. package/dist/os/flow/preflight.js +545 -49
  42. package/dist/os/flow/preflight.js.map +1 -1
  43. package/dist/os/flow/registry.d.ts +2 -2
  44. package/dist/os/flow/standalone-invoke.d.ts +11 -0
  45. package/dist/os/flow/standalone-invoke.d.ts.map +1 -0
  46. package/dist/os/flow/standalone-invoke.js +75 -0
  47. package/dist/os/flow/standalone-invoke.js.map +1 -0
  48. package/dist/os/gate-run/detach.d.ts +27 -0
  49. package/dist/os/gate-run/detach.d.ts.map +1 -0
  50. package/dist/os/gate-run/detach.js +85 -0
  51. package/dist/os/gate-run/detach.js.map +1 -0
  52. package/dist/os/gate-run/gate-run.module.d.ts +3 -0
  53. package/dist/os/gate-run/gate-run.module.d.ts.map +1 -0
  54. package/dist/os/gate-run/gate-run.module.js +23 -0
  55. package/dist/os/gate-run/gate-run.module.js.map +1 -0
  56. package/dist/os/gate-run/index.d.ts +7 -0
  57. package/dist/os/gate-run/index.d.ts.map +1 -0
  58. package/dist/os/gate-run/index.js +5 -0
  59. package/dist/os/gate-run/index.js.map +1 -0
  60. package/dist/os/gate-run/record.d.ts +47 -0
  61. package/dist/os/gate-run/record.d.ts.map +1 -0
  62. package/dist/os/gate-run/record.js +157 -0
  63. package/dist/os/gate-run/record.js.map +1 -0
  64. package/dist/os/gate-run/status.d.ts +41 -0
  65. package/dist/os/gate-run/status.d.ts.map +1 -0
  66. package/dist/os/gate-run/status.js +142 -0
  67. package/dist/os/gate-run/status.js.map +1 -0
  68. package/dist/os/gate-run/types.d.ts +47 -0
  69. package/dist/os/gate-run/types.d.ts.map +1 -0
  70. package/dist/os/gate-run/types.js +24 -0
  71. package/dist/os/gate-run/types.js.map +1 -0
  72. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  73. package/dist/os/mission/handlers/archive.js +12 -8
  74. package/dist/os/mission/handlers/archive.js.map +1 -1
  75. package/dist/os/mission/importer-block.d.ts +19 -0
  76. package/dist/os/mission/importer-block.d.ts.map +1 -0
  77. package/dist/os/mission/importer-block.js +124 -0
  78. package/dist/os/mission/importer-block.js.map +1 -0
  79. package/dist/os/mission/lockfile.d.ts +17 -0
  80. package/dist/os/mission/lockfile.d.ts.map +1 -1
  81. package/dist/os/mission/lockfile.js +38 -0
  82. package/dist/os/mission/lockfile.js.map +1 -1
  83. package/dist/os/rfc/evidence-annotation.d.ts +26 -0
  84. package/dist/os/rfc/evidence-annotation.d.ts.map +1 -0
  85. package/dist/os/rfc/evidence-annotation.js +52 -0
  86. package/dist/os/rfc/evidence-annotation.js.map +1 -0
  87. package/dist/os/rfc/handlers/fixed-inputs.d.ts.map +1 -1
  88. package/dist/os/rfc/handlers/fixed-inputs.js +7 -1
  89. package/dist/os/rfc/handlers/fixed-inputs.js.map +1 -1
  90. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  91. package/dist/os/rfc/handlers/implement-stamp.js +21 -28
  92. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  93. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  94. package/dist/os/rfc/handlers/list-create.js +25 -3
  95. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  96. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  97. package/dist/os/rfc/handlers/validate-rules.js +127 -7
  98. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  99. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  100. package/dist/os/rfc/rfc.module.js +3 -2
  101. package/dist/os/rfc/rfc.module.js.map +1 -1
  102. package/dist/os/rfc/types.d.ts +9 -2
  103. package/dist/os/rfc/types.d.ts.map +1 -1
  104. package/dist/os/rfc/types.js +2 -2
  105. package/dist/os/rfc/types.js.map +1 -1
  106. package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -1
  107. package/dist/os/system/handlers/system-task-collect.js +11 -5
  108. package/dist/os/system/handlers/system-task-collect.js.map +1 -1
  109. package/dist/src/cli-flags.d.ts.map +1 -1
  110. package/dist/src/cli-flags.js +6 -0
  111. package/dist/src/cli-flags.js.map +1 -1
  112. package/dist/src/onboarding/prettierignore.d.ts.map +1 -1
  113. package/dist/src/onboarding/prettierignore.js +2 -0
  114. package/dist/src/onboarding/prettierignore.js.map +1 -1
  115. package/dist/src/types.d.ts +7 -0
  116. package/dist/src/types.d.ts.map +1 -1
  117. package/dist/src/types.js +2 -8
  118. package/dist/src/types.js.map +1 -1
  119. package/os/flow/dirty-classify.ts +21 -0
  120. package/os/flow/flow.module.ts +31 -3
  121. package/os/flow/handlers/flow-check.ts +17 -18
  122. package/os/flow/handlers/flow-cut.ts +28 -11
  123. package/os/flow/handlers/flow-integrate.ts +229 -62
  124. package/os/flow/handlers/flow-open.ts +24 -31
  125. package/os/flow/handlers/flow-peers.ts +142 -0
  126. package/os/flow/index.ts +10 -8
  127. package/os/flow/ops-registry.ts +194 -0
  128. package/os/flow/preflight.ts +608 -55
  129. package/os/flow/standalone-invoke.ts +85 -0
  130. package/os/flow/tests/dirty-classify.test.ts +139 -4
  131. package/os/flow/tests/flow-cut.test.ts +21 -0
  132. package/os/flow/tests/flow-integrate.preflight.test.ts +34 -9
  133. package/os/flow/tests/flow-integrate.test.ts +433 -17
  134. package/os/flow/tests/lockfile-induced.test.ts +328 -0
  135. package/os/flow/tests/ops-registry.test.ts +136 -0
  136. package/os/gate-run/detach.ts +106 -0
  137. package/os/gate-run/gate-run.module.ts +25 -0
  138. package/os/gate-run/index.ts +16 -0
  139. package/os/gate-run/record.ts +194 -0
  140. package/os/gate-run/status.ts +168 -0
  141. package/os/gate-run/tests/gate-run-detach.test.ts +144 -0
  142. package/os/gate-run/tests/gate-run-record.test.ts +200 -0
  143. package/os/gate-run/types.ts +73 -0
  144. package/os/mission/handlers/archive.ts +22 -14
  145. package/os/mission/importer-block.ts +119 -0
  146. package/os/mission/lockfile.ts +41 -0
  147. package/os/rfc/evidence-annotation.ts +61 -0
  148. package/os/rfc/handlers/fixed-inputs.test.ts +70 -0
  149. package/os/rfc/handlers/fixed-inputs.ts +11 -1
  150. package/os/rfc/handlers/implement-stamp.ts +25 -28
  151. package/os/rfc/handlers/list-create.test.ts +58 -5
  152. package/os/rfc/handlers/list-create.ts +30 -3
  153. package/os/rfc/handlers/validate-evidence-shape.test.ts +218 -0
  154. package/os/rfc/handlers/validate-probe-meta.test.ts +71 -0
  155. package/os/rfc/handlers/validate-rules.ts +169 -17
  156. package/os/rfc/handlers/validate-transient-probes.test.ts +222 -0
  157. package/os/rfc/rfc-0000-template.md +10 -10
  158. package/os/rfc/rfc.module.ts +3 -2
  159. package/os/rfc/types.ts +5 -2
  160. package/os/system/handlers/system-task-collect.ts +11 -5
  161. package/os/system/tests/system-task-collect.test.ts +16 -0
  162. package/package.json +17 -1
  163. package/skills/fo/fo-session-retro/SKILL.md +12 -4
  164. package/src/cli-flags.ts +7 -0
  165. package/src/onboarding/prettierignore.ts +2 -0
  166. package/src/tests/prettierignore-manage.test.ts +11 -0
  167. package/src/types.ts +9 -8
@@ -0,0 +1,328 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>ADR-0130 (F-0201): the induced-change lockfile shapes —
4
+ importer-materialize with `optional: true` removals and `key:` → `key: {}`
5
+ collapses on reachable snapshots, and importer-prune with inverse induced
6
+ additions — classify into their tolerated classes instead of `work`, while
7
+ a real content change (a version bump) stays `work`.</purpose>
8
+ <non-goals>
9
+ <item>No integrate-level restore coverage — the foreign-open-mission restore
10
+ path itself is covered in the preflight/integrate suites; these tests pin
11
+ the classification boundary the sweep depends on.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <CHANGE_SUMMARY>
15
+ <item>ADR-0130: induced-change lockfile classifiers — materialize BFS reachability + prune induced additions</item>
16
+ <item>ADR-0130: induced-change lockfile classifiers — BFS reachability for optional-flag removals, collapse pairs, induced packages/snapshots additions</item>
17
+ </CHANGE_SUMMARY>
18
+ */
19
+
20
+ import { describe, expect, it, afterEach } from "vitest";
21
+ import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
22
+ import { tmpdir } from "node:os";
23
+ import { join } from "node:path";
24
+
25
+ import { ambientIo } from "../../../src/utils/io.ts";
26
+ import {
27
+ classifyLockfileMaterializeExtended,
28
+ classifyLockfilePruneIdsExtended,
29
+ } from "../preflight.ts";
30
+
31
+ const dirs: string[] = [];
32
+ afterEach(async () => {
33
+ for (const dir of dirs.splice(0)) {
34
+ await rm(dir, { recursive: true, force: true });
35
+ }
36
+ });
37
+
38
+ // Fixture cut from commit 9fc5be128 (importer materialize + induced removals):
39
+ // HEAD lacks the mission importer; the working file gains it plus
40
+ // `optional: true` removals and a `buffer-from` collapse on reachable snapshots.
41
+ const HEAD_MATERIALIZE = `lockfileVersion: '9.0'
42
+
43
+ importers:
44
+
45
+ .:
46
+ dependencies:
47
+ yaml:
48
+ specifier: ^2.9.1
49
+ version: 2.9.1
50
+
51
+ packages:
52
+
53
+ yaml@2.9.1:
54
+ resolution: {integrity: sha1}
55
+
56
+ buffer-from@1.1.2:
57
+ resolution: {integrity: sha2}
58
+
59
+ buffer-crc32@0.2.13:
60
+ resolution: {integrity: sha3}
61
+
62
+ snapshots:
63
+
64
+ yaml@2.9.1: {}
65
+
66
+ buffer-crc32@0.2.13:
67
+ optional: true
68
+
69
+ buffer-from@1.1.2:
70
+ optional: true
71
+ `;
72
+
73
+ const DIFF_MATERIALIZE = `diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
74
+ index aaa..bbb 100644
75
+ --- a/pnpm-lock.yaml
76
+ +++ b/pnpm-lock.yaml
77
+ @@ -5,7 +5,15 @@ importers:
78
+ .:
79
+ dependencies:
80
+ yaml:
81
+ specifier: ^2.9.1
82
+ version: 2.9.1
83
+
84
+ + missions/site-m000001/workpiece:
85
+ + dependencies:
86
+ + buffer-from:
87
+ + specifier: ^1.1.2
88
+ + version: 1.1.2
89
+ + buffer-crc32:
90
+ + specifier: ^0.2.13
91
+ + version: 0.2.13
92
+ +
93
+ packages:
94
+ @@ -22,10 +30,9 @@ snapshots:
95
+
96
+ yaml@2.9.1: {}
97
+
98
+ buffer-crc32@0.2.13:
99
+ - optional: true
100
+
101
+ - buffer-from@1.1.2:
102
+ - optional: true
103
+ + buffer-from@1.1.2: {}
104
+
105
+ `;
106
+
107
+ const WORK_MATERIALIZE = `lockfileVersion: '9.0'
108
+
109
+ importers:
110
+
111
+ .:
112
+ dependencies:
113
+ yaml:
114
+ specifier: ^2.9.1
115
+ version: 2.9.1
116
+
117
+ missions/site-m000001/workpiece:
118
+ dependencies:
119
+ buffer-from:
120
+ specifier: ^1.1.2
121
+ version: 1.1.2
122
+ buffer-crc32:
123
+ specifier: ^0.2.13
124
+ version: 0.2.13
125
+
126
+ packages:
127
+
128
+ yaml@2.9.1:
129
+ resolution: {integrity: sha1}
130
+
131
+ buffer-from@1.1.2:
132
+ resolution: {integrity: sha2}
133
+
134
+ buffer-crc32@0.2.13:
135
+ resolution: {integrity: sha3}
136
+
137
+ snapshots:
138
+
139
+ yaml@2.9.1: {}
140
+
141
+ buffer-crc32@0.2.13:
142
+
143
+ buffer-from@1.1.2: {}
144
+ `;
145
+
146
+ // Fixture cut from commit 391abcfaf (importer prune + induced additions):
147
+ // HEAD carries the mission importer; the working file drops it and gains
148
+ // `optional: true`/`transitivePeerDependencies`/snapshot entries.
149
+ const HEAD_PRUNE = `lockfileVersion: '9.0'
150
+
151
+ importers:
152
+
153
+ .:
154
+ dependencies:
155
+ yaml:
156
+ specifier: ^2.9.1
157
+ version: 2.9.1
158
+
159
+ missions/site-m000001/workpiece:
160
+ dependencies:
161
+ buffer-from:
162
+ specifier: ^1.1.2
163
+ version: 1.1.2
164
+
165
+ packages:
166
+
167
+ yaml@2.9.1:
168
+ resolution: {integrity: sha1}
169
+
170
+ buffer-from@1.1.2:
171
+ resolution: {integrity: sha2}
172
+
173
+ snapshots:
174
+
175
+ yaml@2.9.1: {}
176
+
177
+ buffer-from@1.1.2: {}
178
+ `;
179
+
180
+ const DIFF_PRUNE = `diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
181
+ index ccc..ddd 100644
182
+ --- a/pnpm-lock.yaml
183
+ +++ b/pnpm-lock.yaml
184
+ @@ -9,7 +9,4 @@ importers:
185
+ specifier: ^2.9.1
186
+ version: 2.9.1
187
+
188
+ - missions/site-m000001/workpiece:
189
+ - dependencies:
190
+ - buffer-from:
191
+ - specifier: ^1.1.2
192
+ - version: 1.1.2
193
+
194
+ packages:
195
+ @@ -25,6 +22,13 @@ snapshots:
196
+
197
+ yaml@2.9.1: {}
198
+
199
+ - buffer-from@1.1.2: {}
200
+ + buffer-from@1.1.2:
201
+ + optional: true
202
+ +
203
+ + buffer-crc32@0.2.13:
204
+ + dependencies:
205
+ + x: 1.0.0
206
+ + transitivePeerDependencies:
207
+ + - prettier
208
+ + optional: true
209
+
210
+ `;
211
+
212
+ const DIFF_VERSION_BUMP = `diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
213
+ index eee..fff 100644
214
+ --- a/pnpm-lock.yaml
215
+ +++ b/pnpm-lock.yaml
216
+ @@ -5,6 +5,11 @@ importers:
217
+ .:
218
+ dependencies:
219
+ yaml:
220
+ - specifier: ^2.9.1
221
+ - version: 2.9.1
222
+ + specifier: ^3.0.0
223
+ + version: 3.0.0
224
+ +
225
+ + missions/site-m000001/workpiece:
226
+ + dependencies:
227
+ + buffer-from:
228
+ + specifier: ^1.1.2
229
+ + version: 1.1.2
230
+ +
231
+ packages:
232
+ `;
233
+
234
+ describe("classifyLockfileMaterializeExtended — ADR-0130", () => {
235
+ it("the 9fc5be128 shape (importer add + optional removals + collapse) classifies importer-materialize", () => {
236
+ expect(
237
+ classifyLockfileMaterializeExtended(DIFF_MATERIALIZE, HEAD_MATERIALIZE, WORK_MATERIALIZE),
238
+ ).toEqual(["site-m000001"]);
239
+ });
240
+
241
+ it("an `optional: true` removal on an unreachable snapshot keeps the diff unattributed", () => {
242
+ // drop buffer-crc32 from the mission's deps — its optional removal is
243
+ // then outside the added importers' closure.
244
+ const narrowed = WORK_MATERIALIZE.replace(
245
+ ` buffer-crc32:
246
+ specifier: ^0.2.13
247
+ version: 0.2.13
248
+ `,
249
+ "",
250
+ );
251
+ expect(
252
+ classifyLockfileMaterializeExtended(DIFF_MATERIALIZE, HEAD_MATERIALIZE, narrowed),
253
+ ).toBeNull();
254
+ });
255
+ });
256
+
257
+ describe("classifyLockfilePruneIdsExtended — ADR-0130", () => {
258
+ it("the 391abcfaf shape (importer prune + induced additions) returns the pruned ids", () => {
259
+ expect(classifyLockfilePruneIdsExtended(DIFF_PRUNE, HEAD_PRUNE)).toEqual(["site-m000001"]);
260
+ });
261
+
262
+ it("a version-string change inside the diff keeps the diff unattributed", () => {
263
+ expect(classifyLockfilePruneIdsExtended(DIFF_VERSION_BUMP, HEAD_MATERIALIZE)).toBeNull();
264
+ expect(
265
+ classifyLockfileMaterializeExtended(DIFF_VERSION_BUMP, HEAD_MATERIALIZE, WORK_MATERIALIZE),
266
+ ).toBeNull();
267
+ });
268
+ });
269
+
270
+ describe("classifyDirt — induced shapes (ADR-0130)", () => {
271
+ it("the 391abcfaf shape against a foreign open mission classifies foreign-open-mission (restored, not swept)", async () => {
272
+ const { classifyDirt } = await import("../preflight.ts");
273
+ const repo = await mkdtemp(join(tmpdir(), "dirt-"));
274
+ dirs.push(repo);
275
+ // classifyDirt reads the working lockfile through io — content is
276
+ // irrelevant for the prune direction (only HEAD text + diff are used).
277
+ await writeFile(join(repo, "pnpm-lock.yaml"), HEAD_PRUNE);
278
+ const runGit = async (_cwd: string, _io: unknown, args: string[]) => {
279
+ const joined = args.join(" ");
280
+ if (joined.includes("diff")) return { exitCode: 0, stdout: DIFF_PRUNE, stderr: "" };
281
+ if (joined.includes("show")) return { exitCode: 0, stdout: HEAD_PRUNE, stderr: "" };
282
+ return { exitCode: 0, stdout: "", stderr: "" };
283
+ };
284
+ const verdict = await classifyDirt(
285
+ repo,
286
+ ambientIo,
287
+ [" M pnpm-lock.yaml"],
288
+ { runGit: runGit as never },
289
+ [],
290
+ async (ids) =>
291
+ ids.map((missionId) => ({
292
+ missionId,
293
+ existsHere: false,
294
+ existsInCheckout: ["/repo@auto/foreign"],
295
+ missionOpen: true,
296
+ })),
297
+ );
298
+ expect(verdict.tolerated).toEqual([
299
+ {
300
+ path: "pnpm-lock.yaml",
301
+ class: "foreign-open-mission",
302
+ missionIds: ["site-m000001"],
303
+ },
304
+ ]);
305
+ expect(verdict.unattributed).toEqual([]);
306
+ });
307
+
308
+ it("the 9fc5be128 shape with an open mission classifies importer-materialize", async () => {
309
+ const { classifyDirt } = await import("../preflight.ts");
310
+ const repo = await mkdtemp(join(tmpdir(), "dirt-"));
311
+ dirs.push(repo);
312
+ await writeFile(join(repo, "pnpm-lock.yaml"), WORK_MATERIALIZE);
313
+ // the mission must read as open — openMissionsIn globs missions/*/mission.yaml
314
+ await mkdir(join(repo, "missions/site-m000001"), { recursive: true });
315
+ await writeFile(join(repo, "missions/site-m000001/mission.yaml"), 'state: "open"\n');
316
+ const runGit = async (_cwd: string, _io: unknown, args: string[]) => {
317
+ const joined = args.join(" ");
318
+ if (joined.includes("diff")) return { exitCode: 0, stdout: DIFF_MATERIALIZE, stderr: "" };
319
+ if (joined.includes("show")) return { exitCode: 0, stdout: HEAD_MATERIALIZE, stderr: "" };
320
+ return { exitCode: 0, stdout: "", stderr: "" };
321
+ };
322
+ const verdict = await classifyDirt(repo, ambientIo, [" M pnpm-lock.yaml"], {
323
+ runGit: runGit as never,
324
+ });
325
+ expect(verdict.tolerated).toEqual([{ path: "pnpm-lock.yaml", class: "importer-materialize" }]);
326
+ expect(verdict.unattributed).toEqual([]);
327
+ });
328
+ });
@@ -0,0 +1,136 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>ops-registry tests (RFC-1543 AC-2/AC-5): claim write lands under the
4
+ shared git dir, liveness requires pid-alive ∧ bootId-match ∧ fresh heartbeat,
5
+ dead records are swept by the next reader, and claimCoversPath honors the
6
+ exact/prefix contract.</purpose>
7
+ <non-goals>
8
+ <item>No classifyDirt coverage — claim→class wiring lives in dirty-classify.test.ts.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1543: op-claim registry probes</item>
13
+ <item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+
17
+ import { rm, writeFile, mkdir } from "node:fs/promises";
18
+ import { join } from "node:path";
19
+ import { afterEach, describe, expect, it } from "vitest";
20
+
21
+ import { ambientIo } from "../../../src/utils/io.ts";
22
+ import {
23
+ claimCoversPath,
24
+ claimOp,
25
+ isClaimLive,
26
+ liveClaims,
27
+ OP_CLAIM_SCHEMA,
28
+ releaseOp,
29
+ } from "../ops-registry.ts";
30
+ import { initRepo } from "./helpers.ts";
31
+
32
+ const dirs: string[] = [];
33
+ afterEach(async () => {
34
+ for (const dir of dirs.splice(0)) {
35
+ await rm(dir, { recursive: true, force: true });
36
+ }
37
+ });
38
+
39
+ async function repo(): Promise<string> {
40
+ const dir = await initRepo({ prefix: "ops-reg-" });
41
+ dirs.push(dir);
42
+ return dir;
43
+ }
44
+
45
+ async function opsDir(repo: string): Promise<string> {
46
+ return join(repo, ".git", "forge", "ops");
47
+ }
48
+
49
+ describe("ops-registry — claim lifecycle (RFC-1543 AC-2)", () => {
50
+ it("claimOp writes a forge/op-claim@1 record the reader reports live", async () => {
51
+ const r = await repo();
52
+ const ok = await claimOp(r, ambientIo, {
53
+ opId: "op-1",
54
+ command: "leitstand.ship",
55
+ workspaceRoot: r,
56
+ paths: ["docs/", "pnpm-lock.yaml"],
57
+ });
58
+ expect(ok).toBe(true);
59
+
60
+ const live = await liveClaims(r, ambientIo);
61
+ expect(live).toHaveLength(1);
62
+ expect(live[0]?.schema).toBe(OP_CLAIM_SCHEMA);
63
+ expect(live[0]?.pid).toBe(process.pid);
64
+ expect(live[0]?.paths).toEqual(["docs/", "pnpm-lock.yaml"]);
65
+ expect(live[0]?.bootId).toBeDefined();
66
+ });
67
+
68
+ it("releaseOp removes the record; a dead pid is swept on read", async () => {
69
+ const r = await repo();
70
+ await claimOp(r, ambientIo, {
71
+ opId: "op-2",
72
+ command: "ecosystem.commit",
73
+ workspaceRoot: r,
74
+ paths: ["docs/"],
75
+ });
76
+ await releaseOp(r, ambientIo, "op-2");
77
+ expect(await liveClaims(r, ambientIo)).toEqual([]);
78
+
79
+ // Hand-write a claim on a pid that cannot be alive.
80
+ const ops = await opsDir(r);
81
+ await mkdir(ops, { recursive: true });
82
+ await writeFile(
83
+ join(ops, "zombie.yaml"),
84
+ [
85
+ `schema: ${OP_CLAIM_SCHEMA}`,
86
+ "opId: zombie",
87
+ "command: mission.git.commit",
88
+ "pid: 999999999",
89
+ `host: ${(await import("node:os")).hostname()}`,
90
+ "startedAt: 2026-11-09T00:00:00Z",
91
+ "heartbeatAt: 2026-11-09T00:00:00Z",
92
+ `workspaceRoot: ${r}`,
93
+ "paths: [docs/]",
94
+ ].join("\n"),
95
+ );
96
+ expect(await liveClaims(r, ambientIo)).toEqual([]);
97
+ // Dead record was swept, not just filtered.
98
+ expect(await ambientIo.exists(join(ops, "zombie.yaml"))).toBe(false);
99
+ });
100
+
101
+ it("an expired heartbeat disqualifies an otherwise-live pid", async () => {
102
+ const r = await repo();
103
+ const stale: import("../ops-registry.ts").OpClaim = {
104
+ schema: OP_CLAIM_SCHEMA,
105
+ opId: "stale-beat",
106
+ command: "x",
107
+ pid: process.pid,
108
+ host: (await import("node:os")).hostname(),
109
+ startedAt: new Date(Date.now() - 600_000).toISOString(),
110
+ heartbeatAt: new Date(Date.now() - 600_000).toISOString(),
111
+ workspaceRoot: r,
112
+ paths: ["docs/"],
113
+ };
114
+ expect(isClaimLive({ ...stale })).toBe(false);
115
+ expect(isClaimLive({ ...stale, heartbeatAt: new Date().toISOString() })).toBe(true);
116
+ });
117
+
118
+ it("claimCoversPath matches exact paths and declared prefixes only", () => {
119
+ const claim: import("../ops-registry.ts").OpClaim = {
120
+ schema: OP_CLAIM_SCHEMA,
121
+ opId: "c",
122
+ command: "x",
123
+ pid: 1,
124
+ host: "h",
125
+ startedAt: "t",
126
+ heartbeatAt: "t",
127
+ workspaceRoot: "/w",
128
+ paths: ["docs/", "pnpm-lock.yaml"],
129
+ };
130
+ expect(claimCoversPath(claim, "pnpm-lock.yaml")).toBe(true);
131
+ expect(claimCoversPath(claim, "docs/rfcs/x.md")).toBe(true);
132
+ expect(claimCoversPath(claim, "docs")).toBe(false); // a FILE named docs is not under docs/
133
+ expect(claimCoversPath(claim, "documentation/x.md")).toBe(false);
134
+ expect(claimCoversPath(claim, "src/docs/x.ts")).toBe(false);
135
+ });
136
+ });
@@ -0,0 +1,106 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1568 — detach mechanics: the parent re-spawns the same CLI
4
+ entrypoint with `--detach` stripped, stdio routed to the run's log file,
5
+ `WERKSTATT_GATE_RUN_ID` in env so the child adopts the parent's record,
6
+ then prints the pointer block and exits 0.</purpose>
7
+ <non-goals>
8
+ <item>No output mirroring — detached output lives only in the log file.</item>
9
+ <item>No waiting on the gate itself — only a ≤2 s heartbeat on the child's
10
+ first record write, so an unspawnable child surfaces before the parent
11
+ returns.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <CHANGE_SUMMARY>
15
+ <item>RFC-1568: step 3 — detachSelf with injected SpawnLike</item>
16
+ <item>RFC-1568: durable gate-run records, --detach mechanics, and forge CLI wiring</item>
17
+ </CHANGE_SUMMARY>
18
+ */
19
+
20
+ // kernel-io-lint IO-01 carve-out (RFC-1568 / DNA-105): a detached gate is the
21
+ // "genuinely long-lived child process" class the spawn carve-out exists for.
22
+ // The spawner stays injectable — unit tests never spawn real gates.
23
+ import { spawn as nodeSpawn } from "node:child_process";
24
+ import { closeSync, openSync } from "node:fs";
25
+ import { join } from "node:path";
26
+
27
+ import type { GateRunRecord, SpawnLike } from "./types.ts";
28
+ import { gateRunsDir } from "./record.ts";
29
+
30
+ export const GATE_RUN_ID_ENV = "WERKSTATT_GATE_RUN_ID";
31
+ /** How long the parent waits for the child's first record write. */
32
+ export const HEARTBEAT_WAIT_MS = 2_000;
33
+
34
+ export interface DetachResult {
35
+ pid: number;
36
+ logPath: string;
37
+ runId: string;
38
+ }
39
+
40
+ /**
41
+ * Re-spawn the current CLI detached. `entry` is process.argv[1] of the
42
+ * running host (`forge` bin or `werkstatt` bin); `argv` carries the command
43
+ * and its flags minus `--detach` — for the kernel host it MUST keep the
44
+ * leading `run` token so the child re-enters the same dispatch path.
45
+ */
46
+ export async function detachSelf(input: {
47
+ entry: string;
48
+ argv: string[];
49
+ record: GateRunRecord;
50
+ commonGitDir: string;
51
+ spawn?: SpawnLike;
52
+ /** Reads the record back for the heartbeat — injected in tests. */
53
+ recordExists?: (runId: string) => Promise<boolean>;
54
+ }): Promise<DetachResult> {
55
+ const doSpawn: SpawnLike = input.spawn ?? (nodeSpawn as unknown as SpawnLike);
56
+ const logPath = join(gateRunsDir(input.commonGitDir), `${input.record.runId}.log`);
57
+ const logFd = openSync(logPath, "a");
58
+ try {
59
+ // process.execArgv forwards the host's loader flags (--import tsx, …) —
60
+ // a bare `node entry.ts` dies with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX.
61
+ const child = doSpawn(process.execPath, [...process.execArgv, input.entry, ...input.argv], {
62
+ detached: true,
63
+ stdio: ["ignore", logFd, logFd],
64
+ env: { ...process.env, [GATE_RUN_ID_ENV]: input.record.runId },
65
+ });
66
+ child.unref();
67
+ const pid = child.pid;
68
+ if (pid === undefined) {
69
+ throw new Error("spawn returned no pid");
70
+ }
71
+
72
+ // ≤2 s heartbeat — the child adopts the record by rewriting it with its
73
+ // own pid; if that write never lands the parent reports the spawn
74
+ // failure instead of leaving an untrackable process.
75
+ if (input.recordExists !== undefined) {
76
+ const deadline = Date.now() + HEARTBEAT_WAIT_MS;
77
+ while (Date.now() < deadline) {
78
+ if (await input.recordExists(input.record.runId)) break;
79
+ await new Promise((r) => setTimeout(r, 50));
80
+ }
81
+ }
82
+ return { pid, logPath, runId: input.record.runId };
83
+ } finally {
84
+ try {
85
+ closeSync(logFd);
86
+ } catch {
87
+ // fd already closed — nothing to do
88
+ }
89
+ }
90
+ }
91
+
92
+ /** Pretty pointer block printed by the parent before exiting. */
93
+ export function detachPointerLines(
94
+ result: DetachResult,
95
+ commonGitDir: string,
96
+ statusCommand: string,
97
+ ): string[] {
98
+ const relLog = result.logPath.startsWith(commonGitDir)
99
+ ? `.git/${result.logPath.slice(commonGitDir.length + 1)}`
100
+ : result.logPath;
101
+ return [
102
+ `[gate-run] started ${result.runId} (pid ${result.pid})`,
103
+ ` log: ${relLog}`,
104
+ ` status: ${statusCommand} --id ${result.runId}`,
105
+ ];
106
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1568 — forge module registration for `gate.run.status`. A forge
4
+ module so both hosts (standalone `forge` CLI + `werkstatt run` kernel) see
5
+ the command through their existing forge-module loading.</purpose>
6
+ </MODULE_CONTRACT>
7
+ <CHANGE_SUMMARY>
8
+ <item>RFC-1568: step 4 — gate-run module</item>
9
+ <item>RFC-1568: durable gate-run records, --detach mechanics, and forge CLI wiring</item>
10
+ </CHANGE_SUMMARY>
11
+ */
12
+
13
+ import type { ForgeModule } from "../../src/forge-module.ts";
14
+
15
+ export async function createForgeGateRunModule(): Promise<ForgeModule> {
16
+ const { gateRunStatusCommand } = await import("./status.ts");
17
+ return {
18
+ name: "forge-gate-run",
19
+ version: "0.1.0",
20
+ runtime: "autonomous",
21
+ declarations: [],
22
+ commands: [gateRunStatusCommand],
23
+ pipelines: [],
24
+ };
25
+ }
@@ -0,0 +1,16 @@
1
+ export { createForgeGateRunModule } from "./gate-run.module.ts";
2
+ export {
3
+ GATE_RUN_RETENTION,
4
+ GATE_RUNS_DIR,
5
+ classifyGateRun,
6
+ finishGateRun,
7
+ gateRunsDir,
8
+ listGateRuns,
9
+ repoRelativeCwd,
10
+ saveGateRun,
11
+ startGateRun,
12
+ } from "./record.ts";
13
+ export { GATE_RUN_ID_ENV, HEARTBEAT_WAIT_MS, detachPointerLines, detachSelf } from "./detach.ts";
14
+ export type { DetachResult } from "./detach.ts";
15
+ export { GATE_RUN_RULES, GATE_RUN_SCHEMA } from "./types.ts";
16
+ export type { GateRunRecord, GateRunStatus, SpawnLike, SpawnLikeChild } from "./types.ts";