@intentius/chant-lexicon-docker 0.124.97 → 0.124.99

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 (241) hide show
  1. package/dist/codegen/docs-cli.d.ts +0 -1
  2. package/dist/codegen/docs.d.ts +0 -1
  3. package/dist/codegen/generate-cli.d.ts +0 -1
  4. package/dist/codegen/generate-compose.d.ts +0 -1
  5. package/dist/codegen/generate-dockerfile.d.ts +0 -1
  6. package/dist/codegen/generate.d.ts +0 -1
  7. package/dist/codegen/naming.d.ts +0 -1
  8. package/dist/codegen/package.d.ts +0 -1
  9. package/dist/codegen/patches.d.ts +0 -1
  10. package/dist/codegen/versions.d.ts +0 -1
  11. package/dist/compose-key.d.ts +0 -1
  12. package/dist/composites/catalog.d.ts +0 -1
  13. package/dist/composites/docker-otel-collector.d.ts +0 -1
  14. package/dist/composites/docker-web-service.d.ts +0 -1
  15. package/dist/composites/index.d.ts +0 -1
  16. package/dist/coverage.d.ts +0 -1
  17. package/dist/default-labels.d.ts +0 -1
  18. package/dist/detect.d.ts +0 -1
  19. package/dist/dockerfile-order.d.ts +0 -1
  20. package/dist/export-resources.d.ts +0 -1
  21. package/dist/generated/index.d.ts +0 -1
  22. package/dist/generated/runtime.d.ts +0 -1
  23. package/dist/import/adapter.d.ts +0 -1
  24. package/dist/import/adapter.js +4 -2
  25. package/dist/import/embedded.d.ts +0 -1
  26. package/dist/import/engine.d.ts +0 -1
  27. package/dist/import/generator.d.ts +9 -2
  28. package/dist/import/generator.js +23 -1
  29. package/dist/import/live-export.d.ts +0 -1
  30. package/dist/import/parser.d.ts +0 -1
  31. package/dist/import/testdata/tar.d.ts +0 -1
  32. package/dist/index.d.ts +0 -1
  33. package/dist/integrity.json +2 -2
  34. package/dist/interpolation.d.ts +0 -1
  35. package/dist/lint/audit-catalog.d.ts +0 -1
  36. package/dist/lint/audit-lineage.d.ts +0 -1
  37. package/dist/lint/post-synth/add-url-checksum.d.ts +0 -1
  38. package/dist/lint/post-synth/apt-no-recommends.d.ts +0 -1
  39. package/dist/lint/post-synth/apt-update-alone.d.ts +0 -1
  40. package/dist/lint/post-synth/cache-busting-copy.d.ts +0 -1
  41. package/dist/lint/post-synth/copy-from-stage.d.ts +0 -1
  42. package/dist/lint/post-synth/docker-helpers.d.ts +0 -1
  43. package/dist/lint/post-synth/index.d.ts +0 -1
  44. package/dist/lint/post-synth/no-latest-image.d.ts +0 -1
  45. package/dist/lint/post-synth/no-root-user.d.ts +0 -1
  46. package/dist/lint/post-synth/prefer-copy.d.ts +0 -1
  47. package/dist/lint/post-synth/relative-workdir.d.ts +0 -1
  48. package/dist/lint/post-synth/repeated-cmd.d.ts +0 -1
  49. package/dist/lint/post-synth/root-after-user.d.ts +0 -1
  50. package/dist/lint/post-synth/ssh-port-exposed.d.ts +0 -1
  51. package/dist/lint/post-synth/unused-global-arg.d.ts +0 -1
  52. package/dist/lint/post-synth/unused-volume.d.ts +0 -1
  53. package/dist/lint/rules/data/deprecated-images.d.ts +0 -1
  54. package/dist/lint/rules/data/known-base-images.d.ts +0 -1
  55. package/dist/lint/rules/index.d.ts +0 -1
  56. package/dist/lint/rules/no-latest-tag.d.ts +0 -1
  57. package/dist/lint/rules/per-kind-order.d.ts +0 -1
  58. package/dist/list-artifacts.d.ts +0 -1
  59. package/dist/lsp/completions.d.ts +0 -1
  60. package/dist/lsp/hover.d.ts +0 -1
  61. package/dist/manifest.json +1 -1
  62. package/dist/package-cli.d.ts +0 -1
  63. package/dist/plugin.d.ts +0 -1
  64. package/dist/serializer.d.ts +0 -1
  65. package/dist/spec/fetch-compose.d.ts +0 -1
  66. package/dist/spec/fetch-engine.d.ts +0 -1
  67. package/dist/spec/parse-compose.d.ts +0 -1
  68. package/dist/spec/parse-engine.d.ts +0 -1
  69. package/dist/validate-cli.d.ts +0 -1
  70. package/dist/validate.d.ts +0 -1
  71. package/dist/variables.d.ts +0 -1
  72. package/package.json +4 -5
  73. package/dist/codegen/docs-cli.d.ts.map +0 -1
  74. package/dist/codegen/docs.d.ts.map +0 -1
  75. package/dist/codegen/generate-cli.d.ts.map +0 -1
  76. package/dist/codegen/generate-compose.d.ts.map +0 -1
  77. package/dist/codegen/generate-dockerfile.d.ts.map +0 -1
  78. package/dist/codegen/generate.d.ts.map +0 -1
  79. package/dist/codegen/naming.d.ts.map +0 -1
  80. package/dist/codegen/package.d.ts.map +0 -1
  81. package/dist/codegen/patches.d.ts.map +0 -1
  82. package/dist/codegen/versions.d.ts.map +0 -1
  83. package/dist/compose-key.d.ts.map +0 -1
  84. package/dist/composites/catalog.d.ts.map +0 -1
  85. package/dist/composites/docker-otel-collector.d.ts.map +0 -1
  86. package/dist/composites/docker-web-service.d.ts.map +0 -1
  87. package/dist/composites/index.d.ts.map +0 -1
  88. package/dist/coverage.d.ts.map +0 -1
  89. package/dist/default-labels.d.ts.map +0 -1
  90. package/dist/detect.d.ts.map +0 -1
  91. package/dist/dockerfile-order.d.ts.map +0 -1
  92. package/dist/export-resources.d.ts.map +0 -1
  93. package/dist/generated/index.d.ts.map +0 -1
  94. package/dist/generated/runtime.d.ts.map +0 -1
  95. package/dist/import/adapter.d.ts.map +0 -1
  96. package/dist/import/embedded.d.ts.map +0 -1
  97. package/dist/import/engine.d.ts.map +0 -1
  98. package/dist/import/generator.d.ts.map +0 -1
  99. package/dist/import/live-export.d.ts.map +0 -1
  100. package/dist/import/parser.d.ts.map +0 -1
  101. package/dist/import/testdata/tar.d.ts.map +0 -1
  102. package/dist/index.d.ts.map +0 -1
  103. package/dist/interpolation.d.ts.map +0 -1
  104. package/dist/lint/audit-catalog.d.ts.map +0 -1
  105. package/dist/lint/audit-lineage.d.ts.map +0 -1
  106. package/dist/lint/post-synth/add-url-checksum.d.ts.map +0 -1
  107. package/dist/lint/post-synth/apt-no-recommends.d.ts.map +0 -1
  108. package/dist/lint/post-synth/apt-update-alone.d.ts.map +0 -1
  109. package/dist/lint/post-synth/cache-busting-copy.d.ts.map +0 -1
  110. package/dist/lint/post-synth/copy-from-stage.d.ts.map +0 -1
  111. package/dist/lint/post-synth/docker-helpers.d.ts.map +0 -1
  112. package/dist/lint/post-synth/index.d.ts.map +0 -1
  113. package/dist/lint/post-synth/no-latest-image.d.ts.map +0 -1
  114. package/dist/lint/post-synth/no-root-user.d.ts.map +0 -1
  115. package/dist/lint/post-synth/prefer-copy.d.ts.map +0 -1
  116. package/dist/lint/post-synth/relative-workdir.d.ts.map +0 -1
  117. package/dist/lint/post-synth/repeated-cmd.d.ts.map +0 -1
  118. package/dist/lint/post-synth/root-after-user.d.ts.map +0 -1
  119. package/dist/lint/post-synth/ssh-port-exposed.d.ts.map +0 -1
  120. package/dist/lint/post-synth/unused-global-arg.d.ts.map +0 -1
  121. package/dist/lint/post-synth/unused-volume.d.ts.map +0 -1
  122. package/dist/lint/rules/data/deprecated-images.d.ts.map +0 -1
  123. package/dist/lint/rules/data/known-base-images.d.ts.map +0 -1
  124. package/dist/lint/rules/index.d.ts.map +0 -1
  125. package/dist/lint/rules/no-latest-tag.d.ts.map +0 -1
  126. package/dist/lint/rules/per-kind-order.d.ts.map +0 -1
  127. package/dist/list-artifacts.d.ts.map +0 -1
  128. package/dist/lsp/completions.d.ts.map +0 -1
  129. package/dist/lsp/hover.d.ts.map +0 -1
  130. package/dist/package-cli.d.ts.map +0 -1
  131. package/dist/plugin.d.ts.map +0 -1
  132. package/dist/serializer.d.ts.map +0 -1
  133. package/dist/spec/fetch-compose.d.ts.map +0 -1
  134. package/dist/spec/fetch-engine.d.ts.map +0 -1
  135. package/dist/spec/parse-compose.d.ts.map +0 -1
  136. package/dist/spec/parse-engine.d.ts.map +0 -1
  137. package/dist/validate-cli.d.ts.map +0 -1
  138. package/dist/validate.d.ts.map +0 -1
  139. package/dist/variables.d.ts.map +0 -1
  140. package/src/codegen/__snapshots__/okf.test.ts.snap +0 -555
  141. package/src/codegen/docs-cli.ts +0 -10
  142. package/src/codegen/docs.ts +0 -171
  143. package/src/codegen/generate-cli.ts +0 -36
  144. package/src/codegen/generate-compose.ts +0 -21
  145. package/src/codegen/generate-dockerfile.ts +0 -21
  146. package/src/codegen/generate.test.ts +0 -115
  147. package/src/codegen/generate.ts +0 -258
  148. package/src/codegen/naming.test.ts +0 -81
  149. package/src/codegen/naming.ts +0 -54
  150. package/src/codegen/okf.test.ts +0 -36
  151. package/src/codegen/package.ts +0 -59
  152. package/src/codegen/patches.ts +0 -42
  153. package/src/codegen/versions.ts +0 -46
  154. package/src/compose-key.ts +0 -31
  155. package/src/composites/catalog.test.ts +0 -39
  156. package/src/composites/catalog.ts +0 -118
  157. package/src/composites/docker-otel-collector.ts +0 -83
  158. package/src/composites/docker-web-service.test.ts +0 -34
  159. package/src/composites/docker-web-service.ts +0 -75
  160. package/src/composites/index.ts +0 -9
  161. package/src/coverage.test.ts +0 -33
  162. package/src/coverage.ts +0 -54
  163. package/src/default-labels.test.ts +0 -85
  164. package/src/default-labels.ts +0 -72
  165. package/src/detect.ts +0 -7
  166. package/src/dockerfile-order.ts +0 -20
  167. package/src/docs-examples.test.ts +0 -141
  168. package/src/export-resources.ts +0 -90
  169. package/src/generated/index.d.ts +0 -407
  170. package/src/generated/index.ts +0 -410
  171. package/src/generated/runtime.ts +0 -4
  172. package/src/import/adapter.ts +0 -99
  173. package/src/import/embedded-live.test.ts +0 -248
  174. package/src/import/embedded.ts +0 -83
  175. package/src/import/engine.ts +0 -107
  176. package/src/import/generator.test.ts +0 -134
  177. package/src/import/generator.ts +0 -202
  178. package/src/import/live-export.test.ts +0 -271
  179. package/src/import/live-export.ts +0 -359
  180. package/src/import/parser.test.ts +0 -137
  181. package/src/import/parser.ts +0 -269
  182. package/src/import/roundtrip.test.ts +0 -257
  183. package/src/import/testdata/configs-secrets.yaml +0 -15
  184. package/src/import/testdata/full.yaml +0 -43
  185. package/src/import/testdata/names-and-fields.yaml +0 -44
  186. package/src/import/testdata/simple.yaml +0 -9
  187. package/src/import/testdata/tar.ts +0 -24
  188. package/src/import/testdata/webapp.yaml +0 -41
  189. package/src/index.ts +0 -32
  190. package/src/interpolation.test.ts +0 -41
  191. package/src/interpolation.ts +0 -76
  192. package/src/lint/audit-catalog.ts +0 -28
  193. package/src/lint/audit-lineage.ts +0 -48
  194. package/src/lint/post-synth/add-url-checksum.ts +0 -38
  195. package/src/lint/post-synth/apt-no-recommends.ts +0 -43
  196. package/src/lint/post-synth/apt-update-alone.ts +0 -39
  197. package/src/lint/post-synth/cache-busting-copy.ts +0 -65
  198. package/src/lint/post-synth/copy-from-stage.ts +0 -54
  199. package/src/lint/post-synth/docker-helpers.ts +0 -194
  200. package/src/lint/post-synth/index.ts +0 -33
  201. package/src/lint/post-synth/no-latest-image.ts +0 -36
  202. package/src/lint/post-synth/no-root-user.ts +0 -38
  203. package/src/lint/post-synth/post-synth.test.ts +0 -330
  204. package/src/lint/post-synth/prefer-copy.ts +0 -53
  205. package/src/lint/post-synth/relative-workdir.ts +0 -38
  206. package/src/lint/post-synth/repeated-cmd.ts +0 -35
  207. package/src/lint/post-synth/root-after-user.ts +0 -44
  208. package/src/lint/post-synth/ssh-port-exposed.ts +0 -68
  209. package/src/lint/post-synth/unused-global-arg.ts +0 -38
  210. package/src/lint/post-synth/unused-volume.ts +0 -49
  211. package/src/lint/rules/data/deprecated-images.ts +0 -28
  212. package/src/lint/rules/data/known-base-images.ts +0 -20
  213. package/src/lint/rules/index.ts +0 -6
  214. package/src/lint/rules/no-latest-tag.ts +0 -63
  215. package/src/lint/rules/per-kind-order.ts +0 -130
  216. package/src/lint/rules/rules.test.ts +0 -170
  217. package/src/list-artifacts.test.ts +0 -141
  218. package/src/list-artifacts.ts +0 -164
  219. package/src/lsp/completions.test.ts +0 -40
  220. package/src/lsp/completions.ts +0 -21
  221. package/src/lsp/hover.test.ts +0 -35
  222. package/src/lsp/hover.ts +0 -39
  223. package/src/package-cli.ts +0 -25
  224. package/src/plugin.test.ts +0 -121
  225. package/src/plugin.ts +0 -268
  226. package/src/serializer.test.ts +0 -545
  227. package/src/serializer.ts +0 -444
  228. package/src/skills/chant-docker-patterns.md +0 -222
  229. package/src/skills/chant-docker.md +0 -156
  230. package/src/spec/fetch-compose.ts +0 -35
  231. package/src/spec/fetch-engine.ts +0 -25
  232. package/src/spec/parse-compose.ts +0 -195
  233. package/src/spec/parse-engine.ts +0 -59
  234. package/src/typecheck.e2e.test.ts +0 -125
  235. package/src/typed-props.test.ts +0 -60
  236. package/src/validate-cli.ts +0 -19
  237. package/src/validate.test.ts +0 -16
  238. package/src/validate.ts +0 -44
  239. package/src/variables.test.ts +0 -32
  240. package/src/variables.ts +0 -47
  241. /package/{src → dist}/generated/lexicon-docker.json +0 -0
