@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
@@ -0,0 +1,321 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Acceptance tests for system.map.validate and edgeVerdict (RFC-1508
4
+ AC-1..AC-6). Fixes exercised: profile gating, cross-file map rules, local
5
+ checkout warnings, and the single-lookup edge resolver's fixed precedence.</purpose>
6
+ <non-goals>
7
+ <item>Fixtures are minimal scaffolding — the handler under test owns the contract.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1508: step 1 — system.map.validate acceptance tests (AC-1..AC-6)</item>
12
+ <item>RFC-1508: implement RFC-1508 — system profile, system map schemas and system.map.validate</item>
13
+ <item>RFC-1508: align rfc-1508 schemas with the normative contract after review r1</item>
14
+ <item>RFC-1508: close rfc-1508 review r2 findings on folder lookup and diagnostics</item>
15
+ <item>RFC-1511: scenarios, version sets and system.versionset.record</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ // @vitest-environment node
20
+
21
+ import { describe, expect, it } from "vitest";
22
+
23
+ import { runSystemMapValidate } from "../handlers/system-map-validate.ts";
24
+ import { edgeVerdict, loadSystemMap } from "../repo.ts";
25
+ import { systemEdgesSchema } from "../schemas.ts";
26
+ import { makeContext, makeSystemRepo, validMapFiles } from "./helpers.ts";
27
+ import { resolveIo } from "../../../src/utils/io.ts";
28
+
29
+ function ruleIds(diagnostics: { ruleId: string }[]): string[] {
30
+ return diagnostics.map((d) => d.ruleId);
31
+ }
32
+
33
+ describe("system.map.validate", () => {
34
+ it("AC-1: refuses outside the system profile with SYSTEM-01", async () => {
35
+ const root = await makeSystemRepo({ "forge.yaml": "profile: forge-shell\n", ...validMapFiles() });
36
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
37
+ expect(result.exitCode).toBe(1);
38
+ const diags = result.data?.diagnostics ?? [];
39
+ expect(ruleIds(diags)).toContain("SYSTEM-01");
40
+ expect(diags.find((d) => d.ruleId === "SYSTEM-01")?.severity).toBe("error");
41
+ });
42
+
43
+ it("AC-1b: refuses when forge.yaml is empty", async () => {
44
+ const bare = await makeSystemRepo({ "forge.yaml": "" });
45
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(bare));
46
+ expect(result.exitCode).toBe(1);
47
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-01");
48
+ });
49
+
50
+ it("AC-2: edge consumer not listed as a product reports SYSTEM-MAP-02", async () => {
51
+ const files = validMapFiles();
52
+ files["system/edges.yaml"] = `schema: forge/system-edges@1
53
+ allowed:
54
+ - consumer: ghost
55
+ contract: alpha-contract
56
+ forbidden: []
57
+ `;
58
+ const root = await makeSystemRepo(files);
59
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
60
+ expect(result.exitCode).toBe(1);
61
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-02");
62
+ });
63
+
64
+ it("AC-3: edge naming an unoffered contract reports SYSTEM-MAP-03", async () => {
65
+ const files = validMapFiles();
66
+ files["system/edges.yaml"] = `schema: forge/system-edges@1
67
+ allowed:
68
+ - consumer: beta
69
+ contract: phantom-contract
70
+ forbidden: []
71
+ `;
72
+ const root = await makeSystemRepo(files);
73
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
74
+ expect(result.exitCode).toBe(1);
75
+ const diags = result.data?.diagnostics ?? [];
76
+ expect(ruleIds(diags)).toContain("SYSTEM-MAP-03");
77
+ expect(diags.find((d) => d.ruleId === "SYSTEM-MAP-03")?.message).toContain("phantom-contract");
78
+ });
79
+
80
+ it("AC-4: pair both allowed and forbidden reports SYSTEM-MAP-04", async () => {
81
+ const files = validMapFiles();
82
+ files["system/edges.yaml"] = `schema: forge/system-edges@1
83
+ allowed:
84
+ - consumer: beta
85
+ contract: alpha-contract
86
+ forbidden:
87
+ - consumer: beta
88
+ contract: alpha-contract
89
+ reason: temporary quarantine
90
+ `;
91
+ const root = await makeSystemRepo(files);
92
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
93
+ expect(result.exitCode).toBe(1);
94
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-04");
95
+ });
96
+
97
+ it("AC-5: product missing from products.local.yaml warns SYSTEM-MAP-05 with exit 0", async () => {
98
+ const files = validMapFiles();
99
+ files["system/products.local.yaml"] =
100
+ "schema: forge/system-products-local@1\nfolders:\n alpha: ./alpha\n";
101
+ const root = await makeSystemRepo(files);
102
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
103
+ expect(result.exitCode).toBe(0);
104
+ const diags = result.data?.diagnostics ?? [];
105
+ const warning = diags.find((d) => d.ruleId === "SYSTEM-MAP-05");
106
+ expect(warning).toBeDefined();
107
+ expect(warning?.severity).toBe("warning");
108
+ expect(warning?.message).toContain("beta");
109
+ });
110
+
111
+ it("AC-5b: absent products.local.yaml warns SYSTEM-MAP-05 with exit 0", async () => {
112
+ const files = validMapFiles();
113
+ delete files["system/products.local.yaml"];
114
+ const root = await makeSystemRepo(files);
115
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
116
+ expect(result.exitCode).toBe(0);
117
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-05");
118
+ });
119
+
120
+ it("AC-6: edgeVerdict returns own-contract for a product's own offered contract", async () => {
121
+ const root = await makeSystemRepo(validMapFiles());
122
+ const { map } = await loadSystemMap(root, resolveIo());
123
+ expect(map).not.toBeNull();
124
+ expect(edgeVerdict(map!, "alpha", "alpha-contract")).toBe("own-contract");
125
+ expect(edgeVerdict(map!, "beta", "alpha-contract")).toBe("allowed");
126
+ expect(edgeVerdict(map!, "beta", "unrelated")).toBe("undeclared");
127
+ });
128
+
129
+ it("AC-6b: edgeVerdict precedence — forbidden checked before allowed", async () => {
130
+ const files = validMapFiles();
131
+ files["system/edges.yaml"] = `schema: forge/system-edges@1
132
+ allowed:
133
+ - consumer: beta
134
+ contract: alpha-contract
135
+ forbidden:
136
+ - consumer: beta
137
+ contract: alpha-contract
138
+ reason: quarantine
139
+ `;
140
+ const root = await makeSystemRepo(files);
141
+ const { map } = await loadSystemMap(root, resolveIo());
142
+ expect(edgeVerdict(map!, "beta", "alpha-contract")).toBe("forbidden");
143
+ });
144
+
145
+ it("a valid repository passes with exit 0", async () => {
146
+ const root = await makeSystemRepo(validMapFiles());
147
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
148
+ expect(result.exitCode).toBe(0);
149
+ expect(result.data?.systemId).toBe("demo-system");
150
+ expect(result.data?.products).toBe(2);
151
+ });
152
+
153
+ it("missing map files report SYSTEM-MAP-01 without throwing", async () => {
154
+ const root = await makeSystemRepo();
155
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
156
+ expect(result.exitCode).toBe(1);
157
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-01");
158
+ });
159
+
160
+ it("duplicate product ids report SYSTEM-MAP-02", async () => {
161
+ const files = validMapFiles();
162
+ files["system/products.yaml"] = `schema: forge/system-products@1
163
+ products:
164
+ - id: alpha
165
+ remote: https://example.invalid/a.git
166
+ offers: [alpha-contract]
167
+ - id: alpha
168
+ remote: https://example.invalid/b.git
169
+ offers: []
170
+ `;
171
+ const root = await makeSystemRepo(files);
172
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
173
+ expect(result.exitCode).toBe(1);
174
+ const diags = result.data?.diagnostics ?? [];
175
+ expect(diags.find((d) => d.ruleId === "SYSTEM-MAP-02")?.message).toContain("duplicate");
176
+ });
177
+
178
+ it("schema-invalid files report SYSTEM-MAP-01 — unknown keys and missing forbidden reason", async () => {
179
+ const files = validMapFiles();
180
+ files["system/edges.yaml"] = `schema: forge/system-edges@1
181
+ allowed:
182
+ - consumer: beta
183
+ contract: alpha-contract
184
+ bogus: key
185
+ forbidden:
186
+ - consumer: beta
187
+ contract: alpha-contract
188
+ `;
189
+ const root = await makeSystemRepo(files);
190
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
191
+ expect(result.exitCode).toBe(1);
192
+ const diags = result.data?.diagnostics ?? [];
193
+ expect(ruleIds(diags)).toContain("SYSTEM-MAP-01");
194
+ expect(diags.every((d) => d.severity === "error")).toBe(true);
195
+ });
196
+
197
+ it("SYSTEM-MAP-01 on a schema-invalid file leaves the map unloaded (no cross-checks)", async () => {
198
+ const files = validMapFiles();
199
+ files["system/products.yaml"] = "schema: forge/system-products@1\nproducts:\n - id: alpha\n";
200
+ const root = await makeSystemRepo(files);
201
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
202
+ expect(result.exitCode).toBe(1);
203
+ const diags = result.data?.diagnostics ?? [];
204
+ expect(diags.map((d) => d.ruleId)).toEqual(["SYSTEM-MAP-01"]);
205
+ });
206
+
207
+ it("SYSTEM-MAP-05 warns when a mapped folder does not exist", async () => {
208
+ const files = validMapFiles();
209
+ files["system/products.local.yaml"] = `schema: forge/system-products-local@1
210
+ folders:
211
+ alpha: ./alpha
212
+ beta: ./missing-beta
213
+ `;
214
+ const root = await makeSystemRepo(files);
215
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
216
+ expect(result.exitCode).toBe(0);
217
+ const warning = result.data?.diagnostics.find((d) => d.ruleId === "SYSTEM-MAP-05");
218
+ expect(warning?.message).toContain("missing-beta");
219
+ });
220
+
221
+ it("a malformed products.local.yaml is SYSTEM-MAP-01, not a throw", async () => {
222
+ const files = validMapFiles();
223
+ files["system/products.local.yaml"] = "schema: forge/system-products-local@1\nfolders: [not-a-map\n";
224
+ const root = await makeSystemRepo(files);
225
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
226
+ expect(result.exitCode).toBe(1);
227
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-01");
228
+ });
229
+
230
+ it("the extended forbidden-edge schema stays strict about unknown keys", () => {
231
+ const parse = systemEdgesSchema.safeParse({
232
+ schema: "forge/system-edges@1",
233
+ forbidden: [
234
+ { consumer: "beta", contract: "alpha-contract", reason: "deprecated", bogus: "key" },
235
+ ],
236
+ });
237
+ expect(parse.success).toBe(false);
238
+ });
239
+
240
+ it("AC-9: a scenario naming an unknown product reports SYSTEM-MAP-06", async () => {
241
+ const files = validMapFiles();
242
+ files["system/scenarios/lead-flow.yaml"] = `schema: forge/system-scenario@1
243
+ id: lead-flow
244
+ title: lead flow
245
+ products: [ghost]
246
+ contracts: []
247
+ checks:
248
+ - product: ghost
249
+ argv: [node, -e, "console.log('x')"]
250
+ `;
251
+ const root = await makeSystemRepo(files);
252
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
253
+ expect(result.exitCode).toBe(1);
254
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-06");
255
+ });
256
+
257
+ it("AC-9: a scenario naming a contract no product offers reports SYSTEM-MAP-06", async () => {
258
+ const files = validMapFiles();
259
+ files["system/scenarios/lead-flow.yaml"] = `schema: forge/system-scenario@1
260
+ id: lead-flow
261
+ title: lead flow
262
+ products: [alpha]
263
+ contracts: [ghost-contract]
264
+ checks:
265
+ - product: alpha
266
+ argv: [node, -e, "console.log('x')"]
267
+ `;
268
+ const root = await makeSystemRepo(files);
269
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
270
+ expect(result.exitCode).toBe(1);
271
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-06");
272
+ });
273
+
274
+ it("a malformed scenario file reports SYSTEM-MAP-01 like any map file", async () => {
275
+ const files = validMapFiles();
276
+ files["system/scenarios/broken.yaml"] = "schema: forge/system-scenario@1\nid: [not-a-string\n";
277
+ const root = await makeSystemRepo(files);
278
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
279
+ expect(result.exitCode).toBe(1);
280
+ expect(ruleIds(result.data?.diagnostics ?? [])).toContain("SYSTEM-MAP-01");
281
+ });
282
+
283
+ it("a valid scenario adds no diagnostics", async () => {
284
+ const files = validMapFiles();
285
+ files["system/scenarios/lead-flow.yaml"] = `schema: forge/system-scenario@1
286
+ id: lead-flow
287
+ title: lead flow
288
+ products: [alpha]
289
+ contracts: [alpha-contract]
290
+ checks:
291
+ - product: alpha
292
+ argv: [node, -e, "console.log('x')"]
293
+ `;
294
+ const root = await makeSystemRepo(files);
295
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
296
+ expect(result.data?.diagnostics.every((d) => d.ruleId !== "SYSTEM-MAP-06")).toBe(true);
297
+ });
298
+
299
+ it("a product id colliding with Object.prototype keys still gets the unmapped-folder warning", async () => {
300
+ const files = validMapFiles();
301
+ files["system/products.yaml"] = `schema: forge/system-products@1
302
+ products:
303
+ - id: alpha
304
+ remote: git@example.com:org/alpha.git
305
+ offers: [alpha-contract]
306
+ - id: beta
307
+ remote: git@example.com:org/beta.git
308
+ offers: []
309
+ - id: constructor
310
+ remote: git@example.com:org/constructor.git
311
+ offers: []
312
+ `;
313
+ const root = await makeSystemRepo(files);
314
+ const result = await runSystemMapValidate({ argv: [], flags: {} }, makeContext(root));
315
+ expect(result.exitCode).toBe(0);
316
+ const warning = result.data?.diagnostics.find(
317
+ (d) => d.ruleId === "SYSTEM-MAP-05" && d.message.includes("constructor"),
318
+ );
319
+ expect(warning).toBeDefined();
320
+ });
321
+ });
@@ -0,0 +1,273 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Tests for system.outbox.scan (RFC-1510): committed open entries
4
+ produce proposals (AC-5), worktree-only entries stay invisible (AC-6),
5
+ --create deduplicates by origin (AC-7) with proposed state (AC-8), forbidden
6
+ edges create nothing (AC-9) and a product forge.yaml naming the system id
7
+ reports SYSTEM-OUTBOX-03 (AC-10).</purpose>
8
+ <non-goals><item>Entry-file validation coverage lives in outbox-validate.test.ts.</item></non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1510: step 1 — system.outbox.scan tests</item>
12
+ <item>RFC-1510: implement RFC-1510 — product outbox for dependency-contract requests</item>
13
+ <item>RFC-1510: close RFC-1510 review r1 findings — folder crash guard, ls-tree allowlist, OUTBOX-02 on develop</item>
14
+ <item>RFC-1510: close RFC-1510 review r2 — declare OUTBOX-02 in scan rules, flat-scope test, readdir TOCTOU guard</item>
15
+ </CHANGE_SUMMARY>
16
+ */
17
+
18
+ // @vitest-environment node
19
+
20
+ import { describe, expect, it } from "vitest";
21
+ import { mkdir, writeFile } from "node:fs/promises";
22
+ import os from "node:os";
23
+ import path from "node:path";
24
+
25
+ import { gitExec } from "../../flow/tests/helpers.ts";
26
+ import { runSystemOutboxScan } from "../handlers/system-outbox-scan.ts";
27
+ import { listTasks } from "../task-store.ts";
28
+ import { resolveIo } from "../../../src/utils/io.ts";
29
+ import {
30
+ localMapFor,
31
+ makeContext,
32
+ makeProduct,
33
+ makeSystemRepo,
34
+ VALID_EDGES_YAML,
35
+ VALID_PRODUCTS_YAML,
36
+ VALID_SYSTEM_YAML,
37
+ } from "./helpers.ts";
38
+
39
+ function input(flags: Record<string, string | string[] | boolean> = {}) {
40
+ return { argv: [], flags };
41
+ }
42
+
43
+ const ENTRY = (id: string, contract = "alpha-contract") => `schema: forge/outbox@1
44
+ id: ${id}
45
+ contract: ${contract}
46
+ need: "a stable surface"
47
+ why: "beta composes it"
48
+ state: open
49
+ `;
50
+
51
+ interface Fixture {
52
+ systemRoot: string;
53
+ alpha: string;
54
+ beta: string;
55
+ }
56
+
57
+ /** System repo + two governed products; beta = asker, alpha = offerer. */
58
+ async function fixture(edges = VALID_EDGES_YAML): Promise<Fixture> {
59
+ const alpha = await makeProduct();
60
+ const beta = await makeProduct();
61
+ const systemRoot = await makeSystemRepo({
62
+ "system/system.yaml": VALID_SYSTEM_YAML,
63
+ "system/products.yaml": VALID_PRODUCTS_YAML,
64
+ "system/edges.yaml": edges,
65
+ "system/products.local.yaml": localMapFor({ alpha, beta }),
66
+ });
67
+ return { systemRoot, alpha, beta };
68
+ }
69
+
70
+ /** Commit a file into a product's develop checkout. */
71
+ async function commitFile(repo: string, rel: string, content: string): Promise<void> {
72
+ const abs = path.join(repo, rel);
73
+ await mkdir(path.dirname(abs), { recursive: true });
74
+ await writeFile(abs, content);
75
+ await gitExec(repo, ["add", rel]);
76
+ const res = await gitExec(repo, ["commit", "-m", `add ${rel}`]);
77
+ if (res.exitCode !== 0) throw new Error(`fixture commit failed: ${res.stderr}`);
78
+ }
79
+
80
+ describe("system.outbox.scan", () => {
81
+ it("AC-5: a committed open entry proposes the offering product as target", async () => {
82
+ const { systemRoot, beta } = await fixture();
83
+ await commitFile(beta, "docs/outbox/OB-0001.yaml", ENTRY("OB-0001"));
84
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
85
+ expect(result.exitCode).toBe(0);
86
+ const [p] = result.data!.proposals;
87
+ expect(p).toMatchObject({
88
+ product: "beta",
89
+ entry: "OB-0001",
90
+ contract: "alpha-contract",
91
+ target: "alpha",
92
+ verdict: "allowed",
93
+ taskId: null,
94
+ });
95
+ });
96
+
97
+ it("AC-6: an entry living only in a dirty worktree is not listed", async () => {
98
+ const { systemRoot, beta } = await fixture();
99
+ await commitFile(beta, "docs/outbox/OB-0001.yaml", ENTRY("OB-0001"));
100
+ // A second entry exists only as an uncommitted worktree file.
101
+ const dirty = path.join(beta, "docs/outbox/OB-0002.yaml");
102
+ await mkdir(path.dirname(dirty), { recursive: true });
103
+ await writeFile(dirty, ENTRY("OB-0002"));
104
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
105
+ const entries = result.data!.proposals.map((p) => p.entry);
106
+ expect(entries).toEqual(["OB-0001"]);
107
+ });
108
+
109
+ it("AC-7+AC-8: --create proposes one task per entry, in state proposed", async () => {
110
+ const { systemRoot, beta } = await fixture();
111
+ await commitFile(beta, "docs/outbox/OB-0001.yaml", ENTRY("OB-0001"));
112
+
113
+ const first = await runSystemOutboxScan(input({ create: true }), makeContext(systemRoot));
114
+ expect(first.exitCode).toBe(0);
115
+ expect(first.data!.created).toEqual(["T-0001"]);
116
+ expect(first.data!.proposals[0].taskId).toBe("T-0001");
117
+
118
+ const second = await runSystemOutboxScan(input({ create: true }), makeContext(systemRoot));
119
+ expect(second.exitCode).toBe(0);
120
+ expect(second.data!.created).toEqual([]);
121
+ expect(second.data!.proposals[0].taskId).toBe("T-0001");
122
+
123
+ const io = resolveIo(undefined);
124
+ const { tasks } = await listTasks(systemRoot, io);
125
+ expect(tasks).toHaveLength(1);
126
+ expect(tasks[0]).toMatchObject({
127
+ id: "T-0001",
128
+ product: "alpha",
129
+ slug: "ob-0001",
130
+ state: "proposed",
131
+ origin: { kind: "outbox", ref: "beta:OB-0001" },
132
+ contracts: ["alpha-contract"],
133
+ });
134
+ });
135
+
136
+ it("AC-9: a forbidden edge creates no task and refuses the scan", async () => {
137
+ const { systemRoot, beta } = await fixture(
138
+ `schema: forge/system-edges@1
139
+ allowed: []
140
+ forbidden:
141
+ - consumer: beta
142
+ contract: alpha-contract
143
+ reason: "beta must not consume it"
144
+ `,
145
+ );
146
+ await commitFile(beta, "docs/outbox/OB-0001.yaml", ENTRY("OB-0001"));
147
+ const result = await runSystemOutboxScan(input({ create: true }), makeContext(systemRoot));
148
+ expect(result.exitCode).toBe(1);
149
+ expect(result.data!.diagnostics.some((d) => d.ruleId === "SYSTEM-OUTBOX-02")).toBe(true);
150
+ expect(result.data!.created).toEqual([]);
151
+
152
+ const io = resolveIo(undefined);
153
+ const { tasks } = await listTasks(systemRoot, io);
154
+ expect(tasks).toHaveLength(0);
155
+ });
156
+
157
+ it("AC-10: a product forge.yaml naming the system id reports SYSTEM-OUTBOX-03", async () => {
158
+ const { systemRoot, alpha, beta } = await fixture();
159
+ await commitFile(
160
+ alpha,
161
+ "forge.yaml",
162
+ 'schema: "forge/workspace@1"\n# adopted from demo-system\n',
163
+ );
164
+ await commitFile(beta, "docs/outbox/OB-0001.yaml", ENTRY("OB-0001"));
165
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
166
+ expect(result.exitCode).toBe(0);
167
+ expect(
168
+ result.data!.diagnostics.some(
169
+ (d) => d.ruleId === "SYSTEM-OUTBOX-03" && d.message.includes("alpha"),
170
+ ),
171
+ ).toBe(true);
172
+ });
173
+
174
+ it("a product without a local folder is warned and skipped (SYSTEM-OUTBOX-04)", async () => {
175
+ const beta = await makeProduct();
176
+ const systemRoot = await makeSystemRepo({
177
+ "system/system.yaml": VALID_SYSTEM_YAML,
178
+ "system/products.yaml": VALID_PRODUCTS_YAML,
179
+ "system/edges.yaml": VALID_EDGES_YAML,
180
+ "system/products.local.yaml": localMapFor({ beta }),
181
+ });
182
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
183
+ expect(result.exitCode).toBe(0);
184
+ expect(
185
+ result.data!.diagnostics.some(
186
+ (d) => d.ruleId === "SYSTEM-OUTBOX-04" && d.message.includes("alpha"),
187
+ ),
188
+ ).toBe(true);
189
+ });
190
+
191
+ it("SYSTEM-OUTBOX-01: an unmatched contract proposes target null", async () => {
192
+ const { systemRoot, beta } = await fixture();
193
+ await commitFile(beta, "docs/outbox/OB-0007.yaml", ENTRY("OB-0007", "ghost-contract"));
194
+ const result = await runSystemOutboxScan(input({ create: true }), makeContext(systemRoot));
195
+ expect(result.exitCode).toBe(0);
196
+ expect(result.data!.proposals[0]).toMatchObject({ target: null });
197
+ expect(result.data!.diagnostics.some((d) => d.ruleId === "SYSTEM-OUTBOX-01")).toBe(true);
198
+ expect(result.data!.created).toEqual([]);
199
+ });
200
+
201
+ it("a stale products.local.yaml folder warns SYSTEM-OUTBOX-04 instead of crashing", async () => {
202
+ const systemRoot = await makeSystemRepo({
203
+ "system/system.yaml": VALID_SYSTEM_YAML,
204
+ "system/products.yaml": VALID_PRODUCTS_YAML,
205
+ "system/edges.yaml": VALID_EDGES_YAML,
206
+ "system/products.local.yaml": localMapFor({
207
+ alpha: path.join(os.tmpdir(), "definitely-missing-alpha"),
208
+ beta: path.join(os.tmpdir(), "definitely-missing-beta"),
209
+ }),
210
+ });
211
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
212
+ expect(result.exitCode).toBe(0);
213
+ expect(
214
+ result.data!.diagnostics.filter((d) => d.ruleId === "SYSTEM-OUTBOX-04"),
215
+ ).toHaveLength(2);
216
+ });
217
+
218
+ it("a committed entry whose id differs from its filename stem refuses OUTBOX-02", async () => {
219
+ const { systemRoot, beta } = await fixture();
220
+ await commitFile(beta, "docs/outbox/OB-0009.yaml", ENTRY("OB-0001"));
221
+ const result = await runSystemOutboxScan(input({ create: true }), makeContext(systemRoot));
222
+ expect(result.exitCode).toBe(1);
223
+ expect(result.data!.diagnostics.some((d) => d.ruleId === "OUTBOX-02")).toBe(true);
224
+ expect(result.data!.proposals).toEqual([]);
225
+ });
226
+
227
+ it("a committed malformed entry refuses OUTBOX-01", async () => {
228
+ const { systemRoot, beta } = await fixture();
229
+ await commitFile(
230
+ beta,
231
+ "docs/outbox/OB-0001.yaml",
232
+ ENTRY("OB-0001").replace("state: open", "state: bogus"),
233
+ );
234
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
235
+ expect(result.exitCode).toBe(1);
236
+ expect(result.data!.diagnostics.some((d) => d.ruleId === "OUTBOX-01")).toBe(true);
237
+ });
238
+
239
+ it("an outbox entry naming the system id reports SYSTEM-OUTBOX-03", async () => {
240
+ const { systemRoot, beta } = await fixture();
241
+ await commitFile(
242
+ beta,
243
+ "docs/outbox/OB-0001.yaml",
244
+ ENTRY("OB-0001").replace('why: "beta composes it"', 'why: "serve demo-system"'),
245
+ );
246
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
247
+ expect(
248
+ result.data!.diagnostics.some(
249
+ (d) => d.ruleId === "SYSTEM-OUTBOX-03" && d.message.includes("OB-0001"),
250
+ ),
251
+ ).toBe(true);
252
+ });
253
+
254
+ it("entries nested below docs/outbox/ are out of scope — the scan is flat like outbox.validate", async () => {
255
+ const { systemRoot, beta } = await fixture();
256
+ await commitFile(beta, "docs/outbox/sub/OB-0002.yaml", ENTRY("OB-0002"));
257
+ const result = await runSystemOutboxScan(input({ create: true }), makeContext(systemRoot));
258
+ expect(result.exitCode).toBe(0);
259
+ expect(result.data!.proposals).toEqual([]);
260
+ expect(result.data!.created).toEqual([]);
261
+ });
262
+
263
+ it("served or withdrawn entries are skipped", async () => {
264
+ const { systemRoot, beta } = await fixture();
265
+ await commitFile(
266
+ beta,
267
+ "docs/outbox/OB-0001.yaml",
268
+ ENTRY("OB-0001").replace("state: open", "state: served"),
269
+ );
270
+ const result = await runSystemOutboxScan(input(), makeContext(systemRoot));
271
+ expect(result.data!.proposals).toEqual([]);
272
+ });
273
+ });
@@ -0,0 +1,90 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Acceptance tests for the system stack profile (RFC-1508 AC-7..AC-10):
4
+ forge create --in-place --profile system scaffolds a repository that carries the
5
+ system map, ignores products.local.yaml and passes system.map.validate; the
6
+ profile file itself satisfies the stack-profile schema.</purpose>
7
+ <non-goals>
8
+ <item>Fixtures are minimal scaffolding — forge.create owns the contract.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1508: step 4 — system profile acceptance tests (AC-7..AC-10)</item>
13
+ <item>RFC-1508: implement RFC-1508 — system profile, system map schemas and system.map.validate</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+
17
+ // @vitest-environment node
18
+
19
+ import { execFileSync } from "node:child_process";
20
+ import { existsSync, readFileSync } from "node:fs";
21
+ import { mkdtemp } from "node:fs/promises";
22
+ import os from "node:os";
23
+ import path from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+
26
+ import { describe, expect, it } from "vitest";
27
+
28
+ import { runCreate } from "../../../src/onboarding/create.ts";
29
+ import { loadStackProfile, listStackProfiles } from "../../../src/profiles/stack-profile.ts";
30
+ import type { ForgeRuntimeContext } from "../../../src/types.ts";
31
+ import { runSystemMapValidate } from "../handlers/system-map-validate.ts";
32
+
33
+ const FORGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
34
+
35
+ function createContext(root: string): ForgeRuntimeContext {
36
+ const sink = (_msg: string, _details?: unknown): void => {};
37
+ return {
38
+ workspaceRoot: root,
39
+ forgeRoot: FORGE_ROOT,
40
+ logger: { section: sink, info: sink, warn: sink, error: sink, success: sink },
41
+ dryRun: false,
42
+ outputFormat: "json",
43
+ };
44
+ }
45
+
46
+ describe("system profile (forge create)", () => {
47
+ it("AC-7..AC-9: create produces a map-bearing repo that ignores local file and validates", async () => {
48
+ const root = await mkdtemp(path.join(os.tmpdir(), "forge-system-create-"));
49
+ const result = await runCreate(
50
+ {
51
+ argv: [],
52
+ flags: { "in-place": true, profile: "system", name: "demo-system", "no-flow": true },
53
+ },
54
+ createContext(root),
55
+ );
56
+ expect(result.exitCode).toBe(0);
57
+
58
+ // AC-7: the scaffolded map exists and declares the project
59
+ const systemYaml = path.join(root, "system", "system.yaml");
60
+ expect(existsSync(systemYaml)).toBe(true);
61
+ expect(readFileSync(systemYaml, "utf8")).toContain("schema: forge/system@1");
62
+ expect(readFileSync(path.join(root, "system", "products.yaml"), "utf8")).toContain(
63
+ "forge/system-products@1",
64
+ );
65
+ expect(readFileSync(path.join(root, "system", "edges.yaml"), "utf8")).toContain(
66
+ "forge/system-edges@1",
67
+ );
68
+
69
+ // AC-8: products.local.yaml is git-ignored
70
+ const gitignore = readFileSync(path.join(root, ".gitignore"), "utf8");
71
+ expect(gitignore).toContain("system/products.local.yaml");
72
+ expect(() =>
73
+ execFileSync("git", ["check-ignore", "system/products.local.yaml"], { cwd: root }),
74
+ ).not.toThrow();
75
+
76
+ // AC-9: the freshly created repository passes system.map.validate
77
+ const validate = await runSystemMapValidate({ argv: [], flags: {} }, createContext(root));
78
+ expect(validate.exitCode).toBe(0);
79
+ expect(validate.data?.systemId).toBe("demo-system");
80
+ });
81
+
82
+ it("AC-10: profiles/system.yaml satisfies the stack-profile schema with a unique id", () => {
83
+ const profile = loadStackProfile(path.join(FORGE_ROOT, "profiles", "system.yaml"));
84
+ expect(profile.id).toBe("system");
85
+ expect(profile.workspace.dirs).toContain("system");
86
+ expect(profile.workspace.dirs).not.toContain("missions");
87
+ const ids = listStackProfiles(FORGE_ROOT).map((p) => p.id);
88
+ expect(ids.filter((id) => id === "system")).toHaveLength(1);
89
+ });
90
+ });