@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,170 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { noLatestTagRule } from "./no-latest-tag";
3
- import { perKindOrderRule } from "./per-kind-order";
4
- import { dockerSerializer } from "../../serializer";
5
- import { Dockerfile } from "../../generated/index";
6
- import type { Declarable } from "@intentius/chant/declarable";
7
- import type { LintContext } from "@intentius/chant/lint/rule";
8
- import * as ts from "typescript";
9
-
10
- function makeContext(code: string): LintContext {
11
- const sourceFile = ts.createSourceFile(
12
- "test.ts",
13
- code,
14
- ts.ScriptTarget.Latest,
15
- true,
16
- ts.ScriptKind.TS,
17
- );
18
- return {
19
- sourceFile,
20
- entities: [],
21
- filePath: "test.ts",
22
- lexicon: "docker",
23
- };
24
- }
25
-
26
- // ── DKRS001: no-latest-tag ────────────────────────────────────────
27
-
28
- describe("DKRS001: no-latest-tag", () => {
29
- test("has correct id and severity", () => {
30
- expect(noLatestTagRule.id).toBe("DKRS001");
31
- expect(noLatestTagRule.severity).toBe("warning");
32
- expect(noLatestTagRule.category).toBe("correctness");
33
- });
34
-
35
- test("flags :latest tag", () => {
36
- const ctx = makeContext(`
37
- import { Service } from "@intentius/chant-lexicon-docker";
38
- export const api = new Service({ image: "nginx:latest" });
39
- `);
40
- const diags = noLatestTagRule.check(ctx);
41
- expect(diags.length).toBeGreaterThanOrEqual(1);
42
- expect(diags[0].ruleId).toBe("DKRS001");
43
- expect(diags[0].message).toContain("nginx:latest");
44
- });
45
-
46
- test("flags untagged image (no colon)", () => {
47
- const ctx = makeContext(`
48
- const svc = { image: "nginx" };
49
- `);
50
- const diags = noLatestTagRule.check(ctx);
51
- expect(diags.length).toBeGreaterThanOrEqual(1);
52
- expect(diags[0].message).toContain("nginx");
53
- });
54
-
55
- test("does not flag explicitly versioned image", () => {
56
- const ctx = makeContext(`
57
- const svc = { image: "nginx:1.25-alpine" };
58
- `);
59
- const diags = noLatestTagRule.check(ctx);
60
- expect(diags).toHaveLength(0);
61
- });
62
-
63
- test("does not flag digest-pinned image", () => {
64
- const ctx = makeContext(`
65
- const svc = { image: "nginx@sha256:abc123" };
66
- `);
67
- const diags = noLatestTagRule.check(ctx);
68
- expect(diags).toHaveLength(0);
69
- });
70
-
71
- test("does not flag env() interpolation", () => {
72
- const ctx = makeContext(`
73
- const svc = { image: "\${APP_IMAGE:-myapp:latest}" };
74
- `);
75
- const diags = noLatestTagRule.check(ctx);
76
- expect(diags).toHaveLength(0);
77
- });
78
-
79
- test("does not flag non-image string properties", () => {
80
- const ctx = makeContext(`
81
- const svc = { restart: "latest" };
82
- `);
83
- const diags = noLatestTagRule.check(ctx);
84
- expect(diags).toHaveLength(0);
85
- });
86
- });
87
-
88
- // ── DKRS002: per-kind fields in a different order ─────────────────
89
-
90
- /** Apply a rule's fixes the way `chant lint --fix` does: last range first. */
91
- function applyFixes(code: string, fixes: Array<{ range: [number, number]; replacement: string }>): string {
92
- for (const f of [...fixes].sort((a, b) => b.range[0] - a.range[0])) {
93
- code = code.slice(0, f.range[0]) + f.replacement + code.slice(f.range[1]);
94
- }
95
- return code;
96
- }
97
-
98
- /** Run a module's `export const x = new Dockerfile(...)` and serialize what it declares. */
99
- function build(code: string): string {
100
- const body = code.replace(/^\s*import .*$/m, "").replace(/export const (\w+) =/g, "out.$1 =");
101
- const out: Record<string, Declarable> = {};
102
- new Function("Dockerfile", "out", body)(Dockerfile, out);
103
- const result = dockerSerializer.serialize(new Map(Object.entries(out))) as { files: Record<string, string> };
104
- return Object.values(result.files).join("---\n");
105
- }
106
-
107
- describe("DKRS002: per-kind-order", () => {
108
- const reordered = `import { Dockerfile } from "@intentius/chant-lexicon-docker";
109
- export const app = new Dockerfile({
110
- stages: [
111
- {
112
- from: "node:20-alpine",
113
- as: "build",
114
- workdir: "/app",
115
- copy: ["package*.json ./", ". ."],
116
- run: ["npm ci", "npm run build"],
117
- },
118
- {
119
- from: "node:20-alpine",
120
- workdir: "/app",
121
- user: "node",
122
- cmd: "node dist/index.js",
123
- },
124
- ],
125
- });
126
- `;
127
-
128
- test("flags a stage whose fields read in a different order than they are written", () => {
129
- const diags = perKindOrderRule.check(makeContext(reordered));
130
- expect(diags).toHaveLength(1);
131
- expect(diags[0].ruleId).toBe("DKRS002");
132
- expect(diags[0].line).toBe(7);
133
- expect(diags[0].message).toContain("declared as workdir, copy, run are written in the fixed order workdir, run, copy");
134
- });
135
-
136
- test("flags USER declared after RUN, on a single-stage Dockerfile", () => {
137
- const diags = perKindOrderRule.check(makeContext(`new Dockerfile({ from: "debian:12", run: ["useradd app"], user: "app" });`));
138
- expect(diags).toHaveLength(1);
139
- expect(diags[0].message).toContain("run, user");
140
- });
141
-
142
- test("does not flag fields already in the fixed order, steps, or other objects", () => {
143
- expect(perKindOrderRule.check(makeContext(`new Dockerfile({ from: "a:1", workdir: "/app", user: "node", run: ["x"], copy: [". ."], cmd: "y" });`))).toHaveLength(0);
144
- expect(perKindOrderRule.check(makeContext(`new Dockerfile({ from: "a:1", steps: [{ copy: ". ." }, { run: "x" }] });`))).toHaveLength(0);
145
- expect(perKindOrderRule.check(makeContext(`const o = { copy: ["a"], run: ["b"] };`))).toHaveLength(0);
146
- });
147
-
148
- test("the fix rewrites the fields as steps and the output does not change", () => {
149
- const fixes = perKindOrderRule.fix!(makeContext(reordered));
150
- expect(fixes).toHaveLength(1);
151
- const fixed = applyFixes(reordered, fixes);
152
- expect(fixed).toContain(` // Written by the DKRS002 fix`);
153
- expect(fixed).toContain(` steps: [
154
- { workdir: "/app" },
155
- { run: "npm ci" },
156
- { run: "npm run build" },
157
- { copy: "package*.json ./" },
158
- { copy: ". ." },
159
- ],
160
- },`);
161
- expect(build(fixed)).toBe(build(reordered));
162
- expect(perKindOrderRule.check(makeContext(fixed))).toHaveLength(0);
163
- });
164
-
165
- test("no fix when a list value can't be split into steps", () => {
166
- const diags = perKindOrderRule.check(makeContext(`new Dockerfile({ from: "a:1", copy: files, run: ["x"] });`));
167
- expect(diags).toHaveLength(1);
168
- expect(diags[0].fix).toBeUndefined();
169
- });
170
- });
@@ -1,141 +0,0 @@
1
- import { describe, test, expect, vi, beforeEach } from "vitest";
2
-
3
- const execMock = vi.fn();
4
- vi.mock("node:child_process", async () => {
5
- const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
6
- return { ...actual, exec: (cmd: string, cb: (err: Error | null, out: { stdout: string; stderr: string }) => void) => {
7
- Promise.resolve(execMock(cmd)).then(
8
- (out) => cb(null, out),
9
- (err) => cb(err as Error, { stdout: "", stderr: "" }),
10
- );
11
- } };
12
- });
13
-
14
- const { listArtifacts } = await import("./list-artifacts");
15
-
16
- describe("docker listArtifacts", () => {
17
- beforeEach(() => {
18
- execMock.mockReset();
19
- });
20
-
21
- test("happy path: containers + images + networks all reported", async () => {
22
- execMock.mockImplementation((cmd: string) => {
23
- if (cmd.startsWith("docker ps")) {
24
- return {
25
- stdout: [
26
- JSON.stringify({ Names: "web", ID: "abc123", Image: "nginx:latest", State: "running", Status: "Up 5 minutes" }),
27
- JSON.stringify({ Names: "db", ID: "def456", Image: "postgres:16", State: "running", Status: "Up 2 hours" }),
28
- ].join("\n"),
29
- stderr: "",
30
- };
31
- }
32
- if (cmd.startsWith("docker image ls")) {
33
- return {
34
- stdout: [
35
- JSON.stringify({ ID: "img1", Repository: "nginx", Tag: "latest", Size: "187MB", CreatedAt: "2026-04-01" }),
36
- JSON.stringify({ ID: "img2", Repository: "postgres", Tag: "16", Size: "412MB", CreatedAt: "2026-03-20" }),
37
- ].join("\n"),
38
- stderr: "",
39
- };
40
- }
41
- if (cmd.startsWith("docker network ls")) {
42
- return {
43
- stdout: [
44
- JSON.stringify({ ID: "net1", Name: "bridge", Driver: "bridge", Scope: "local" }),
45
- ].join("\n"),
46
- stderr: "",
47
- };
48
- }
49
- throw new Error(`unexpected cmd: ${cmd}`);
50
- });
51
-
52
- const result = await listArtifacts({ environment: "prod", entities: new Map() });
53
-
54
- expect(Object.keys(result).sort()).toEqual([
55
- "container/db",
56
- "container/web",
57
- "image/nginx:latest",
58
- "image/postgres:16",
59
- "network/bridge",
60
- ]);
61
- expect(result["container/web"]).toMatchObject({
62
- type: "Docker::Container",
63
- physicalId: "abc123",
64
- status: "running",
65
- });
66
- expect(result["image/nginx:latest"]).toMatchObject({ type: "Docker::Image", physicalId: "img1" });
67
- expect(result["network/bridge"]).toMatchObject({ type: "Docker::Network", physicalId: "net1" });
68
- });
69
-
70
- test("daemon unreachable on all queries → returns {}", async () => {
71
- execMock.mockImplementation(() => { throw new Error("Cannot connect to the Docker daemon"); });
72
- const result = await listArtifacts({ environment: "prod", entities: new Map() });
73
- expect(result).toEqual({});
74
- });
75
-
76
- test("per-query failure isolation: containers fail → still get images + networks", async () => {
77
- execMock.mockImplementation((cmd: string) => {
78
- if (cmd.startsWith("docker ps")) {
79
- throw new Error("ps failed");
80
- }
81
- if (cmd.startsWith("docker image ls")) {
82
- return { stdout: JSON.stringify({ ID: "img1", Repository: "alpine", Tag: "3.20", Size: "8MB" }), stderr: "" };
83
- }
84
- if (cmd.startsWith("docker network ls")) {
85
- return { stdout: JSON.stringify({ ID: "net1", Name: "host", Driver: "host", Scope: "local" }), stderr: "" };
86
- }
87
- throw new Error(`unexpected cmd: ${cmd}`);
88
- });
89
-
90
- const result = await listArtifacts({ environment: "prod", entities: new Map() });
91
-
92
- expect(Object.keys(result).filter((k) => k.startsWith("container/"))).toEqual([]);
93
- expect(result["image/alpine:3.20"]).toBeDefined();
94
- expect(result["network/host"]).toBeDefined();
95
- });
96
-
97
- test("container Status surfaces in attributes.fullStatus", async () => {
98
- execMock.mockImplementation((cmd: string) => {
99
- if (cmd.startsWith("docker ps")) {
100
- return { stdout: JSON.stringify({ Names: "web", ID: "x", Image: "i", State: "running", Status: "Up 5 minutes" }), stderr: "" };
101
- }
102
- return { stdout: "", stderr: "" };
103
- });
104
- const result = await listArtifacts({ environment: "prod", entities: new Map() });
105
- expect(result["container/web"].attributes).toMatchObject({ fullStatus: "Up 5 minutes" });
106
- });
107
-
108
- test("dangling images (Repository=<none>) are skipped", async () => {
109
- execMock.mockImplementation((cmd: string) => {
110
- if (cmd.startsWith("docker image ls")) {
111
- return {
112
- stdout: [
113
- JSON.stringify({ ID: "img1", Repository: "<none>", Tag: "<none>", Size: "8MB" }),
114
- JSON.stringify({ ID: "img2", Repository: "nginx", Tag: "latest", Size: "187MB" }),
115
- ].join("\n"),
116
- stderr: "",
117
- };
118
- }
119
- return { stdout: "", stderr: "" };
120
- });
121
- const result = await listArtifacts({ environment: "prod", entities: new Map() });
122
- expect(Object.keys(result).filter((k) => k.startsWith("image/"))).toEqual(["image/nginx:latest"]);
123
- });
124
-
125
- test("malformed NDJSON line is skipped, others still parsed", async () => {
126
- execMock.mockImplementation((cmd: string) => {
127
- if (cmd.startsWith("docker ps")) {
128
- return {
129
- stdout: [
130
- "this is not json",
131
- JSON.stringify({ Names: "web", ID: "x", State: "running", Status: "Up", Image: "i" }),
132
- ].join("\n"),
133
- stderr: "",
134
- };
135
- }
136
- return { stdout: "", stderr: "" };
137
- });
138
- const result = await listArtifacts({ environment: "prod", entities: new Map() });
139
- expect(result["container/web"]).toBeDefined();
140
- });
141
- });
@@ -1,164 +0,0 @@
1
- /**
2
- * Live introspection of a Docker host via three independent CLI queries.
3
- *
4
- * The Docker lexicon's chant entities describe Compose / Dockerfile
5
- * authoring primitives. The runtime concept (running containers, local
6
- * images, networks) is created by `docker compose up` / `docker run` /
7
- * `docker network create` outside chant's entity model.
8
- *
9
- * docker ps --format '{{json .}}' → running containers
10
- * docker image ls --format '{{json .}}' → local images
11
- * docker network ls --format '{{json .}}' → networks
12
- *
13
- * Output is one JSON object per line (NDJSON), not a JSON array. Daemon
14
- * unreachable on any query → that query returns nothing; other queries
15
- * still proceed.
16
- */
17
-
18
- import { exec } from "node:child_process";
19
- import { promisify } from "node:util";
20
- import type { ArtifactMetadata } from "@intentius/chant/lexicon";
21
-
22
- const execAsync = promisify(exec);
23
-
24
- interface DockerContainer {
25
- Names?: string;
26
- ID?: string;
27
- Image?: string;
28
- Command?: string;
29
- State?: string; // "running" | "exited" | "created" | ...
30
- Status?: string; // "Up 5 minutes" | "Exited (0) 1 hour ago" | ...
31
- Ports?: string;
32
- Mounts?: string;
33
- }
34
-
35
- interface DockerImage {
36
- ID?: string;
37
- Repository?: string;
38
- Tag?: string;
39
- CreatedAt?: string;
40
- Size?: string;
41
- }
42
-
43
- interface DockerNetwork {
44
- ID?: string;
45
- Name?: string;
46
- Driver?: string;
47
- Scope?: string;
48
- CreatedAt?: string;
49
- }
50
-
51
- function parseNdjson<T>(stdout: string): T[] {
52
- const out: T[] = [];
53
- for (const line of stdout.split("\n")) {
54
- const trimmed = line.trim();
55
- if (!trimmed) continue;
56
- try {
57
- out.push(JSON.parse(trimmed));
58
- } catch {
59
- // skip malformed lines
60
- }
61
- }
62
- return out;
63
- }
64
-
65
- function pruneUndefined<T extends Record<string, unknown>>(obj: T): Record<string, unknown> {
66
- const out: Record<string, unknown> = {};
67
- for (const [k, v] of Object.entries(obj)) {
68
- if (v !== undefined && v !== "") out[k] = v;
69
- }
70
- return out;
71
- }
72
-
73
- async function listContainers(): Promise<Record<string, ArtifactMetadata>> {
74
- const result: Record<string, ArtifactMetadata> = {};
75
- try {
76
- const { stdout } = await execAsync("docker ps --format '{{json .}}'");
77
- const containers = parseNdjson<DockerContainer>(stdout);
78
- for (const c of containers) {
79
- const name = c.Names;
80
- if (!name) continue;
81
- result[`container/${name}`] = {
82
- type: "Docker::Container",
83
- physicalId: c.ID,
84
- status: c.State ?? c.Status ?? "PRESENT",
85
- attributes: pruneUndefined({
86
- image: c.Image,
87
- command: c.Command,
88
- ports: c.Ports,
89
- mounts: c.Mounts,
90
- fullStatus: c.Status,
91
- }),
92
- };
93
- }
94
- } catch {
95
- // Docker daemon unreachable — return empty, don't fail the lexicon
96
- }
97
- return result;
98
- }
99
-
100
- async function listImages(): Promise<Record<string, ArtifactMetadata>> {
101
- const result: Record<string, ArtifactMetadata> = {};
102
- try {
103
- const { stdout } = await execAsync("docker image ls --format '{{json .}}'");
104
- const images = parseNdjson<DockerImage>(stdout);
105
- for (const img of images) {
106
- if (!img.Repository || img.Repository === "<none>") continue;
107
- const tag = img.Tag && img.Tag !== "<none>" ? img.Tag : "latest";
108
- const key = `image/${img.Repository}:${tag}`;
109
- result[key] = {
110
- type: "Docker::Image",
111
- physicalId: img.ID,
112
- status: "PRESENT",
113
- lastUpdated: img.CreatedAt,
114
- attributes: pruneUndefined({
115
- repository: img.Repository,
116
- tag,
117
- size: img.Size,
118
- }),
119
- };
120
- }
121
- } catch {
122
- // Docker daemon unreachable
123
- }
124
- return result;
125
- }
126
-
127
- async function listNetworks(): Promise<Record<string, ArtifactMetadata>> {
128
- const result: Record<string, ArtifactMetadata> = {};
129
- try {
130
- const { stdout } = await execAsync("docker network ls --format '{{json .}}'");
131
- const networks = parseNdjson<DockerNetwork>(stdout);
132
- for (const net of networks) {
133
- const name = net.Name;
134
- if (!name) continue;
135
- result[`network/${name}`] = {
136
- type: "Docker::Network",
137
- physicalId: net.ID,
138
- status: "PRESENT",
139
- lastUpdated: net.CreatedAt,
140
- attributes: pruneUndefined({
141
- driver: net.Driver,
142
- scope: net.Scope,
143
- }),
144
- };
145
- }
146
- } catch {
147
- // Docker daemon unreachable
148
- }
149
- return result;
150
- }
151
-
152
- export async function listArtifacts(_options: {
153
- environment: string;
154
- entities: Map<string, { entityType: string; props: Record<string, unknown> }>;
155
- }): Promise<Record<string, ArtifactMetadata>> {
156
- // Three independent queries — failure of one doesn't block the others.
157
- const [containers, images, networks] = await Promise.all([
158
- listContainers(),
159
- listImages(),
160
- listNetworks(),
161
- ]);
162
-
163
- return { ...containers, ...images, ...networks };
164
- }
@@ -1,40 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { dockerCompletions } from "./completions";
3
- import type { CompletionContext } from "@intentius/chant/lsp/types";
4
-
5
- // The context these tests build must match the real CompletionContext.
6
- // They previously used an older shape (word / isConstructorContext / prefix /
7
- // fileContent) the interface no longer has — vitest strips types without
8
- // checking them, so every assertion passed while exercising no completion
9
- // path at all.
10
- function ctx(partial: Partial<CompletionContext>): CompletionContext {
11
- return {
12
- uri: "file:///infra.ts",
13
- content: "",
14
- position: { line: 0, character: 0 },
15
- wordAtCursor: "",
16
- linePrefix: "",
17
- ...partial,
18
- };
19
- }
20
-
21
- describe("dockerCompletions", () => {
22
- test("suggests resource class names after `new `", () => {
23
- const items = dockerCompletions(ctx({ linePrefix: "const s = new " }));
24
-
25
- expect(items.length).toBeGreaterThan(0);
26
- expect(items.map((i) => i.label)).toContain("Service");
27
- expect(items.every((i) => i.kind === "resource")).toBe(true);
28
- });
29
-
30
- test("narrows on a typed prefix", () => {
31
- const items = dockerCompletions(ctx({ linePrefix: "new Serv", wordAtCursor: "Serv" }));
32
-
33
- expect(items.map((i) => i.label)).toContain("Service");
34
- expect(items.every((i) => i.label.toLowerCase().startsWith("serv"))).toBe(true);
35
- });
36
-
37
- test("returns nothing in an unrelated position", () => {
38
- expect(dockerCompletions(ctx({ linePrefix: "const x = 1" }))).toEqual([]);
39
- });
40
- });
@@ -1,21 +0,0 @@
1
- import { createRequire } from "module";
2
- import { moduleSourceUrl } from "@intentius/chant/module-source";
3
- import type { CompletionContext, CompletionItem } from "@intentius/chant/lsp/types";
4
- import { LexiconIndex, lexiconCompletions, type LexiconEntry } from "@intentius/chant/lsp/lexicon-providers";
5
- const require = createRequire(moduleSourceUrl(import.meta.url));
6
-
7
- let cachedIndex: LexiconIndex | null = null;
8
-
9
- function getIndex(): LexiconIndex {
10
- if (cachedIndex) return cachedIndex;
11
- const data = require("../generated/lexicon-docker.json") as Record<string, LexiconEntry>;
12
- cachedIndex = new LexiconIndex(data);
13
- return cachedIndex;
14
- }
15
-
16
- /**
17
- * Provide Docker entity completions based on context.
18
- */
19
- export function dockerCompletions(ctx: CompletionContext): CompletionItem[] {
20
- return lexiconCompletions(ctx, getIndex(), "Docker entity");
21
- }
@@ -1,35 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { dockerHover } from "./hover";
3
- import type { HoverContext } from "@intentius/chant/lsp/types";
4
-
5
- // Same correction as completions.test.ts: the old shape (word / fileContent /
6
- // position) no longer matches HoverContext, and the assertions were written to
7
- // pass either way ("undefined or an object", "if result !== undefined"), so a
8
- // hover that returned nothing at all still looked healthy.
9
- function ctx(word: string): HoverContext {
10
- return {
11
- uri: "file:///infra.ts",
12
- content: "",
13
- position: { line: 0, character: 0 },
14
- word,
15
- lineText: "",
16
- };
17
- }
18
-
19
- describe("dockerHover", () => {
20
- test("returns undefined for an unknown word", () => {
21
- expect(dockerHover(ctx("NotADockerThing"))).toBeUndefined();
22
- expect(dockerHover(ctx(""))).toBeUndefined();
23
- });
24
-
25
- test("describes a known resource with its docker type", () => {
26
- const info = dockerHover(ctx("Service"));
27
-
28
- expect(info?.contents).toContain("**Service**");
29
- expect(info?.contents).toContain("Docker::Compose::Service");
30
- });
31
-
32
- test("notes which artifact a resource serializes into", () => {
33
- expect(dockerHover(ctx("Service"))?.contents).toContain("docker-compose.yml");
34
- });
35
- });
package/src/lsp/hover.ts DELETED
@@ -1,39 +0,0 @@
1
- import { createRequire } from "module";
2
- import { moduleSourceUrl } from "@intentius/chant/module-source";
3
- import type { HoverContext, HoverInfo } from "@intentius/chant/lsp/types";
4
- import { LexiconIndex, lexiconHover, type LexiconEntry } from "@intentius/chant/lsp/lexicon-providers";
5
- const require = createRequire(moduleSourceUrl(import.meta.url));
6
-
7
- let cachedIndex: LexiconIndex | null = null;
8
-
9
- function getIndex(): LexiconIndex {
10
- if (cachedIndex) return cachedIndex;
11
- const data = require("../generated/lexicon-docker.json") as Record<string, LexiconEntry>;
12
- cachedIndex = new LexiconIndex(data);
13
- return cachedIndex;
14
- }
15
-
16
- /**
17
- * Provide hover information for Docker entity types.
18
- */
19
- export function dockerHover(ctx: HoverContext): HoverInfo | undefined {
20
- return lexiconHover(ctx, getIndex(), resourceHover);
21
- }
22
-
23
- function resourceHover(className: string, entry: LexiconEntry): HoverInfo | undefined {
24
- const lines: string[] = [];
25
-
26
- lines.push(`**${className}**`);
27
- lines.push("");
28
- lines.push(`Docker type: \`${entry.resourceType}\``);
29
-
30
- if (entry.resourceType.startsWith("Docker::Compose::")) {
31
- lines.push("");
32
- lines.push("*Compose resource — serialized into docker-compose.yml*");
33
- } else if (entry.resourceType === "Docker::Dockerfile") {
34
- lines.push("");
35
- lines.push("*Dockerfile resource — serialized as Dockerfile.{name}*");
36
- }
37
-
38
- return { contents: lines.join("\n") };
39
- }
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env tsx
2
- /**
3
- * Thin entry point for `npm run bundle` in lexicon-docker.
4
- */
5
- import { generate, writeGeneratedFiles } from "./codegen/generate";
6
- import { packageLexicon } from "./codegen/package";
7
- import { writeBundleSpec } from "@intentius/chant/codegen/package";
8
- import { join, dirname } from "path";
9
- import { fileURLToPath } from "url";
10
-
11
- const pkgDir = dirname(dirname(fileURLToPath(import.meta.url)));
12
-
13
- // 1. Generate src/generated/ files
14
- const genResult = await generate({ verbose: true });
15
- writeGeneratedFiles(genResult, pkgDir);
16
- console.error(`Generated ${genResult.resources} entities, ${genResult.properties} property types, ${genResult.enums} enums`);
17
-
18
- // 2. Run package pipeline and write dist/
19
- const { spec, stats } = await packageLexicon({ verbose: true });
20
-
21
- const distDir = join(pkgDir, "dist");
22
- writeBundleSpec(spec, distDir);
23
-
24
- console.error(`Packaged ${stats.resources} entities, ${stats.ruleCount} rules, ${stats.skillCount} skills`);
25
- console.error(`dist/ written to ${distDir}`);