@warpgogol/forge 9.7.0 → 10.0.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 (327) hide show
  1. package/AGENTS.md +50 -27
  2. package/CHANGELOG.md +52 -0
  3. package/bin/cli.js +0 -0
  4. package/dist/os/adr/handlers/archive.d.ts.map +1 -1
  5. package/dist/os/adr/handlers/archive.js +3 -7
  6. package/dist/os/adr/handlers/archive.js.map +1 -1
  7. package/dist/os/adr/handlers/list-create.d.ts.map +1 -1
  8. package/dist/os/adr/handlers/list-create.js +8 -6
  9. package/dist/os/adr/handlers/list-create.js.map +1 -1
  10. package/dist/os/audit/handlers/archive.d.ts.map +1 -1
  11. package/dist/os/audit/handlers/archive.js +3 -7
  12. package/dist/os/audit/handlers/archive.js.map +1 -1
  13. package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
  14. package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
  15. package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
  16. package/dist/os/core/archive-regen.d.ts +1 -0
  17. package/dist/os/core/archive-regen.d.ts.map +1 -1
  18. package/dist/os/core/archive-regen.js +31 -6
  19. package/dist/os/core/archive-regen.js.map +1 -1
  20. package/dist/os/core/core.module.d.ts.map +1 -1
  21. package/dist/os/core/core.module.js +6 -69
  22. package/dist/os/core/core.module.js.map +1 -1
  23. package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
  24. package/dist/os/core/handlers/assets-helpers.js +2 -3
  25. package/dist/os/core/handlers/assets-helpers.js.map +1 -1
  26. package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
  27. package/dist/os/core/handlers/determinism-check.js +2 -3
  28. package/dist/os/core/handlers/determinism-check.js.map +1 -1
  29. package/dist/os/core/handlers/pinned-check.d.ts +13 -0
  30. package/dist/os/core/handlers/pinned-check.d.ts.map +1 -1
  31. package/dist/os/core/handlers/pinned-check.js +25 -0
  32. package/dist/os/core/handlers/pinned-check.js.map +1 -1
  33. package/dist/os/core/handlers/pinned-types.d.ts +7 -0
  34. package/dist/os/core/handlers/pinned-types.d.ts.map +1 -1
  35. package/dist/os/core/handlers/pinned-validate.d.ts.map +1 -1
  36. package/dist/os/core/handlers/pinned-validate.js +24 -1
  37. package/dist/os/core/handlers/pinned-validate.js.map +1 -1
  38. package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
  39. package/dist/os/core/handlers/release-prepare.js +2 -4
  40. package/dist/os/core/handlers/release-prepare.js.map +1 -1
  41. package/dist/os/flow/digest.d.ts +73 -1
  42. package/dist/os/flow/digest.d.ts.map +1 -1
  43. package/dist/os/flow/digest.js +344 -92
  44. package/dist/os/flow/digest.js.map +1 -1
  45. package/dist/os/flow/evidence-lock.d.ts +36 -0
  46. package/dist/os/flow/evidence-lock.d.ts.map +1 -0
  47. package/dist/os/flow/evidence-lock.js +156 -0
  48. package/dist/os/flow/evidence-lock.js.map +1 -0
  49. package/dist/os/flow/flow.module.d.ts.map +1 -1
  50. package/dist/os/flow/flow.module.js +36 -14
  51. package/dist/os/flow/flow.module.js.map +1 -1
  52. package/dist/os/flow/git.d.ts +50 -3
  53. package/dist/os/flow/git.d.ts.map +1 -1
  54. package/dist/os/flow/git.js +144 -12
  55. package/dist/os/flow/git.js.map +1 -1
  56. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  57. package/dist/os/flow/handlers/flow-digest.js +3 -5
  58. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  59. package/dist/os/flow/handlers/flow-peers.js +1 -1
  60. package/dist/os/flow/handlers/flow-peers.js.map +1 -1
  61. package/dist/os/flow/handlers/flow-push.d.ts +81 -0
  62. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
  63. package/dist/os/flow/handlers/flow-push.js +642 -138
  64. package/dist/os/flow/handlers/flow-push.js.map +1 -1
  65. package/dist/os/flow/locks.d.ts +8 -0
  66. package/dist/os/flow/locks.d.ts.map +1 -1
  67. package/dist/os/flow/locks.js +6 -3
  68. package/dist/os/flow/locks.js.map +1 -1
  69. package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
  70. package/dist/os/flow/open-missions.d.ts.map +1 -0
  71. package/dist/os/flow/open-missions.js +37 -0
  72. package/dist/os/flow/open-missions.js.map +1 -0
  73. package/dist/os/flow/preflight.d.ts.map +1 -1
  74. package/dist/os/flow/preflight.js +5 -3
  75. package/dist/os/flow/preflight.js.map +1 -1
  76. package/dist/os/flow/registry.d.ts +9 -5
  77. package/dist/os/flow/registry.d.ts.map +1 -1
  78. package/dist/os/flow/registry.js +2 -2
  79. package/dist/os/flow/registry.js.map +1 -1
  80. package/dist/os/friction/friction.module.d.ts.map +1 -1
  81. package/dist/os/friction/friction.module.js +30 -5
  82. package/dist/os/friction/friction.module.js.map +1 -1
  83. package/dist/os/friction/handlers/friction-add.d.ts.map +1 -1
  84. package/dist/os/friction/handlers/friction-add.js +10 -17
  85. package/dist/os/friction/handlers/friction-add.js.map +1 -1
  86. package/dist/os/friction/handlers/friction-migrate.d.ts.map +1 -1
  87. package/dist/os/friction/handlers/friction-migrate.js +188 -2
  88. package/dist/os/friction/handlers/friction-migrate.js.map +1 -1
  89. package/dist/os/friction/store.d.ts +4 -0
  90. package/dist/os/friction/store.d.ts.map +1 -1
  91. package/dist/os/friction/store.js +20 -0
  92. package/dist/os/friction/store.js.map +1 -1
  93. package/dist/os/friction/types.d.ts +12 -0
  94. package/dist/os/friction/types.d.ts.map +1 -1
  95. package/dist/os/friction/types.js +8 -0
  96. package/dist/os/friction/types.js.map +1 -1
  97. package/dist/os/gate/handlers/gate-probe-catalog.d.ts.map +1 -1
  98. package/dist/os/gate/handlers/gate-probe-catalog.js +38 -5
  99. package/dist/os/gate/handlers/gate-probe-catalog.js.map +1 -1
  100. package/dist/os/plan/handlers/archive.d.ts.map +1 -1
  101. package/dist/os/plan/handlers/archive.js +3 -7
  102. package/dist/os/plan/handlers/archive.js.map +1 -1
  103. package/dist/os/rfc/handlers/archive.d.ts.map +1 -1
  104. package/dist/os/rfc/handlers/archive.js +3 -7
  105. package/dist/os/rfc/handlers/archive.js.map +1 -1
  106. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  107. package/dist/os/rfc/handlers/list-create.js +15 -7
  108. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  109. package/dist/os/session/handlers/archive.d.ts.map +1 -1
  110. package/dist/os/session/handlers/archive.js +3 -7
  111. package/dist/os/session/handlers/archive.js.map +1 -1
  112. package/dist/os/system/handlers/system-product-register.d.ts +24 -0
  113. package/dist/os/system/handlers/system-product-register.d.ts.map +1 -0
  114. package/dist/os/system/handlers/system-product-register.js +322 -0
  115. package/dist/os/system/handlers/system-product-register.js.map +1 -0
  116. package/dist/os/system/handlers/system-products-status.d.ts +23 -0
  117. package/dist/os/system/handlers/system-products-status.d.ts.map +1 -0
  118. package/dist/os/system/handlers/system-products-status.js +235 -0
  119. package/dist/os/system/handlers/system-products-status.js.map +1 -0
  120. package/dist/os/system/schemas.d.ts +13 -0
  121. package/dist/os/system/schemas.d.ts.map +1 -1
  122. package/dist/os/system/schemas.js +15 -0
  123. package/dist/os/system/schemas.js.map +1 -1
  124. package/dist/os/system/system.module.d.ts.map +1 -1
  125. package/dist/os/system/system.module.js +113 -3
  126. package/dist/os/system/system.module.js.map +1 -1
  127. package/dist/src/command-modules.d.ts.map +1 -1
  128. package/dist/src/command-modules.js +0 -2
  129. package/dist/src/command-modules.js.map +1 -1
  130. package/dist/src/config/forge-config.d.ts +2 -0
  131. package/dist/src/config/forge-config.d.ts.map +1 -1
  132. package/dist/src/config/forge-config.js +11 -10
  133. package/dist/src/config/forge-config.js.map +1 -1
  134. package/dist/src/index.d.ts +0 -2
  135. package/dist/src/index.d.ts.map +1 -1
  136. package/dist/src/index.js +0 -2
  137. package/dist/src/index.js.map +1 -1
  138. package/dist/src/onboarding/create.d.ts.map +1 -1
  139. package/dist/src/onboarding/create.js +27 -2
  140. package/dist/src/onboarding/create.js.map +1 -1
  141. package/dist/src/onboarding/doctor.d.ts +0 -5
  142. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  143. package/dist/src/onboarding/doctor.js +6 -79
  144. package/dist/src/onboarding/doctor.js.map +1 -1
  145. package/dist/src/onboarding/npm-token-check.d.ts +1 -1
  146. package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
  147. package/dist/src/onboarding/npm-token-check.js +2 -2
  148. package/dist/src/onboarding/npm-token-check.js.map +1 -1
  149. package/dist/src/profiles/stack-profile.js +2 -2
  150. package/dist/src/types.js +2 -2
  151. package/dist/src/utils/hash.d.ts +1 -0
  152. package/dist/src/utils/hash.d.ts.map +1 -1
  153. package/dist/src/utils/hash.js +4 -0
  154. package/dist/src/utils/hash.js.map +1 -1
  155. package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
  156. package/dist/src/utils/lockfile.d.ts.map +1 -0
  157. package/dist/src/utils/lockfile.js +70 -0
  158. package/dist/src/utils/lockfile.js.map +1 -0
  159. package/dist/src/utils/verifier-git.d.ts +27 -1
  160. package/dist/src/utils/verifier-git.d.ts.map +1 -1
  161. package/dist/src/utils/verifier-git.js +36 -6
  162. package/dist/src/utils/verifier-git.js.map +1 -1
  163. package/docs/reference/system-hub.md +104 -0
  164. package/os/adr/handlers/archive.ts +3 -11
  165. package/os/adr/handlers/list-create.test.ts +174 -0
  166. package/os/adr/handlers/list-create.ts +16 -8
  167. package/os/audit/handlers/archive.ts +3 -11
  168. package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
  169. package/os/core/archive-regen.ts +33 -7
  170. package/os/core/core.module.ts +10 -76
  171. package/os/core/docs-archive.test.ts +25 -0
  172. package/os/core/handlers/assets-helpers.ts +2 -4
  173. package/os/core/handlers/determinism-check.ts +2 -3
  174. package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
  175. package/os/core/handlers/pinned-check.ts +30 -0
  176. package/os/core/handlers/pinned-types.ts +7 -0
  177. package/os/core/handlers/pinned-validate.ts +28 -3
  178. package/os/core/handlers/release-prepare.ts +2 -4
  179. package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
  180. package/os/flow/digest.ts +436 -95
  181. package/os/flow/evidence-lock.ts +184 -0
  182. package/os/flow/flow.module.ts +37 -14
  183. package/os/flow/git.ts +206 -11
  184. package/os/flow/handlers/flow-digest.ts +12 -8
  185. package/os/flow/handlers/flow-peers.ts +1 -1
  186. package/os/flow/handlers/flow-push.ts +725 -137
  187. package/os/flow/locks.ts +24 -7
  188. package/os/flow/open-missions.ts +45 -0
  189. package/os/flow/preflight.ts +5 -3
  190. package/os/flow/registry.ts +7 -3
  191. package/os/flow/tests/digest-id-inputs.test.ts +106 -0
  192. package/os/flow/tests/digest-persist.test.ts +243 -0
  193. package/os/flow/tests/evidence-preflight-surface-skip.test.ts +218 -0
  194. package/os/flow/tests/flow-push-attest.test.ts +137 -0
  195. package/os/flow/tests/flow-push-review-baseline.test.ts +339 -0
  196. package/os/flow/tests/flow-push-verifier-batch.test.ts +134 -0
  197. package/os/flow/tests/release-lines.test.ts +136 -0
  198. package/os/flow/tests/state-roots.test.ts +1 -48
  199. package/os/friction/friction-add.test.ts +42 -0
  200. package/os/friction/friction-migrate.test.ts +67 -2
  201. package/os/friction/friction.module.ts +33 -5
  202. package/os/friction/handlers/friction-add.ts +10 -15
  203. package/os/friction/handlers/friction-migrate.ts +220 -1
  204. package/os/friction/store.ts +19 -0
  205. package/os/friction/types.ts +8 -0
  206. package/os/gate/handlers/gate-probe-catalog.ts +39 -7
  207. package/os/gate/handlers/gate-probe-ratchet.test.ts +57 -22
  208. package/os/plan/handlers/archive.ts +3 -11
  209. package/os/rfc/handlers/archive.ts +3 -11
  210. package/os/rfc/handlers/list-create.ts +22 -17
  211. package/os/rfc/handlers/validate-corpus.test.ts +149 -0
  212. package/os/rfc/probe-batch.test.ts +253 -0
  213. package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
  214. package/os/session/handlers/archive.ts +3 -11
  215. package/os/system/handlers/system-product-register.ts +492 -0
  216. package/os/system/handlers/system-products-status.ts +395 -0
  217. package/os/system/schemas.ts +17 -0
  218. package/os/system/system.module.ts +117 -3
  219. package/os/system/tests/system-product-register.test.ts +304 -0
  220. package/os/system/tests/system-products-status.test.ts +154 -0
  221. package/package.json +161 -506
  222. package/profiles/root-agents-system.md +82 -0
  223. package/profiles/system.yaml +1 -0
  224. package/src/command-modules.ts +0 -2
  225. package/src/config/forge-config.ts +16 -11
  226. package/src/index.ts +0 -2
  227. package/src/onboarding/create-superfolder-guard.test.ts +73 -0
  228. package/src/onboarding/create.ts +28 -2
  229. package/src/onboarding/doctor.ts +9 -96
  230. package/src/onboarding/npm-token-check.ts +3 -3
  231. package/src/profiles/stack-profile.ts +2 -2
  232. package/src/tests/evidence-consult-serialization.test.ts +202 -0
  233. package/src/tests/pinned-validate.test.ts +194 -0
  234. package/src/tests/pkg-health-self-scan.test.ts +29 -0
  235. package/src/tests/profile-flow-hooks.test.ts +1 -0
  236. package/src/tests/profile-schema.test.ts +1 -0
  237. package/src/tests/rfc-evidence-sync.test.ts +369 -0
  238. package/src/tests/skill-agents-sync.test.ts +192 -0
  239. package/src/tests/stack-profile.test.ts +1 -0
  240. package/src/types.ts +2 -2
  241. package/src/utils/hash.ts +5 -0
  242. package/src/utils/lockfile.ts +78 -0
  243. package/src/utils/verifier-git.ts +53 -5
  244. package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
  245. package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
  246. package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
  247. package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
  248. package/dist/os/mission/handlers/archive.d.ts +0 -4
  249. package/dist/os/mission/handlers/archive.d.ts.map +0 -1
  250. package/dist/os/mission/handlers/archive.js +0 -587
  251. package/dist/os/mission/handlers/archive.js.map +0 -1
  252. package/dist/os/mission/importer-block.d.ts +0 -19
  253. package/dist/os/mission/importer-block.d.ts.map +0 -1
  254. package/dist/os/mission/importer-block.js +0 -124
  255. package/dist/os/mission/importer-block.js.map +0 -1
  256. package/dist/os/mission/index.d.ts +0 -2
  257. package/dist/os/mission/index.d.ts.map +0 -1
  258. package/dist/os/mission/index.js +0 -15
  259. package/dist/os/mission/index.js.map +0 -1
  260. package/dist/os/mission/lockfile.d.ts.map +0 -1
  261. package/dist/os/mission/lockfile.js +0 -138
  262. package/dist/os/mission/lockfile.js.map +0 -1
  263. package/dist/os/mission/mission.module.d.ts +0 -3
  264. package/dist/os/mission/mission.module.d.ts.map +0 -1
  265. package/dist/os/mission/mission.module.js +0 -63
  266. package/dist/os/mission/mission.module.js.map +0 -1
  267. package/dist/os/mission/open-missions.d.ts.map +0 -1
  268. package/dist/os/mission/open-missions.js +0 -42
  269. package/dist/os/mission/open-missions.js.map +0 -1
  270. package/dist/os/mission/types.d.ts +0 -23
  271. package/dist/os/mission/types.d.ts.map +0 -1
  272. package/dist/os/mission/types.js +0 -19
  273. package/dist/os/mission/types.js.map +0 -1
  274. package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
  275. package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
  276. package/dist/os/werkstatt/handlers/lock.js +0 -153
  277. package/dist/os/werkstatt/handlers/lock.js.map +0 -1
  278. package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
  279. package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
  280. package/dist/os/werkstatt/handlers/schema.js +0 -42
  281. package/dist/os/werkstatt/handlers/schema.js.map +0 -1
  282. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
  283. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
  284. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
  285. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
  286. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
  287. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
  288. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
  289. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
  290. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
  291. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
  292. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
  293. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
  294. package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
  295. package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
  296. package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
  297. package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
  298. package/dist/os/werkstatt/index.d.ts +0 -7
  299. package/dist/os/werkstatt/index.d.ts.map +0 -1
  300. package/dist/os/werkstatt/index.js +0 -18
  301. package/dist/os/werkstatt/index.js.map +0 -1
  302. package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
  303. package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
  304. package/dist/os/werkstatt/werkstatt.module.js +0 -91
  305. package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
  306. package/os/core/handlers/forge-autonomy-validate.ts +0 -276
  307. package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
  308. package/os/mission/handlers/archive.test.ts +0 -764
  309. package/os/mission/handlers/archive.ts +0 -719
  310. package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
  311. package/os/mission/importer-block.ts +0 -119
  312. package/os/mission/index.ts +0 -15
  313. package/os/mission/lockfile.ts +0 -152
  314. package/os/mission/mission.module.ts +0 -68
  315. package/os/mission/open-missions.ts +0 -50
  316. package/os/mission/types.ts +0 -42
  317. package/os/werkstatt/handlers/lock.ts +0 -168
  318. package/os/werkstatt/handlers/schema.ts +0 -47
  319. package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
  320. package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
  321. package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
  322. package/os/werkstatt/handlers/workspace-deps.ts +0 -56
  323. package/os/werkstatt/index.ts +0 -39
  324. package/os/werkstatt/werkstatt.module.ts +0 -95
  325. package/src/tests/doctor-autonomy.test.ts +0 -246
  326. package/src/tests/forge-autonomy-validate.test.ts +0 -159
  327. package/src/tests/werkstatt-lock.test.ts +0 -357