@@ -1,545 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { dockerSerializer } from "./serializer";
3
- import { composeKey } from "./compose-key";
4
- import { DECLARABLE_MARKER, type Declarable } from "@intentius/chant/declarable";
5
- import { INTRINSIC_MARKER } from "@intentius/chant/intrinsic";
6
- import { dockerfileText, productImageStages } from "@intentius/chant/ci-image";
7
-
8
- // ── Mock entities ──────────────────────────────────────────────────
9
-
10
- class MockService implements Declarable {
11
- readonly [DECLARABLE_MARKER] = true as const;
12
- readonly lexicon = "docker";
13
- readonly entityType = "Docker::Compose::Service";
14
- readonly kind = "resource" as const;
15
- readonly props: Record<string, unknown>;
16
-
17
- constructor(props: Record<string, unknown> = {}) {
18
- this.props = props;
19
- }
20
- }
21
-
22
- class MockVolume implements Declarable {
23
- readonly [DECLARABLE_MARKER] = true as const;
24
- readonly lexicon = "docker";
25
- readonly entityType = "Docker::Compose::Volume";
26
- readonly kind = "resource" as const;
27
- readonly props: Record<string, unknown>;
28
-
29
- constructor(props: Record<string, unknown> = {}) {
30
- this.props = props;
31
- }
32
- }
33
-
34
- class MockNetwork implements Declarable {
35
- readonly [DECLARABLE_MARKER] = true as const;
36
- readonly lexicon = "docker";
37
- readonly entityType = "Docker::Compose::Network";
38
- readonly kind = "resource" as const;
39
- readonly props: Record<string, unknown>;
40
-
41
- constructor(props: Record<string, unknown> = {}) {
42
- this.props = props;
43
- }
44
- }
45
-
46
- class MockDockerfile implements Declarable {
47
- readonly [DECLARABLE_MARKER] = true as const;
48
- readonly lexicon = "docker";
49
- readonly entityType = "Docker::Dockerfile";
50
- readonly kind = "resource" as const;
51
- readonly props: Record<string, unknown>;
52
-
53
- constructor(props: Record<string, unknown> = {}) {
54
- this.props = props;
55
- }
56
- }
57
-
58
- class MockPropertyDeclarable implements Declarable {
59
- readonly [DECLARABLE_MARKER] = true as const;
60
- readonly lexicon = "docker";
61
- readonly entityType = "Docker::Compose::HealthCheck";
62
- readonly kind = "property" as const;
63
- readonly props: Record<string, unknown>;
64
-
65
- constructor(props: Record<string, unknown> = {}) {
66
- this.props = props;
67
- }
68
- }
69
-
70
- class MockDefaultLabels implements Declarable {
71
- readonly [DECLARABLE_MARKER] = true as const;
72
- readonly [Symbol.for("docker.defaultLabels")] = true as const;
73
- readonly lexicon = "docker";
74
- readonly entityType = "Docker::DefaultLabels";
75
- readonly kind = "resource" as const;
76
- readonly props: Record<string, unknown>;
77
-
78
- constructor(props: Record<string, unknown> = {}) {
79
- this.props = props;
80
- }
81
- }
82
-
83
- // ── Identity tests ─────────────────────────────────────────────────
84
-
85
- describe("dockerSerializer", () => {
86
- test("has correct name", () => {
87
- expect(dockerSerializer.name).toBe("docker");
88
- });
89
-
90
- test("has correct rulePrefix", () => {
91
- expect(dockerSerializer.rulePrefix).toBe("DKR");
92
- });
93
- });
94
-
95
- // ── Empty input ────────────────────────────────────────────────────
96
-
97
- describe("dockerSerializer.serialize — empty", () => {
98
- test("returns newline for empty entities", () => {
99
- const output = dockerSerializer.serialize(new Map());
100
- expect(output).toBe("\n");
101
- });
102
- });
103
-
104
- // ── Single service ─────────────────────────────────────────────────
105
-
106
- describe("dockerSerializer.serialize — single service", () => {
107
- test("serializes one service with image", () => {
108
- const entities = new Map<string, Declarable>();
109
- entities.set("api", new MockService({ image: "nginx:1.25" }));
110
-
111
- const output = dockerSerializer.serialize(entities) as string;
112
- expect(output).toContain("services:");
113
- expect(output).toContain("api:");
114
- expect(output).toContain("image: nginx:1.25");
115
- });
116
-
117
- test("omits null/undefined properties", () => {
118
- const entities = new Map<string, Declarable>();
119
- entities.set("api", new MockService({ image: "nginx", restart: undefined }));
120
-
121
- const output = dockerSerializer.serialize(entities) as string;
122
- expect(output).not.toContain("restart:");
123
- });
124
-
125
- test("emits short-form depends_on (list)", () => {
126
- const entities = new Map<string, Declarable>();
127
- entities.set("api", new MockService({ image: "nginx", depends_on: ["db"] }));
128
-
129
- const output = dockerSerializer.serialize(entities) as string;
130
- expect(output).toContain("depends_on:");
131
- expect(output).toContain("- db");
132
- });
133
-
134
- test("emits long-form depends_on with a wait condition", () => {
135
- const entities = new Map<string, Declarable>();
136
- entities.set(
137
- "api",
138
- new MockService({
139
- image: "nginx",
140
- depends_on: { db: { condition: "service_healthy" } },
141
- }),
142
- );
143
-
144
- const output = dockerSerializer.serialize(entities) as string;
145
- expect(output).toContain("depends_on:");
146
- expect(output).toContain("db:");
147
- expect(output).toContain("condition: service_healthy");
148
- });
149
- });
150
-
151
- // ── Multi-resource ────────────────────────────────────────────────
152
-
153
- describe("dockerSerializer.serialize — multi-resource", () => {
154
- test("serializes services, volumes, networks in order", () => {
155
- const entities = new Map<string, Declarable>();
156
- entities.set("api", new MockService({ image: "myapp:latest" }));
157
- entities.set("data", new MockVolume({}));
158
- entities.set("frontend", new MockNetwork({}));
159
-
160
- const output = dockerSerializer.serialize(entities) as string;
161
- expect(output).toContain("services:");
162
- expect(output).toContain("volumes:");
163
- expect(output).toContain("networks:");
164
-
165
- const servicesIdx = output.indexOf("services:");
166
- const volumesIdx = output.indexOf("volumes:");
167
- const networksIdx = output.indexOf("networks:");
168
- expect(servicesIdx).toBeLessThan(volumesIdx);
169
- expect(volumesIdx).toBeLessThan(networksIdx);
170
- });
171
- });
172
-
173
- // ── Dockerfile emission ───────────────────────────────────────────
174
-
175
- describe("dockerSerializer.serialize — Dockerfile", () => {
176
- test("emits Dockerfile.{name} in SerializerResult", () => {
177
- const entities = new Map<string, Declarable>();
178
- entities.set("api", new MockService({ image: "myapp:latest" }));
179
- entities.set("api", new MockService({
180
- build: { dockerfile: "Dockerfile.builder" },
181
- }));
182
- entities.set("builder", new MockDockerfile({
183
- from: "node:20-alpine",
184
- run: ["npm ci", "npm run build"],
185
- cmd: `["node", "dist/index.js"]`,
186
- }));
187
-
188
- const output = dockerSerializer.serialize(entities);
189
- expect(typeof output).toBe("object");
190
- const result = output as { primary: string; files: Record<string, string> };
191
- expect(result.files).toBeDefined();
192
- expect(result.files["Dockerfile.builder"]).toBeDefined();
193
- expect(result.files["Dockerfile.builder"]).toContain("FROM node:20-alpine");
194
- expect(result.files["Dockerfile.builder"]).toContain("RUN npm ci");
195
- });
196
-
197
- test("primary contains compose YAML when Dockerfile present", () => {
198
- const entities = new Map<string, Declarable>();
199
- entities.set("web", new MockService({ image: "nginx" }));
200
- entities.set("builder", new MockDockerfile({ from: "node:20" }));
201
-
202
- const result = dockerSerializer.serialize(entities) as { primary: string; files: Record<string, string> };
203
- expect(result.primary).toContain("services:");
204
- expect(result.primary).toContain("web:");
205
- });
206
-
207
- test("Dockerfiles alone leave the compose output blank, so `chant build -o <dir>/` writes only them (#4950)", () => {
208
- const entities = new Map<string, Declarable>();
209
- entities.set("tofu", new MockDockerfile({ from: "tofu" }));
210
- entities.set("node", new MockDockerfile({ from: "node:22" }));
211
-
212
- const result = dockerSerializer.serialize(entities) as { primary: string; files: Record<string, string> };
213
- expect(result.primary.trim()).toBe("");
214
- expect(Object.keys(result.files).sort()).toEqual(["Dockerfile.node", "Dockerfile.tofu"]);
215
- });
216
-
217
- test("returns string (no SerializerResult) when no Dockerfile entities", () => {
218
- const entities = new Map<string, Declarable>();
219
- entities.set("web", new MockService({ image: "nginx" }));
220
-
221
- const output = dockerSerializer.serialize(entities);
222
- expect(typeof output).toBe("string");
223
- });
224
- });
225
-
226
- // ── Default labels ────────────────────────────────────────────────
227
-
228
- describe("dockerSerializer.serialize — default labels", () => {
229
- test("merges default labels into every service", () => {
230
- const entities = new Map<string, Declarable>();
231
- entities.set("labels", new MockDefaultLabels({ labels: { "app.team": "platform" } }));
232
- entities.set("api", new MockService({ image: "myapp:1.0" }));
233
- entities.set("worker", new MockService({ image: "myworker:1.0" }));
234
-
235
- const output = dockerSerializer.serialize(entities) as string;
236
- expect(output).toContain("app.team: platform");
237
- });
238
-
239
- test("default labels are not emitted as a top-level key", () => {
240
- const entities = new Map<string, Declarable>();
241
- entities.set("labels", new MockDefaultLabels({ labels: { "app.team": "platform" } }));
242
- entities.set("api", new MockService({ image: "myapp:1.0" }));
243
-
244
- const output = dockerSerializer.serialize(entities) as string;
245
- expect(output).not.toContain("Docker::DefaultLabels");
246
- });
247
- });
248
-
249
- // ── Property kind skipping ─────────────────────────────────────────
250
-
251
- describe("dockerSerializer.serialize — property skipping", () => {
252
- test("skips entities with kind=property", () => {
253
- const entities = new Map<string, Declarable>();
254
- entities.set("api", new MockService({ image: "myapp:1.0" }));
255
- entities.set("hc", new MockPropertyDeclarable({ test: "curl -f http://localhost" }));
256
-
257
- const output = dockerSerializer.serialize(entities) as string;
258
- // Property entities should not appear as top-level services
259
- expect(output).not.toContain("Docker::Compose::HealthCheck");
260
- });
261
- });
262
-
263
- // ── Key order ────────────────────────────────────────────────────
264
-
265
- describe("dockerSerializer.serialize — key order", () => {
266
- test("services appears before volumes appears before networks", () => {
267
- const entities = new Map<string, Declarable>();
268
- entities.set("net", new MockNetwork({ driver: "bridge" }));
269
- entities.set("vol", new MockVolume({ driver: "local" }));
270
- entities.set("svc", new MockService({ image: "nginx" }));
271
-
272
- const output = dockerSerializer.serialize(entities) as string;
273
- const svcIdx = output.indexOf("services:");
274
- const volIdx = output.indexOf("volumes:");
275
- const netIdx = output.indexOf("networks:");
276
-
277
- expect(svcIdx).toBeLessThan(volIdx);
278
- expect(volIdx).toBeLessThan(netIdx);
279
- });
280
- });
281
-
282
- // ── Intrinsic serialization ───────────────────────────────────────
283
-
284
- describe("dockerSerializer.serialize — intrinsics", () => {
285
- test("serializes env() intrinsic to ${VAR} string", () => {
286
- const mockEnvIntrinsic = {
287
- [INTRINSIC_MARKER]: true,
288
- toJSON: () => "${APP_IMAGE:-myapp:latest}",
289
- toString: () => "${APP_IMAGE:-myapp:latest}",
290
- };
291
-
292
- const entities = new Map<string, Declarable>();
293
- entities.set("api", new MockService({ image: mockEnvIntrinsic }));
294
-
295
- const output = dockerSerializer.serialize(entities) as string;
296
- expect(output).toContain("${APP_IMAGE:-myapp:latest}");
297
- });
298
- });
299
-
300
- // ── Multi-stage Dockerfile ────────────────────────────────────────
301
-
302
- describe("dockerSerializer.serialize — multi-stage Dockerfile", () => {
303
- test("emits multiple FROM instructions for stages", () => {
304
- const entities = new Map<string, Declarable>();
305
- entities.set("app", new MockDockerfile({
306
- stages: [
307
- { from: "node:20-alpine", as: "builder", run: ["npm ci", "npm run build"] },
308
- { from: "nginx:alpine", copy: ["--from=builder /app/dist /usr/share/nginx/html"] },
309
- ],
310
- }));
311
-
312
- const output = dockerSerializer.serialize(entities);
313
- const result = output as { primary: string; files: Record<string, string> };
314
- const dockerfile = result.files["Dockerfile.app"];
315
- expect(dockerfile).toContain("FROM node:20-alpine AS builder");
316
- expect(dockerfile).toContain("FROM nginx:alpine");
317
- expect(dockerfile).toContain("RUN npm ci");
318
- });
319
- });
320
-
321
- // ── Dockerfile steps ──────────────────────────────────────────────
322
-
323
- describe("dockerSerializer.serialize — Dockerfile steps", () => {
324
- const dockerfile = (props: Record<string, unknown>): string => {
325
- const result = dockerSerializer.serialize(new Map<string, Declarable>([["app", new MockDockerfile(props)]]));
326
- return (result as { files: Record<string, string> }).files["Dockerfile.app"]!;
327
- };
328
-
329
- test("a product image's stages from @intentius/chant/ci-image serialize as ci-image writes them (#4784)", () => {
330
- const stages = productImageStages({
331
- name: "terragucci-tofu",
332
- product: "terragucci",
333
- description: "OpenTofu 1.13.1 and the terragucci engine",
334
- source: "https://github.com/INTENTIUS/terragucci",
335
- tools: [{ tool: "tofu", version: "1.13.1" }],
336
- bundle: { file: "packages/terragucci/dist/terragucci.mjs", bin: "terragucci" },
337
- });
338
- expect(dockerfile({ stages })).toBe(dockerfileText(stages));
339
- });
340
-
341
- test("steps are written in the order given, interleaving COPY and RUN", () => {
342
- expect(dockerfile({
343
- from: "node:20-alpine",
344
- steps: [
345
- { workdir: "/app" },
346
- { copy: "package*.json ./" },
347
- { run: "npm ci" },
348
- { copy: ". ." },
349
- { run: "npm run build" },
350
- { user: "node" },
351
- { cmd: ["node", "dist/index.js"] },
352
- ],
353
- })).toBe([
354
- "FROM node:20-alpine",
355
- "WORKDIR /app",
356
- "COPY package*.json ./",
357
- "RUN npm ci",
358
- "COPY . .",
359
- "RUN npm run build",
360
- "USER node",
361
- 'CMD ["node","dist/index.js"]',
362
- "",
363
- ].join("\n"));
364
- });
365
-
366
- test("every instruction is available as a step, and ARG before FROM comes from globalArgs", () => {
367
- expect(dockerfile({
368
- globalArgs: ["NODE_VERSION=20"],
369
- stages: [{
370
- from: "node:${NODE_VERSION}-alpine",
371
- as: "base",
372
- steps: [
373
- { shell: ["/bin/sh", "-eo", "pipefail", "-c"] },
374
- { arg: "APP_ENV=production" },
375
- { env: "NODE_ENV=$APP_ENV" },
376
- { label: 'org.opencontainers.image.title="app"' },
377
- { workdir: "/app" },
378
- { add: "https://example.com/a.tgz /tmp/" },
379
- { volume: "/data" },
380
- { expose: 8080 },
381
- { stopsignal: "SIGTERM" },
382
- { healthcheck: "CMD wget -qO- http://localhost:8080/health || exit 1" },
383
- { onbuild: "COPY . /app" },
384
- { entrypoint: ["/sbin/tini", "--"] },
385
- { cmd: "node index.js" },
386
- ],
387
- }],
388
- })).toBe([
389
- "ARG NODE_VERSION=20",
390
- "FROM node:${NODE_VERSION}-alpine AS base",
391
- 'SHELL ["/bin/sh","-eo","pipefail","-c"]',
392
- "ARG APP_ENV=production",
393
- "ENV NODE_ENV=$APP_ENV",
394
- 'LABEL org.opencontainers.image.title="app"',
395
- "WORKDIR /app",
396
- "ADD https://example.com/a.tgz /tmp/",
397
- "VOLUME /data",
398
- "EXPOSE 8080",
399
- "STOPSIGNAL SIGTERM",
400
- "HEALTHCHECK CMD wget -qO- http://localhost:8080/health || exit 1",
401
- "ONBUILD COPY . /app",
402
- 'ENTRYPOINT ["/sbin/tini","--"]',
403
- "CMD node index.js",
404
- "",
405
- ].join("\n"));
406
- });
407
-
408
- test("per-kind fields keep their fixed order, byte for byte", () => {
409
- expect(dockerfile({
410
- from: "node:20-alpine",
411
- cmd: "node index.js",
412
- copy: [". ."],
413
- run: ["npm ci"],
414
- user: "node",
415
- workdir: "/app",
416
- })).toBe("FROM node:20-alpine\nWORKDIR /app\nUSER node\nRUN npm ci\nCOPY . .\nCMD node index.js\n");
417
- });
418
-
419
- test("a stage that mixes steps with per-kind fields is an error", () => {
420
- expect(() => dockerfile({ from: "alpine:3.20", run: ["true"], steps: [{ user: "nobody" }] }))
421
- .toThrow(/Dockerfile\.app: steps can't be combined with the per-kind fields \(run\)/);
422
- expect(() => dockerfile({ stages: [{ from: "alpine:3.20", as: "b", copy: ["a b"], steps: [] }] }))
423
- .toThrow(/stage "b": steps can't be combined/);
424
- });
425
-
426
- test("a step names exactly one known instruction", () => {
427
- expect(() => dockerfile({ from: "alpine:3.20", steps: [{ run: "a", copy: "b" }] })).toThrow(/exactly one instruction, found run, copy/);
428
- expect(() => dockerfile({ from: "alpine:3.20", steps: [{}] })).toThrow(/found none/);
429
- expect(() => dockerfile({ from: "alpine:3.20", steps: [{ from: "x" }] })).toThrow(/"from" is not a Dockerfile instruction a step can name/);
430
- expect(() => dockerfile({ from: "alpine:3.20", steps: [{ copy: ["a", "b"] }] })).toThrow(/COPY takes a string/);
431
- });
432
-
433
- test("steps on the Dockerfile itself with stages is an error", () => {
434
- expect(() => dockerfile({ stages: [{ from: "alpine:3.20" }], steps: [{ run: "true" }] })).toThrow(/steps belongs on each stage/);
435
- });
436
-
437
- test("stages and step lists are plain values that can be shared and spread", () => {
438
- const install = [{ copy: "package*.json ./" }, { run: "npm ci" }];
439
- const base = { from: "node:20-alpine", as: "deps", steps: [{ workdir: "/app" }, ...install] };
440
- expect(dockerfile({ stages: [base, { from: "node:20-alpine", steps: [{ copy: "--from=deps /app/node_modules ./node_modules" }] }] }))
441
- .toBe("FROM node:20-alpine AS deps\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci\nFROM node:20-alpine\nCOPY --from=deps /app/node_modules ./node_modules\n");
442
- });
443
- });
444
-
445
- // ── Name generation ───────────────────────────────────────────────
446
-
447
- describe("dockerSerializer.serialize — name gen", () => {
448
- test("uses export name as service key", () => {
449
- const entities = new Map<string, Declarable>();
450
- entities.set("myWebServer", new MockService({ image: "nginx" }));
451
-
452
- const output = dockerSerializer.serialize(entities) as string;
453
- expect(output).toContain("myWebServer:");
454
- });
455
- });
456
-
457
- // ── Telemetry attribution (#2558, D22) ─────────────────────────────
458
-
459
- describe("telemetry attribution", () => {
460
- const run = (props: Record<string, unknown>, telemetry?: { workspace?: string; member?: string; environment?: string }) => {
461
- const result = dockerSerializer.serialize(new Map([["api", new MockService(props)]]), [], telemetry ? { telemetry } : undefined);
462
- return typeof result === "string" ? result : result.primary;
463
- };
464
- const attrs = { workspace: "acme", member: "delivery", environment: "prod" };
465
-
466
- test("a build with no telemetry context is the same bytes as one that passes an empty context", () => {
467
- const props = { image: "nginx:1" };
468
- expect(run(props)).toBe(dockerSerializer.serialize(new Map([["api", new MockService(props)]]), [], {}) as string);
469
- expect(run(props)).not.toContain("OTEL_");
470
- });
471
-
472
- test("stamps the service name and the resource attributes into the environment", () => {
473
- const out = run({ image: "nginx:1" }, attrs);
474
- expect(out).toContain("OTEL_SERVICE_NAME: api");
475
- expect(out).toContain("OTEL_RESOURCE_ATTRIBUTES: chant.workspace=acme,chant.member=delivery,chant.decl=api,deployment.environment.name=prod");
476
- });
477
-
478
- test("leaves out an attribute the build does not know", () => {
479
- const out = run({ image: "nginx:1" }, { workspace: "acme" });
480
- expect(out).toContain("OTEL_RESOURCE_ATTRIBUTES: chant.workspace=acme,chant.decl=api");
481
- expect(out).not.toContain("chant.member");
482
- expect(out).not.toContain("deployment.environment.name");
483
- });
484
-
485
- test("stamps service.version when the image is pinned by digest", () => {
486
- const out = run({ image: "ghcr.io/acme/api@sha256:abc123" }, attrs);
487
- expect(out).toContain("service.version=sha256%3Aabc123");
488
- });
489
-
490
- test("keeps the keys a map environment already sets and appends the missing attributes", () => {
491
- const out = run({ image: "x", environment: { OTEL_SERVICE_NAME: "checkout", OTEL_RESOURCE_ATTRIBUTES: "chant.member=mine,team=pay", PORT: "80" } }, attrs);
492
- expect(out).toContain("OTEL_SERVICE_NAME: checkout");
493
- expect(out).toContain("OTEL_RESOURCE_ATTRIBUTES: chant.member=mine,team=pay,chant.workspace=acme,chant.decl=api,deployment.environment.name=prod");
494
- expect(out).toContain("PORT:");
495
- });
496
-
497
- test("adds the variables to a list environment, keeping an entry already there", () => {
498
- const out = run({ image: "x", environment: ["PORT=80", "OTEL_SERVICE_NAME=checkout"] }, attrs);
499
- expect(out).toContain("- PORT=80");
500
- expect(out).toContain("- OTEL_SERVICE_NAME=checkout");
501
- expect(out).not.toContain("OTEL_SERVICE_NAME=api");
502
- expect(out).toContain("- OTEL_RESOURCE_ATTRIBUTES=chant.workspace=acme,chant.member=delivery");
503
- });
504
-
505
- test("the resource attributes end with the release reference a deploy fills, once (#3061)", () => {
506
- expect(run({ image: "nginx:1" }, attrs)).toContain(
507
- "OTEL_RESOURCE_ATTRIBUTES: chant.workspace=acme,chant.member=delivery,chant.decl=api,deployment.environment.name=prod${CHANT_RELEASE_ATTRIBUTES:-}",
508
- );
509
- const own = run({ image: "x", environment: { OTEL_RESOURCE_ATTRIBUTES: "team=pay${CHANT_RELEASE_ATTRIBUTES:-}" } }, { workspace: "acme" });
510
- expect(own.match(/CHANT_RELEASE_ATTRIBUTES/g)).toHaveLength(1);
511
- expect(run({ image: "x", environment: ["OTEL_RESOURCE_ATTRIBUTES=team=pay"] }, { workspace: "acme" })).toContain(
512
- "- OTEL_RESOURCE_ATTRIBUTES=team=pay,chant.workspace=acme,chant.decl=api${CHANT_RELEASE_ATTRIBUTES:-}",
513
- );
514
- });
515
- });
516
-
517
- describe("composeKey (#3937)", () => {
518
- test("the entity takes the key, and a reference to it serializes as the key", () => {
519
- const data = composeKey("app-data", new MockVolume({ driver: "local" }));
520
- const out = dockerSerializer.serialize(new Map<string, Declarable>([
521
- ["web", composeKey("web-app", new MockService({ image: "nginx", volumes: [data] }))],
522
- ["appData", data],
523
- ])) as string;
524
- expect(out).toContain(" web-app:\n");
525
- expect(out).toContain(" app-data:\n");
526
- expect(out).toContain(" - app-data\n");
527
- expect(out).not.toContain("appData");
528
- });
529
-
530
- test("two entities of one kind with the same key is an error", () => {
531
- expect(() => dockerSerializer.serialize(new Map<string, Declarable>([
532
- ["db", new MockService({ image: "postgres" })],
533
- ["primary", composeKey("db", new MockService({ image: "postgres" }))],
534
- ]))).toThrow('docker: db and primary both take the compose key "db"');
535
- });
536
-
537
- test("a service and a volume may share a key", () => {
538
- const out = dockerSerializer.serialize(new Map<string, Declarable>([
539
- ["db", new MockService({ image: "postgres" })],
540
- ["dbVolume", composeKey("db", new MockVolume({}))],
541
- ])) as string;
542
- expect(out).toContain("services:\n db:\n");
543
- expect(out).toContain("volumes:\n db:");
544
- });
545
- });