@intentius/chant-lexicon-k8s 0.124.97 → 0.124.98

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 (228) hide show
  1. package/dist/application-paths.d.ts +4 -0
  2. package/dist/application-paths.d.ts.map +1 -0
  3. package/dist/application-paths.js +95 -0
  4. package/dist/application-set.d.ts +46 -0
  5. package/dist/application-set.d.ts.map +1 -0
  6. package/dist/application-set.js +303 -0
  7. package/dist/cluster-secret.d.ts +36 -0
  8. package/dist/cluster-secret.d.ts.map +1 -0
  9. package/dist/cluster-secret.js +55 -0
  10. package/dist/components/kustomize-apply.d.ts +6 -0
  11. package/dist/components/kustomize-apply.d.ts.map +1 -1
  12. package/dist/components/kustomize-apply.js +1 -1
  13. package/dist/config-schema.d.ts +8 -0
  14. package/dist/config-schema.d.ts.map +1 -1
  15. package/dist/config-schema.js +6 -2
  16. package/dist/config.d.ts +26 -3
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/helm-references.d.ts +113 -0
  19. package/dist/helm-references.d.ts.map +1 -0
  20. package/dist/helm-references.js +389 -0
  21. package/dist/import/generator.d.ts +11 -2
  22. package/dist/import/generator.d.ts.map +1 -1
  23. package/dist/import/generator.js +37 -55
  24. package/dist/import/parser.d.ts.map +1 -1
  25. package/dist/import/parser.js +34 -5
  26. package/dist/import/typed-classes.d.ts +57 -0
  27. package/dist/import/typed-classes.d.ts.map +1 -0
  28. package/dist/import/typed-classes.js +126 -0
  29. package/dist/integrity.json +41 -41
  30. package/dist/kustomize/render.d.ts +41 -2
  31. package/dist/kustomize/render.d.ts.map +1 -1
  32. package/dist/kustomize/render.js +114 -7
  33. package/dist/kustomize/root.d.ts +3 -3
  34. package/dist/kustomize/root.d.ts.map +1 -1
  35. package/dist/kustomize/root.js +6 -1
  36. package/dist/lint/post-synth/argo-helpers.d.ts +3 -0
  37. package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
  38. package/dist/lint/post-synth/argo-helpers.js +8 -2
  39. package/dist/lint/post-synth/argo002.d.ts.map +1 -1
  40. package/dist/lint/post-synth/argo002.js +2 -1
  41. package/dist/lint/post-synth/argo003.d.ts.map +1 -1
  42. package/dist/lint/post-synth/argo003.js +2 -1
  43. package/dist/lint/post-synth/argo005.d.ts.map +1 -1
  44. package/dist/lint/post-synth/argo005.js +36 -9
  45. package/dist/lint/post-synth/crd-schema-helpers.d.ts +1 -1
  46. package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
  47. package/dist/lint/post-synth/crd-schema-helpers.js +3 -3
  48. package/dist/lint/post-synth/flux002.d.ts.map +1 -1
  49. package/dist/lint/post-synth/flux002.js +2 -1
  50. package/dist/lint/post-synth/flux003.d.ts.map +1 -1
  51. package/dist/lint/post-synth/flux003.js +2 -1
  52. package/dist/lint/post-synth/k8s-helpers.d.ts +32 -0
  53. package/dist/lint/post-synth/k8s-helpers.d.ts.map +1 -1
  54. package/dist/lint/post-synth/k8s-helpers.js +57 -10
  55. package/dist/lint/post-synth/wk8005.d.ts +9 -0
  56. package/dist/lint/post-synth/wk8005.d.ts.map +1 -1
  57. package/dist/lint/post-synth/wk8005.js +53 -3
  58. package/dist/lint/post-synth/wk8006.d.ts.map +1 -1
  59. package/dist/lint/post-synth/wk8006.js +4 -2
  60. package/dist/lint/post-synth/wk8041.d.ts.map +1 -1
  61. package/dist/lint/post-synth/wk8041.js +3 -2
  62. package/dist/lint/post-synth/wk8042.js +2 -2
  63. package/dist/lint/post-synth/wk8101.js +2 -2
  64. package/dist/lint/post-synth/wk8102.d.ts.map +1 -1
  65. package/dist/lint/post-synth/wk8102.js +7 -3
  66. package/dist/lint/post-synth/wk8103.d.ts.map +1 -1
  67. package/dist/lint/post-synth/wk8103.js +3 -2
  68. package/dist/lint/post-synth/wk8104.d.ts.map +1 -1
  69. package/dist/lint/post-synth/wk8104.js +3 -2
  70. package/dist/lint/post-synth/wk8105.d.ts.map +1 -1
  71. package/dist/lint/post-synth/wk8105.js +3 -2
  72. package/dist/lint/post-synth/wk8201.d.ts.map +1 -1
  73. package/dist/lint/post-synth/wk8201.js +3 -2
  74. package/dist/lint/post-synth/wk8202.d.ts.map +1 -1
  75. package/dist/lint/post-synth/wk8202.js +3 -2
  76. package/dist/lint/post-synth/wk8203.d.ts.map +1 -1
  77. package/dist/lint/post-synth/wk8203.js +3 -2
  78. package/dist/lint/post-synth/wk8204.d.ts.map +1 -1
  79. package/dist/lint/post-synth/wk8204.js +5 -2
  80. package/dist/lint/post-synth/wk8205.d.ts.map +1 -1
  81. package/dist/lint/post-synth/wk8205.js +3 -2
  82. package/dist/lint/post-synth/wk8207.js +2 -2
  83. package/dist/lint/post-synth/wk8208.js +2 -2
  84. package/dist/lint/post-synth/wk8209.js +2 -2
  85. package/dist/lint/post-synth/wk8301.d.ts.map +1 -1
  86. package/dist/lint/post-synth/wk8301.js +3 -2
  87. package/dist/lint/post-synth/wk8302.js +2 -2
  88. package/dist/lint/post-synth/wk8303.js +2 -2
  89. package/dist/lint/post-synth/wk8304.js +2 -2
  90. package/dist/lint/post-synth/wk8305.js +2 -2
  91. package/dist/lint/post-synth/wk8306.d.ts.map +1 -1
  92. package/dist/lint/post-synth/wk8306.js +3 -2
  93. package/dist/lint/post-synth/wk8401.js +2 -2
  94. package/dist/lint/post-synth/wk8402.js +2 -2
  95. package/dist/lint/post-synth/wk8403.js +2 -2
  96. package/dist/lint/post-synth/wk8404.d.ts.map +1 -1
  97. package/dist/lint/post-synth/wk8404.js +2 -2
  98. package/dist/lint/post-synth/wk8405.js +2 -2
  99. package/dist/lint/post-synth/wk8406.d.ts.map +1 -1
  100. package/dist/lint/post-synth/wk8406.js +3 -2
  101. package/dist/lint/post-synth/wk8407.js +2 -2
  102. package/dist/lint/post-synth/wk8503.js +2 -2
  103. package/dist/manifest.json +1 -1
  104. package/dist/reference-catalog.d.ts +3 -1
  105. package/dist/reference-catalog.d.ts.map +1 -1
  106. package/dist/reference-catalog.js +283 -15
  107. package/dist/rules/argo-helpers.ts +9 -2
  108. package/dist/rules/argo002.ts +2 -1
  109. package/dist/rules/argo003.ts +2 -1
  110. package/dist/rules/argo005.ts +36 -10
  111. package/dist/rules/crd-schema-helpers.ts +3 -3
  112. package/dist/rules/flux002.ts +2 -1
  113. package/dist/rules/flux003.ts +2 -1
  114. package/dist/rules/k8s-helpers.ts +56 -11
  115. package/dist/rules/wk8005.ts +56 -3
  116. package/dist/rules/wk8006.ts +4 -2
  117. package/dist/rules/wk8041.ts +3 -2
  118. package/dist/rules/wk8042.ts +2 -2
  119. package/dist/rules/wk8101.ts +2 -2
  120. package/dist/rules/wk8102.ts +7 -3
  121. package/dist/rules/wk8103.ts +3 -2
  122. package/dist/rules/wk8104.ts +3 -2
  123. package/dist/rules/wk8105.ts +3 -2
  124. package/dist/rules/wk8201.ts +3 -2
  125. package/dist/rules/wk8202.ts +3 -2
  126. package/dist/rules/wk8203.ts +3 -2
  127. package/dist/rules/wk8204.ts +5 -2
  128. package/dist/rules/wk8205.ts +3 -2
  129. package/dist/rules/wk8207.ts +2 -2
  130. package/dist/rules/wk8208.ts +2 -2
  131. package/dist/rules/wk8209.ts +2 -2
  132. package/dist/rules/wk8301.ts +3 -2
  133. package/dist/rules/wk8302.ts +2 -2
  134. package/dist/rules/wk8303.ts +2 -2
  135. package/dist/rules/wk8304.ts +2 -2
  136. package/dist/rules/wk8305.ts +2 -2
  137. package/dist/rules/wk8306.ts +3 -2
  138. package/dist/rules/wk8401.ts +2 -2
  139. package/dist/rules/wk8402.ts +2 -2
  140. package/dist/rules/wk8403.ts +2 -2
  141. package/dist/rules/wk8404.ts +2 -1
  142. package/dist/rules/wk8405.ts +2 -2
  143. package/dist/rules/wk8406.ts +3 -2
  144. package/dist/rules/wk8407.ts +2 -2
  145. package/dist/rules/wk8503.ts +2 -2
  146. package/dist/workspace-member.d.ts +15 -3
  147. package/dist/workspace-member.d.ts.map +1 -1
  148. package/dist/workspace-member.js +151 -21
  149. package/package.json +5 -5
  150. package/src/application-paths.ts +96 -0
  151. package/src/application-set.test.ts +130 -0
  152. package/src/application-set.ts +336 -0
  153. package/src/cluster-secret.test.ts +117 -0
  154. package/src/cluster-secret.ts +76 -0
  155. package/src/components/kustomize-apply.ts +7 -1
  156. package/src/config-schema.ts +6 -2
  157. package/src/config.ts +24 -4
  158. package/src/helm-references.test.ts +149 -0
  159. package/src/helm-references.ts +425 -0
  160. package/src/import/generator.test.ts +57 -0
  161. package/src/import/generator.ts +35 -61
  162. package/src/import/parser.test.ts +59 -0
  163. package/src/import/parser.ts +38 -5
  164. package/src/import/roundtrip-build.test.ts +91 -0
  165. package/src/import/typed-classes.ts +168 -0
  166. package/src/kustomize/helm.test.ts +183 -0
  167. package/src/kustomize/render.ts +142 -6
  168. package/src/kustomize/root.ts +8 -3
  169. package/src/lint/post-synth/argo-helpers.ts +9 -2
  170. package/src/lint/post-synth/argo002.ts +2 -1
  171. package/src/lint/post-synth/argo003.ts +2 -1
  172. package/src/lint/post-synth/argo005.ts +36 -10
  173. package/src/lint/post-synth/audit-identity.test.ts +65 -0
  174. package/src/lint/post-synth/crd-schema-helpers.ts +3 -3
  175. package/src/lint/post-synth/flux002.ts +2 -1
  176. package/src/lint/post-synth/flux003.ts +2 -1
  177. package/src/lint/post-synth/k8s-helpers.ts +56 -11
  178. package/src/lint/post-synth/post-synth.test.ts +144 -0
  179. package/src/lint/post-synth/wk8005.ts +56 -3
  180. package/src/lint/post-synth/wk8006.ts +4 -2
  181. package/src/lint/post-synth/wk8041.ts +3 -2
  182. package/src/lint/post-synth/wk8042.ts +2 -2
  183. package/src/lint/post-synth/wk8101.ts +2 -2
  184. package/src/lint/post-synth/wk8102.ts +7 -3
  185. package/src/lint/post-synth/wk8103.ts +3 -2
  186. package/src/lint/post-synth/wk8104.ts +3 -2
  187. package/src/lint/post-synth/wk8105.ts +3 -2
  188. package/src/lint/post-synth/wk8201.ts +3 -2
  189. package/src/lint/post-synth/wk8202.ts +3 -2
  190. package/src/lint/post-synth/wk8203.ts +3 -2
  191. package/src/lint/post-synth/wk8204.ts +5 -2
  192. package/src/lint/post-synth/wk8205.ts +3 -2
  193. package/src/lint/post-synth/wk8207.ts +2 -2
  194. package/src/lint/post-synth/wk8208.ts +2 -2
  195. package/src/lint/post-synth/wk8209.ts +2 -2
  196. package/src/lint/post-synth/wk8301.ts +3 -2
  197. package/src/lint/post-synth/wk8302.ts +2 -2
  198. package/src/lint/post-synth/wk8303.ts +2 -2
  199. package/src/lint/post-synth/wk8304.ts +2 -2
  200. package/src/lint/post-synth/wk8305.ts +2 -2
  201. package/src/lint/post-synth/wk8306.ts +3 -2
  202. package/src/lint/post-synth/wk8401.ts +2 -2
  203. package/src/lint/post-synth/wk8402.ts +2 -2
  204. package/src/lint/post-synth/wk8403.ts +2 -2
  205. package/src/lint/post-synth/wk8404.ts +2 -1
  206. package/src/lint/post-synth/wk8405.ts +2 -2
  207. package/src/lint/post-synth/wk8406.ts +3 -2
  208. package/src/lint/post-synth/wk8407.ts +2 -2
  209. package/src/lint/post-synth/wk8503.ts +2 -2
  210. package/src/reference-catalog.test.ts +78 -0
  211. package/src/reference-catalog.ts +297 -16
  212. package/src/testdata/helm-chart-missing/kustomization.yaml +8 -0
  213. package/src/testdata/helm-chart-root/charts/webchart/Chart.yaml +3 -0
  214. package/src/testdata/helm-chart-root/charts/webchart/templates/configmap.yaml +6 -0
  215. package/src/testdata/helm-chart-root/charts/webchart/values.yaml +1 -0
  216. package/src/testdata/helm-chart-root/kustomization.yaml +9 -0
  217. package/src/testdata/helm-chart-root/values.yaml +1 -0
  218. package/src/testdata/workspace-members/argo-clusters/clusters.yaml +34 -0
  219. package/src/testdata/workspace-members/argo-set/all.yaml +43 -0
  220. package/src/testdata/workspace-members/plain/deploy.yaml +27 -0
  221. package/src/testdata/workspace-members/plain/es.yaml +15 -0
  222. package/src/testdata/workspace-members/templated/block.yaml +6 -0
  223. package/src/testdata/workspace-members/templated/chart-cm.yaml +4 -0
  224. package/src/testdata/workspace-members/templated/cm.yaml +6 -0
  225. package/src/workspace-kinds.test.ts +9 -1
  226. package/src/workspace-member.test.ts +69 -3
  227. package/src/workspace-member.ts +165 -24
  228. package/workspace-kinds.json +45 -6
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Helm inflation for kustomize renders (#5112). What must hold: --enable-helm
3
+ * is passed only when the entry asks for it; a kustomization with helmCharts
4
+ * and no such ask fails naming the charts and the option; a chart that is not
5
+ * in the chart home fails naming the chart, without a pull, unless fetchCharts
6
+ * allows the network; and a workspace member that cannot render keeps the
7
+ * chart and values nodes it read as data.
8
+ *
9
+ * The fixtures hold a local chart in their chart home, so nothing here
10
+ * reaches the network. The real-binary test runs when kubectl and helm are
11
+ * installed.
12
+ */
13
+ import { describe, expect, test } from "vitest";
14
+ import { execFileSync } from "node:child_process";
15
+ import { dirname, join } from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+ import { checkHelmOptions, renderCommand, renderKustomizeDocuments, KustomizeHelmDisabledError, KustomizeHelmRenderError, type KustomizeRunner } from "./render";
18
+ import { renderKustomizeRoots } from "./root";
19
+ import { memberHelmOptions, readK8sMember } from "../workspace-member";
20
+ import { createKustomizeApplyCapability } from "../components/kustomize-apply";
21
+
22
+ const here = dirname(fileURLToPath(import.meta.url));
23
+ const withChart = join(here, "..", "testdata", "helm-chart-root");
24
+ const noChart = join(here, "..", "testdata", "helm-chart-missing");
25
+ const plain = join(here, "..", "testdata", "kustomize-root", "overlays", "prod");
26
+
27
+ const CONFIGMAP = "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: web-config\ndata:\n message: hello from values\n";
28
+
29
+ /** Records each command and answers with the rendered ConfigMap. */
30
+ function recording(): { commands: string[]; run: KustomizeRunner } {
31
+ const commands: string[] = [];
32
+ return { commands, run: async (command) => (commands.push(command), { stdout: CONFIGMAP }) };
33
+ }
34
+
35
+ describe("renderCommand", () => {
36
+ test("passes no helm flag by default", () => {
37
+ expect(renderCommand("/x")).toBe("kustomize build '/x'");
38
+ expect(renderCommand("/x", "kubectl")).toBe("kubectl kustomize '/x'");
39
+ });
40
+ test("enableHelm adds --enable-helm to either binary, and helmCommand adds --helm-command", () => {
41
+ expect(renderCommand("/x", "kustomize", { enableHelm: true })).toBe("kustomize build --enable-helm '/x'");
42
+ expect(renderCommand("/x", "kubectl", { enableHelm: true, helmCommand: "/opt/bin/helm" })).toBe(
43
+ "kubectl kustomize --enable-helm --helm-command '/opt/bin/helm' '/x'",
44
+ );
45
+ });
46
+ test("helmCommand and fetchCharts alone add nothing without enableHelm", () => {
47
+ expect(renderCommand("/x", "kustomize", { helmCommand: "helm", fetchCharts: true })).toBe("kustomize build '/x'");
48
+ });
49
+ });
50
+
51
+ describe("checkHelmOptions", () => {
52
+ test("a kustomization with no helmCharts needs nothing", () => {
53
+ expect(() => checkHelmOptions(plain)).not.toThrow();
54
+ });
55
+ test("helmCharts without enableHelm is refused naming the chart and the option, before any run", async () => {
56
+ const { commands, run } = recording();
57
+ await expect(renderKustomizeDocuments(withChart, run)).rejects.toThrow(KustomizeHelmDisabledError);
58
+ await expect(renderKustomizeDocuments(withChart, run)).rejects.toThrow(/"webchart" 0\.1\.0.*enableHelm: true/s);
59
+ expect(commands).toEqual([]);
60
+ });
61
+ test("a chart in the chart home renders with no network setting", async () => {
62
+ const { commands, run } = recording();
63
+ const docs = await renderKustomizeDocuments(withChart, run, { enableHelm: true });
64
+ expect(docs).toHaveLength(1);
65
+ expect(commands).toEqual([`kustomize build --enable-helm '${withChart}'`]);
66
+ });
67
+ test("a chart that is not in the chart home fails naming it, and starts no pull", async () => {
68
+ const { commands, run } = recording();
69
+ const err = await renderKustomizeDocuments(noChart, run, { enableHelm: true }).catch((e) => e);
70
+ expect(err).toBeInstanceOf(KustomizeHelmRenderError);
71
+ expect(err.message).toMatch(/"absent" 9\.9\.9/);
72
+ expect(err.message).toMatch(/no network is used/);
73
+ expect(err.message).toMatch(/fetchCharts: true/);
74
+ expect(commands).toEqual([]);
75
+ });
76
+ test("fetchCharts lets the render run, which is the one setting that reaches the network", async () => {
77
+ const { commands, run } = recording();
78
+ await renderKustomizeDocuments(noChart, run, { enableHelm: true, fetchCharts: true });
79
+ expect(commands).toHaveLength(1);
80
+ });
81
+ test("kustomize's own refusal from a base the pre-check cannot see still names the option", async () => {
82
+ const run: KustomizeRunner = async () => {
83
+ throw new Error("error: trouble configuring builtin HelmChartInflationGenerator with config: x: must specify --enable-helm");
84
+ };
85
+ await expect(renderKustomizeDocuments(plain, run)).rejects.toThrow(/enableHelm: true/);
86
+ });
87
+ test("a missing helm binary reported by kustomize is a helm failure, not a missing kustomize", async () => {
88
+ const run: KustomizeRunner = async () => {
89
+ throw new Error('Error: unable to run: \'helm pull\' (is \'helm\' installed?): exec: "helm": executable file not found in $PATH');
90
+ };
91
+ await expect(renderKustomizeDocuments(withChart, run, { enableHelm: true })).rejects.toThrow(KustomizeHelmRenderError);
92
+ });
93
+ });
94
+
95
+ describe("kustomize.roots entries", () => {
96
+ test("an entry with enableHelm renders; one without is refused naming the entry's charts", async () => {
97
+ const { commands, run } = recording();
98
+ const ok = await renderKustomizeRoots({ projectRoot: dirname(withChart), roots: [{ path: "helm-chart-root", enableHelm: true, helmCommand: "helm" }], run });
99
+ expect([...ok.entities.keys()]).toEqual(["helm-chart-root/configMapWebConfig"]);
100
+ expect(commands[0]).toBe(`kustomize build --enable-helm --helm-command 'helm' '${withChart}'`);
101
+ await expect(renderKustomizeRoots({ projectRoot: dirname(withChart), roots: ["helm-chart-root"], run })).rejects.toThrow(/"webchart".*enableHelm: true/s);
102
+ });
103
+ });
104
+
105
+ describe("the deploy-time render", () => {
106
+ test("kustomize-apply passes the same options", async () => {
107
+ const { commands, run } = recording();
108
+ const cap = createKustomizeApplyCapability(run, async () => ({ applied: [], pruned: [] }) as never);
109
+ await cap.run({ env: "dev" } as never, { dir: withChart, enableHelm: true });
110
+ expect(commands[0]).toContain("--enable-helm");
111
+ });
112
+ });
113
+
114
+ describe("a workspace member with helmCharts", () => {
115
+ const member = { kind: "kustomize" as const, dir: withChart, label: "web", workspace: dirname(withChart) };
116
+
117
+ test("the environment allows inflation when the config says nothing", () => {
118
+ expect(memberHelmOptions(member, {})).toEqual({ enableHelm: false, helmCommand: undefined, fetchCharts: false });
119
+ expect(memberHelmOptions(member, { CHANT_K8S_ENABLE_HELM: "1", CHANT_K8S_HELM_COMMAND: "/b/helm", CHANT_K8S_FETCH_CHARTS: "true" })).toEqual({
120
+ enableHelm: true,
121
+ helmCommand: "/b/helm",
122
+ fetchCharts: true,
123
+ });
124
+ expect(memberHelmOptions({ ...member, enableHelm: false }, { CHANT_K8S_ENABLE_HELM: "1" }).enableHelm).toBe(false);
125
+ });
126
+
127
+ test("with inflation off the member is not rendered but keeps its kustomization node and says why", async () => {
128
+ const { commands, run } = recording();
129
+ const read = await readK8sMember({ member, run });
130
+ expect(commands).toEqual([]);
131
+ expect(read.report.rendered).toBe(false);
132
+ expect(read.report.reason).toMatch(/enableHelm: true/);
133
+ expect(read.warnings.join("\n")).toMatch(/was not rendered/);
134
+ const kinds = [...read.entities.values()].map((e) => (e as unknown as { kind?: string; props?: { kind?: string } }).props?.kind ?? (e as { kind?: string }).kind);
135
+ expect(kinds).toContain("Kustomization");
136
+ expect(kinds).not.toContain("ConfigMap");
137
+ });
138
+
139
+ test("with inflation on the objects the chart renders join the nodes read as data", async () => {
140
+ const { commands, run } = recording();
141
+ const read = await readK8sMember({ member: { ...member, enableHelm: true }, run });
142
+ expect(commands[0]).toContain("--enable-helm");
143
+ expect(read.report.rendered).toBe(true);
144
+ const kinds = [...read.entities.values()].map((e) => (e as unknown as { kind?: string; props?: { kind?: string } }).props?.kind ?? (e as { kind?: string }).kind);
145
+ expect(kinds).toContain("Kustomization");
146
+ expect(kinds).toContain("ConfigMap");
147
+ });
148
+
149
+ test("with inflation on and the chart missing the member is not rendered, not lost", async () => {
150
+ const { run } = recording();
151
+ const read = await readK8sMember({ member: { ...member, dir: noChart, label: "absent", enableHelm: true }, run });
152
+ expect(read.report.rendered).toBe(false);
153
+ expect(read.report.reason).toMatch(/"absent" 9\.9\.9/);
154
+ expect(read.entities.size).toBeGreaterThan(0);
155
+ });
156
+
157
+ test("a render failure with no helm in it still fails the member", async () => {
158
+ const run: KustomizeRunner = async () => {
159
+ throw new Error("error: accumulating resources: missing base");
160
+ };
161
+ await expect(readK8sMember({ member: { ...member, dir: plain, label: "p" }, run })).rejects.toThrow(/missing base/);
162
+ });
163
+ });
164
+
165
+ function installed(bin: string, arg: string): boolean {
166
+ try {
167
+ execFileSync(bin, [arg], { stdio: "ignore" });
168
+ return true;
169
+ } catch {
170
+ return false;
171
+ }
172
+ }
173
+
174
+ describe.skipIf(!(installed("kubectl", "version") && installed("helm", "version")))("with the real binaries", () => {
175
+ test("a local chart renders with enableHelm, with no network", async () => {
176
+ const docs = await renderKustomizeDocuments(withChart, undefined, { enableHelm: true });
177
+ expect(docs).toHaveLength(1);
178
+ expect(docs[0]).toMatchObject({ kind: "ConfigMap", metadata: { name: "web-config" }, data: { message: "hello from values" } });
179
+ });
180
+ test("a chart that is not cached fails naming it, and writes nothing into the root", async () => {
181
+ await expect(renderKustomizeDocuments(noChart, undefined, { enableHelm: true })).rejects.toThrow(/"absent" 9\.9\.9/);
182
+ });
183
+ });
@@ -21,8 +21,11 @@
21
21
  * megabytes.
22
22
  */
23
23
  import { exec } from "node:child_process";
24
+ import { existsSync, statSync } from "node:fs";
25
+ import { isAbsolute, join, relative, resolve } from "node:path";
24
26
  import { promisify } from "node:util";
25
27
  import { loadAll } from "js-yaml";
28
+ import { readKustomizationFile } from "../helm-references";
26
29
 
27
30
  const execAsync = promisify(exec);
28
31
 
@@ -37,9 +40,116 @@ function q(v: string): string {
37
40
  return `'${v.replace(/'/g, "'\\''")}'`;
38
41
  }
39
42
 
43
+ /**
44
+ * Helm inflation for a render (#5112). A kustomization with `helmCharts` only
45
+ * renders when kustomize is given `--enable-helm`, and kustomize then runs
46
+ * `helm pull` for any chart that is not already in the chart home, which
47
+ * reaches the network. Both are off until the caller asks.
48
+ */
49
+ export interface KustomizeHelmOptions {
50
+ /** Pass `--enable-helm`. Without it a kustomization that has `helmCharts` is refused with a message naming this option. */
51
+ enableHelm?: boolean;
52
+ /** The `helm` binary, passed as `--helm-command`. Unset, kustomize looks for `helm` on PATH. */
53
+ helmCommand?: string;
54
+ /** Let kustomize pull a chart that is not in the chart home. Unset, a chart that is missing fails naming the chart, and no network is used. Needs `enableHelm`. */
55
+ fetchCharts?: boolean;
56
+ }
57
+
40
58
  /** The exact render command, standalone binary first. Pure; exported for tests. */
41
- export function renderCommand(dir: string, tool: "kustomize" | "kubectl" = "kustomize"): string {
42
- return tool === "kustomize" ? `kustomize build ${q(dir)}` : `kubectl kustomize ${q(dir)}`;
59
+ export function renderCommand(dir: string, tool: "kustomize" | "kubectl" = "kustomize", helm: KustomizeHelmOptions = {}): string {
60
+ const flags = helm.enableHelm ? ` --enable-helm${helm.helmCommand ? ` --helm-command ${q(helm.helmCommand)}` : ""}` : "";
61
+ return tool === "kustomize" ? `kustomize build${flags} ${q(dir)}` : `kubectl kustomize${flags} ${q(dir)}`;
62
+ }
63
+
64
+ /**
65
+ * A kustomization names a chart and the render was not allowed to inflate it
66
+ * (`enableHelm` unset). A class of its own so the workspace graph reader tells
67
+ * it from a render the binary ran and refused.
68
+ */
69
+ export class KustomizeHelmDisabledError extends Error {
70
+ constructor(message: string) {
71
+ super(message);
72
+ this.name = "KustomizeHelmDisabledError";
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Helm inflation was asked for and a chart could not be had: it is not in the
78
+ * chart home and `fetchCharts` is off, or helm failed on it. The member reader
79
+ * keeps the Helm nodes it read as data when it sees this.
80
+ */
81
+ export class KustomizeHelmRenderError extends Error {
82
+ constructor(message: string) {
83
+ super(message);
84
+ this.name = "KustomizeHelmRenderError";
85
+ }
86
+ }
87
+
88
+ interface ChartEntry {
89
+ /** The directory of the kustomization that names the chart. */
90
+ dir: string;
91
+ name: string;
92
+ version: string;
93
+ chartHome: string;
94
+ }
95
+
96
+ /** Every `helmCharts` entry of the kustomization at `dir` and of the local directories it lists in `resources`, `bases` and `components`. */
97
+ function helmChartEntries(dir: string, seen = new Set<string>()): ChartEntry[] {
98
+ const root = resolve(dir);
99
+ if (seen.has(root)) return [];
100
+ seen.add(root);
101
+ const read = readKustomizationFile(root);
102
+ if (!read) return [];
103
+ const { doc } = read;
104
+ const entries: ChartEntry[] = [];
105
+ const globals = doc.helmGlobals && typeof doc.helmGlobals === "object" && !Array.isArray(doc.helmGlobals) ? (doc.helmGlobals as Record<string, unknown>) : {};
106
+ const home = typeof globals.chartHome === "string" && globals.chartHome !== "" ? globals.chartHome : "charts";
107
+ for (const c of Array.isArray(doc.helmCharts) ? doc.helmCharts : []) {
108
+ if (!c || typeof c !== "object" || Array.isArray(c)) continue;
109
+ const e = c as Record<string, unknown>;
110
+ if (typeof e.name !== "string" || e.name === "") continue;
111
+ entries.push({ dir: root, name: e.name, version: typeof e.version === "string" ? e.version : "", chartHome: isAbsolute(home) ? home : join(root, home) });
112
+ }
113
+ for (const key of ["resources", "bases", "components"]) {
114
+ for (const item of Array.isArray(doc[key]) ? doc[key] : []) {
115
+ if (typeof item !== "string" || /^[a-z][a-z0-9+.-]*:\/\//i.test(item) || item.includes("::") || item.startsWith("git@")) continue;
116
+ const child = resolve(root, item);
117
+ if (existsSync(child) && statSync(child).isDirectory()) entries.push(...helmChartEntries(child, seen));
118
+ }
119
+ }
120
+ return entries;
121
+ }
122
+
123
+ const chartLabel = (c: ChartEntry): string => `"${c.name}"${c.version ? ` ${c.version}` : ""}`;
124
+
125
+ /**
126
+ * Check a render's Helm settings before any subprocess runs. With inflation
127
+ * off, a kustomization that has `helmCharts` is refused here, naming the
128
+ * charts and the option. With it on and `fetchCharts` off, a chart that is
129
+ * not in its chart home is refused naming the chart and the directory it is
130
+ * expected in, so a render with no network says what is missing and never
131
+ * starts a pull. Kustomizations the root lists are checked too.
132
+ */
133
+ export function checkHelmOptions(dir: string, helm: KustomizeHelmOptions = {}): void {
134
+ const charts = helmChartEntries(dir);
135
+ if (charts.length === 0) return;
136
+ if (!helm.enableHelm) {
137
+ throw new KustomizeHelmDisabledError(
138
+ `Kustomization "${dir}" names Helm charts (${charts.map(chartLabel).join(", ")}), which kustomize renders only with --enable-helm. ` +
139
+ `Set enableHelm: true on the entry (k8s.kustomize.roots, or the member's k8s.member) to allow it; kustomize pulls a chart that is not in its chart home, so also set fetchCharts: true to allow the network.`,
140
+ );
141
+ }
142
+ if (helm.fetchCharts) return;
143
+ // kustomize uses `<chartHome>/<name>`, and puts a chart it pulled at `<chartHome>/<name>-<version>/<name>`.
144
+ const missing = charts.filter((c) => !existsSync(join(c.chartHome, c.name)) && !(c.version && existsSync(join(c.chartHome, `${c.name}-${c.version}`, c.name))));
145
+ if (missing.length > 0) {
146
+ const first = missing[0]!;
147
+ throw new KustomizeHelmRenderError(
148
+ `Kustomization "${dir}" names Helm chart ${chartLabel(first)}${missing.length > 1 ? ` and ${missing.length - 1} more (${missing.slice(1).map(chartLabel).join(", ")})` : ""}, ` +
149
+ `which is not in the chart home (${relative(resolve(dir), join(first.chartHome, first.name)) || "."} was expected), and fetching charts is off, so no network is used. ` +
150
+ `Put the chart there, or set fetchCharts: true to let kustomize pull it from its repository.`,
151
+ );
152
+ }
43
153
  }
44
154
 
45
155
  /**
@@ -57,9 +167,33 @@ export class KustomizeBinaryMissingError extends Error {
57
167
  /** Does this error mean "the binary is not installed" (vs "the render failed")? */
58
168
  function isMissingBinary(err: unknown): boolean {
59
169
  const message = err instanceof Error ? err.message : String(err);
170
+ // Go's "exec: \"helm\": executable file not found" is kustomize reporting a missing helm, not a missing kustomize.
171
+ if (/executable file not found/.test(message)) return false;
60
172
  return /ENOENT|not found|command not found|127/.test(message);
61
173
  }
62
174
 
175
+ /**
176
+ * A failure from the binary that is about Helm gets a message that names the
177
+ * option or the chart; any other failure is kustomize's own and passes through.
178
+ * The pre-check reads the root and the directories it lists, so this catches
179
+ * what it cannot see: a base that is a remote reference, or a chart helm
180
+ * itself refuses.
181
+ */
182
+ function refineHelmFailure(dir: string, err: unknown, helm: KustomizeHelmOptions): unknown {
183
+ const text = err instanceof Error ? err.message : String(err);
184
+ if (!helm.enableHelm && /must specify --enable-helm/.test(text)) {
185
+ return new KustomizeHelmDisabledError(
186
+ `Kustomization "${dir}" names Helm charts, which kustomize renders only with --enable-helm. Set enableHelm: true on the entry to allow it. kustomize said: ${text}`,
187
+ );
188
+ }
189
+ if (helm.enableHelm && /helm|chart/i.test(text) && helmChartEntries(dir).length > 0) {
190
+ return new KustomizeHelmRenderError(
191
+ `Kustomization "${dir}" has Helm charts and helm failed on them${helm.fetchCharts ? "" : " (fetching charts is off)"}. kustomize said: ${text}`,
192
+ );
193
+ }
194
+ return err;
195
+ }
196
+
63
197
  /**
64
198
  * Render the kustomization at `dir` and parse the emitted YAML into document
65
199
  * objects. Falls back to kubectl's vendored kustomize when the standalone
@@ -69,14 +203,16 @@ function isMissingBinary(err: unknown): boolean {
69
203
  export async function renderKustomizeDocuments(
70
204
  dir: string,
71
205
  run: KustomizeRunner = defaultKustomizeRunner,
206
+ helm: KustomizeHelmOptions = {},
72
207
  ): Promise<Array<Record<string, unknown>>> {
208
+ checkHelmOptions(dir, helm);
73
209
  let stdout: string;
74
210
  try {
75
- ({ stdout } = await run(renderCommand(dir, "kustomize")));
211
+ ({ stdout } = await run(renderCommand(dir, "kustomize", helm)));
76
212
  } catch (err) {
77
- if (!isMissingBinary(err)) throw err;
213
+ if (!isMissingBinary(err)) throw refineHelmFailure(dir, err, helm);
78
214
  try {
79
- ({ stdout } = await run(renderCommand(dir, "kubectl")));
215
+ ({ stdout } = await run(renderCommand(dir, "kubectl", helm)));
80
216
  } catch (err2) {
81
217
  if (isMissingBinary(err2)) {
82
218
  throw new KustomizeBinaryMissingError(
@@ -85,7 +221,7 @@ export async function renderKustomizeDocuments(
85
221
  `Install kustomize or kubectl and retry.`,
86
222
  );
87
223
  }
88
- throw err2;
224
+ throw refineHelmFailure(dir, err2, helm);
89
225
  }
90
226
  }
91
227
  const documents: Array<Record<string, unknown>> = [];
@@ -20,6 +20,10 @@
20
20
  * - **Deterministic**: entity names derive from the root dir plus each
21
21
  * document's kind/name/namespace, disambiguated in render order — the same
22
22
  * overlay renders the same entity set every build.
23
+ * - **Helm is opt-in** (#5112): a root with `helmCharts` renders only with
24
+ * `enableHelm: true` on its entry, and a chart that is not already in the
25
+ * chart home is pulled only with `fetchCharts: true` (the one setting that
26
+ * reaches the network).
23
27
  * - **Fail loudly, not weirdly**: a root that doesn't exist, or a dir with no
24
28
  * kustomization file, refuses with the path in the message before any
25
29
  * subprocess runs — offline, the failure mode is a sentence, never a
@@ -28,7 +32,7 @@
28
32
  import { existsSync } from "node:fs";
29
33
  import { isAbsolute, join, relative, resolve } from "node:path";
30
34
  import type { Declarable } from "@intentius/chant/declarable";
31
- import { defaultKustomizeRunner, renderKustomizeDocuments, type KustomizeRunner } from "./render";
35
+ import { defaultKustomizeRunner, renderKustomizeDocuments, type KustomizeHelmOptions, type KustomizeRunner } from "./render";
32
36
  import { addRenderedEntity, renderedManifestEntity } from "./rendered-entity";
33
37
  import { applyRenderedPatches, type RenderedPatch } from "../patch/rendered-patch";
34
38
 
@@ -36,7 +40,7 @@ import { applyRenderedPatches, type RenderedPatch } from "../patch/rendered-patc
36
40
  * One `k8s.kustomize.roots` entry: a directory, or a directory plus patches
37
41
  * applied to its rendered documents (#3566).
38
42
  */
39
- export type KustomizeRootEntry = string | { path: string; patches?: RenderedPatch[] };
43
+ export type KustomizeRootEntry = string | ({ path: string; patches?: RenderedPatch[] } & KustomizeHelmOptions);
40
44
 
41
45
  const KUSTOMIZATION_FILES = ["kustomization.yaml", "kustomization.yml", "Kustomization"];
42
46
 
@@ -64,6 +68,7 @@ export async function renderKustomizeRoots(opts: {
64
68
  for (const entry of opts.roots) {
65
69
  const root = typeof entry === "string" ? entry : entry.path;
66
70
  const patches = typeof entry === "string" ? undefined : entry.patches;
71
+ const helm: KustomizeHelmOptions = typeof entry === "string" ? {} : { enableHelm: entry.enableHelm, helmCommand: entry.helmCommand, fetchCharts: entry.fetchCharts };
67
72
  const rootDir = isAbsolute(root) ? root : resolve(opts.projectRoot, root);
68
73
  // The label rendered docs carry as provenance: the declared (relative)
69
74
  // form when possible, so it names the overlay the way the config does.
@@ -79,7 +84,7 @@ export async function renderKustomizeRoots(opts: {
79
84
  );
80
85
  }
81
86
 
82
- const rendered = await renderKustomizeDocuments(rootDir, run);
87
+ const rendered = await renderKustomizeDocuments(rootDir, run, helm);
83
88
  const documents = applyRenderedPatches(rendered, patches, `kustomize root "${rootLabel}"`);
84
89
  for (const doc of documents) {
85
90
  const entity = renderedManifestEntity(doc, rootLabel);
@@ -6,8 +6,12 @@
6
6
  * Excluded from check auto-discovery by the "helper" filename filter.
7
7
  */
8
8
  import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
9
+ import { MASKED } from "@intentius/chant/deep-observation";
9
10
  import { docsToManifests, type K8sManifest } from "./k8s-helpers";
10
11
 
12
+ /** What the live lister (`<masked>`) and the deep observation (`[REDACTED]`) leave where a value was. */
13
+ const MASKED_VALUES: ReadonlySet<string> = new Set([MASKED, "<masked>"]);
14
+
11
15
  /** The always-present, in-cluster Argo destination. */
12
16
  export const IN_CLUSTER_SERVER = "https://kubernetes.default.svc";
13
17
  export const IN_CLUSTER_NAME = "in-cluster";
@@ -28,14 +32,17 @@ export function manifestsOfKind(manifests: K8sManifest[], kind: string): K8sMani
28
32
  /**
29
33
  * Read a string field from a Secret's stringData or data block.
30
34
  * (Argo cluster Secrets conventionally use stringData.)
35
+ *
36
+ * A value the live reader masked is not a value: it reads as absent, so a
37
+ * masked `name` or `server` never registers a cluster called "<masked>" or "[REDACTED]".
31
38
  */
32
39
  export function secretField(manifest: K8sManifest, key: string): string | undefined {
33
40
  const stringData = manifest.stringData as Record<string, unknown> | undefined;
34
41
  const data = manifest.data as Record<string, unknown> | undefined;
35
42
  const fromStringData = stringData?.[key];
36
- if (typeof fromStringData === "string") return fromStringData;
43
+ if (typeof fromStringData === "string" && !MASKED_VALUES.has(fromStringData)) return fromStringData;
37
44
  const fromData = data?.[key];
38
- if (typeof fromData === "string") return fromData;
45
+ if (typeof fromData === "string" && !MASKED_VALUES.has(fromData)) return fromData;
39
46
  return undefined;
40
47
  }
41
48
 
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
11
  import { allManifests, manifestsOfKind } from "./argo-helpers";
12
+ import { nameOf } from "./k8s-helpers";
12
13
 
13
14
  export const argo002: PostSynthCheck = {
14
15
  id: "ARGO002",
@@ -28,7 +29,7 @@ export const argo002: PostSynthCheck = {
28
29
 
29
30
  for (const app of manifestsOfKind(manifests, "Application")) {
30
31
  const project = app.spec?.project;
31
- const name = app.metadata?.name ?? "Application";
32
+ const name = nameOf(app, "Application");
32
33
  // No project set → defaults to `default` at sync time; not this check's job.
33
34
  if (typeof project !== "string" || project === "") continue;
34
35
  if (declaredProjects.has(project)) continue;
@@ -18,6 +18,7 @@ import {
18
18
  IN_CLUSTER_SERVER,
19
19
  IN_CLUSTER_NAME,
20
20
  } from "./argo-helpers";
21
+ import { nameOf } from "./k8s-helpers";
21
22
 
22
23
  export const argo003: PostSynthCheck = {
23
24
  id: "ARGO003",
@@ -37,7 +38,7 @@ export const argo003: PostSynthCheck = {
37
38
  }
38
39
 
39
40
  for (const app of manifestsOfKind(manifests, "Application")) {
40
- const name = app.metadata?.name ?? "Application";
41
+ const name = nameOf(app, "Application");
41
42
  const destination = app.spec?.destination as
42
43
  | { server?: unknown; name?: unknown }
43
44
  | undefined;
@@ -2,10 +2,23 @@
2
2
  * ARGO005: Application source.path should point at an existing directory (warn)
3
3
  *
4
4
  * When an Argo `Application` syncs from a git source it names a `source.path`
5
- * inside the repo. In the common monorepo layout — Argo watches the same repo
6
- * Chant builds — that path is relative to the build root, so a typo'd or moved
7
- * path surfaces as a sync error only after deploy. This check warns when the
8
- * path doesn't resolve to a directory under the build root.
5
+ * inside the repository `source.repoURL` names. This check warns when the path
6
+ * does not resolve to a directory in the tree being read.
7
+ *
8
+ * Which tree depends on the command:
9
+ *
10
+ * - `chant build` and `chant lint` read the project, so a relative path
11
+ * resolves against the project root (the directory of the project config).
12
+ * The common monorepo layout, where Argo watches the same repo Chant builds,
13
+ * is the one this assumes.
14
+ * - `chant audit <dir>` reads a tree that need not be the working directory.
15
+ * The path resolves against the root of the checkout the audited directory
16
+ * is in, never the working directory, and only when that checkout's `origin`
17
+ * remote is the repository `repoURL` names. When the remote names another
18
+ * repository the path lives in a tree that is not on disk and the check is
19
+ * silent. A tree with no `origin` (an extracted archive) resolves against
20
+ * the audited directory. A remote tree fetch has nothing on disk and gets no
21
+ * findings. The resolution is `resolveRepoPath` in core.
9
22
  *
10
23
  * It is a warning, not an error: Applications that sync from a *different*
11
24
  * remote repo legitimately reference paths that don't exist locally. Helm chart
@@ -14,11 +27,13 @@
14
27
  import { existsSync, statSync } from "fs";
15
28
  import { isAbsolute, resolve } from "path";
16
29
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
30
+ import { resolveRepoPath } from "@intentius/chant/repo-path";
17
31
  import { allManifests, manifestsOfKind } from "./argo-helpers";
32
+ import { nameOf } from "./k8s-helpers";
18
33
 
19
- function dirExists(path: string): boolean {
34
+ function dirExists(base: string, path: string): boolean {
20
35
  try {
21
- const full = isAbsolute(path) ? path : resolve(process.cwd(), path);
36
+ const full = isAbsolute(path) ? path : resolve(base, path);
22
37
  return existsSync(full) && statSync(full).isDirectory();
23
38
  } catch {
24
39
  return false;
@@ -33,9 +48,9 @@ export const argo005: PostSynthCheck = {
33
48
  const diagnostics: PostSynthDiagnostic[] = [];
34
49
 
35
50
  for (const app of manifestsOfKind(allManifests(ctx), "Application")) {
36
- const name = app.metadata?.name ?? "Application";
51
+ const name = nameOf(app, "Application");
37
52
  const source = app.spec?.source as
38
- | { path?: unknown; chart?: unknown }
53
+ | { path?: unknown; chart?: unknown; repoURL?: unknown }
39
54
  | undefined;
40
55
  if (!source) continue;
41
56
  // Helm chart sources have no filesystem path.
@@ -43,12 +58,23 @@ export const argo005: PostSynthCheck = {
43
58
 
44
59
  const path = source.path;
45
60
  if (typeof path !== "string" || path === "") continue;
46
- if (dirExists(path)) continue;
61
+
62
+ let where = "under the build root";
63
+ if (ctx.audit) {
64
+ // No tree on disk (a remote fetch): nothing to resolve against.
65
+ if (ctx.audit.root === undefined) continue;
66
+ const repoURL = typeof source.repoURL === "string" ? source.repoURL : undefined;
67
+ const found = resolveRepoPath(ctx.audit.root, repoURL, path);
68
+ if (found.status !== "missing") continue;
69
+ where = found.path === path ? "in the audited repository" : `in the audited repository (looked for "${found.path}" from its root)`;
70
+ } else if (dirExists(ctx.projectDir ?? process.cwd(), path)) {
71
+ continue;
72
+ }
47
73
 
48
74
  diagnostics.push({
49
75
  checkId: "ARGO005",
50
76
  severity: "warning",
51
- message: `Application "${name}" source.path "${path}" does not resolve to a directory under the build root. Confirm the path (or ignore if it lives in a different repo).`,
77
+ message: `Application "${name}" source.path "${path}" does not resolve to a directory ${where}. Confirm the path (or ignore if it lives in a different repo).`,
52
78
  entity: name,
53
79
  lexicon: "k8s",
54
80
  });
@@ -0,0 +1,65 @@
1
+ import { beforeAll, describe, test, expect } from "vitest";
2
+ import { auditFiles } from "@intentius/chant/audit/core";
3
+ import { buildReportJson } from "@intentius/chant/audit/report-model";
4
+ import { wk8105 } from "./wk8105";
5
+ import { wk8201 } from "./wk8201";
6
+ import { wk8203 } from "./wk8203";
7
+
8
+ const checks = [wk8105, wk8201, wk8203];
9
+
10
+ const deployment = (containers: string[]) =>
11
+ [
12
+ "apiVersion: apps/v1",
13
+ "kind: Deployment",
14
+ "metadata:",
15
+ " name: slack-welcomer",
16
+ "spec:",
17
+ " template:",
18
+ " spec:",
19
+ " containers:",
20
+ ...containers.flatMap((c) => [` - name: ${c}`, " image: example.com/app:1.0"]),
21
+ "",
22
+ ].join("\n");
23
+
24
+ async function report(content: string) {
25
+ const findings = await auditFiles([{ path: "app.yaml", content, lexicon: "k8s" }], { checksProvider: async () => checks });
26
+ return buildReportJson(findings).findings;
27
+ }
28
+
29
+ describe("finding identity (#5106)", () => {
30
+ // The first audit pays for loading the rule catalog; keep that out of the per-test budget.
31
+ beforeAll(async () => {
32
+ await report(deployment(["warm"]));
33
+ }, 60_000);
34
+
35
+ test("renaming a container changes every message and no identity", async () => {
36
+ const before = await report(deployment(["slack-moderator"]));
37
+ const after = await report(deployment(["slack-welcomer"]));
38
+ expect(before.length).toBeGreaterThanOrEqual(3);
39
+ expect(after.map((f) => f.checkId)).toEqual(before.map((f) => f.checkId));
40
+ expect(after.map((f) => f.message)).not.toEqual(before.map((f) => f.message));
41
+ expect(after.map((f) => f.identity)).toEqual(before.map((f) => f.identity));
42
+ });
43
+
44
+ test("two containers keep their own identities when the first stops having the defect", async () => {
45
+ const two = await report(deployment(["a", "b"]));
46
+ const secondOf = (fs: typeof two, id: string) => fs.filter((f) => f.checkId === id)[1]?.identity;
47
+ const fixedFirst = deployment(["a", "b"]).replace("- name: a\n image: example.com/app:1.0", "- name: a\n image: example.com/app:1.0\n imagePullPolicy: Always");
48
+ const after = await report(fixedFirst);
49
+ const pullPolicy = (fs: typeof two) => fs.filter((f) => f.checkId === "WK8105");
50
+ expect(pullPolicy(two)).toHaveLength(2);
51
+ expect(pullPolicy(after)).toHaveLength(1);
52
+ expect(pullPolicy(after)[0].identity).toBe(secondOf(two, "WK8105"));
53
+ });
54
+
55
+ test("identities are distinct within a report", async () => {
56
+ const fs = await report(deployment(["a", "b", "c"]));
57
+ expect(new Set(fs.map((f) => f.identity)).size).toBe(fs.length);
58
+ });
59
+
60
+ test("renaming the Deployment changes the identity", async () => {
61
+ const before = await report(deployment(["a"]));
62
+ const after = await report(deployment(["a"]).replace("slack-welcomer", "other"));
63
+ expect(after[0].identity).not.toBe(before[0].identity);
64
+ });
65
+ });
@@ -15,7 +15,7 @@ import { createRequire } from "module";
15
15
  import { moduleSourceUrl } from "@intentius/chant/module-source";
16
16
  import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
17
17
  import type { CrdFieldSchema } from "../../spec/parse";
18
- import { docsToManifests, type K8sManifest } from "./k8s-helpers";
18
+ import { docsToManifests, nameOf, type K8sManifest } from "./k8s-helpers";
19
19
  import { projectSpecSchema } from "../../project-kinds";
20
20
 
21
21
  export type { CrdFieldSchema };
@@ -229,7 +229,7 @@ export function suggestField(unknown: string, known: string[]): string | undefin
229
229
  return best;
230
230
  }
231
231
 
232
- /** `metadata.name` or the kind, for diagnostics. */
232
+ /** `metadata.name` when it is a string, else the kind, for diagnostics. */
233
233
  export function resourceLabel(manifest: K8sManifest): string {
234
- return manifest.metadata?.name ?? manifest.kind ?? "resource";
234
+ return nameOf(manifest, manifest.kind ?? "resource");
235
235
  }