@warpgogol/forge 9.2.3 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/bin/cli.ts +3 -2
  3. package/dist/bin/cli.js +3 -2
  4. package/dist/bin/cli.js.map +1 -1
  5. package/dist/os/adr/handlers/implement-stamp.d.ts +6 -0
  6. package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
  7. package/dist/os/adr/handlers/implement-stamp.js +23 -15
  8. package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
  9. package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -1
  10. package/dist/os/checks/handlers/counters-journal.js +9 -1
  11. package/dist/os/checks/handlers/counters-journal.js.map +1 -1
  12. package/dist/os/core/core.module.d.ts.map +1 -1
  13. package/dist/os/core/core.module.js +27 -36
  14. package/dist/os/core/core.module.js.map +1 -1
  15. package/dist/os/core/lock-holder.d.ts +32 -0
  16. package/dist/os/core/lock-holder.d.ts.map +1 -0
  17. package/dist/os/core/lock-holder.js +81 -0
  18. package/dist/os/core/lock-holder.js.map +1 -0
  19. package/dist/os/core/stamp-lock.d.ts +30 -0
  20. package/dist/os/core/stamp-lock.d.ts.map +1 -0
  21. package/dist/os/core/stamp-lock.js +112 -0
  22. package/dist/os/core/stamp-lock.js.map +1 -0
  23. package/dist/os/flow/digest.d.ts +19 -0
  24. package/dist/os/flow/digest.d.ts.map +1 -1
  25. package/dist/os/flow/digest.js +33 -4
  26. package/dist/os/flow/digest.js.map +1 -1
  27. package/dist/os/flow/flow.module.d.ts.map +1 -1
  28. package/dist/os/flow/flow.module.js +61 -6
  29. package/dist/os/flow/flow.module.js.map +1 -1
  30. package/dist/os/flow/handlers/flow-cut.d.ts +8 -0
  31. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  32. package/dist/os/flow/handlers/flow-cut.js +91 -5
  33. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  34. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  35. package/dist/os/flow/handlers/flow-digest.js +6 -0
  36. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  37. package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
  38. package/dist/os/flow/handlers/flow-discard.js +17 -13
  39. package/dist/os/flow/handlers/flow-discard.js.map +1 -1
  40. package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
  41. package/dist/os/flow/handlers/flow-fix.js +99 -10
  42. package/dist/os/flow/handlers/flow-fix.js.map +1 -1
  43. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  44. package/dist/os/flow/handlers/flow-integrate.js +32 -15
  45. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  46. package/dist/os/flow/handlers/flow-publication-retire.d.ts +17 -0
  47. package/dist/os/flow/handlers/flow-publication-retire.d.ts.map +1 -0
  48. package/dist/os/flow/handlers/flow-publication-retire.js +132 -0
  49. package/dist/os/flow/handlers/flow-publication-retire.js.map +1 -0
  50. package/dist/os/flow/handlers/flow-push.d.ts +7 -0
  51. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
  52. package/dist/os/flow/handlers/flow-push.js +106 -15
  53. package/dist/os/flow/handlers/flow-push.js.map +1 -1
  54. package/dist/os/flow/locks.d.ts +6 -1
  55. package/dist/os/flow/locks.d.ts.map +1 -1
  56. package/dist/os/flow/locks.js +53 -23
  57. package/dist/os/flow/locks.js.map +1 -1
  58. package/dist/os/flow/publication-order.d.ts +25 -0
  59. package/dist/os/flow/publication-order.d.ts.map +1 -0
  60. package/dist/os/flow/publication-order.js +75 -0
  61. package/dist/os/flow/publication-order.js.map +1 -0
  62. package/dist/os/flow/publish.d.ts +18 -0
  63. package/dist/os/flow/publish.d.ts.map +1 -1
  64. package/dist/os/flow/publish.js +58 -2
  65. package/dist/os/flow/publish.js.map +1 -1
  66. package/dist/os/flow/registry.d.ts +1 -1
  67. package/dist/os/flow/registry.d.ts.map +1 -1
  68. package/dist/os/flow/registry.js +2 -1
  69. package/dist/os/flow/registry.js.map +1 -1
  70. package/dist/os/flow/release-tags.d.ts +1 -0
  71. package/dist/os/flow/release-tags.d.ts.map +1 -1
  72. package/dist/os/flow/release-tags.js +5 -4
  73. package/dist/os/flow/release-tags.js.map +1 -1
  74. package/dist/os/flow/scripts.d.ts +1 -1
  75. package/dist/os/flow/scripts.d.ts.map +1 -1
  76. package/dist/os/flow/scripts.js +6 -1
  77. package/dist/os/flow/scripts.js.map +1 -1
  78. package/dist/os/flow/task-files.d.ts +11 -0
  79. package/dist/os/flow/task-files.d.ts.map +1 -0
  80. package/dist/os/flow/task-files.js +51 -0
  81. package/dist/os/flow/task-files.js.map +1 -0
  82. package/dist/os/flow/tests/helpers.d.ts +4 -1
  83. package/dist/os/flow/tests/helpers.d.ts.map +1 -1
  84. package/dist/os/flow/tests/helpers.js +9 -5
  85. package/dist/os/flow/tests/helpers.js.map +1 -1
  86. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  87. package/dist/os/mission/handlers/archive.js +30 -74
  88. package/dist/os/mission/handlers/archive.js.map +1 -1
  89. package/dist/os/mission/lockfile.d.ts +21 -0
  90. package/dist/os/mission/lockfile.d.ts.map +1 -0
  91. package/dist/os/mission/lockfile.js +76 -0
  92. package/dist/os/mission/lockfile.js.map +1 -0
  93. package/dist/os/mission/mission.module.d.ts.map +1 -1
  94. package/dist/os/mission/mission.module.js +2 -1
  95. package/dist/os/mission/mission.module.js.map +1 -1
  96. package/dist/os/rfc/handlers/implement-stamp.d.ts +6 -0
  97. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  98. package/dist/os/rfc/handlers/implement-stamp.js +24 -19
  99. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  100. package/dist/os/system/handlers/outbox-validate.d.ts +8 -0
  101. package/dist/os/system/handlers/outbox-validate.d.ts.map +1 -0
  102. package/dist/os/system/handlers/outbox-validate.js +102 -0
  103. package/dist/os/system/handlers/outbox-validate.js.map +1 -0
  104. package/dist/os/system/handlers/system-map-validate.d.ts +13 -0
  105. package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -0
  106. package/dist/os/system/handlers/system-map-validate.js +78 -0
  107. package/dist/os/system/handlers/system-map-validate.js.map +1 -0
  108. package/dist/os/system/handlers/system-outbox-scan.d.ts +10 -0
  109. package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -0
  110. package/dist/os/system/handlers/system-outbox-scan.js +195 -0
  111. package/dist/os/system/handlers/system-outbox-scan.js.map +1 -0
  112. package/dist/os/system/handlers/system-task-collect.d.ts +13 -0
  113. package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -0
  114. package/dist/os/system/handlers/system-task-collect.js +238 -0
  115. package/dist/os/system/handlers/system-task-collect.js.map +1 -0
  116. package/dist/os/system/handlers/system-task-create.d.ts +32 -0
  117. package/dist/os/system/handlers/system-task-create.d.ts.map +1 -0
  118. package/dist/os/system/handlers/system-task-create.js +216 -0
  119. package/dist/os/system/handlers/system-task-create.js.map +1 -0
  120. package/dist/os/system/handlers/system-task-dispatch.d.ts +14 -0
  121. package/dist/os/system/handlers/system-task-dispatch.d.ts.map +1 -0
  122. package/dist/os/system/handlers/system-task-dispatch.js +290 -0
  123. package/dist/os/system/handlers/system-task-dispatch.js.map +1 -0
  124. package/dist/os/system/handlers/system-task-move.d.ts +12 -0
  125. package/dist/os/system/handlers/system-task-move.d.ts.map +1 -0
  126. package/dist/os/system/handlers/system-task-move.js +217 -0
  127. package/dist/os/system/handlers/system-task-move.js.map +1 -0
  128. package/dist/os/system/handlers/system-task-status.d.ts +20 -0
  129. package/dist/os/system/handlers/system-task-status.d.ts.map +1 -0
  130. package/dist/os/system/handlers/system-task-status.js +139 -0
  131. package/dist/os/system/handlers/system-task-status.js.map +1 -0
  132. package/dist/os/system/handlers/system-versionset-record.d.ts +12 -0
  133. package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -0
  134. package/dist/os/system/handlers/system-versionset-record.js +332 -0
  135. package/dist/os/system/handlers/system-versionset-record.js.map +1 -0
  136. package/dist/os/system/index.d.ts +6 -0
  137. package/dist/os/system/index.d.ts.map +1 -0
  138. package/dist/os/system/index.js +18 -0
  139. package/dist/os/system/index.js.map +1 -0
  140. package/dist/os/system/outbox-schema.d.ts +30 -0
  141. package/dist/os/system/outbox-schema.d.ts.map +1 -0
  142. package/dist/os/system/outbox-schema.js +29 -0
  143. package/dist/os/system/outbox-schema.js.map +1 -0
  144. package/dist/os/system/repo.d.ts +64 -0
  145. package/dist/os/system/repo.d.ts.map +1 -0
  146. package/dist/os/system/repo.js +364 -0
  147. package/dist/os/system/repo.js.map +1 -0
  148. package/dist/os/system/scenario-schemas.d.ts +26 -0
  149. package/dist/os/system/scenario-schemas.d.ts.map +1 -0
  150. package/dist/os/system/scenario-schemas.js +53 -0
  151. package/dist/os/system/scenario-schemas.js.map +1 -0
  152. package/dist/os/system/schemas.d.ts +63 -0
  153. package/dist/os/system/schemas.d.ts.map +1 -0
  154. package/dist/os/system/schemas.js +83 -0
  155. package/dist/os/system/schemas.js.map +1 -0
  156. package/dist/os/system/system.module.d.ts +3 -0
  157. package/dist/os/system/system.module.d.ts.map +1 -0
  158. package/dist/os/system/system.module.js +429 -0
  159. package/dist/os/system/system.module.js.map +1 -0
  160. package/dist/os/system/task-schemas.d.ts +108 -0
  161. package/dist/os/system/task-schemas.d.ts.map +1 -0
  162. package/dist/os/system/task-schemas.js +152 -0
  163. package/dist/os/system/task-schemas.js.map +1 -0
  164. package/dist/os/system/task-store.d.ts +41 -0
  165. package/dist/os/system/task-store.d.ts.map +1 -0
  166. package/dist/os/system/task-store.js +142 -0
  167. package/dist/os/system/task-store.js.map +1 -0
  168. package/dist/os/system/tests/helpers.d.ts +30 -0
  169. package/dist/os/system/tests/helpers.d.ts.map +1 -0
  170. package/dist/os/system/tests/helpers.js +178 -0
  171. package/dist/os/system/tests/helpers.js.map +1 -0
  172. package/dist/src/index.d.ts +3 -0
  173. package/dist/src/index.d.ts.map +1 -1
  174. package/dist/src/index.js +5 -4
  175. package/dist/src/index.js.map +1 -1
  176. package/os/adr/handlers/implement-stamp-lock.test.ts +90 -0
  177. package/os/adr/handlers/implement-stamp.ts +29 -20
  178. package/os/checks/handlers/counters-journal.test.ts +10 -0
  179. package/os/checks/handlers/counters-journal.ts +8 -1
  180. package/os/core/core.module.ts +32 -36
  181. package/os/core/lock-holder.ts +88 -0
  182. package/os/core/stamp-lock.ts +142 -0
  183. package/os/flow/digest.ts +46 -4
  184. package/os/flow/flow.module.ts +62 -6
  185. package/os/flow/handlers/flow-cut.ts +118 -5
  186. package/os/flow/handlers/flow-digest.ts +6 -0
  187. package/os/flow/handlers/flow-discard.ts +22 -13
  188. package/os/flow/handlers/flow-fix.ts +116 -10
  189. package/os/flow/handlers/flow-integrate.ts +31 -15
  190. package/os/flow/handlers/flow-publication-retire.ts +156 -0
  191. package/os/flow/handlers/flow-push.ts +128 -13
  192. package/os/flow/locks.ts +75 -25
  193. package/os/flow/publication-order.ts +99 -0
  194. package/os/flow/publish.ts +73 -2
  195. package/os/flow/registry.ts +5 -2
  196. package/os/flow/release-tags.ts +5 -4
  197. package/os/flow/scripts.ts +12 -5
  198. package/os/flow/task-files.ts +59 -0
  199. package/os/flow/tests/flow-cut-prepare.test.ts +298 -0
  200. package/os/flow/tests/flow-cut.test.ts +5 -1
  201. package/os/flow/tests/flow-publication-retire.test.ts +191 -0
  202. package/os/flow/tests/flow-push-supersede.test.ts +221 -0
  203. package/os/flow/tests/flow-task-files.test.ts +59 -0
  204. package/os/flow/tests/helpers.ts +9 -5
  205. package/os/flow/tests/locks.test.ts +219 -0
  206. package/os/flow/tests/publication-order.test.ts +102 -0
  207. package/os/flow/tests/scripts.test.ts +13 -0
  208. package/os/mission/handlers/archive.test.ts +97 -52
  209. package/os/mission/handlers/archive.ts +31 -76
  210. package/os/mission/lockfile.ts +84 -0
  211. package/os/mission/mission.module.ts +2 -1
  212. package/os/rfc/handlers/implement-stamp-lock.test.ts +133 -0
  213. package/os/rfc/handlers/implement-stamp.ts +30 -24
  214. package/os/system/handlers/outbox-validate.ts +120 -0
  215. package/os/system/handlers/system-map-validate.ts +107 -0
  216. package/os/system/handlers/system-outbox-scan.ts +320 -0
  217. package/os/system/handlers/system-task-collect.ts +305 -0
  218. package/os/system/handlers/system-task-create.ts +271 -0
  219. package/os/system/handlers/system-task-dispatch.ts +387 -0
  220. package/os/system/handlers/system-task-move.ts +353 -0
  221. package/os/system/handlers/system-task-status.ts +176 -0
  222. package/os/system/handlers/system-versionset-record.ts +476 -0
  223. package/os/system/index.ts +47 -0
  224. package/os/system/outbox-schema.ts +47 -0
  225. package/os/system/repo.ts +451 -0
  226. package/os/system/scenario-schemas.ts +62 -0
  227. package/os/system/schemas.ts +102 -0
  228. package/os/system/system.module.ts +449 -0
  229. package/os/system/task-schemas.ts +190 -0
  230. package/os/system/task-store.ts +184 -0
  231. package/os/system/tests/helpers.ts +189 -0
  232. package/os/system/tests/outbox-validate.test.ts +92 -0
  233. package/os/system/tests/system-map-validate.test.ts +321 -0
  234. package/os/system/tests/system-outbox-scan.test.ts +273 -0
  235. package/os/system/tests/system-profile.test.ts +90 -0
  236. package/os/system/tests/system-task-collect.test.ts +293 -0
  237. package/os/system/tests/system-task-dispatch.test.ts +279 -0
  238. package/os/system/tests/system-task-status.test.ts +153 -0
  239. package/os/system/tests/system-task.test.ts +330 -0
  240. package/os/system/tests/system-versionset.test.ts +314 -0
  241. package/package.json +33 -1
  242. package/profiles/forge-shell.yaml +1 -2
  243. package/profiles/knowledge.yaml +1 -1
  244. package/profiles/system.yaml +650 -0
  245. package/profiles/typescript.yaml +0 -1
  246. package/skills/fo/fo-outbox/SKILL.md +71 -0
  247. package/skills/fo/fo-system-dispatch/SKILL.md +65 -0
  248. package/skills/fo/fo-task-run/SKILL.md +75 -0
  249. package/src/index.ts +11 -4
  250. package/src/tests/fixtures/agents-generate-business-before.txt +6 -0
  251. package/src/tests/profile-flow-hooks.test.ts +15 -0
  252. package/src/tests/profile-schema.test.ts +2 -1
