@intentius/chant-lexicon-k8s 0.42.1 → 0.44.2

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 (127) hide show
  1. package/dist/api/classify.d.ts.map +1 -1
  2. package/dist/api/connect.d.ts.map +1 -1
  3. package/dist/codegen/docs.d.ts.map +1 -1
  4. package/dist/components/argo-app.d.ts +104 -0
  5. package/dist/components/argo-app.d.ts.map +1 -0
  6. package/dist/components/builders.d.ts +8 -0
  7. package/dist/components/builders.d.ts.map +1 -1
  8. package/dist/components/capability-plugin.d.ts +1 -0
  9. package/dist/components/capability-plugin.d.ts.map +1 -1
  10. package/dist/components/flux-reconcile.d.ts +84 -0
  11. package/dist/components/flux-reconcile.d.ts.map +1 -0
  12. package/dist/components/index.d.ts +2 -0
  13. package/dist/components/index.d.ts.map +1 -1
  14. package/dist/components/kustomize-apply.d.ts +29 -7
  15. package/dist/components/kustomize-apply.d.ts.map +1 -1
  16. package/dist/composites/flux-app.d.ts +132 -0
  17. package/dist/composites/flux-app.d.ts.map +1 -0
  18. package/dist/composites/index.d.ts +2 -0
  19. package/dist/composites/index.d.ts.map +1 -1
  20. package/dist/config-schema.d.ts +3 -0
  21. package/dist/config-schema.d.ts.map +1 -1
  22. package/dist/config.d.ts +32 -5
  23. package/dist/config.d.ts.map +1 -1
  24. package/dist/crd/crd-sources.d.ts.map +1 -1
  25. package/dist/crd/parser.d.ts.map +1 -1
  26. package/dist/describe-resources.d.ts +10 -8
  27. package/dist/describe-resources.d.ts.map +1 -1
  28. package/dist/generated/index.d.ts +15 -4
  29. package/dist/generated/index.d.ts.map +1 -1
  30. package/dist/index.d.ts +2 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/integrity.json +10 -6
  33. package/dist/kube/connect.d.ts +5 -4
  34. package/dist/kube/connect.d.ts.map +1 -1
  35. package/dist/kube/get.d.ts +4 -4
  36. package/dist/kustomize/render.d.ts +15 -0
  37. package/dist/kustomize/render.d.ts.map +1 -0
  38. package/dist/kustomize/rendered-entity.d.ts +39 -0
  39. package/dist/kustomize/rendered-entity.d.ts.map +1 -0
  40. package/dist/kustomize/root.d.ts +19 -0
  41. package/dist/kustomize/root.d.ts.map +1 -0
  42. package/dist/lint/audit-catalog.d.ts.map +1 -1
  43. package/dist/lint/post-synth/argo-helpers.d.ts +2 -0
  44. package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
  45. package/dist/lint/post-synth/flux002.d.ts +14 -0
  46. package/dist/lint/post-synth/flux002.d.ts.map +1 -0
  47. package/dist/lint/post-synth/flux003.d.ts +17 -0
  48. package/dist/lint/post-synth/flux003.d.ts.map +1 -0
  49. package/dist/lint/post-synth/index.d.ts.map +1 -1
  50. package/dist/lint/rules/flux-source-ref-pin.d.ts +16 -0
  51. package/dist/lint/rules/flux-source-ref-pin.d.ts.map +1 -0
  52. package/dist/manifest.json +1 -1
  53. package/dist/meta.json +92 -16
  54. package/dist/okf/index.md +7 -1
  55. package/dist/okf/rules/FLUX001.md +17 -0
  56. package/dist/okf/rules/FLUX002.md +19 -0
  57. package/dist/okf/rules/FLUX003.md +15 -0
  58. package/dist/okf/types/Addon.md +14 -0
  59. package/dist/okf/types/Bucket.md +4 -0
  60. package/dist/okf/types/{HelmChart.md → FluxHelmChart.md} +2 -2
  61. package/dist/okf/types/GitRepository.md +5 -0
  62. package/dist/okf/types/HelmChartConfig.md +14 -0
  63. package/dist/okf/types/K3sHelmChart.md +14 -0
  64. package/dist/okf/types/Kustomization.md +6 -0
  65. package/dist/okf/types/Namespace.md +1 -0
  66. package/dist/okf/types/Node.md +1 -0
  67. package/dist/okf/types/OCIRepository.md +4 -0
  68. package/dist/plugin.d.ts.map +1 -1
  69. package/dist/rules/argo-helpers.ts +2 -0
  70. package/dist/rules/flux-source-ref-pin.ts +52 -0
  71. package/dist/rules/flux002.ts +77 -0
  72. package/dist/rules/flux003.ts +75 -0
  73. package/dist/serializer.d.ts.map +1 -1
  74. package/dist/skills/chant-k8s-flux.md +162 -0
  75. package/dist/types/index.d.ts +41 -3
  76. package/dist/validate.d.ts.map +1 -1
  77. package/package.json +3 -3
  78. package/src/api/classify.test.ts +37 -0
  79. package/src/api/classify.ts +11 -1
  80. package/src/api/connect.ts +10 -0
  81. package/src/codegen/docs.ts +11 -0
  82. package/src/components/argo-app.test.ts +137 -0
  83. package/src/components/argo-app.ts +163 -0
  84. package/src/components/builders.ts +8 -0
  85. package/src/components/capability-plugin.ts +11 -1
  86. package/src/components/flux-reconcile.test.ts +145 -0
  87. package/src/components/flux-reconcile.ts +159 -0
  88. package/src/components/index.ts +13 -0
  89. package/src/components/kustomize-apply.ts +12 -41
  90. package/src/composites/composites.test.ts +122 -0
  91. package/src/composites/flux-app.ts +274 -0
  92. package/src/composites/index.ts +9 -0
  93. package/src/config-augmentation.test.ts +72 -0
  94. package/src/config-schema.ts +5 -0
  95. package/src/config.ts +33 -5
  96. package/src/crd/crd-sources.ts +37 -0
  97. package/src/crd/parser.ts +6 -0
  98. package/src/describe-resources.test.ts +290 -6
  99. package/src/describe-resources.ts +235 -127
  100. package/src/generated/index.d.ts +41 -3
  101. package/src/generated/index.ts +15 -4
  102. package/src/generated/lexicon-k8s.json +92 -16
  103. package/src/generated/operations.json +48 -0
  104. package/src/index.ts +4 -0
  105. package/src/kube/connect.ts +5 -4
  106. package/src/kube/get.ts +4 -4
  107. package/src/kustomize/render.ts +84 -0
  108. package/src/kustomize/rendered-entity.ts +72 -0
  109. package/src/kustomize/root.test.ts +268 -0
  110. package/src/kustomize/root.ts +109 -0
  111. package/src/lint/audit-catalog.ts +2 -0
  112. package/src/lint/post-synth/argo-helpers.ts +2 -0
  113. package/src/lint/post-synth/flux002.ts +77 -0
  114. package/src/lint/post-synth/flux003.ts +75 -0
  115. package/src/lint/post-synth/index.ts +4 -0
  116. package/src/lint/post-synth/post-synth.test.ts +132 -0
  117. package/src/lint/rules/flux-source-ref-pin.ts +52 -0
  118. package/src/lint/rules/rules.test.ts +51 -0
  119. package/src/plugin.test.ts +2 -0
  120. package/src/plugin.ts +47 -0
  121. package/src/serializer.ts +34 -4
  122. package/src/skills/chant-k8s-flux.md +162 -0
  123. package/src/testdata/kustomize-root/base/deployment.yaml +17 -0
  124. package/src/testdata/kustomize-root/base/kustomization.yaml +3 -0
  125. package/src/testdata/kustomize-root/base/service.yaml +9 -0
  126. package/src/testdata/kustomize-root/overlays/prod/kustomization.yaml +6 -0
  127. package/src/validate.ts +4 -0
