@intentius/chant 0.124.85 → 0.124.87

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 (286) hide show
  1. package/dist/bundle-check.d.ts +102 -0
  2. package/dist/bundle-check.d.ts.map +1 -0
  3. package/dist/bundle-check.js +310 -0
  4. package/dist/chant-install.d.ts +100 -0
  5. package/dist/chant-install.d.ts.map +1 -0
  6. package/dist/chant-install.js +158 -0
  7. package/dist/ci-commit.d.ts +19 -6
  8. package/dist/ci-commit.d.ts.map +1 -1
  9. package/dist/ci-commit.js +23 -4
  10. package/dist/ci-evidence-jobs.d.ts +78 -0
  11. package/dist/ci-evidence-jobs.d.ts.map +1 -0
  12. package/dist/ci-evidence-jobs.js +85 -0
  13. package/dist/ci-image.d.ts +274 -0
  14. package/dist/ci-image.d.ts.map +1 -0
  15. package/dist/ci-image.js +635 -0
  16. package/dist/ci-login.d.ts +150 -0
  17. package/dist/ci-login.d.ts.map +1 -0
  18. package/dist/ci-login.js +240 -0
  19. package/dist/ci-product.d.ts +16 -0
  20. package/dist/ci-product.d.ts.map +1 -1
  21. package/dist/ci-product.js +17 -0
  22. package/dist/cli/commands/import-index.js +2 -2
  23. package/dist/cli/handlers/build.d.ts +8 -0
  24. package/dist/cli/handlers/build.d.ts.map +1 -1
  25. package/dist/cli/handlers/build.js +22 -4
  26. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  27. package/dist/cli/handlers/ci-check.js +61 -2
  28. package/dist/cli/handlers/ci-evidence.d.ts +3 -0
  29. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
  30. package/dist/cli/handlers/ci-evidence.js +174 -0
  31. package/dist/cli/handlers/components.js +3 -3
  32. package/dist/cli/handlers/dead-guards.d.ts +3 -0
  33. package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
  34. package/dist/cli/handlers/dead-guards.js +35 -0
  35. package/dist/cli/handlers/graph.js +4 -4
  36. package/dist/cli/handlers/lifecycle.d.ts +2 -1
  37. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  38. package/dist/cli/handlers/lifecycle.js +5 -4
  39. package/dist/cli/handlers/local-chant.d.ts +16 -0
  40. package/dist/cli/handlers/local-chant.d.ts.map +1 -0
  41. package/dist/cli/handlers/local-chant.js +109 -0
  42. package/dist/cli/handlers/operator.js +2 -2
  43. package/dist/cli/handlers/search.js +5 -5
  44. package/dist/cli/main.d.ts.map +1 -1
  45. package/dist/cli/main.js +38 -0
  46. package/dist/cli/parse-args.d.ts.map +1 -1
  47. package/dist/cli/parse-args.js +28 -0
  48. package/dist/cli/registry.d.ts +16 -0
  49. package/dist/cli/registry.d.ts.map +1 -1
  50. package/dist/components/check-hooks.d.ts +49 -0
  51. package/dist/components/check-hooks.d.ts.map +1 -1
  52. package/dist/components/check-hooks.js +64 -4
  53. package/dist/components/check-steps.d.ts +17 -0
  54. package/dist/components/check-steps.d.ts.map +1 -1
  55. package/dist/components/check-steps.js +37 -5
  56. package/dist/components/product-pipeline.d.ts +23 -0
  57. package/dist/components/product-pipeline.d.ts.map +1 -1
  58. package/dist/components/product-pipeline.js +6 -2
  59. package/dist/components/product-plan.d.ts +143 -0
  60. package/dist/components/product-plan.d.ts.map +1 -0
  61. package/dist/components/product-plan.js +145 -0
  62. package/dist/components/release-compile.d.ts.map +1 -1
  63. package/dist/components/release-compile.js +2 -2
  64. package/dist/config.d.ts +39 -1
  65. package/dist/config.d.ts.map +1 -1
  66. package/dist/config.js +35 -3
  67. package/dist/dead-guards.d.ts +82 -0
  68. package/dist/dead-guards.d.ts.map +1 -0
  69. package/dist/dead-guards.js +436 -0
  70. package/dist/discovery/files.d.ts +3 -1
  71. package/dist/discovery/files.d.ts.map +1 -1
  72. package/dist/discovery/files.js +5 -3
  73. package/dist/drift-issue.d.ts +152 -0
  74. package/dist/drift-issue.d.ts.map +1 -0
  75. package/dist/drift-issue.js +167 -0
  76. package/dist/floor-table.d.ts +30 -0
  77. package/dist/floor-table.d.ts.map +1 -0
  78. package/dist/floor-table.data.d.ts +3 -0
  79. package/dist/floor-table.data.d.ts.map +1 -0
  80. package/dist/floor-table.data.js +179 -0
  81. package/dist/floor-table.js +56 -0
  82. package/dist/forge-flags.d.ts +90 -0
  83. package/dist/forge-flags.d.ts.map +1 -0
  84. package/dist/forge-flags.js +184 -0
  85. package/dist/lexicon.d.ts +69 -0
  86. package/dist/lexicon.d.ts.map +1 -1
  87. package/dist/lifecycle/gated-op.d.ts +7 -1
  88. package/dist/lifecycle/gated-op.d.ts.map +1 -1
  89. package/dist/lifecycle/gated-op.js +7 -4
  90. package/dist/local-chant.d.ts +98 -0
  91. package/dist/local-chant.d.ts.map +1 -0
  92. package/dist/local-chant.js +307 -0
  93. package/dist/op/activities/predict-behaviour.js +2 -2
  94. package/dist/op/op-waves-evidence-spec.d.ts +13 -0
  95. package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
  96. package/dist/op/op-waves-evidence-spec.js +21 -0
  97. package/dist/op/op-waves-evidence.d.ts +40 -0
  98. package/dist/op/op-waves-evidence.d.ts.map +1 -0
  99. package/dist/op/op-waves-evidence.js +58 -0
  100. package/dist/op/op-waves-run.d.ts +4 -0
  101. package/dist/op/op-waves-run.d.ts.map +1 -1
  102. package/dist/op/op-waves-run.js +24 -1
  103. package/dist/op/op-waves.d.ts +17 -1
  104. package/dist/op/op-waves.d.ts.map +1 -1
  105. package/dist/op/op-waves.js +23 -0
  106. package/dist/op/schedule-overdue.d.ts +41 -9
  107. package/dist/op/schedule-overdue.d.ts.map +1 -1
  108. package/dist/op/schedule-overdue.js +154 -25
  109. package/dist/plan-summary.d.ts +25 -0
  110. package/dist/plan-summary.d.ts.map +1 -1
  111. package/dist/plan-summary.js +31 -0
  112. package/dist/pr-plan-note.d.ts +35 -0
  113. package/dist/pr-plan-note.d.ts.map +1 -1
  114. package/dist/pr-plan-note.js +10 -0
  115. package/dist/pr-post.d.ts +23 -0
  116. package/dist/pr-post.d.ts.map +1 -1
  117. package/dist/pr-post.js +125 -3
  118. package/dist/release-floors.d.ts +33 -1
  119. package/dist/release-floors.d.ts.map +1 -1
  120. package/dist/release-floors.js +33 -1
  121. package/dist/state-migration.d.ts +24 -0
  122. package/dist/state-migration.d.ts.map +1 -1
  123. package/dist/state-migration.js +100 -5
  124. package/dist/wave-runtime.mjs +309 -302
  125. package/dist/workspace/ci-green.d.ts.map +1 -1
  126. package/dist/workspace/ci-green.js +4 -3
  127. package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
  128. package/dist/workspace/lexicon-outputs.js +21 -7
  129. package/dist/workspace/reason-codes.d.ts +3 -0
  130. package/dist/workspace/reason-codes.d.ts.map +1 -1
  131. package/dist/workspace/reason-codes.js +4 -0
  132. package/dist/workspace/ref-gate.schema.json +85 -0
  133. package/dist/workspace/search-contract.d.ts +1 -1
  134. package/dist/workspace/search-contract.d.ts.map +1 -1
  135. package/dist/workspace/trust/check-evidence-report.d.ts +58 -0
  136. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
  137. package/dist/workspace/trust/check-evidence-report.js +109 -0
  138. package/dist/workspace/trust/check-evidence.d.ts +160 -0
  139. package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
  140. package/dist/workspace/trust/check-evidence.js +309 -0
  141. package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
  142. package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
  143. package/dist/workspace/trust/dsse.d.ts +40 -2
  144. package/dist/workspace/trust/dsse.d.ts.map +1 -1
  145. package/dist/workspace/trust/dsse.js +34 -2
  146. package/dist/workspace/trust/evidence.d.ts +2 -2
  147. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  148. package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
  149. package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
  150. package/dist/workspace/trust/keyless-fixture.js +161 -0
  151. package/dist/workspace/trust/keyless.d.ts +202 -0
  152. package/dist/workspace/trust/keyless.d.ts.map +1 -0
  153. package/dist/workspace/trust/keyless.js +488 -0
  154. package/dist/workspace/trust/local-evidence.d.ts +123 -0
  155. package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
  156. package/dist/workspace/trust/local-evidence.js +259 -0
  157. package/dist/workspace/trust/op-run-statement.d.ts +2 -2
  158. package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
  159. package/dist/workspace/trust/policy.d.ts +140 -1
  160. package/dist/workspace/trust/policy.d.ts.map +1 -1
  161. package/dist/workspace/trust/policy.js +197 -3
  162. package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
  163. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
  164. package/dist/workspace/trust/ref-gate-cli.js +234 -0
  165. package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
  166. package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
  167. package/dist/workspace/trust/ref-gate-fixture.js +97 -0
  168. package/dist/workspace/trust/ref-gate.d.ts +187 -0
  169. package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
  170. package/dist/workspace/trust/ref-gate.js +432 -0
  171. package/dist/workspace/trust/run-statement.d.ts +3 -3
  172. package/dist/workspace/trust/run-statement.d.ts.map +1 -1
  173. package/dist/workspace/trust/runner-identity.d.ts +56 -0
  174. package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
  175. package/dist/workspace/trust/runner-identity.js +65 -0
  176. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  177. package/dist/workspace/trust/trust-files.js +25 -1
  178. package/package.json +1 -1
  179. package/src/bundle-check.test.ts +140 -0
  180. package/src/bundle-check.ts +352 -0
  181. package/src/chant-install.test.ts +112 -0
  182. package/src/chant-install.ts +179 -0
  183. package/src/ci-commit.test.ts +45 -0
  184. package/src/ci-commit.ts +38 -4
  185. package/src/ci-evidence-jobs.ts +105 -0
  186. package/src/ci-image.test.ts +506 -0
  187. package/src/ci-image.ts +822 -0
  188. package/src/ci-login.test.ts +235 -0
  189. package/src/ci-login.ts +307 -0
  190. package/src/ci-product.ts +18 -0
  191. package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
  192. package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
  193. package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
  194. package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
  195. package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
  196. package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
  197. package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
  198. package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
  199. package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
  200. package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
  201. package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
  202. package/src/cli/commands/import-index.ts +2 -2
  203. package/src/cli/handlers/build-source-dir.test.ts +64 -0
  204. package/src/cli/handlers/build.ts +21 -4
  205. package/src/cli/handlers/ci-check.ts +60 -3
  206. package/src/cli/handlers/ci-evidence.ts +167 -0
  207. package/src/cli/handlers/components.ts +3 -3
  208. package/src/cli/handlers/dead-guards.ts +37 -0
  209. package/src/cli/handlers/graph.ts +4 -4
  210. package/src/cli/handlers/lifecycle.ts +5 -4
  211. package/src/cli/handlers/local-chant.ts +106 -0
  212. package/src/cli/handlers/operator.ts +2 -2
  213. package/src/cli/handlers/search.ts +5 -5
  214. package/src/cli/main.test.ts +7 -0
  215. package/src/cli/main.ts +38 -0
  216. package/src/cli/parse-args.ts +21 -0
  217. package/src/cli/registry.ts +16 -0
  218. package/src/components/check-evidence-stage.test.ts +80 -0
  219. package/src/components/check-hooks.ts +84 -4
  220. package/src/components/check-local-evidence-stage.test.ts +141 -0
  221. package/src/components/check-steps.ts +56 -6
  222. package/src/components/product-pipeline.ts +28 -3
  223. package/src/components/product-plan.test.ts +87 -0
  224. package/src/components/product-plan.ts +230 -0
  225. package/src/components/release-compile.ts +2 -2
  226. package/src/config.ts +44 -3
  227. package/src/dead-guards.test.ts +206 -0
  228. package/src/dead-guards.ts +446 -0
  229. package/src/discovery/files.ts +5 -3
  230. package/src/drift-issue-bundle.test.ts +31 -0
  231. package/src/drift-issue.test.ts +206 -0
  232. package/src/drift-issue.ts +274 -0
  233. package/src/fit-note.test.ts +44 -0
  234. package/src/floor-table.data.ts +181 -0
  235. package/src/floor-table.ts +77 -0
  236. package/src/forge-flags.test.ts +110 -0
  237. package/src/forge-flags.ts +208 -0
  238. package/src/gate-decision-bundle.test.ts +1 -0
  239. package/src/lexicon.ts +68 -0
  240. package/src/lifecycle/gated-op.ts +10 -5
  241. package/src/local-chant.e2e.test.ts +94 -0
  242. package/src/local-chant.test.ts +162 -0
  243. package/src/local-chant.ts +341 -0
  244. package/src/op/activities/predict-behaviour.ts +2 -2
  245. package/src/op/op-waves-evidence-spec.ts +24 -0
  246. package/src/op/op-waves-evidence.test.ts +130 -0
  247. package/src/op/op-waves-evidence.ts +58 -0
  248. package/src/op/op-waves-run.ts +25 -1
  249. package/src/op/op-waves.ts +31 -1
  250. package/src/op/schedule-overdue.test.ts +85 -0
  251. package/src/op/schedule-overdue.ts +162 -26
  252. package/src/plan-summary.ts +40 -0
  253. package/src/pr-plan-note.ts +34 -0
  254. package/src/pr-post-plan-note.test.ts +146 -0
  255. package/src/pr-post.ts +127 -3
  256. package/src/release-floors.ts +47 -1
  257. package/src/stage-hooks-bundle.test.ts +1 -0
  258. package/src/state-migration.test.ts +52 -1
  259. package/src/state-migration.ts +107 -5
  260. package/src/workspace/ci-green.ts +4 -3
  261. package/src/workspace/lexicon-outputs.ts +23 -6
  262. package/src/workspace/reason-codes.test.ts +3 -0
  263. package/src/workspace/reason-codes.ts +4 -0
  264. package/src/workspace/ref-gate.schema.json +85 -0
  265. package/src/workspace/trust/check-evidence-report.ts +115 -0
  266. package/src/workspace/trust/check-evidence.test.ts +133 -0
  267. package/src/workspace/trust/check-evidence.ts +327 -0
  268. package/src/workspace/trust/ci-tag-statement.ts +2 -2
  269. package/src/workspace/trust/dsse.ts +48 -4
  270. package/src/workspace/trust/evidence.ts +2 -2
  271. package/src/workspace/trust/keyless-fixture.ts +214 -0
  272. package/src/workspace/trust/keyless.test.ts +220 -0
  273. package/src/workspace/trust/keyless.ts +557 -0
  274. package/src/workspace/trust/local-evidence.test.ts +127 -0
  275. package/src/workspace/trust/local-evidence.ts +268 -0
  276. package/src/workspace/trust/op-run-statement.ts +2 -2
  277. package/src/workspace/trust/policy.ts +263 -3
  278. package/src/workspace/trust/ref-gate-cli.ts +244 -0
  279. package/src/workspace/trust/ref-gate-fixture.ts +125 -0
  280. package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
  281. package/src/workspace/trust/ref-gate.test.ts +247 -0
  282. package/src/workspace/trust/ref-gate.ts +539 -0
  283. package/src/workspace/trust/run-statement.ts +3 -3
  284. package/src/workspace/trust/runner-identity.ts +92 -0
  285. package/src/workspace/trust/trust-files.test.ts +22 -0
  286. package/src/workspace/trust/trust-files.ts +54 -1