@@ -18,6 +18,7 @@ the branch worktree and the declared FLOW_* environment.</purpose>
18
18
  <item>RFC-1487: step 2 — primary-side hook-script runner</item>
19
19
  <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
20
20
  <item>RFC-1491: step 5 — flow.push atomic outbound path + extract publication</item>
21
+ <item>RFC-1502: step 2 — release-prepare hook name</item>
21
22
  </CHANGE_SUMMARY>
22
23
  */
23
24
 
@@ -29,6 +30,7 @@ export type FlowScriptName =
29
30
  | "worktree-setup"
30
31
  | "integration-gate"
31
32
  | "worktree-teardown"
33
+ | "release-prepare"
32
34
  | "release-fingerprints"
33
35
  | "extract-verify";
34
36
 
@@ -58,11 +60,16 @@ export async function runFlowScript(
58
60
  return { status: "skipped", exitCode: null, stderrTail: "", stdout: "" };
59
61
  }
60
62
  const result = await io.exec("sh", [scriptPath], { cwd: opts.cwd, env: opts.env });
61
- const tail = result.stderr
62
- .split("\n")
63
- .filter((line) => line.length > 0)
64
- .slice(-STDERR_TAIL_LINES)
65
- .join("\n");
63
+ // A failing hook may report only on stdout (forge commands do); an empty tail
64
+ // would leave the refusal without a reason.
65
+ const tailOf = (text: string): string =>
66
+ text
67
+ .split("\n")
68
+ .filter((line) => line.length > 0)
69
+ .slice(-STDERR_TAIL_LINES)
70
+ .join("\n");
71
+ const stderrTail = tailOf(result.stderr);
72
+ const tail = stderrTail === "" && result.exitCode !== 0 ? tailOf(result.stdout) : stderrTail;
66
73
  const stdout =