@@ -0,0 +1,162 @@
1
+ ---
2
+ skill: chant-k8s-flux
3
+ description: Flux CD composites for GitOps reconciliation — FluxGitSource + FluxAppFor, the one-source-many-apps shape, dependsOn ordering, the FLUX rules, and the flux-reconcile deploy step
4
+ user-invocable: true
5
+ ---
6
+
7
+ # Flux CD Composites
8
+
9
+ Chant authors typed infrastructure into manifests. Flux continuously reconciles those manifests into a cluster from git. These composites are the opt-in bridge — the k8s lexicon itself stays runtime-agnostic and only emits YAML; nothing here is implied unless you reach for it.
10
+
11
+ ## The split
12
+
13
+ | Layer | Owns | In Chant |
14
+ |---|---|---|
15
+ | **Chant** | Authoring typed infra → manifests, committed to git | the lexicons |
16
+ | **Flux** | Continuously reconciling those manifests (source-controller fetches, kustomize-controller applies) | `FluxGitSource` / `FluxAppFor` |
17
+ | **Chant again** | Reading convergence back | `flux-reconcile` deploy step, `chant components status --live` |
18
+
19
+ Flux never learns Chant exists — it fetches a git path and applies what it finds there. Chant's job ends at emitting the manifests and the Flux CRs that point at them.
20
+
21
+ ## Prerequisites
22
+
23
+ The Flux controllers must be installed in the target cluster before applying any Flux CRs:
24
+
25
+ ```bash
26
+ kubectl apply -f https://github.com/fluxcd/flux2/releases/download/v2.9.1/install.yaml
27
+ kubectl -n flux-system wait deploy --all --for=condition=Available --timeout=180s
28
+ ```
29
+
30
+ (Or `flux install` / `flux bootstrap` with the Flux CLI. `flux bootstrap` also creates a `flux-system` `GitRepository` — FLUX002 knows about it, see below.)
31
+
32
+ ## When to use which
33
+
34
+ | Composite | Use case |
35
+ |---|---|
36
+ | `FluxGitSource` | Declare the git repo the source-controller fetches — **once per repo** |
37
+ | `FluxAppFor` | One `Kustomization` reconciling one path out of a declared source — once per app |
38
+
39
+ ---
40
+
41
+ ## FluxGitSource — declare the repo once
42
+
43
+ ```typescript
44
+ import { FluxGitSource } from "@intentius/chant-lexicon-k8s";
45
+
46
+ export const source = FluxGitSource("home-chant", {
47
+ url: "https://github.com/jhgaylor/home-chant",
48
+ branch: "main",
49
+ });
50
+ ```
51
+
52
+ `FluxGitSource(name, options)` returns `{ gitRepository }` — a single `K8s::Flux::GitRepository` in `flux-system`. Options:
53
+
54
+ - **`url`** (required) — the repo the source-controller fetches.
55
+ - **`branch`** — defaults to `"main"`. **`tag`** pins a tag instead and wins over `branch`.
56
+ - **`interval`** — fetch interval, default `"5m"`.
57
+ - **`secretRef`** — name of the Secret holding git credentials, for private repos.
58
+ - **`fluxNamespace`** — where the CR lives, default `"flux-system"`.
59
+
60
+ > **FLUX001** — a hand-written `GitRepository` whose spec has a `url` but no `ref` is flagged: an unset `spec.ref` falls back to the `master` branch, which on most repos no longer exists, so the source stalls with a checkout error and every Kustomization downstream stalls too. `FluxGitSource` always emits a `ref` (branch or tag), so composite output is FLUX001-clean by construction.
61
+
62
+ ## FluxAppFor — one Kustomization per app
63
+
64
+ ```typescript
65
+ import { FluxAppFor } from "@intentius/chant-lexicon-k8s";
66
+
67
+ export const hello = FluxAppFor("hello-chant", {
68
+ source, // the FluxGitSource result above
69
+ path: "./apps/hello-chant/k8s",
70
+ targetNamespace: "default",
71
+ dependsOn: ["cert-manager", "traefik"],
72
+ });
73
+ ```
74
+
75
+ `FluxAppFor(target, options)` returns `{ kustomization }` — a single `K8s::Flux::Kustomization`. Defaults are taken from real Flux estates, not the docs:
76
+
77
+ - **`interval`** — `"10m"` (the source polls at 5m; reconcile less often than you fetch).
78
+ - **`prune: true`** — resources that disappear from the source are deleted.
79
+ - **`wait: true`** — the Kustomization reports Ready only when the reconciled resources are ready.
80
+ - **`targetNamespace`** — optional; sets `spec.targetNamespace` (kustomize-controller stamps it on every reconciled resource).
81
+ - **`timeout`**, **`suspend`**, **`serviceAccountName`** — pass-throughs for the matching spec fields.
82
+
83
+ ### The source option
84
+
85
+ `source` accepts three shapes:
86
+
87
+ ```typescript
88
+ FluxAppFor("app", { source, path: "./apps/app" }); // FluxGitSource result
89
+ FluxAppFor("app", { source: "flux-system", path: "./apps/app" }); // name of an existing GitRepository
90
+ FluxAppFor("app", { source: { kind: "OCIRepository", name: "images" }, path: "./apps/app" }); // explicit ref
91
+ ```
92
+
93
+ The first is the normal case. The second targets a source declared elsewhere — typically the bootstrap-created `flux-system` repo. The third covers `OCIRepository` / `Bucket` sources.
94
+
95
+ > **FLUX002** — every `Kustomization.spec.sourceRef` must name a source the build declares (`GitRepository`, `OCIRepository`, or `Bucket`), or the kustomize-controller waits forever on an artifact that never arrives. The bootstrap-created `flux-system` `GitRepository` is exempt — it always exists on a bootstrapped cluster, the Flux analogue of ARGO002's built-in `default` project.
96
+
97
+ ### One source, many apps
98
+
99
+ The common estate shape is **one `GitRepository` shared by many `Kustomization`s** — a multi-app repo with one Kustomization per path. A `GitRepository` per app is the mistake the composite split makes hard: declare the source once, hand its result to every `FluxAppFor`.
100
+
101
+ ```typescript
102
+ const source = FluxGitSource("infra", { url: "https://github.com/acme/infra" });
103
+
104
+ export const platform = FluxAppFor("platform", { source, path: "./dist/platform" });
105
+ export const api = FluxAppFor("api", { source, path: "./dist/apps/api", dependsOn: ["platform"] });
106
+ export const web = FluxAppFor("web", { source, path: "./dist/apps/web", dependsOn: ["platform", "api"] });
107
+ ```
108
+
109
+ ### dependsOn — ordering as a validated name list
110
+
111
+ `dependsOn` is a plain string list rendered to `spec.dependsOn`; the Kustomization stays pending until every named Kustomization is Ready. In raw YAML those names have no referential integrity — a typo, or an entry left behind after a rename, stalls the app silently.
112
+
113
+ > **FLUX003** — every `dependsOn` entry is joined against the Kustomizations the build actually declares. An entry naming nothing is a warning (not an error — estates legitimately split infra and apps across repos, so `cert-manager` may be declared by a build this one never sees). A self-referencing entry is always flagged: Flux can never satisfy it.
114
+
115
+ ---
116
+
117
+ ## Deploying — the flux-reconcile step
118
+
119
+ Applying `dist/flux.yaml` with `kubectl` works. For the component model, `fluxReconcile` is the typed deploy leaf (the sibling of `argo-app`):
120
+
121
+ ```typescript
122
+ import { phase, type Component } from "@intentius/chant/components/component";
123
+ import { fluxReconcile } from "@intentius/chant-lexicon-k8s/components";
124
+
125
+ export const bootstrap: Component = {
126
+ name: "flux-bootstrap",
127
+ archetype: "service",
128
+ dependsOn: [],
129
+ deploy: [
130
+ phase("Reconcile", [
131
+ fluxReconcile({
132
+ manifest: "dist/flux.yaml",
133
+ stack: "my-estate",
134
+ noRollback: "server-side apply keeps no previous object state; the declared source is the restore path",
135
+ }),
136
+ ]),
137
+ ],
138
+ };
139
+ ```
140
+
141
+ What it does:
142
+
143
+ 1. **Applies** the Flux CRs through the same server-side apply `kubectl-apply` uses — ownership stamping, marker-scoped prune, stack labels all identical.
144
+ 2. **Waits for Ready, sources first.** A Kustomization cannot become Ready before its GitRepository has an artifact, so gating on `source.toolkit.fluxcd.io` kinds first surfaces a wedged clone as the source's error rather than a reconciler timeout downstream. The generic `waitForReady` handles the rest of the toolkit (kstatus-conformant), with fail-fast on wedge reasons like `BuildFailed` or `UpgradeFailed` from the readiness registry.
145
+ 3. **Refuses non-Flux manifests.** If the manifest applies no Flux CR at all, the step errors — a plain manifest belongs on `kubectl-apply`, and two things applying the same resources is the failure mode worth engineering against.
146
+
147
+ It is a `needs-opt-out` capability (COMP003): every step needs `noRollback: "<reason>"`, a component `rollback` phase, or a sibling safety step — same posture as `kubectl-apply`, and for the same reason.
148
+
149
+ ## Reading convergence back
150
+
151
+ The build stamps `app.kubernetes.io/managed-by: chant` and (with `ownership` configured) `chant.intentius.io/stack: <stack>` labels on every resource. Flux applies the manifests, but the labels travel with them — so `chant components status --live` attributes the running workloads to the stack through the k8s lexicon's label-selector read, regardless of who did the applying. Flux prunes by its own labels; chant observes by its own labels; neither needs the other's.
152
+
153
+ ## Troubleshooting
154
+
155
+ | Symptom | Likely cause | Fix |
156
+ |---|---|---|
157
+ | Kustomization stuck, no artifact | Source stalled — unset `spec.ref` fell back to `master` | Pin a branch/tag (FLUX001); `FluxGitSource` does this by default |
158
+ | Kustomization waits forever | `sourceRef` names an undeclared source | Declare it with `FluxGitSource`, or point at the bootstrap `flux-system` repo (FLUX002) |
159
+ | App pending, dependencies "not ready" | `dependsOn` names a Kustomization that doesn't exist (typo/rename) | Fix the name (FLUX003), or confirm the other repo declares it |
160
+ | App pending forever, no error | `dependsOn` self-reference | Remove the self-edge (FLUX003 flags it) |
161
+ | Resources deleted unexpectedly | `prune: true` (the default) and the path stopped emitting them | Intended GitOps behavior; pass `prune: false` to opt out |
162
+ | `flux-reconcile` step errors immediately | Manifest contains no Flux CR | Use `kubectl-apply` for plain manifests |
@@ -2,6 +2,18 @@
2
2
 