@@ -0,0 +1,304 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Unit tests for system.product.register (RFC-1641) — explicit
4
+ registration writes the roster + local map (AC-2, AC-8), --discover sibling
5
+ scan semantics (AC-3), refusal cases write nothing (AC-4).</purpose>
6
+ <non-goals>
7
+ <item>Not a contract source of truth — the implementation under test owns the behaviour.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1641: system.product.register — roster write surface with --discover sibling scan</item>
12
+ <item>RFC-1641: step 1 — system.product.register handler + tests</item>
13
+ </CHANGE_SUMMARY>
14
+ */
15
+
16
+ import { test, expect, describe, beforeEach, afterEach } from "vitest";
17
+ import fs from "node:fs/promises";
18
+ import path from "node:path";
19
+ import os from "node:os";
20
+ import YAML from "yaml";
21
+
22
+ import { runSystemProductRegister } from "../handlers/system-product-register.ts";
23
+ import type { ForgeFlagValue } from "../../../src/types.ts";
24
+ import { gitExec, initRepo } from "../../flow/tests/helpers.ts";
25
+ import { localMapFor, makeContext, VALID_EDGES_YAML, VALID_SYSTEM_YAML } from "./helpers.ts";
26
+
27
+ // Discover scans dirname(root), so the hub must sit inside a controlled
28
+ // parent — never directly under os.tmpdir() where concurrent fixtures
29
+ // would read as candidate siblings.
30
+ let parent: string;
31
+ let hub: string;
32
+
33
+ const PRODUCTS_YAML = `schema: forge/system-products@1
34
+ products:
35
+ - id: alpha
36
+ remote: https://example.invalid/alpha.git
37
+ offers:
38
+ - alpha-contract
39
+ ignored:
40
+ - id: ignored-one
41
+ note: deliberate non-product
42
+ `;
43
+
44
+ const MEMBER_FORGE_YAML = `schema: forge/workspace@1
45
+ profile: typescript
46
+ forge:
47
+ syncedVersion: "9.7.0"
48
+ `;
49
+
50
+ async function writeHub(files: Record<string, string> = {}): Promise<void> {
51
+ const all: Record<string, string> = {
52
+ "forge.yaml": `schema: forge/workspace@1\nprofile: system\nforge:\n syncedVersion: "9.7.0"\n`,
53
+ "system/system.yaml": VALID_SYSTEM_YAML,
54
+ "system/products.yaml": PRODUCTS_YAML,
55
+ "system/edges.yaml": VALID_EDGES_YAML,
56
+ ...files,
57
+ };
58
+ for (const [rel, content] of Object.entries(all)) {
59
+ const abs = path.join(hub, rel);
60
+ await fs.mkdir(path.dirname(abs), { recursive: true });
61
+ await fs.writeFile(abs, content);
62
+ }
63
+ }
64
+
65
+ async function readYaml(rel: string): Promise<Record<string, unknown>> {
66
+ return YAML.parse(await fs.readFile(path.join(hub, rel), "utf8")) as Record<string, unknown>;
67
+ }
68
+
69
+ function productsOf(
70
+ parsed: Record<string, unknown>,
71
+ ): { id: string; remote?: string; offers?: string[]; frozen?: boolean }[] {
72
+ return (parsed["products"] as { id: string }[] | undefined) ?? [];
73
+ }
74
+
75
+ function foldersOf(parsed: Record<string, unknown>): Record<string, string> {
76
+ return (parsed["folders"] as Record<string, string> | undefined) ?? {};
77
+ }
78
+
79
+ function ctx(flags: Record<string, ForgeFlagValue>) {
80
+ return { input: { argv: [], flags }, context: makeContext(hub) };
81
+ }
82
+
83
+ beforeEach(async () => {
84
+ parent = await fs.mkdtemp(path.join(os.tmpdir(), "sys-register-parent-"));
85
+ hub = path.join(parent, "warpgogol-verbund");
86
+ await fs.mkdir(hub, { recursive: true });
87
+ await writeHub();
88
+ });
89
+
90
+ afterEach(async () => {
91
+ await fs.rm(parent, { recursive: true, force: true });
92
+ });
93
+
94
+ describe("system.product.register — explicit (RFC-1641 AC-2, AC-8)", () => {
95
+ test("appends products.yaml and maps the folder in products.local.yaml", async () => {
96
+ const gammaDir = path.join(parent, "gamma");
97
+ await fs.mkdir(gammaDir, { recursive: true });
98
+ const { input, context } = ctx({
99
+ id: "gamma",
100
+ remote: "https://example.invalid/gamma.git",
101
+ folder: "../gamma",
102
+ offers: ["gamma-contract", "gamma-events"],
103
+ frozen: true,
104
+ });
105
+ const result = await runSystemProductRegister(input, context);
106
+ expect(result.exitCode).toBe(0);
107
+ const products = productsOf(await readYaml("system/products.yaml"));
108
+ const gamma = products.find((p) => p.id === "gamma");
109
+ expect(gamma?.remote).toBe("https://example.invalid/gamma.git");
110
+ expect(gamma?.offers).toEqual(["gamma-contract", "gamma-events"]);
111
+ expect(gamma?.frozen).toBe(true);
112
+ const local = await readYaml("system/products.local.yaml");
113
+ expect(local["schema"]).toBe("forge/system-products-local@1");
114
+ expect(foldersOf(local)["gamma"]).toBe("../gamma");
115
+ expect(result.data?.written).toContain("system/products.yaml");
116
+ expect(result.data?.written).toContain("system/products.local.yaml");
117
+ });
118
+
119
+ test("an identical re-run is a skip, not a write", async () => {
120
+ await fs.mkdir(path.join(parent, "gamma"), { recursive: true });
121
+ const flags = { id: "gamma", remote: "https://example.invalid/gamma.git", folder: "../gamma" };
122
+ await runSystemProductRegister(ctx(flags).input, ctx(flags).context);
123
+ const second = await runSystemProductRegister(ctx(flags).input, ctx(flags).context);
124
+ expect(second.exitCode).toBe(0);
125
+ expect(second.data?.registered).toEqual([]);
126
+ expect(second.data?.skipped).toEqual([{ name: "gamma", reason: "already-registered" }]);
127
+ expect(second.data?.written).toEqual([]);
128
+ });
129
+
130
+ test("--update mutates offers and remote on an existing id", async () => {
131
+ const { input, context } = ctx({
132
+ id: "alpha",
133
+ update: true,
134
+ remote: "https://example.invalid/alpha-v2.git",
135
+ offers: ["alpha-contract", "alpha-v2"],
136
+ });
137
+ const result = await runSystemProductRegister(input, context);
138
+ expect(result.exitCode).toBe(0);
139
+ const alpha = productsOf(await readYaml("system/products.yaml")).find((p) => p.id === "alpha");
140
+ expect(alpha?.remote).toBe("https://example.invalid/alpha-v2.git");
141
+ expect(alpha?.offers).toEqual(["alpha-contract", "alpha-v2"]);
142
+ });
143
+
144
+ test("products.local.yaml keeps an existing launcher on write", async () => {
145
+ await writeHub({
146
+ "system/products.local.yaml": `schema: forge/system-products-local@1\nfolders:\n alpha: /x/alpha\nlauncher:\n argv: ["run", "agent"]\n`,
147
+ });
148
+ const { input, context } = ctx({
149
+ id: "gamma",
150
+ remote: "https://example.invalid/gamma.git",
151
+ folder: "../gamma",
152
+ });
153
+ const result = await runSystemProductRegister(input, context);
154
+ expect(result.exitCode).toBe(0);
155
+ const local = await readYaml("system/products.local.yaml");
156
+ expect(local["launcher"]).toEqual({ argv: ["run", "agent"] });
157
+ expect(foldersOf(local)["gamma"]).toBe("../gamma");
158
+ expect(foldersOf(local)["alpha"]).toBe("/x/alpha");
159
+ });
160
+ });
161
+
162
+ describe("system.product.register — refusals (RFC-1641 AC-4)", () => {
163
+ test("non-kebab id refuses SYSTEM-PRODUCTS-03 and writes nothing", async () => {
164
+ const { input, context } = ctx({ id: "Not_Kebab", remote: "https://x.invalid/y.git" });
165
+ const result = await runSystemProductRegister(input, context);
166
+ expect(result.exitCode).toBe(1);
167
+ expect(result.data?.errors[0]?.ruleId).toBe("SYSTEM-PRODUCTS-03");
168
+ expect(productsOf(await readYaml("system/products.yaml")).map((p) => p.id)).toEqual(["alpha"]);
169
+ });
170
+
171
+ test("duplicate id without --update refuses", async () => {
172
+ const { input, context } = ctx({ id: "alpha", remote: "https://other.invalid/a.git" });
173
+ const result = await runSystemProductRegister(input, context);
174
+ expect(result.exitCode).toBe(1);
175
+ expect(result.data?.errors[0]?.ruleId).toBe("SYSTEM-PRODUCTS-03");
176
+ });
177
+
178
+ test("new product without --remote refuses", async () => {
179
+ const { input, context } = ctx({ id: "gamma" });
180
+ const result = await runSystemProductRegister(input, context);
181
+ expect(result.exitCode).toBe(1);
182
+ expect(result.data?.errors[0]?.ruleId).toBe("SYSTEM-PRODUCTS-03");
183
+ });
184
+
185
+ test("a folder already mapped to another product refuses", async () => {
186
+ await writeHub({ "system/products.local.yaml": localMapFor({ alpha: "../shared" }) });
187
+ const { input, context } = ctx({
188
+ id: "gamma",
189
+ remote: "https://x.invalid/g.git",
190
+ folder: "../shared",
191
+ });
192
+ const result = await runSystemProductRegister(input, context);
193
+ expect(result.exitCode).toBe(1);
194
+ expect(result.data?.errors[0]?.ruleId).toBe("SYSTEM-PRODUCTS-03");
195
+ expect(foldersOf(await readYaml("system/products.local.yaml"))["gamma"]).toBeUndefined();
196
+ });
197
+
198
+ test("missing --id and --discover refuses", async () => {
199
+ const result = await runSystemProductRegister({ argv: [], flags: {} }, makeContext(hub));
200
+ expect(result.exitCode).toBe(1);
201
+ expect(result.data?.errors[0]?.ruleId).toBe("SYSTEM-PRODUCTS-03");
202
+ });
203
+
204
+ test("a missing --folder on disk warns SYSTEM-PRODUCTS-04 but still writes", async () => {
205
+ const { input, context } = ctx({
206
+ id: "gamma",
207
+ remote: "https://x.invalid/g.git",
208
+ folder: "../absent",
209
+ });
210
+ const result = await runSystemProductRegister(input, context);
211
+ expect(result.exitCode).toBe(0);
212
+ expect(result.data?.warnings.some((d) => d.ruleId === "SYSTEM-PRODUCTS-04")).toBe(true);
213
+ expect(foldersOf(await readYaml("system/products.local.yaml"))["gamma"]).toBe("../absent");
214
+ });
215
+
216
+ test("--dry-run resolves the result and writes nothing", async () => {
217
+ const { input, context } = ctx({
218
+ id: "gamma",
219
+ remote: "https://x.invalid/g.git",
220
+ "dry-run": true,
221
+ });
222
+ const result = await runSystemProductRegister(input, context);
223
+ expect(result.exitCode).toBe(0);
224
+ expect(result.data?.dryRun).toBe(true);
225
+ expect(result.data?.written).toContain("system/products.yaml");
226
+ expect(
227
+ await fs.stat(path.join(hub, "system/products.local.yaml")).catch(() => null),
228
+ ).toBeNull();
229
+ expect(productsOf(await readYaml("system/products.yaml")).map((p) => p.id)).toEqual(["alpha"]);
230
+ });
231
+ });
232
+
233
+ describe("system.product.register — discover (RFC-1641 AC-3)", () => {
234
+ test("registers forge siblings with remotes; skips ignored, hidden, @-dirs, non-forge and remoteless candidates", async () => {
235
+ // gamma — a real git checkout with forge.yaml and an origin remote.
236
+ const gammaDir = path.join(parent, "gamma");
237
+ const seeded = await initRepo({ prefix: "sys-gamma-", branch: "develop" });
238
+ await fs.rename(seeded, gammaDir);
239
+ await fs.writeFile(path.join(gammaDir, "forge.yaml"), MEMBER_FORGE_YAML);
240
+ await gitExec(gammaDir, ["remote", "add", "origin", "https://example.invalid/gamma.git"]);
241
+ // remoteless — forge.yaml, git, but no origin.
242
+ const remotelessDir = path.join(parent, "remoteless");
243
+ const seeded2 = await initRepo({ prefix: "sys-remoteless-", branch: "develop" });
244
+ await fs.rename(seeded2, remotelessDir);
245
+ await fs.writeFile(path.join(remotelessDir, "forge.yaml"), MEMBER_FORGE_YAML);
246
+ // ignored-one — named in ignored[].
247
+ await fs.mkdir(path.join(parent, "ignored-one"), { recursive: true });
248
+ await fs.writeFile(path.join(parent, "ignored-one", "forge.yaml"), MEMBER_FORGE_YAML);
249
+ // hidden, @-worktree, plain non-forge dirs — never candidates.
250
+ await fs.mkdir(path.join(parent, ".cache"), { recursive: true });
251
+ await fs.writeFile(path.join(parent, ".cache", "forge.yaml"), MEMBER_FORGE_YAML);
252
+ await fs.mkdir(path.join(parent, "delta@auto-x"), { recursive: true });
253
+ await fs.writeFile(path.join(parent, "delta@auto-x", "forge.yaml"), MEMBER_FORGE_YAML);
254
+ await fs.mkdir(path.join(parent, "plain-docs"), { recursive: true });
255
+ // alpha — dir on disk, already registered: skip reason already-registered.
256
+ const alphaDir = path.join(parent, "alpha");
257
+ const seeded3 = await initRepo({ prefix: "sys-alpha-", branch: "develop" });
258
+ await fs.rename(seeded3, alphaDir);
259
+ await fs.writeFile(path.join(alphaDir, "forge.yaml"), MEMBER_FORGE_YAML);
260
+
261
+ const { input, context } = ctx({ discover: true });
262
+ const result = await runSystemProductRegister(input, context);
263
+ expect(result.exitCode).toBe(0);
264
+ expect(result.data?.mode).toBe("discover");
265
+
266
+ const registeredIds = result.data?.registered.map((r) => r.id) ?? [];
267
+ expect(registeredIds).toEqual(["gamma"]);
268
+ const products = productsOf(await readYaml("system/products.yaml"));
269
+ expect(products.map((p) => p.id)).toEqual(["alpha", "gamma"]);
270
+ expect(products.find((p) => p.id === "gamma")?.remote).toBe(
271
+ "https://example.invalid/gamma.git",
272
+ );
273
+ expect(foldersOf(await readYaml("system/products.local.yaml"))["gamma"]).toBe("../gamma");
274
+
275
+ const skip = Object.fromEntries((result.data?.skipped ?? []).map((s) => [s.name, s.reason]));
276
+ expect(skip["ignored-one"]).toBe("ignored[]");
277
+ expect(skip["remoteless"]).toContain("no origin remote");
278
+ expect(skip["alpha"]).toBe("already-registered");
279
+ expect(skip[".cache"]).toBeUndefined();
280
+ expect(skip["delta@auto-x"]).toBeUndefined();
281
+ expect(skip["plain-docs"]).toBeUndefined();
282
+ expect(skip["warpgogol-verbund"]).toBeUndefined();
283
+ });
284
+
285
+ test("a non-kebab sibling name warns and skips", async () => {
286
+ await fs.mkdir(path.join(parent, "Not_Kebab"), { recursive: true });
287
+ await fs.writeFile(path.join(parent, "Not_Kebab", "forge.yaml"), MEMBER_FORGE_YAML);
288
+ const { input, context } = ctx({ discover: true });
289
+ const result = await runSystemProductRegister(input, context);
290
+ expect(result.exitCode).toBe(0);
291
+ expect(result.data?.warnings.some((d) => d.ruleId === "SYSTEM-PRODUCTS-04")).toBe(true);
292
+ expect(result.data?.skipped.find((s) => s.name === "Not_Kebab")?.reason).toContain("kebab");
293
+ });
294
+ });
295
+
296
+ describe("system.product.register — SYSTEM-01 gate", () => {
297
+ test("refuses outside the system profile", async () => {
298
+ await fs.writeFile(path.join(hub, "forge.yaml"), `profile: typescript\n`);
299
+ const { input, context } = ctx({ id: "gamma", remote: "https://x.invalid/g.git" });
300
+ const result = await runSystemProductRegister(input, context);
301
+ expect(result.exitCode).toBe(1);
302
+ expect(result.data?.errors[0]?.ruleId).toBe("SYSTEM-01");
303
+ });
304
+ });
@@ -0,0 +1,154 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Unit tests for system.products.status (RFC-1639) — member health probing (AC-2), sibling-scan warnings (AC-3), frozen-product semantics (AC-6).</purpose>
4
+ <non-goals>
5
+ <item>Not a contract source of truth — the implementation under test owns the behaviour.</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>RFC-1639: step 5-6 — acceptance tests, system-hub reference, regenerated manifests</item>
10
+ <item>RFC-1639: review — SYSTEM-MAP-01 rules decl, git-probe warnings, sibling kind/path discriminants, friction.add provenance, ingest hardening</item>
11
+ </CHANGE_SUMMARY>
12
+ */
13
+
14
+ import { test, expect, describe, beforeEach, afterEach } from "vitest";
15
+ import fs from "node:fs/promises";
16
+ import path from "node:path";
17
+ import os from "node:os";
18
+
19
+ import { runSystemProductsStatus } from "../handlers/system-products-status.ts";
20
+ import { gitExec, initRepo } from "../../flow/tests/helpers.ts";
21
+ import { localMapFor, makeContext, VALID_EDGES_YAML, VALID_SYSTEM_YAML } from "./helpers.ts";
22
+
23
+ // The sibling scan walks dirname(root), so the hub must sit inside a
24
+ // controlled parent — never directly under os.tmpdir() where concurrent
25
+ // fixtures would read as unregistered siblings.
26
+ let parent: string;
27
+ let hub: string;
28
+ let alphaDir: string;
29
+ let betaDir: string;
30
+
31
+ const PRODUCTS_YAML = `schema: forge/system-products@1
32
+ products:
33
+ - id: alpha
34
+ remote: https://example.invalid/alpha.git
35
+ offers: []
36
+ - id: beta
37
+ remote: https://example.invalid/beta.git
38
+ offers: []
39
+ - id: ghost
40
+ remote: https://example.invalid/ghost.git
41
+ offers: []
42
+ frozen: true
43
+ ignored:
44
+ - id: ignored-one
45
+ note: scratch area
46
+ `;
47
+
48
+ const MEMBER_FORGE_YAML = `schema: forge/workspace@1
49
+ profile: typescript
50
+ forge:
51
+ syncedVersion: "9.7.0"
52
+ `;
53
+
54
+ beforeEach(async () => {
55
+ parent = await fs.mkdtemp(path.join(os.tmpdir(), "sys-status-parent-"));
56
+ hub = path.join(parent, "warpgogol-verbund");
57
+ alphaDir = path.join(parent, "alpha");
58
+ betaDir = path.join(parent, "beta");
59
+ // alpha — a real git checkout: commit forge.yaml, then dirty a tracked file.
60
+ let seeded = await initRepo({ prefix: "sys-alpha-", branch: "develop" });
61
+ await fs.rename(seeded, alphaDir);
62
+ await fs.writeFile(path.join(alphaDir, "forge.yaml"), MEMBER_FORGE_YAML);
63
+ await gitExec(alphaDir, ["add", "forge.yaml"]);
64
+ await gitExec(alphaDir, ["commit", "-m", "forge.yaml"]);
65
+ await fs.appendFile(path.join(alphaDir, "seed.txt"), "dirty\n");
66
+ // beta — a second real checkout, clean.
67
+ seeded = await initRepo({ prefix: "sys-beta-", branch: "develop" });
68
+ await fs.rename(seeded, betaDir);
69
+ await fs.writeFile(path.join(betaDir, "forge.yaml"), MEMBER_FORGE_YAML);
70
+ await gitExec(betaDir, ["add", "forge.yaml"]);
71
+ await gitExec(betaDir, ["commit", "-m", "forge.yaml"]);
72
+
73
+ const hubFiles: Record<string, string> = {
74
+ "forge.yaml": `schema: forge/workspace@1\nprofile: system\nforge:\n syncedVersion: "9.7.0"\n`,
75
+ "system/system.yaml": VALID_SYSTEM_YAML,
76
+ "system/products.yaml": PRODUCTS_YAML,
77
+ "system/edges.yaml": VALID_EDGES_YAML,
78
+ "system/products.local.yaml": localMapFor({
79
+ alpha: alphaDir,
80
+ beta: betaDir,
81
+ ghost: path.join(parent, "ghost"),
82
+ }),
83
+ };
84
+ for (const [rel, content] of Object.entries(hubFiles)) {
85
+ const abs = path.join(hub, rel);
86
+ await fs.mkdir(path.dirname(abs), { recursive: true });
87
+ await fs.writeFile(abs, content);
88
+ }
89
+ });
90
+
91
+ afterEach(async () => {
92
+ await fs.rm(parent, { recursive: true, force: true });
93
+ });
94
+
95
+ describe("system.products.status — member health (RFC-1639 AC-2)", () => {
96
+ test("reports presence, profile, version parity and git fields per member", async () => {
97
+ const result = await runSystemProductsStatus({ argv: [], flags: {} }, makeContext(hub));
98
+ expect(result.exitCode).toBe(0);
99
+ const data = result.data;
100
+ expect(data?.baseline).toBe("9.7.0");
101
+ const alpha = data?.products.find((p) => p.id === "alpha");
102
+ expect(alpha?.folder).toBe(alphaDir);
103
+ expect(alpha?.profile).toBe("typescript");
104
+ expect(alpha?.forgeVersion).toBe("9.7.0");
105
+ expect(alpha?.versionOk).toBe(true);
106
+ expect(alpha?.dirty).toBe(true); // tracked seed.txt modified post-commit
107
+ const beta = data?.products.find((p) => p.id === "beta");
108
+ expect(beta?.folder).toBe(betaDir);
109
+ expect(beta?.dirty).toBe(false);
110
+ // alpha/beta carry no upstream — aheadOfOrigin degrades to null + warning.
111
+ expect(alpha?.aheadOfOrigin).toBeNull();
112
+ });
113
+ });
114
+
115
+ describe("system.products.status — sibling scan (RFC-1639 AC-3)", () => {
116
+ test("warns on an unregistered forge.yaml sibling and a git sibling without forge.yaml", async () => {
117
+ await fs.mkdir(path.join(parent, "rogue"), { recursive: true });
118
+ await fs.writeFile(path.join(parent, "rogue", "forge.yaml"), MEMBER_FORGE_YAML);
119
+ await fs.mkdir(path.join(parent, "ignored-one"), { recursive: true });
120
+ await fs.writeFile(path.join(parent, "ignored-one", "forge.yaml"), MEMBER_FORGE_YAML);
121
+ await fs.mkdir(path.join(parent, "git-only"), { recursive: true });
122
+ const init = await gitExec(path.join(parent, "git-only"), ["init", "-b", "main"]);
123
+ expect(init.exitCode).toBe(0);
124
+
125
+ const result = await runSystemProductsStatus({ argv: [], flags: {} }, makeContext(hub));
126
+ expect(result.exitCode).toBe(0);
127
+ const warned = result.data?.warnings.map((w) => w.message).join("\n") ?? "";
128
+ expect(warned).toContain("rogue");
129
+ expect(warned).toContain("git-only");
130
+ expect(warned).not.toContain("ignored-one");
131
+ });
132
+ });
133
+
134
+ describe("system.products.status — frozen members (RFC-1639 AC-6)", () => {
135
+ test("a missing frozen member reports null probes with a warning, never an error", async () => {
136
+ const result = await runSystemProductsStatus({ argv: [], flags: {} }, makeContext(hub));
137
+ expect(result.exitCode).toBe(0);
138
+ const ghost = result.data?.products.find((p) => p.id === "ghost");
139
+ expect(ghost?.frozen).toBe(true);
140
+ expect(ghost?.versionOk).toBeNull();
141
+ expect(result.data?.errors ?? []).toHaveLength(0);
142
+ const warned = result.data?.warnings.map((w) => w.message).join("\n") ?? "";
143
+ expect(warned).toContain("ghost");
144
+ });
145
+
146
+ test("a missing non-frozen member is an error and fails the command", async () => {
147
+ const products = PRODUCTS_YAML.replace(" frozen: true\n", "");
148
+ await fs.writeFile(path.join(hub, "system", "products.yaml"), products);
149
+ const result = await runSystemProductsStatus({ argv: [], flags: {} }, makeContext(hub));
150
+ expect(result.exitCode).toBe(1);
151
+ const errors = result.data?.errors.map((e) => e.message).join("\n") ?? "";
152
+ expect(errors).toContain("ghost");
153
+ });
154
+ });