@@ -0,0 +1,506 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { crc32, deflateRawSync, gzipSync } from "node:zlib";
7
+ import { describe, expect, test } from "vitest";
8
+ import {
9
+ CI_BASE_IMAGES,
10
+ CI_IMAGE_FLOOR,
11
+ CI_TOOL_DOCKER_ARCH,
12
+ CI_TOOL_SHA256,
13
+ CI_TOOLS,
14
+ checksumFor,
15
+ ciToolBin,
16
+ ciToolFetchScript,
17
+ ciToolInstallLine,
18
+ ciToolRelease,
19
+ ciToolSha256,
20
+ derivedImageDockerfile,
21
+ dockerfileText,
22
+ installCiTool,
23
+ productImageDockerfile,
24
+ productImageStages,
25
+ unzipEntry,
26
+ type CiTool,
27
+ } from "./ci-image";
28
+ import { NEXT_RELEASE } from "./release-floors";
29
+
30
+ const tmp = (): string => mkdtempSync(join(tmpdir(), "ci-image-"));
31
+ const sha = (b: Uint8Array): string => createHash("sha256").update(b).digest("hex");
32
+
33
+ /** A ustar archive of `files`, gzipped, as a release's `.tar.gz` holds them. */
34
+ function tarGz(files: Record<string, string>): Uint8Array {
35
+ const blocks: Buffer[] = [];
36
+ for (const [name, text] of Object.entries(files)) {
37
+ const body = Buffer.from(text);
38
+ const h = Buffer.alloc(512);
39
+ h.write(name, 0, "utf-8");
40
+ h.write("0000755\0", 100);
41
+ h.write("0000000\0", 108);
42
+ h.write("0000000\0", 116);
43
+ h.write(body.length.toString(8).padStart(11, "0") + "\0", 124);
44
+ h.write("00000000000\0", 136);
45
+ h.write("0", 156);
46
+ h.write("ustar\0", 257);
47
+ h.write("00", 263);
48
+ h.fill(" ", 148, 156);
49
+ let sum = 0;
50
+ for (const b of h) sum += b;
51
+ h.write(sum.toString(8).padStart(6, "0") + "\0 ", 148);
52
+ blocks.push(h, body, Buffer.alloc((512 - (body.length % 512)) % 512));
53
+ }
54
+ blocks.push(Buffer.alloc(1024));
55
+ return gzipSync(Buffer.concat(blocks));
56
+ }
57
+
58
+ /** A zip of `files`, deflated, with a central directory, as a release's `.zip` holds them. */
59
+ function zip(files: Record<string, string>): Uint8Array {
60
+ const locals: Buffer[] = [];
61
+ const centrals: Buffer[] = [];
62
+ let offset = 0;
63
+ for (const [name, text] of Object.entries(files)) {
64
+ const raw = Buffer.from(text);
65
+ const data = deflateRawSync(raw);
66
+ const n = Buffer.from(name);
67
+ const local = Buffer.alloc(30);
68
+ local.writeUInt32LE(0x04034b50, 0);
69
+ local.writeUInt16LE(20, 4);
70
+ local.writeUInt16LE(8, 8);
71
+ local.writeUInt32LE(crc32(raw), 14);
72
+ local.writeUInt32LE(data.length, 18);
73
+ local.writeUInt32LE(raw.length, 22);
74
+ local.writeUInt16LE(n.length, 26);
75
+ const central = Buffer.alloc(46);
76
+ central.writeUInt32LE(0x02014b50, 0);
77
+ central.writeUInt16LE(20, 4);
78
+ central.writeUInt16LE(20, 6);
79
+ central.writeUInt16LE(8, 10);
80
+ central.writeUInt32LE(crc32(raw), 16);
81
+ central.writeUInt32LE(data.length, 20);
82
+ central.writeUInt32LE(raw.length, 24);
83
+ central.writeUInt16LE(n.length, 28);
84
+ central.writeUInt32LE(offset, 42);
85
+ locals.push(local, n, data);
86
+ centrals.push(central, n);
87
+ offset += 30 + n.length + data.length;
88
+ }
89
+ const cd = Buffer.concat(centrals);
90
+ const end = Buffer.alloc(22);
91
+ end.writeUInt32LE(0x06054b50, 0);
92
+ end.writeUInt16LE(Object.keys(files).length, 8);
93
+ end.writeUInt16LE(Object.keys(files).length, 10);
94
+ end.writeUInt32LE(cd.length, 12);
95
+ end.writeUInt32LE(offset, 16);
96
+ return Buffer.concat([...locals, cd, end]);
97
+ }
98
+
99
+ /** A download that serves `files` by URL and never reaches the network. */
100
+ function served(files: Record<string, Uint8Array | string>): { download: (url: string) => Promise<Uint8Array>; urls: string[] } {
101
+ const urls: string[] = [];
102
+ return {
103
+ urls,
104
+ download: async (url) => {
105
+ urls.push(url);
106
+ const f = files[url];
107
+ if (f === undefined) throw new Error(`${url}: HTTP 404`);
108
+ return typeof f === "string" ? Buffer.from(f) : f;
109
+ },
110
+ };
111
+ }
112
+
113
+ /**
114
+ * Runs a fetch script with a `curl` on PATH that serves files from a local
115
+ * directory by the URL's last segment, so the real shell check runs against
116
+ * fixtures and nothing reaches the network.
117
+ */
118
+ function runShell(script: string, fixtures: Record<string, Uint8Array | string>, env: Record<string, string> = {}): { status: number; stderr: string; urls: string[] } {
119
+ const dir = tmp();
120
+ const serve = join(dir, "serve");
121
+ const bin = join(dir, "bin");
122
+ mkdirSync(serve);
123
+ mkdirSync(bin);
124
+ for (const [name, body] of Object.entries(fixtures)) writeFileSync(join(serve, name), body);
125
+ const log = join(dir, "urls");
126
+ writeFileSync(
127
+ join(bin, "curl"),
128
+ `#!/bin/sh\n# curl -fsSLo <out> <url>\nprintf '%s\\n' "$3" >> "${log}"\nf="${serve}/$(basename "$3")"\n[ -f "$f" ] || { echo "curl: (22) 404 $3" >&2; exit 22; }\ncp "$f" "$2"\n`,
129
+ );
130
+ chmodSync(join(bin, "curl"), 0o755);
131
+ const r = spawnSync("sh", ["-c", `set -e; ${script}`], { env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, ...env }, encoding: "utf-8" });
132
+ return { status: r.status ?? -1, stderr: r.stderr, urls: existsSync(log) ? readFileSync(log, "utf-8").trim().split("\n") : [] };
133
+ }
134
+
135
+ describe("ciToolRelease", () => {
136
+ test("names each release file and its checksums file per architecture", () => {
137
+ expect(ciToolRelease("tofu", "1.13.1", "arm64")).toMatchObject({
138
+ url: "https://github.com/opentofu/opentofu/releases/download/v1.13.1/tofu_1.13.1_linux_arm64.tar.gz",
139
+ checksumsUrl: "https://github.com/opentofu/opentofu/releases/download/v1.13.1/tofu_1.13.1_SHA256SUMS",
140
+ layout: "tar.gz",
141
+ member: "tofu",
142
+ });
143
+ expect(ciToolRelease("terramate", "0.14.0", "amd64").asset).toBe("terramate_0.14.0_linux_x86_64.tar.gz");
144
+ expect(ciToolRelease("infracost", "0.10.45", "amd64").checksumsUrl).toBe("https://github.com/infracost/infracost/releases/download/v0.10.45/infracost-linux-amd64.tar.gz.sha256");
145
+ expect(ciToolRelease("pulumi", "3.272.0", "amd64").asset).toBe("pulumi-v3.272.0-linux-x64.tar.gz");
146
+ expect(ciToolRelease("aws-cli", "2.22.0", "arm64")).toMatchObject({ url: "https://awscli.amazonaws.com/awscli-exe-linux-aarch64-2.22.0.zip", bin: "aws", path: "v2/current/bin/aws" });
147
+ expect(ciToolRelease("aws-cli", "2.22.0", "arm64").checksumsUrl).toBeUndefined();
148
+ for (const tool of CI_TOOLS) expect(ciToolRelease(tool, "1.0.0", "amd64").url).toMatch(/^https:\/\//);
149
+ });
150
+
151
+ test("refuses a version that is not a release, and a tool chant does not know", () => {
152
+ expect(() => ciToolRelease("tofu", "1.13; rm -rf /", "amd64")).toThrow(/not a release version/);
153
+ expect(() => ciToolRelease("helm" as CiTool, "1.0.0", "amd64")).toThrow(/chant installs/);
154
+ });
155
+
156
+ test("the recorded sums are 64 hex digits for both architectures, and a caller's replace them", () => {
157
+ for (const [k, v] of Object.entries(CI_TOOL_SHA256)) {
158
+ expect(v, k).toMatch(/^[0-9a-f]{64}$/);
159
+ expect(CI_TOOL_SHA256[k.replace(/-(amd64|arm64)$/, (_m, a) => (a === "amd64" ? "-arm64" : "-amd64"))], k).toBeDefined();
160
+ }
161
+ expect(ciToolSha256("tofu", "1.13.1").amd64).toBe(CI_TOOL_SHA256["tofu-1.13.1-linux-amd64"]);
162
+ expect(ciToolSha256("tofu", "1.13.1", { arm64: "a".repeat(64) })).toEqual({ arm64: "a".repeat(64) });
163
+ expect(() => ciToolSha256("tofu", "1.13.1", { amd64: "nothex" })).toThrow(/64 lower-case hex/);
164
+ });
165
+
166
+ test("CI_IMAGE_FLOOR is the next release", () => {
167
+ expect(CI_IMAGE_FLOOR).toBe(NEXT_RELEASE);
168
+ });
169
+ });
170
+
171
+ describe("ciToolFetchScript against local fixtures", () => {
172
+ const archive = tarGz({ tofu: "#!/bin/sh\necho tofu\n" });
173
+ const sum = sha(archive);
174
+ const sums = (s: string) => `${s} tofu_1.13.1_linux_amd64.tar.gz\n${"0".repeat(64)} tofu_1.13.1_linux_arm64.tar.gz\n`;
175
+ const pin = { amd64: sum, arm64: "1".repeat(64) };
176
+
177
+ test("installs a release whose checksums file and recorded sha256 both match", () => {
178
+ const out = tmp();
179
+ const script = ciToolFetchScript("tofu", "1.13.1", { dir: `${out}/tofu-1.13.1`, arch: CI_TOOL_DOCKER_ARCH, sha256: pin, requirePin: true });
180
+ const r = runShell(script, { "tofu_1.13.1_linux_amd64.tar.gz": archive, "tofu_1.13.1_SHA256SUMS": sums(sum) }, { TARGETARCH: "amd64" });
181
+ expect(r.stderr).toBe("");
182
+ expect(r.status).toBe(0);
183
+ expect(readFileSync(`${out}/tofu-1.13.1/tofu`, "utf-8")).toContain("echo tofu");
184
+ expect(r.urls).toEqual([
185
+ "https://github.com/opentofu/opentofu/releases/download/v1.13.1/tofu_1.13.1_linux_amd64.tar.gz",
186
+ "https://github.com/opentofu/opentofu/releases/download/v1.13.1/tofu_1.13.1_SHA256SUMS",
187
+ ]);
188
+ });
189
+
190
+ test("fails a tampered archive", () => {
191
+ const out = tmp();
192
+ const script = ciToolFetchScript("tofu", "1.13.1", { dir: `${out}/d`, arch: CI_TOOL_DOCKER_ARCH, sha256: pin });
193
+ const tampered = tarGz({ tofu: "#!/bin/sh\necho evil\n" });
194
+ // The checksums file still lists the real sum, so the archive fails sha256sum.
195
+ const r = runShell(script, { "tofu_1.13.1_linux_amd64.tar.gz": tampered, "tofu_1.13.1_SHA256SUMS": sums(sum) }, { TARGETARCH: "amd64" });
196
+ expect(r.status).not.toBe(0);
197
+ expect(existsSync(`${out}/d/tofu`)).toBe(false);
198
+ });
199
+
200
+ test("fails a tampered checksums file that lists the tampered archive's sum", () => {
201
+ const out = tmp();
202
+ const script = ciToolFetchScript("tofu", "1.13.1", { dir: `${out}/d`, arch: CI_TOOL_DOCKER_ARCH, sha256: pin, checksumsUrl: '"$CHECKSUMS_URL"' });
203
+ const tampered = tarGz({ tofu: "#!/bin/sh\necho evil\n" });
204
+ const r = runShell(script, { "tofu_1.13.1_linux_amd64.tar.gz": tampered, "evil-sums": sums(sha(tampered)) }, { TARGETARCH: "amd64", CHECKSUMS_URL: "https://example.invalid/evil-sums" });
205
+ expect(r.status).toBe(1);
206
+ expect(r.stderr).toContain(`tofu 1.13.1: tofu_1.13.1_SHA256SUMS lists ${sha(tampered)} for tofu_1.13.1_linux_amd64.tar.gz; chant records ${sum}`);
207
+ expect(r.urls[1]).toBe("https://example.invalid/evil-sums");
208
+ expect(existsSync(`${out}/d/tofu`)).toBe(false);
209
+ });
210
+
211
+ test("fails an archive its checksums file does not list", () => {
212
+ const script = ciToolFetchScript("tofu", "1.13.1", { dir: `${tmp()}/d`, arch: CI_TOOL_DOCKER_ARCH, sha256: pin });
213
+ const r = runShell(script, { "tofu_1.13.1_linux_amd64.tar.gz": archive, "tofu_1.13.1_SHA256SUMS": "" }, { TARGETARCH: "amd64" });
214
+ expect(r.status).toBe(1);
215
+ expect(r.stderr).toContain("tofu_1.13.1_linux_amd64.tar.gz is not in tofu_1.13.1_SHA256SUMS");
216
+ });
217
+
218
+ test("fails an architecture chant has no build for", () => {
219
+ const script = ciToolFetchScript("tofu", "1.13.1", { dir: `${tmp()}/d`, arch: CI_TOOL_DOCKER_ARCH, sha256: pin });
220
+ const r = runShell(script, {}, { TARGETARCH: "riscv64" });
221
+ expect(r.status).toBe(1);
222
+ expect(r.stderr).toContain("chant fetches it for amd64 and arm64, not riscv64");
223
+ expect(r.urls).toEqual([]);
224
+ });
225
+
226
+ test("a release with no checksums file installs on its recorded sha256 alone, and fails another file", () => {
227
+ const binary = Buffer.from("#!/bin/sh\necho just\n");
228
+ const archiveJust = tarGz({ just: binary.toString() });
229
+ const out = tmp();
230
+ const script = ciToolFetchScript("just", "1.36.0", { dir: `${out}/d`, arch: CI_TOOL_DOCKER_ARCH, sha256: { amd64: sha(archiveJust), arm64: "2".repeat(64) } });
231
+ expect(script).not.toContain("sums");
232
+ expect(runShell(script, { "just-1.36.0-x86_64-unknown-linux-musl.tar.gz": archiveJust }, { TARGETARCH: "amd64" }).status).toBe(0);
233
+ expect(readFileSync(`${out}/d/just`, "utf-8")).toContain("echo just");
234
+ const r = runShell(script, { "just-1.36.0-aarch64-unknown-linux-musl.tar.gz": archiveJust }, { TARGETARCH: "arm64" });
235
+ expect(r.status).not.toBe(0);
236
+ });
237
+
238
+ test("a bare binary, and a zip's member, install as the command", () => {
239
+ const tg = Buffer.from("#!/bin/sh\necho terragrunt\n");
240
+ const out = tmp();
241
+ const s1 = ciToolFetchScript("terragrunt", "1.2.0", { dir: `${out}/tg`, arch: CI_TOOL_DOCKER_ARCH });
242
+ expect(runShell(s1, { terragrunt_linux_arm64: tg, SHA256SUMS: `${sha(tg)} *terragrunt_linux_arm64\n` }, { TARGETARCH: "arm64" }).status).toBe(0);
243
+ expect(readFileSync(`${out}/tg/terragrunt`, "utf-8")).toContain("echo terragrunt");
244
+
245
+ const z = zip({ terraform: "#!/bin/sh\necho terraform\n", "LICENSE.txt": "x" });
246
+ const s2 = ciToolFetchScript("terraform", "1.14.9", { dir: `${out}/tf`, arch: CI_TOOL_DOCKER_ARCH });
247
+ const r = runShell(s2, { "terraform_1.14.9_linux_amd64.zip": z, "terraform_1.14.9_SHA256SUMS": `${sha(z)} terraform_1.14.9_linux_amd64.zip\n` }, { TARGETARCH: "amd64" });
248
+ expect(r.stderr).toBe("");
249
+ expect(readFileSync(`${out}/tf/terraform`, "utf-8")).toContain("echo terraform");
250
+ });
251
+
252
+ test("a choudoufu checksums file names the file as ./<file>", () => {
253
+ const a = tarGz({ choudoufu: "#!/bin/sh\n" });
254
+ const out = tmp();
255
+ const s = ciToolFetchScript("choudoufu", "0.31.0", { dir: `${out}/c`, arch: CI_TOOL_DOCKER_ARCH, sha256: { amd64: sha(a), arm64: "3".repeat(64) } });
256
+ expect(runShell(s, { "choudoufu_v0.31.0_linux_amd64.tar.gz": a, SHA256SUMS: `${sha(a)} ./choudoufu_v0.31.0_linux_amd64.tar.gz\n` }, { TARGETARCH: "amd64" }).status).toBe(0);
257
+ });
258
+
259
+ test("refuses, before any shell, a release that needs a recorded sha256 it lacks", () => {
260
+ expect(() => ciToolFetchScript("act", "0.2.89", { dir: "/out/act" })).toThrow(/no recorded sha256 for act 0.2.89 on amd64 and arm64; act's release publishes no checksums file/);
261
+ expect(() => ciToolFetchScript("terragrunt", "1.2.0", { dir: "/out/tg", requirePin: true })).toThrow(/no recorded sha256 for terragrunt 1.2.0/);
262
+ expect(() => ciToolFetchScript("tofu", "1.13.1", { dir: "/out/x y" })).toThrow(/absolute path/);
263
+ });
264
+ });
265
+
266
+ describe("ciToolInstallLine", () => {
267
+ test("skips when the versioned directory holds the binary, else fetches, checks and links", () => {
268
+ const line = ciToolInstallLine("choudoufu", "0.31.0");
269
+ expect(line.startsWith('{ [ -x "/opt/chant/choudoufu-0.31.0/choudoufu" ] || (set -e; a="$(uname -m')).toBe(true);
270
+ expect(line).toContain(CI_TOOL_SHA256["choudoufu-0.31.0-linux-amd64"]);
271
+ expect(line.endsWith('ln -sf "/opt/chant/choudoufu-0.31.0/choudoufu" /usr/local/bin/choudoufu')).toBe(true);
272
+ expect(ciToolInstallLine("tofu", "1.13.1", { link: false, root: "/opt/terragucci" })).not.toContain("ln -sf");
273
+ expect(ciToolInstallLine("tofu", "1.13.1", { onPath: true }).startsWith("command -v tofu >/dev/null 2>&1 || { ")).toBe(true);
274
+ expect(ciToolBin("aws-cli", "2.22.0", "/opt/p")).toBe("/opt/p/aws-cli-2.22.0/v2/current/bin/aws");
275
+ });
276
+
277
+ test("runs: installs once, then skips without a download", () => {
278
+ const a = tarGz({ tofu: "#!/bin/sh\necho installed\n" });
279
+ const root = tmp();
280
+ const line = ciToolInstallLine("tofu", "1.13.1", { root, link: false, sha256: { amd64: sha(a), arm64: sha(a) } });
281
+ const files = { "tofu_1.13.1_linux_amd64.tar.gz": a, "tofu_1.13.1_linux_arm64.tar.gz": a, "tofu_1.13.1_SHA256SUMS": `${sha(a)} tofu_1.13.1_linux_amd64.tar.gz\n${sha(a)} tofu_1.13.1_linux_arm64.tar.gz\n` };
282
+ expect(runShell(line, files).status).toBe(0);
283
+ expect(existsSync(`${root}/tofu-1.13.1/tofu`)).toBe(true);
284
+ expect(runShell(line, files).urls).toEqual([]);
285
+ });
286
+ });
287
+
288
+ describe("installCiTool", () => {
289
+ const a = tarGz({ tofu: "#!/bin/sh\necho node-install\n" });
290
+ const base = "https://github.com/opentofu/opentofu/releases/download/v1.13.1";
291
+ const files = (archive: Uint8Array, listed = sha(archive)) => ({
292
+ [`${base}/tofu_1.13.1_linux_amd64.tar.gz`]: archive,
293
+ [`${base}/tofu_1.13.1_SHA256SUMS`]: `${listed} tofu_1.13.1_linux_amd64.tar.gz\n`,
294
+ });
295
+ const opts = { platform: "linux", arch: "amd64" as const };
296
+
297
+ test("installs a release that matches its checksums and its recorded sha256, then reuses it", async () => {
298
+ const root = tmp();
299
+ const s = served(files(a));
300
+ const got = await installCiTool("tofu", "1.13.1", { ...opts, root, download: s.download, sha256: { amd64: sha(a) } });
301
+ expect(got).toEqual({ dir: join(root, "tofu-1.13.1"), bin: join(root, "tofu-1.13.1", "tofu") });
302
+ expect(readFileSync(got.bin, "utf-8")).toContain("node-install");
303
+ const again = served({});
304
+ await installCiTool("tofu", "1.13.1", { ...opts, root, download: again.download });
305
+ expect(again.urls).toEqual([]);
306
+ });
307
+
308
+ test("refuses a tampered archive and writes nothing", async () => {
309
+ const root = tmp();
310
+ const evil = tarGz({ tofu: "evil" });
311
+ await expect(installCiTool("tofu", "1.13.1", { ...opts, root, download: served(files(evil, sha(a))).download, sha256: {} })).rejects.toThrow(/has sha256 .* not installing it/);
312
+ expect(existsSync(join(root, "tofu-1.13.1", "tofu"))).toBe(false);
313
+ });
314
+
315
+ test("refuses a checksums file that lists another sum than the recorded one", async () => {
316
+ const root = tmp();
317
+ const evil = tarGz({ tofu: "evil" });
318
+ await expect(installCiTool("tofu", "1.13.1", { ...opts, root, download: served(files(evil)).download, sha256: { amd64: sha(a) } })).rejects.toThrow(
319
+ `tofu 1.13.1: tofu_1.13.1_SHA256SUMS lists ${sha(evil)} for tofu_1.13.1_linux_amd64.tar.gz; chant records ${sha(a)}`,
320
+ );
321
+ });
322
+
323
+ test("with no recorded sha256, the checksums file decides, unless requirePin", async () => {
324
+ const root = tmp();
325
+ await installCiTool("tofu", "1.13.1", { ...opts, root, download: served(files(a)).download, sha256: {} });
326
+ expect(existsSync(join(root, "tofu-1.13.1", "tofu"))).toBe(true);
327
+ const none = served(files(a));
328
+ await expect(installCiTool("tofu", "1.13.1", { ...opts, root: tmp(), download: none.download, sha256: {}, requirePin: true })).rejects.toThrow(/no recorded sha256 for tofu 1.13.1 on amd64/);
329
+ expect(none.urls).toEqual([]);
330
+ });
331
+
332
+ test("unpacks a zip's member, a bare binary and a tree", async () => {
333
+ const root = tmp();
334
+ const z = zip({ terraform: "tf" });
335
+ const tf = "https://releases.hashicorp.com/terraform/1.14.9";
336
+ await installCiTool("terraform", "1.14.9", { ...opts, root, download: served({ [`${tf}/terraform_1.14.9_linux_amd64.zip`]: z, [`${tf}/terraform_1.14.9_SHA256SUMS`]: `${sha(z)} terraform_1.14.9_linux_amd64.zip\n` }).download });
337
+ expect(readFileSync(join(root, "terraform-1.14.9", "terraform"), "utf-8")).toBe("tf");
338
+
339
+ const cosign = Buffer.from("cosign");
340
+ const cb = "https://github.com/sigstore/cosign/releases/download/v2.6.5";
341
+ await installCiTool("cosign", "2.6.5", { ...opts, root, download: served({ [`${cb}/cosign-linux-amd64`]: cosign, [`${cb}/cosign_checksums.txt`]: `${sha(cosign)} cosign-linux-amd64\n` }).download });
342
+ expect(readFileSync(join(root, "cosign-2.6.5", "cosign"), "utf-8")).toBe("cosign");
343
+
344
+ const tree = tarGz({ "pulumi/pulumi": "p", "pulumi/pulumi-language-nodejs": "n" });
345
+ const pb = "https://github.com/pulumi/pulumi/releases/download/v3.300.0";
346
+ const got = await installCiTool("pulumi", "3.300.0", { ...opts, root, download: served({ [`${pb}/pulumi-v3.300.0-linux-x64.tar.gz`]: tree, [`${pb}/pulumi-3.300.0-checksums.txt`]: `${sha(tree)} pulumi-v3.300.0-linux-x64.tar.gz\n` }).download });
347
+ expect(readFileSync(got.bin, "utf-8")).toBe("p");
348
+ expect(readFileSync(join(got.dir, "pulumi-language-nodejs"), "utf-8")).toBe("n");
349
+ });
350
+
351
+ test("refuses another platform, and the AWS CLI's installer", async () => {
352
+ await expect(installCiTool("tofu", "1.13.1", { platform: "darwin" })).rejects.toThrow(/Linux builds of tofu .* this machine is darwin/);
353
+ await expect(installCiTool("aws-cli", "2.22.0", opts)).rejects.toThrow(/its own installer/);
354
+ });
355
+
356
+ test("checksumFor and unzipEntry read what releases publish", () => {
357
+ expect(checksumFor(`${"A".repeat(64)} *x.tar.gz\n`, "x.tar.gz")).toBe("a".repeat(64));
358
+ expect(checksumFor(`${"b".repeat(64)} ./x.tar.gz\n`, "x.tar.gz")).toBe("b".repeat(64));
359
+ expect(checksumFor(`${"b".repeat(64)} y.tar.gz\n`, "x.tar.gz")).toBeUndefined();
360
+ expect(Buffer.from(unzipEntry(zip({ a: "1", b: "2" }), "b")!).toString()).toBe("2");
361
+ expect(unzipEntry(zip({ a: "1" }), "c")).toBeUndefined();
362
+ });
363
+ });
364
+
365
+ describe("productImageStages", () => {
366
+ const terragucci = {
367
+ name: "terragucci-terragrunt",
368
+ product: "terragucci",
369
+ description: "Terragrunt 1.2.0, OpenTofu 1.13.1 and the terragucci engine",
370
+ source: "https://github.com/INTENTIUS/terragucci",
371
+ tools: [
372
+ { tool: "tofu" as const, version: "1.13.1" },
373
+ { tool: "terragrunt" as const, version: "1.2.0", sha256: { amd64: "4".repeat(64), arm64: "5".repeat(64) } },
374
+ ],
375
+ npm: ["@cdktn/hcl2json@0.24.0"],
376
+ chant: "0.124.81",
377
+ bundle: { file: "packages/terragucci/dist/terragucci.mjs", bin: "terragucci" },
378
+ };
379
+
380
+ test("a terragucci image: the fetch stage checks each engine against a recorded sha256, the final stage is the shared base", () => {
381
+ const text = productImageDockerfile(terragucci);
382
+ const lines = text.split("\n");
383
+ expect(lines[0]).toBe(`FROM ${CI_BASE_IMAGES.debian} AS fetch`);
384
+ expect(lines[1]).toBe("ARG TARGETARCH");
385
+ expect(text).toContain(`case "$a" in (amd64) want=${CI_TOOL_SHA256["tofu-1.13.1-linux-amd64"]} ;; (arm64) want=${CI_TOOL_SHA256["tofu-1.13.1-linux-arm64"]} ;;`);
386
+ expect(text).toContain(`(amd64) want=${"4".repeat(64)} ;; (arm64) want=${"5".repeat(64)} ;;`);
387
+ expect(lines).toContain(`FROM ${CI_BASE_IMAGES.node}`);
388
+ const final = lines.slice(lines.indexOf(`FROM ${CI_BASE_IMAGES.node}`));
389
+ expect(final.slice(0, 6)).toEqual(["FROM " + CI_BASE_IMAGES.node, "ARG CHANT_RELEASE_LABEL", "ENV USER=terragucci", "ENV HOME=/tmp", "ENV NODE_DISABLE_COMPILE_CACHE=1", "ENV npm_config_logs_max=0"]);
390
+ expect(final).toContain("RUN git config --system --add safe.directory '*'");
391
+ expect(final).toContain("RUN npm install --prefix /usr/local --no-save --omit=dev --no-audit --no-fund @cdktn/hcl2json@0.24.0 && npm cache clean --force && rm -rf /tmp/.npm");
392
+ expect(final.some((l) => l.includes("npm pack --silent @intentius/chant@0.124.81"))).toBe(true);
393
+ expect(final).toContain("COPY --from=fetch /opt/terragucci/ /opt/terragucci/");
394
+ expect(final).toContain("RUN ln -sf /opt/terragucci/tofu-1.13.1/tofu /usr/local/bin/tofu && ln -sf /opt/terragucci/terragrunt-1.2.0/terragrunt /usr/local/bin/terragrunt");
395
+ expect(final).toContain("COPY --chmod=0755 packages/terragucci/dist/terragucci.mjs /usr/local/bin/terragucci");
396
+ expect(final.slice(-7)).toEqual([
397
+ 'LABEL org.opencontainers.image.title="terragucci-terragrunt"',
398
+ 'LABEL org.opencontainers.image.description="Terragrunt 1.2.0, OpenTofu 1.13.1 and the terragucci engine"',
399
+ 'LABEL org.opencontainers.image.version="${CHANT_RELEASE_LABEL}"',
400
+ 'LABEL org.opencontainers.image.source="https://github.com/INTENTIUS/terragucci"',
401
+ 'LABEL org.opencontainers.image.licenses="Apache-2.0"',
402
+ 'CMD ["bash"]',
403
+ "",
404
+ ]);
405
+ // curl is in the fetch stage only.
406
+ expect(final.join("\n")).not.toContain("curl");
407
+ });
408
+
409
+ test("an image refuses an engine with no recorded sha256", () => {
410
+ expect(() => productImageStages({ ...terragucci, tools: [{ tool: "terragrunt", version: "1.2.0" }] })).toThrow(/no recorded sha256 for terragrunt 1.2.0 on amd64 and arm64/);
411
+ expect(() => productImageStages({ ...terragucci, tools: [{ tool: "tofu", version: "1.13.1" }, { tool: "tofu", version: "1.13.1" }] })).toThrow(/listed twice/);
412
+ });
413
+
414
+ test("a plywood image: engine with a checksums build argument, the AWS CLI, plugin steps and a packed tarball", () => {
415
+ const stages = productImageStages({
416
+ name: "plywood-pulumi",
417
+ product: "plywood",
418
+ description: "Pulumi 3.272.0, the AWS CLI 2.22.0 and the plywood CLI",
419
+ source: "https://github.com/INTENTIUS/plywood",
420
+ tools: [
421
+ { tool: "pulumi", version: "3.272.0", checksumsArg: "CHECKSUMS_URL" },
422
+ { tool: "aws-cli", version: "2.22.0" },
423
+ ],
424
+ env: ["PULUMI_HOME=/opt/plywood/pulumi-home", "PULUMI_SKIP_UPDATE_CHECK=true"],
425
+ steps: [{ run: "mkdir -p /opt/plywood/pulumi-home && chmod 1777 /opt/plywood/pulumi-home && pulumi plugin install resource command 1.0.1 && chmod -R a+rX /opt/plywood/pulumi-home" }],
426
+ bundle: { tarball: "images/pack/intentius-plywood-${CHANT_RELEASE_LABEL}.tgz", check: "plywood --version" },
427
+ });
428
+ const fetch = dockerfileText([stages[0]!]);
429
+ expect(fetch).toContain("ARG CHECKSUMS_URL=https://github.com/pulumi/pulumi/releases/download/v3.272.0/pulumi-3.272.0-checksums.txt");
430
+ expect(fetch).toContain('curl -fsSLo "$t/sums" "$CHECKSUMS_URL"');
431
+ expect(fetch).toContain('tar -xzf "$t/$f" -C "/opt/plywood/pulumi-3.272.0" --strip-components=1');
432
+ expect(fetch).toContain('"$t/aws/install" -i "/opt/plywood/aws-cli-2.22.0" -b "/opt/plywood/aws-cli-2.22.0/bin"');
433
+ const final = dockerfileText([stages[1]!]);
434
+ expect(final).toContain("RUN ln -sf /opt/plywood/pulumi-3.272.0/pulumi /usr/local/bin/pulumi && ln -sf /opt/plywood/aws-cli-2.22.0/v2/current/bin/aws /usr/local/bin/aws\nRUN mkdir -p /opt/plywood/pulumi-home");
435
+ expect(final).toContain("COPY images/pack/intentius-plywood-${CHANT_RELEASE_LABEL}.tgz /tmp/intentius-plywood-${CHANT_RELEASE_LABEL}.tgz");
436
+ expect(final).toContain("RUN npm install -g --omit=dev --no-audit --no-fund /tmp/intentius-plywood-${CHANT_RELEASE_LABEL}.tgz && rm -f /tmp/intentius-plywood-${CHANT_RELEASE_LABEL}.tgz && npm cache clean --force && plywood --version");
437
+ });
438
+
439
+ test("a SQL Yodeler image: no engines, so no fetch stage; npm packages into a prefix with their own version argument", () => {
440
+ const stages = productImageStages({
441
+ name: "sql-yodeler",
442
+ product: "yodel",
443
+ description: "yodel, chant and the sql lexicon on Node 22, for CI jobs",
444
+ source: "https://github.com/INTENTIUS/sql-yodeler",
445
+ versionArg: "YODEL_VERSION",
446
+ args: ["YODEL_PACKAGE", "CHANT_PINS"],
447
+ packages: ["openssh-client"],
448
+ bundle: {
449
+ npm: '"${YODEL_PACKAGE:-@intentius/sql-yodeler@$YODEL_VERSION}" $CHANT_PINS',
450
+ prefix: "/opt/yodel",
451
+ mountContext: true,
452
+ require: ["YODEL_VERSION"],
453
+ check: ['test "$(yodel --version)" = "$YODEL_VERSION"', "chant --version"],
454
+ },
455
+ });
456
+ expect(stages).toHaveLength(1);
457
+ const text = dockerfileText(stages);
458
+ expect(text).toContain("ARG YODEL_VERSION\nARG YODEL_PACKAGE\nARG CHANT_PINS\n");
459
+ expect(text).toContain("ENV PATH=/opt/yodel/node_modules/.bin:$PATH");
460
+ expect(text).toContain("apt-get install -y --no-install-recommends git ca-certificates openssh-client");
461
+ expect(text).toContain('RUN --mount=type=bind,target=/ctx test -n "$YODEL_VERSION" && mkdir -p /opt/yodel && cd /opt/yodel');
462
+ expect(text).toContain('grep -qE "E404|ETARGET" /tmp/npm.err');
463
+ expect(text).toContain('ln -s /opt/yodel/node_modules /node_modules && test "$(yodel --version)" = "$YODEL_VERSION" && chant --version');
464
+ expect(text).toContain('LABEL org.opencontainers.image.version="${YODEL_VERSION}"');
465
+ });
466
+
467
+ test("the rendered fetch stage's RUN lines pass and fail on local fixtures as the build would", () => {
468
+ const a = tarGz({ tofu: "#!/bin/sh\n" });
469
+ const stages = productImageStages({ ...terragucci, toolRoot: "/opt/terragucci", tools: [{ tool: "tofu", version: "1.13.1", sha256: { amd64: sha(a), arm64: sha(a) } }] });
470
+ const run = stages[0]!.steps.map((s) => s.run).filter((r): r is string => !!r && r.startsWith("set -e;"))[0]!;
471
+ const out = tmp();
472
+ const local = run.replaceAll("/opt/terragucci", out);
473
+ const good = { "tofu_1.13.1_linux_arm64.tar.gz": a, "tofu_1.13.1_SHA256SUMS": `${sha(a)} tofu_1.13.1_linux_arm64.tar.gz\n` };
474
+ expect(runShell(local, good, { TARGETARCH: "arm64" }).status).toBe(0);
475
+ expect(existsSync(`${out}/tofu-1.13.1/tofu`)).toBe(true);
476
+ const bad = { ...good, "tofu_1.13.1_linux_arm64.tar.gz": tarGz({ tofu: "evil" }) };
477
+ expect(runShell(local.replaceAll(out, tmp()), bad, { TARGETARCH: "arm64" }).status).not.toBe(0);
478
+ });
479
+
480
+ test("refuses a label that would break the line, and names that are not names", () => {
481
+ expect(() => productImageStages({ ...terragucci, description: 'say "hi"' })).toThrow(/double quote/);
482
+ expect(() => productImageStages({ ...terragucci, npm: ["@cdktn/hcl2json@latest"] })).toThrow(/exact version/);
483
+ expect(() => productImageStages({ ...terragucci, name: "Bad Name" })).toThrow(/image name/);
484
+ });
485
+ });
486
+
487
+ describe("derivedImageDockerfile", () => {
488
+ test("FROM the product's image, with the user's steps under a header", () => {
489
+ const text = derivedImageDockerfile({
490
+ from: "ghcr.io/intentius/plywood-pulumi:0.4.0-pulumi3.272.0@sha256:" + "6".repeat(64),
491
+ header: ["A prepared image for plywood's jobs.", "Build and push it in your own CI."],
492
+ steps: [{ run: "pulumi plugin install resource aws 7.4.0" }, { run: "chmod -R a+rX /opt/plywood/pulumi-home" }],
493
+ });
494
+ expect(text).toBe(
495
+ [
496
+ "# A prepared image for plywood's jobs.",
497
+ "# Build and push it in your own CI.",
498
+ `FROM ghcr.io/intentius/plywood-pulumi:0.4.0-pulumi3.272.0@sha256:${"6".repeat(64)}`,
499
+ "RUN pulumi plugin install resource aws 7.4.0",
500
+ "RUN chmod -R a+rX /opt/plywood/pulumi-home",
501
+ "",
502
+ ].join("\n"),
503
+ );
504
+ expect(() => derivedImageDockerfile({ from: "a b", steps: [] })).toThrow(/image reference/);
505
+ });
506
+ });