3
3
  // --- Kubernetes Resource classes ---
4
4
 
5
+ export declare class Addon {
6
+ constructor(props: {
7
+ /** Standard object's metadata. */
8
+ metadata?: ObjectMeta;
9
+ /** Spec provides information about the on-disk manifest backing this resource. */
10
+ spec?: Record<string, unknown>;
11
+ });
12
+ readonly name: string;
13
+ readonly namespace: string;
14
+ readonly uid: string;
15
+ }
16
+
5
17
  export declare class Alert {
6
18
  constructor(props: {
7
19
  /** Standard object's metadata. */
@@ -920,6 +932,19 @@ export declare class FlowSchemaList {
920
932
  readonly uid: string;
921
933
  }
922
934
 
935
+ export declare class FluxHelmChart {
936
+ constructor(props: {
937
+ /** Standard object's metadata. */
938
+ metadata?: ObjectMeta;
939
+ /** HelmChartSpec specifies the desired state of a Helm chart. */
940
+ spec?: Record<string, unknown>;
941
+ });
942
+ readonly name: string;
943
+ readonly namespace: string;
944
+ readonly status: Record<string, unknown>;
945
+ readonly uid: string;
946
+ }
947
+
923
948
  export declare class FluxInstance {
924
949
  constructor(props: {
925
950
  /** Standard object's metadata. */
@@ -999,16 +1024,16 @@ export declare class GRPCRoute {
999
1024
  readonly uid: string;
1000
1025
  }
1001
1026
 
1002
- export declare class HelmChart {
1027
+ export declare class HelmChartConfig {
1003
1028
  constructor(props: {
1004
1029
  /** Standard object's metadata. */
1005
1030
  metadata?: ObjectMeta;
1006
- /** HelmChartSpec specifies the desired state of a Helm chart. */
1031
+ /** HelmChartConfigSpec represents additional user-configurable details of an installed and configured Helm chart release.
1032
+ These fields are merged with or override the corresponding fields on the related HelmChart resource. */
1007
1033
  spec?: Record<string, unknown>;
1008
1034
  });
1009
1035
  readonly name: string;
1010
1036
  readonly namespace: string;
1011
- readonly status: Record<string, unknown>;
1012
1037
  readonly uid: string;
1013
1038
  }
1014
1039
 
@@ -1325,6 +1350,19 @@ export declare class JobList {
1325
1350
  readonly uid: string;
1326
1351
  }
1327
1352
 
1353
+ export declare class K3sHelmChart {
1354
+ constructor(props: {
1355
+ /** Standard object's metadata. */
1356
+ metadata?: ObjectMeta;
1357
+ /** HelmChartSpec represents the user-configurable details for installation and upgrade of a Helm chart release. */
1358
+ spec?: Record<string, unknown>;
1359
+ });
1360
+ readonly name: string;
1361
+ readonly namespace: string;
1362
+ readonly status: Record<string, unknown>;
1363
+ readonly uid: string;
1364
+ }
1365
+
1328
1366
  export declare class Kustomization {
1329
1367
  constructor(props: {
1330
1368
  /** Standard object's metadata. */
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAElG,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAuBvF;;GAEG;AACH,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAQpF"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAElG,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAuBvF;;GAEG;AACH,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAYpF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-k8s",
3
- "version": "0.42.1",
3
+ "version": "0.44.2",
4
4
  "description": "Kubernetes lexicon for chant — declarative IaC in TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -76,7 +76,7 @@
76
76
  "@types/js-yaml": "^4.0.9"
77
77
  },
78
78
  "optionalDependencies": {
79
- "@intentius/chant-k8s-client": "^0.41.5"
79
+ "@intentius/chant-k8s-client": "^0.44.2"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@intentius/chant": "*",
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "peerDependencies": {
86
86
  "zod": "^4.3.6",
87
- "@intentius/chant": "^0.42.1",
87
+ "@intentius/chant": "^0.44.2",
88
88
  "typescript": "^5.9.3"
89
89
  }
90
90
  }
@@ -93,6 +93,43 @@ describe("classifyApiFailure", () => {
93
93
  }
94
94
  });
95
95
 
96
+ test("the detail names the context the client read, when the failure carries it (#1488)", () => {
97
+ const err = status(500, "InternalError");
98
+ err.contextNote = 'context "k3d-kubemicrovm-local" (ambient; no k8s.profiles.local binding)';
99
+ const outcome = classifyApiFailure(err);
100
+ expect(outcome.kind).toBe("unobserved");
101
+ if (outcome.kind === "unobserved") {
102
+ expect(outcome.detail).toContain('context "k3d-kubemicrovm-local" (ambient; no k8s.profiles.local binding)');
103
+ }
104
+ });
105
+
106
+ test("the context note leads the detail, so it survives the one-line cap and any consumer truncation (#1488, #1620)", () => {
107
+ const err = new K8sApiError(500, "InternalError", "x".repeat(500));
108
+ err.contextNote = 'context "prod-eks" (bound by k8s.profiles.prod.context)';
109
+ const outcome = classifyApiFailure(err);
110
+ expect(outcome.kind).toBe("unobserved");
111
+ if (outcome.kind === "unobserved") {
112
+ expect(outcome.detail.startsWith('context "prod-eks" (bound by k8s.profiles.prod.context)')).toBe(true);
113
+ // The error itself still follows — leading with the cluster does not
114
+ // cost the message.
115
+ expect(outcome.detail).toContain("xxx");
116
+ }
117
+ });
118
+
119
+ test("the context appears within the first 160 chars of a long multi-line error's detail (#1620)", () => {
120
+ // behold's estate overlay truncates a reason to its first line / 160 chars;
121
+ // the context must land inside that window or it vanishes exactly on the
122
+ // failures long enough to need it.
123
+ const err = new K8sApiError(500, "InternalError", `${"y".repeat(300)}\n${"z".repeat(300)}`);
124
+ err.contextNote = 'context "prod-eks" (bound by k8s.profiles.prod.context)';
125
+ const outcome = classifyApiFailure(err);
126
+ expect(outcome.kind).toBe("unobserved");
127
+ if (outcome.kind === "unobserved") {
128
+ const firstLine = outcome.detail.split("\n")[0];
129
+ expect(firstLine.slice(0, 160)).toContain('context "prod-eks" (bound by k8s.profiles.prod.context)');
130
+ }
131
+ });
132
+
96
133
  test("classification survives a duplicated copy of the client package", () => {
97
134
  // Discrimination is by `name`, not `instanceof`, so an error from a second
98
135
  // physical copy of the package in a consumer's tree still classifies.
@@ -47,6 +47,8 @@ interface ErrorLike {
47
47
  message?: string;
48
48
  statusCode?: number;
49
49
  reason?: string;
50
+ /** Which cluster the failing read talked to — stamped by the typed client (chant #1488). */
51
+ contextNote?: string;
50
52
  }
51
53
 
52
54
  function shapeOf(err: unknown): ErrorLike {
@@ -140,5 +142,13 @@ export const MISSING_CLIENT_DETAIL =
140
142
  function detailOf(err: unknown): string {
141
143
  const text = err instanceof Error ? err.message : String(err);
142
144
  const line = text.split("\n").find((l) => l.trim().length > 0)?.trim() ?? text.trim();
143
- return line.length > 200 ? `${line.slice(0, 197)}...` : line;
145
+ const capped = line.length > 200 ? `${line.slice(0, 197)}...` : line;
146
+ // #1488 — a reason that does not say which cluster was read turned an
147
+ // ambient-context switch into an afternoon. The client stamps the context it
148
+ // resolved onto every failure. The note LEADS the detail (#1620): consumers
149
+ // truncate a reason to its first line and ~160 chars, and a note appended
150
+ // after a long error is cut off exactly when the error is long enough to
151
+ // need it. Leading, it survives any suffix truncation.
152
+ const note = shapeOf(err).contextNote;
153
+ return note ? `${note} — ${capped}` : capped;
144
154
  }
@@ -65,6 +65,7 @@ export const defaultK8sConnector: K8sConnector = async (options) => {
65
65
  const client = await createK8sClient({
66
66
  context: options.context,
67
67
  contextSource: "bound",
68
+ contextLabel: "explicit --context",
68
69
  ...options.client,
69
70
  });
70
71
  return { client, target: { context: options.context, source: "bound" } };
@@ -84,10 +85,19 @@ export const defaultK8sConnector: K8sConnector = async (options) => {
84
85
  // is supplied.
85
86
  const target = await resolveClusterTarget(config as Record<string, unknown>, options.environment, "k8s");
86
87
 
88
+ // #1488 — every failure the client throws names the cluster it read and how
89
+ // that cluster was selected, so a `read-failed` against the wrong context is
90
+ // legible from the reason alone.
91
+ const contextLabel =
92
+ target.source === "bound"
93
+ ? `bound by k8s.profiles.${options.environment}.context`
94
+ : `ambient; no k8s.profiles.${options.environment} binding`;
95
+
87
96
  const client = await createK8sClient({
88
97
  ...options.client,
89
98
  ...(target.context ? { context: target.context } : {}),
90
99
  contextSource: target.source,
100
+ contextLabel,
91
101
  ...(execAllowlist ? { execAllowlist } : {}),
92
102
  });
93
103
  return { client, target };
@@ -409,6 +409,16 @@ Quality checks for the [Argo CD composites](/chant/lexicons/k8s/argo-composites/
409
409
  | ARGO004 | \`ApplicationSet\` template doesn't scope to a single static \`AppProject\` |
410
410
  | ARGO005 | \`Application\` \`source.path\` doesn't resolve to a directory (warn) |
411
411
 
412
+ ### Flux
413
+
414
+ Quality checks for the [Flux composites](/chant/lexicons/k8s/flux-composites/) (\`FluxGitSource\` / \`FluxAppFor\`). FLUX001 is declarative (source AST); FLUX002/003 are post-synth (cross-resource).
415
+
416
+ | Rule | Description |
417
+ |------|-------------|
418
+ | FLUX001 | \`GitRepository\` has no \`spec.ref\` pin — Flux falls back to the \`master\` branch |
419
+ | FLUX002 | \`Kustomization.spec.sourceRef\` references an undeclared source (the bootstrap \`flux-system\` repo is exempt) |
420
+ | FLUX003 | \`Kustomization.spec.dependsOn\` names a \`Kustomization\` nothing in the build declares, or itself (warn) |
421
+
412
422
  ## Running lint
413
423
 
414
424
  \`\`\`bash
@@ -1160,6 +1170,7 @@ The lexicon also provides MCP (Model Context Protocol) tools and resources:
1160
1170
  },
1161
1171
  { label: "CRD-Generated Classes", slug: "crd-classes" },
1162
1172
  { label: "Argo CD Composites", slug: "argo-composites" },
1173
+ { label: "Flux Composites", slug: "flux-composites" },
1163
1174
  {
1164
1175
  label: "Vendor Composites",
1165
1176
  items: [
@@ -0,0 +1,137 @@
1
+ /**
2
+ * `argo-app` (#1549 piece 2) — the Argo CD deploy leaf. What must hold: the
3
+ * capability registers under its kind in the gitops family, the apply goes
4
+ * through the SAME applier delegation kubectl-apply uses (env + stack +
5
+ * deleteMode), the wait runs `waitForArgoSync` once per applied Application
6
+ * (and only for Applications), a manifest with no Application is an error
7
+ * not a silent no-wait, and the stack is the deploy unit core's status walk
8
+ * reads.
9
+ */
10
+ import { describe, test, expect } from "vitest";
11
+ import { createArgoAppCapability, argoAppCapability, type ArgoAppInput } from "./argo-app";
12
+ import { k8sCapabilityPlugin, K8S_VERB_FAMILIES } from "./capability-plugin";
13
+ import { isCapabilityPlugin } from "@intentius/chant/components/capability-plugin";
14
+ import type { DeployContext } from "@intentius/chant/components/capability";
15
+
16
+ const ctx = { env: "dev" } as DeployContext;
17
+
18
+ const APP_REF = { apiVersion: "argoproj.io/v1alpha1", kind: "Application", name: "web", namespace: "argocd" };
19
+ const PROJECT_REF = { apiVersion: "argoproj.io/v1alpha1", kind: "AppProject", name: "team" };
20
+
21
+ describe("argo-app capability (#1549 piece 2)", () => {
22
+ test("registers on the k8s plugin, in the gitops family", () => {
23
+ expect(isCapabilityPlugin(k8sCapabilityPlugin)).toBe(true);
24
+ expect(k8sCapabilityPlugin.capabilities().map((c) => c.kind)).toContain("argo-app");
25
+ expect(K8S_VERB_FAMILIES.gitops).toContain("argo-app");
26
+ });
27
+
28
+ test("rollback is needs-opt-out — a server-side apply keeps no previous state", () => {
29
+ expect(argoAppCapability.rollbackPolicy).toBe("needs-opt-out");
30
+ });
31
+
32
+ test("applies through the kubectl-apply delegation, then waits Healthy+Synced on each Application only", async () => {
33
+ const applierArgs: unknown[] = [];
34
+ const waited: unknown[] = [];
35
+ const cap = createArgoAppCapability(
36
+ async (args) => {
37
+ applierArgs.push(args);
38
+ return { fieldManager: "chant:gitops", applied: [PROJECT_REF, APP_REF], pruned: [] };
39
+ },
40
+ async (args) => {
41
+ waited.push(args);
42
+ return { health: "Healthy", sync: "Synced" };
43
+ },
44
+ );
45
+
46
+ const outcome = await cap.run(ctx, {
47
+ manifest: "argo/app.yaml",
48
+ stack: "gitops",
49
+ delete: "owned-only",
50
+ intervalMs: 500,
51
+ } as ArgoAppInput as never);
52
+
53
+ // The exact args kubectl-apply hands the shared applier — same path, same stamping.
54
+ expect(applierArgs).toEqual([
55
+ { manifest: "argo/app.yaml", environment: "dev", stack: "gitops", deleteMode: "owned-only" },
56
+ ]);
57
+ // One wait, for the Application — the AppProject applies but is not synced on.
58
+ expect(waited).toEqual([{ appName: "web", namespace: "argocd", intervalMs: 500 }]);
59
+ expect(outcome.synced).toEqual([{ name: "web", namespace: "argocd", health: "Healthy", sync: "Synced" }]);
60
+ expect(outcome.fieldManager).toBe("chant:gitops");
61
+ });
62
+
63
+ test("REST-API wait knobs (server/authToken/insecure) and context pass through to waitForArgoSync", async () => {
64
+ const waited: unknown[] = [];
65
+ const cap = createArgoAppCapability(
66
+ async () => ({ fieldManager: "chant", applied: [APP_REF], pruned: [] }),
67
+ async (args) => {
68
+ waited.push(args);
69
+ return { health: "Healthy", sync: "Synced" };
70
+ },
71
+ );
72
+ await cap.run(ctx, {
73
+ manifest: "argo/app.yaml",
74
+ context: "kind-dev",
75
+ server: "https://argocd.example.com",
76
+ authToken: "t0ken",
77
+ insecure: true,
78
+ } as ArgoAppInput as never);
79
+ expect(waited).toEqual([
80
+ {
81
+ appName: "web",
82
+ namespace: "argocd",
83
+ server: "https://argocd.example.com",
84
+ authToken: "t0ken",
85
+ insecure: true,
86
+ context: "kind-dev",
87
+ },
88
+ ]);
89
+ });
90
+
91
+ test("an Application without a namespace waits in argocd, the controller's default", async () => {
92
+ const waited: Array<{ namespace?: string }> = [];
93
+ const cap = createArgoAppCapability(
94
+ async () => ({
95
+ fieldManager: "chant",
96
+ applied: [{ apiVersion: "argoproj.io/v1alpha1", kind: "Application", name: "web" }],
97
+ pruned: [],
98
+ }),
99
+ async (args) => {
100
+ waited.push(args);
101
+ return { health: "Healthy", sync: "Synced" };
102
+ },
103
+ );
104
+ await cap.run(ctx, { manifest: "argo/app.yaml" } as ArgoAppInput as never);
105
+ expect(waited[0]?.namespace).toBe("argocd");
106
+ });
107
+
108
+ test("a manifest that applied no Application is an error, not a silent no-wait", async () => {
109
+ const cap = createArgoAppCapability(
110
+ async () => ({ fieldManager: "chant", applied: [PROJECT_REF], pruned: [] }),
111
+ async () => ({ health: "Healthy", sync: "Synced" }),
112
+ );
113
+ await expect(cap.run(ctx, { manifest: "argo/project.yaml" } as ArgoAppInput as never)).rejects.toThrow(
114
+ /no argoproj\.io Application/,
115
+ );
116
+ });
117
+
118
+ test("a failed sync propagates — the step does not report success past a Degraded app", async () => {
119
+ const cap = createArgoAppCapability(
120
+ async () => ({ fieldManager: "chant", applied: [APP_REF], pruned: [] }),
121
+ async () => {
122
+ throw new Error('Argo Application "web" reached a terminal unhealthy state');
123
+ },
124
+ );
125
+ await expect(cap.run(ctx, { manifest: "argo/app.yaml" } as ArgoAppInput as never)).rejects.toThrow(
126
+ /terminal unhealthy state/,
127
+ );
128
+ });
129
+
130
+ test("the stack field is the deploy unit core's status walk reads (#1549 piece 2)", async () => {
131
+ const { deployUnits } = await import("@intentius/chant/components/deploy-units");
132
+ const units = deployUnits([
133
+ { phase: "Apply", steps: [{ kind: "argo-app", manifest: "argo/app.yaml", stack: "gitops" }] } as never,
134
+ ]);
135
+ expect(units).toEqual([{ unit: "gitops", lexicon: "k8s" }]);
136
+ });
137
+ });