67
74
  result.stdout.length > STDOUT_CAP
68
75
  ? `${result.stdout.slice(0, STDOUT_CAP)}…[truncated]`
@@ -0,0 +1,59 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Preserve a task worktree's .forge/task/ payload into the common git
4
+ dir before flow.integrate / flow.discard removes the worktree (RFC-1509
5
+ Q-15/Q-16). The task report then survives teardown — system.task.collect
6
+ reads it from &lt;common&gt;/forge/tasks/&lt;owner id&gt;/ once the worktree
7
+ is gone. Copies are idempotent (same owner id re-copies over).</purpose>
8
+ <non-goals>
9
+ <item>No report validation — collect owns forge/task-report@1 checks.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1509: step 4 — preserve .forge/task/ under the common git dir</item>
14
+ <item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
15
+ <item>RFC-1509: close RFC-1509 review r1 findings — mark-failed escape, open-error refusal, dry-run coverage</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ import { join } from "node:path";
20
+
21
+ import type { WorkspaceIO } from "../../src/types.ts";
22
+
23
+ /** Directory inside a task worktree that carries brief/report payloads. */
24
+ export const TASK_FILES_DIR = ".forge/task";
25
+
26
+ async function copyTree(src: string, dst: string, io: WorkspaceIO, into: string[]): Promise<void> {
27
+ for (const entry of await io.readdir(src)) {
28
+ const s = join(src, entry.name);
29
+ const d = join(dst, entry.name);
30
+ if (entry.isDirectory) {
31
+ await io.mkdir(d);
32
+ await copyTree(s, d, io, into);
33
+ } else if (entry.isFile) {
34
+ await io.copyFile(s, d);
35
+ into.push(d);
36
+ }
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Copy `<worktree>/.forge/task/` to `<commonGitDir>/forge/tasks/<ownerId>/`
42
+ * (recursive — subdirectories are preserved). Returns the copied file paths;
43
+ * an absent source directory is a no-op — a task branch is allowed to end
44
+ * without a report (collect then reports SYSTEM-TASK-07).
45
+ */
46
+ export async function preserveTaskFiles(
47
+ commonGitDir: string,
48
+ worktree: string,
49
+ ownerId: string,
50
+ io: WorkspaceIO,
51
+ ): Promise<string[]> {
52
+ const src = join(worktree, TASK_FILES_DIR);
53
+ if (!(await io.exists(src))) return [];
54
+ const dst = join(commonGitDir, "forge", "tasks", ownerId);
55
+ await io.mkdir(dst);
56
+ const copied: string[] = [];
57
+ await copyTree(src, dst, io, copied);
58
+ return copied;
59
+ }
@@ -0,0 +1,298 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.cut release-prepare hook + pre-tag extract verification tests
4
+ (RFC-1502, AC-1..6, AC-9, AC-10): a hooks/release-prepare.sh that edits a
5
+ tracked file folds into the release commit (ordinary and fix), a failing
6
+ hook refuses FLOW-CUT-12 with the release branch removed, untracked hook
7
+ output stays out of the commit as a FLOW-CUT-14 warning, a named package
8
+ line extracts at the release commit into a scratch (never the configured
9
+ destination) and a failing extract-verify refuses FLOW-CUT-13 leaving
10
+ develop and the tags untouched, --dry-run lists the steps, and a refused
11
+ fix cut rolls the fix branch back to its pre-release tip so the cut is
12
+ rerun-safe.</purpose>
13
+ <non-goals>
14
+ <item>Never touches the enclosing repository — all fixtures are mkdtemp
15
+ repos with their own hooks/ and a fake node_modules/.bin/repo-extract
16
+ honoring --dest.</item>
17
+ </non-goals>
18
+ </MODULE_CONTRACT>
19
+ <KEY_DECISIONS>
20
+ <item>Hooks are written untracked into the primary's hooks/ — runFlowScript reads the primary's copy, so no adoption commit is needed for them.</item>
21
+ <item>Extract failure is injected via a .fail-extract marker the fake checks in $PWD (cwd = primary); verify failure via hooks/extract-verify.sh exiting non-zero.</item>
22
+ </KEY_DECISIONS>
23
+ <CHANGE_SUMMARY>
24
+ <item>RFC-1502: step 1 — release-prepare + pre-tag verify tests</item>
25
+ <item>RFC-1502: steps 1-5 — release-prepare hook, pre-tag extract verification, ordered steps</item>
26
+ <item>RFC-1502: review r1 — fix-cut rollback on FLOW-CUT-12/13, populated steps[], hook validation, GIT_* env scrub</item>
27
+ </CHANGE_SUMMARY>
28
+ */
29
+
30
+ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
31
+ import { tmpdir } from "node:os";
32
+ import { join } from "node:path";
33
+ import { existsSync } from "node:fs";
34
+
35
+ import { afterEach, describe, expect, it } from "vitest";
36
+
37
+ import { ambientIo } from "../../../src/utils/io.ts";
38
+ import { gitExec, initRepo, installFakeRepoExtract, installGuard } from "./helpers.ts";
39
+ import { runOrdinaryCut } from "../handlers/flow-cut.ts";
40
+ import { fixFlow, runFixCut } from "../handlers/flow-fix.ts";
41
+ import { commonGitDir, readRegistry } from "../registry.ts";
42
+
43
+ const dirs: string[] = [];
44
+ afterEach(async () => {
45
+ for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true });
46
+ }, 30_000);
47
+
48
+ async function commitIn(repo: string, file: string, content: string): Promise<void> {
49
+ await writeFile(join(repo, file), content);
50
+ await gitExec(repo, ["add", file]);
51
+ const r = await gitExec(repo, ["commit", "-m", `add ${file}`]);
52
+ if (r.exitCode !== 0) throw new Error(`commit failed: ${r.stderr}`);
53
+ }
54
+
55
+ async function sha(repo: string, ref: string): Promise<string> {
56
+ return (await gitExec(repo, ["rev-parse", ref])).stdout.trim();
57
+ }
58
+
59
+ async function writeHook(repo: string, name: string, body: string): Promise<void> {
60
+ const path = join(repo, "hooks", `${name}.sh`);
61
+ await writeFile(path, body);
62
+ await chmod(path, 0o755);
63
+ }
64
+
65
+ /**
66
+ * Adopted repository: guard installed, baseline tag v0.1.0, a tracked.txt to
67
+ * modify, pending work on develop. packageLine adds packages/lib
68
+ * (extract.config.yaml + package.json v2.0.0, baseline tag lib@2.0.0).
69
+ */
70
+ async function adoptedRepo(opts?: { packageLine?: boolean }): Promise<{
71
+ repo: string;
72
+ extractLog: string;
73
+ }> {
74
+ const repo = await initRepo({ prefix: "flow-cut-prepare-" });
75
+ dirs.push(repo);
76
+ const extractLog = join(repo, "extract.log");
77
+ await writeFile(join(repo, "forge.yaml"), 'schema: "forge/workspace@1"\n');
78
+ await writeFile(join(repo, "package.json"), '{\n "name": "fixture",\n "version": "0.1.0"\n}\n');
79
+ await writeFile(join(repo, "tracked.txt"), "base\n");
80
+ if (opts?.packageLine) {
81
+ await writeFile(join(repo, "pnpm-workspace.yaml"), 'packages:\n - "packages/*"\n');
82
+ await mkdir(join(repo, "packages/lib"), { recursive: true });
83
+ await writeFile(
84
+ join(repo, "packages/lib/package.json"),
85
+ '{\n "name": "lib",\n "version": "2.0.0"\n}\n',
86
+ );
87
+ await writeFile(
88
+ join(repo, "packages/lib/extract.config.yaml"),
89
+ "schema: extract\ndestName: ac-dest\n",
90
+ );
91
+ }
92
+ await gitExec(repo, ["add", "-A"]);
93
+ await gitExec(repo, ["commit", "-m", "config"]);
94
+ await gitExec(repo, ["switch", "-c", "develop"]);
95
+ await commitIn(repo, "work.txt", "work");
96
+ if (opts?.packageLine) {
97
+ // The lib line needs a pending commit touching its paths — the cut
98
+ // refuses FLOW-CUT-04 on a line with nothing to release. Committed
99
+ // before the guard installs so the pre-guard state can carry it.
100
+ await commitIn(repo, "packages/lib/pending.txt", "lib work");
101
+ }
102
+ await installGuard(repo);
103
+ await gitExec(repo, ["add", "hooks"]);
104
+ const adopt = await gitExec(repo, ["commit", "-m", "adopt"], { FORGE_FLOW_OP: "install" });
105
+ if (adopt.exitCode !== 0) throw new Error(`adoption commit failed: ${adopt.stderr}`);
106
+ await gitExec(repo, ["tag", "-a", "v0.1.0", "main", "-m", "release v0.1.0"]);
107
+ if (opts?.packageLine) {
108
+ await gitExec(repo, ["tag", "-a", "lib@2.0.0", "main", "-m", "release lib@2.0.0"]);
109
+ }
110
+ await installFakeRepoExtract(repo, extractLog);
111
+ return { repo, extractLog };
112
+ }
113
+
114
+ describe("flow.cut — release-prepare hook and pre-tag verify (RFC-1502)", () => {
115
+ it("AC-1: a tracked change from release-prepare lands in the release commit", async () => {
116
+ const { repo } = await adoptedRepo();
117
+ await writeHook(repo, "release-prepare", "#!/bin/sh\nset -eu\necho prepared >> tracked.txt\n");
118
+
119
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: [], dryRun: false });
120
+
121
+ expect(data.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
122
+ expect(data.released).toBe(true);
123
+ const shown = await gitExec(repo, ["show", "main:tracked.txt"]);
124
+ expect(shown.stdout).toContain("prepared");
125
+ }, 30_000);
126
+
127
+ it("AC-2: a failing release-prepare refuses FLOW-CUT-12 and removes the branch", async () => {
128
+ const { repo } = await adoptedRepo();
129
+ await writeHook(repo, "release-prepare", "#!/bin/sh\necho boom >&2\nexit 2\n");
130
+ const tipBefore = await sha(repo, "develop");
131
+
132
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: [], dryRun: false });
133
+
134
+ expect(data.released).toBe(false);
135
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-CUT-12");
136
+ expect(data.diagnostics[0]?.message).toContain("boom");
137
+ expect(await sha(repo, "develop")).toBe(tipBefore);
138
+ const branches = (await gitExec(repo, ["branch", "--list", "auto/*"])).stdout.trim();
139
+ expect(branches).toBe("");
140
+ }, 30_000);
141
+
142
+ it("AC-10: an untracked file the hook leaves stays out of the commit (FLOW-CUT-14)", async () => {
143
+ const { repo } = await adoptedRepo();
144
+ await writeHook(
145
+ repo,
146
+ "release-prepare",
147
+ "#!/bin/sh\nset -eu\necho prepared >> tracked.txt\necho stray > stray-new.txt\n",
148
+ );
149
+
150
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: [], dryRun: false });
151
+
152
+ expect(data.released).toBe(true);
153
+ const warn = data.diagnostics.find((d) => d.ruleId === "FLOW-CUT-14");
154
+ expect(warn?.severity).toBe("warning");
155
+ expect(warn?.message).toContain("stray-new.txt");
156
+ const listed = await gitExec(repo, ["ls-tree", "-r", "--name-only", "main"]);
157
+ expect(listed.stdout).not.toContain("stray-new.txt");
158
+ expect(listed.stdout).toContain("tracked.txt");
159
+ }, 30_000);
160
+
161
+ it("AC-3+AC-4: a failing extract-verify refuses FLOW-CUT-13 — no tag, develop untouched", async () => {
162
+ const { repo } = await adoptedRepo({ packageLine: true });
163
+ await writeHook(repo, "extract-verify", "#!/bin/sh\necho verify-boom >&2\nexit 4\n");
164
+ const tipBefore = await sha(repo, "develop");
165
+
166
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: ["lib"], dryRun: false });
167
+
168
+ expect(data.released).toBe(false);
169
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-CUT-13");
170
+ expect(data.diagnostics[0]?.message).toContain("lib");
171
+ expect(await sha(repo, "develop")).toBe(tipBefore);
172
+ expect((await gitExec(repo, ["rev-parse", "--verify", "-q", "refs/tags/lib@2.0.1"])).exitCode).not.toBe(0);
173
+ expect((await gitExec(repo, ["rev-parse", "--verify", "-q", "refs/tags/v0.1.1"])).exitCode).not.toBe(0);
174
+ const branches = (await gitExec(repo, ["branch", "--list", "auto/*"])).stdout.trim();
175
+ expect(branches).toBe("");
176
+ }, 30_000);
177
+
178
+ it("AC-3b: a failing extract step also refuses FLOW-CUT-13", async () => {
179
+ const { repo } = await adoptedRepo({ packageLine: true });
180
+ await writeFile(join(repo, ".fail-extract"), "1");
181
+
182
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: ["lib"], dryRun: false });
183
+
184
+ expect(data.released).toBe(false);
185
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-CUT-13");
186
+ }, 30_000);
187
+
188
+ it("AC-5: the configured extract destination gains no commit — scratch only", async () => {
189
+ const { repo, extractLog } = await adoptedRepo({ packageLine: true });
190
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: ["lib"], dryRun: false });
191
+
192
+ expect(data.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
193
+ expect(data.released).toBe(true);
194
+ // The fake extract ran with --dest <scratch>, never the configured dest.
195
+ const argv = await readFile(extractLog, "utf8");
196
+ expect(argv).toContain("--dest");
197
+ expect(argv).not.toContain("ac-dest");
198
+ // The configured destination (anchored at dirname(repo)) does not exist.
199
+ const configuredDest = join(tmpdir(), "packages", "ac-dest");
200
+ expect(existsSync(configuredDest)).toBe(false);
201
+ }, 30_000);
202
+
203
+ it("AC-6: --dry-run lists release-prepare and extract-verify:<line>", async () => {
204
+ const { repo } = await adoptedRepo({ packageLine: true });
205
+ const data = await runOrdinaryCut(repo, ambientIo, { lines: ["lib"], dryRun: true });
206
+
207
+ expect(data.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
208
+ expect(data.steps).toContain("release-prepare");
209
+ expect(data.steps).toContain("extract-verify:lib");
210
+ }, 20_000);
211
+
212
+ it("AC-9: a tracked change from release-prepare lands in a fix release commit", async () => {
213
+ const { repo } = await adoptedRepo();
214
+ // First release so a fix can open on the tagged main.
215
+ const first = await runOrdinaryCut(repo, ambientIo, { lines: [], dryRun: false });
216
+ expect(first.released).toBe(true);
217
+
218
+ const fix = await fixFlow(repo, ambientIo, { slug: "fix-prepare", brief: "t", dryRun: false });
219
+ expect(fix.opened).toBe(true);
220
+ const fixBranch = fix.branch!;
221
+ const wt = fix.worktree!;
222
+ dirs.push(wt);
223
+ await commitIn(wt, "hotfix.txt", "fix");
224
+
225
+ await writeHook(repo, "release-prepare", "#!/bin/sh\nset -eu\necho fix-prepared >> tracked.txt\n");
226
+
227
+ const common = await commonGitDir(ambientIo, repo);
228
+ const entry = (await readRegistry(ambientIo, common)).branches.find((b) => b.name === fixBranch);
229
+ const data = await runFixCut(repo, ambientIo, { entry: entry!, linesGiven: false, dryRun: false });
230
+
231
+ expect(data.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
232
+ expect(data.released).toBe(true);
233
+ const shown = await gitExec(repo, ["show", "main:tracked.txt"]);
234
+ expect(shown.stdout).toContain("fix-prepared");
235
+ }, 60_000);
236
+
237
+ it("fix-mode FLOW-CUT-12 rolls the fix branch back — the cut re-runs cleanly", async () => {
238
+ const { repo } = await adoptedRepo();
239
+ const first = await runOrdinaryCut(repo, ambientIo, { lines: [], dryRun: false });
240
+ expect(first.released).toBe(true);
241
+
242
+ const fix = await fixFlow(repo, ambientIo, { slug: "fix-rollback", brief: "t", dryRun: false });
243
+ const fixBranch = fix.branch!;
244
+ const wt = fix.worktree!;
245
+ dirs.push(wt);
246
+ await commitIn(wt, "hotfix.txt", "fix");
247
+
248
+ await writeHook(repo, "release-prepare", "#!/bin/sh\necho boom >&2\nexit 2\n");
249
+ const common = await commonGitDir(ambientIo, repo);
250
+ const entry = (await readRegistry(ambientIo, common)).branches.find((b) => b.name === fixBranch);
251
+ const tipBefore = await sha(repo, fixBranch);
252
+
253
+ const failed = await runFixCut(repo, ambientIo, { entry: entry!, linesGiven: false, dryRun: false });
254
+ expect(failed.released).toBe(false);
255
+ expect(failed.diagnostics[0]?.ruleId).toBe("FLOW-CUT-12");
256
+ // Rolled back: tip unchanged, worktree clean — a re-run cannot hit
257
+ // FLOW-CUT-07 on the leftover version writes.
258
+ expect(await sha(repo, fixBranch)).toBe(tipBefore);
259
+ expect((await gitExec(wt, ["status", "--porcelain"])).stdout.trim()).toBe("");
260
+
261
+ // Re-run with a working hook — no manual recovery needed.
262
+ await writeHook(repo, "release-prepare", "#!/bin/sh\nset -eu\necho fix-prepared >> tracked.txt\n");
263
+ const retried = await runFixCut(repo, ambientIo, { entry: entry!, linesGiven: false, dryRun: false });
264
+ expect(retried.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
265
+ expect(retried.released).toBe(true);
266
+ }, 60_000);
267
+
268
+ it("fix-mode FLOW-CUT-13 removes the failed release commit — the cut re-runs cleanly", async () => {
269
+ const { repo } = await adoptedRepo({ packageLine: true });
270
+ const first = await runOrdinaryCut(repo, ambientIo, { lines: [], dryRun: false });
271
+ expect(first.released).toBe(true);
272
+
273
+ const fix = await fixFlow(repo, ambientIo, { slug: "fix-rollback13", brief: "t", dryRun: false });
274
+ const fixBranch = fix.branch!;
275
+ const wt = fix.worktree!;
276
+ dirs.push(wt);
277
+ // Touch the lib line so the fix releases it and extract-verify runs.
278
+ await commitIn(wt, "packages/lib/hotfix.txt", "fix");
279
+
280
+ await writeHook(repo, "extract-verify", "#!/bin/sh\necho verify-boom >&2\nexit 4\n");
281
+ const common = await commonGitDir(ambientIo, repo);
282
+ const entry = (await readRegistry(ambientIo, common)).branches.find((b) => b.name === fixBranch);
283
+ const tipBefore = await sha(repo, fixBranch);
284
+
285
+ const failed = await runFixCut(repo, ambientIo, { entry: entry!, linesGiven: false, dryRun: false });
286
+ expect(failed.released).toBe(false);
287
+ expect(failed.diagnostics[0]?.ruleId).toBe("FLOW-CUT-13");
288
+ // The failed chore(release) commit is gone — a re-run cannot produce an
289
+ // empty release commit (FLOW-CUT-01) or stack a duplicate.
290
+ expect(await sha(repo, fixBranch)).toBe(tipBefore);
291
+ expect((await gitExec(wt, ["status", "--porcelain"])).stdout.trim()).toBe("");
292
+
293
+ await rm(join(repo, "hooks", "extract-verify.sh"));
294
+ const retried = await runFixCut(repo, ambientIo, { entry: entry!, linesGiven: false, dryRun: false });
295
+ expect(retried.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
296
+ expect(retried.released).toBe(true);
297
+ }, 60_000);
298
+ });
@@ -20,6 +20,7 @@ resume path (AC-5: subject-named tags missing → tail re-runs).</purpose>
20
20
  <item>RFC-1490: step 4 — flow.cut happy path, refusals, and resume tests</item>
21
21
  <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
22
22
  <item>RFC-1490: independent-review pass — lock-held planning, fix-branch verification, spec-shaped data, coverage</item>
23
+ <item>RFC-1502: steps 1-5 — release-prepare hook, pre-tag extract verification, ordered steps</item>
23
24
  </CHANGE_SUMMARY>
24
25
  */
25
26
 
@@ -30,7 +31,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
30
31
 
31
32
  import { ambientIo } from "../../../src/utils/io.ts";
32
33
  import type { ForgeRuntimeContext } from "../../../src/types.ts";
33
- import { gitExec, initRepo, installGuard } from "./helpers.ts";
34
+ import { gitExec, initRepo, installFakeRepoExtract, installGuard } from "./helpers.ts";
34
35
  import { runFlowCut, runOrdinaryCut } from "../handlers/flow-cut.ts";
35
36
  import { openFlowBranch } from "../handlers/flow-open.ts";
36
37
  import { flowWorktreePath } from "../worktree-path.ts";
@@ -105,6 +106,9 @@ async function adoptedRepo(opts?: { pending?: boolean; packageLine?: boolean }):
105
106
  await gitExec(repo, ["tag", "-a", "v0.1.0", "main", "-m", "release v0.1.0"]);
106
107
  if (opts?.packageLine) {
107
108
  await gitExec(repo, ["tag", "-a", "lib@2.0.0", "main", "-m", "release lib@2.0.0"]);
109
+ // The lib line carries extract.config.yaml — RFC-1502's pre-tag verify
110
+ // runs repo-extract on it, so the fixture links the fake binary.
111
+ await installFakeRepoExtract(repo, join(repo, "extract.log"));
108
112
  }
109
113
  return repo;
110
114
  }
@@ -0,0 +1,191 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.publication.retire tests (RFC-1503, AC-6, AC-7): retiring a
4
+ pending tag appends a publish-retired journal event and removes the tag
5
+ from the digest's pending list; a tag that is not pending refuses
6
+ FLOW-RETIRE-01; an empty --reason refuses FLOW-RETIRE-02.</purpose>
7
+ <non-goals>
8
+ <item>No real repo-extract — the fixture installs node_modules/.bin/repo-extract.</item>
9
+ <item>Never touches the enclosing repository — all fixtures are mkdtemp repos.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1503: step 1 — publication-retire tests</item>
14
+ <item>RFC-1503: steps 1-5 — highest-per-line pending selection, publish-superseded/publish-retired journal events, flow.publication.retire</item>
15
+ <item>RFC-1503: review r1 — FLOW-07 on retire journal failure, journal re-read before publish, publication-order unit tests, stale catalog/inventory regen</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ import { mkdir, rm, writeFile } from "node:fs/promises";
20
+ import { join } from "node:path";
21
+
22
+ import { afterEach, describe, expect, it } from "vitest";
23
+
24
+ import { ambientIo } from "../../../src/utils/io.ts";
25
+ import { collectDigest } from "../digest.ts";
26
+ import { retirePublication } from "../handlers/flow-publication-retire.ts";
27
+ import { pushFlow } from "../handlers/flow-push.ts";
28
+ import { markerContent } from "../markers.ts";
29
+ import { releaseTagAnnotation, writeReleaseTag } from "../release-tags.ts";
30
+ import { commonGitDir, readJournal } from "../registry.ts";
31
+ import { gitExec, initRepoWithOrigin } from "./helpers.ts";
32
+
33
+ const dirs: string[] = [];
34
+ afterEach(async () => {
35
+ for (const dir of dirs.splice(0)) {
36
+ await rm(dir, { recursive: true, force: true });
37
+ }
38
+ delete process.env["FAKE_EXTRACT_FAIL"];
39
+ }, 20_000);
40
+
41
+ async function addPackageLine(repo: string): Promise<void> {
42
+ await mkdir(join(repo, "packages", "lib"), { recursive: true });
43
+ await writeFile(
44
+ join(repo, "packages", "lib", "extract.config.yaml"),
45
+ "standalone: true\ndestName: lib-export\n",
46
+ );
47
+ await writeFile(
48
+ join(repo, "packages", "lib", "package.json"),
49
+ '{\n "name": "lib",\n "version": "2.1.0"\n}\n',
50
+ );
51
+ await writeFile(join(repo, "packages", "lib", "forge.generated.yaml"), markerContent("test"));
52
+ await gitExec(repo, ["add", "-A"]);
53
+ await gitExec(repo, ["commit", "-m", "package line lib"]);
54
+ const push = await gitExec(repo, ["push", "origin", "develop"]);
55
+ if (push.exitCode !== 0) throw new Error(`push failed: ${push.stderr}`);
56
+ }
57
+
58
+ async function tag(repo: string, name: string, line: string, version: string): Promise<void> {
59
+ const tip = (await gitExec(repo, ["rev-parse", "develop"])).stdout.trim();
60
+ const res = await writeReleaseTag(repo, ambientIo, {
61
+ name,
62
+ target: tip,
63
+ annotation: releaseTagAnnotation({
64
+ tag: name,
65
+ line,
66
+ version,
67
+ level: "minor",
68
+ previous: null,
69
+ rfcs: [],
70
+ fingerprints: {},
71
+ }),
72
+ });
73
+ if (res.exitCode !== 0) throw new Error(`tag ${name} failed: ${res.stderr}`);
74
+ }
75
+
76
+ async function makePending(repo: string, name: string): Promise<void> {
77
+ await tag(repo, name, "lib", name.split("@")[1]!);
78
+ process.env["FAKE_EXTRACT_FAIL"] = "1";
79
+ const digest = await collectDigest(repo, ambientIo, { fetch: false });
80
+ await pushFlow(repo, ambientIo, { digest: digest.digestId, dryRun: false });
81
+ delete process.env["FAKE_EXTRACT_FAIL"];
82
+ }
83
+
84
+ describe("flow.publication.retire (RFC-1503)", () => {
85
+ it("retires a pending tag — journal record, gone from pendingPublications (AC-6)", async () => {
86
+ const { repo } = await initRepoWithOrigin(dirs, {
87
+ prefix: "flow-ret-",
88
+ fakeExtract: true,
89
+ });
90
+ await addPackageLine(repo);
91
+ await makePending(repo, "lib@1.0.0");
92
+
93
+ const before = await collectDigest(repo, ambientIo, { fetch: false });
94
+ expect(before.pendingPublications).toEqual([{ tag: "lib@1.0.0", line: "lib" }]);
95
+
96
+ const res = await retirePublication(repo, ambientIo, {
97
+ tag: "lib@1.0.0",
98
+ reason: "never passes extract-verify",
99
+ });
100
+ expect(res.diagnostics).toEqual([]);
101
+ expect(res.retired).toBe("lib@1.0.0");
102
+
103
+ const common = await commonGitDir(ambientIo, repo);
104
+ const journal = await readJournal(ambientIo, common);
105
+ const retired = journal.filter((e) => e.event === "publish-retired");
106
+ expect(retired.map((e) => [e.branch, e.detail])).toEqual([
107
+ ["lib@1.0.0", "never passes extract-verify"],
108
+ ]);
109
+
110
+ const after = await collectDigest(repo, ambientIo, { fetch: false });
111
+ expect(after.pendingPublications).toEqual([]);
112
+ expect(after.supersededPublications).toEqual([]);
113
+
114
+ // A second retire on the same tag refuses — it is no longer pending.
115
+ const again = await retirePublication(repo, ambientIo, {
116
+ tag: "lib@1.0.0",
117
+ reason: "again",
118
+ });
119
+ expect(again.diagnostics[0]?.ruleId).toBe("FLOW-RETIRE-01");
120
+ }, 120_000);
121
+
122
+ it("refuses a tag that is not pending with FLOW-RETIRE-01 (AC-7)", async () => {
123
+ const { repo } = await initRepoWithOrigin(dirs, {
124
+ prefix: "flow-ret-",
125
+ fakeExtract: true,
126
+ });
127
+ await addPackageLine(repo);
128
+ await tag(repo, "lib@1.0.0", "lib", "1.0.0"); // never pushed → not pending
129
+
130
+ const res = await retirePublication(repo, ambientIo, {
131
+ tag: "lib@1.0.0",
132
+ reason: "not pending",
133
+ });
134
+ expect(res.diagnostics[0]?.ruleId).toBe("FLOW-RETIRE-01");
135
+ expect(res.retired).toBeNull();
136
+
137
+ const unknown = await retirePublication(repo, ambientIo, {
138
+ tag: "lib@9.9.9",
139
+ reason: "does not exist",
140
+ });
141
+ expect(unknown.diagnostics[0]?.ruleId).toBe("FLOW-RETIRE-01");
142
+
143
+ const common = await commonGitDir(ambientIo, repo);
144
+ const journal = await readJournal(ambientIo, common);
145
+ expect(journal.filter((e) => e.event === "publish-retired")).toEqual([]);
146
+ }, 120_000);
147
+
148
+ it("retires a shadowed (superseded-by-null) pending tag too", async () => {
149
+ const { repo } = await initRepoWithOrigin(dirs, {
150
+ prefix: "flow-ret-",
151
+ fakeExtract: true,
152
+ });
153
+ await addPackageLine(repo);
154
+ await makePending(repo, "lib@1.0.0");
155
+ await makePending(repo, "lib@1.1.0");
156
+
157
+ const before = await collectDigest(repo, ambientIo, { fetch: false });
158
+ expect(before.pendingPublications).toEqual([{ tag: "lib@1.1.0", line: "lib" }]);
159
+ expect(before.supersededPublications).toEqual([
160
+ { tag: "lib@1.0.0", line: "lib", by: null },
161
+ ]);
162
+
163
+ const res = await retirePublication(repo, ambientIo, {
164
+ tag: "lib@1.0.0",
165
+ reason: "shadowed and unwanted",
166
+ });
167
+ expect(res.diagnostics).toEqual([]);
168
+ const after = await collectDigest(repo, ambientIo, { fetch: false });
169
+ expect(after.pendingPublications).toEqual([{ tag: "lib@1.1.0", line: "lib" }]);
170
+ expect(after.supersededPublications).toEqual([]);
171
+ }, 120_000);
172
+
173
+ it("refuses an empty reason with FLOW-RETIRE-02", async () => {
174
+ const { repo } = await initRepoWithOrigin(dirs, {
175
+ prefix: "flow-ret-",
176
+ fakeExtract: true,
177
+ });
178
+ await addPackageLine(repo);
179
+ await makePending(repo, "lib@1.0.0");
180
+
181
+ const res = await retirePublication(repo, ambientIo, {
182
+ tag: "lib@1.0.0",
183
+ reason: " ",
184
+ });
185
+ expect(res.diagnostics[0]?.ruleId).toBe("FLOW-RETIRE-02");
186
+
187
+ const common = await commonGitDir(ambientIo, repo);
188
+ const journal = await readJournal(ambientIo, common);
189
+ expect(journal.filter((e) => e.event === "publish-retired")).toEqual([]);
190
+ }, 120_000);
191
+ });