caixa_helm/lib.rs
1//! caixa-helm — typed renderer that emits a per-program `lareira-<name>`
2//! Helm chart from a [`Caixa`] manifest plus its `servicos/<name>.computeunit.yaml`.
3//!
4//! ## Output shape
5//!
6//! Every chart emitted here mirrors the canonical
7//! `pleme-io/helmworks/charts/lareira-<name>/` layout, which is *thin*:
8//!
9//! Chart.yaml ; metadata + dependency on pleme-computeunit
10//! values.yaml ; pleme-computeunit values block (the typed L2 ComputeUnit shape)
11//! README.md ; one-line elevator pitch for the chart
12//!
13//! There are no `templates/` — the rendering is delegated to the
14//! `pleme-computeunit` library chart in helmworks (per `theory/META-FRAMEWORK.md`
15//! §I, Layer 3 → Layer 2 transformation). caixa-helm's job is to derive the
16//! values block from a Caixa, not to render Kubernetes objects directly.
17//!
18//! ## Why a separate crate
19//!
20//! Same pattern as [`caixa_flake`] (renders flake.nix) and [`caixa_pangea`]
21//! (renders pangea Ruby) — `caixa-<target>` crates take a typed Caixa and
22//! emit the canonical source for `<target>`. Naming is uniform across the
23//! workspace.
24//!
25//! ## V0 contract
26//!
27//! ```rust,ignore
28//! use caixa_core::Caixa;
29//! use caixa_helm::{ChartDir, render_chart_for_servico};
30//!
31//! let caixa: Caixa = Caixa::from_lisp(src)?;
32//! let cu_yaml: serde_yaml::Value =
33//! serde_yaml::from_str(std::fs::read_to_string("servicos/hello-rio.computeunit.yaml")?)?;
34//! let dir: ChartDir = render_chart_for_servico(&caixa, &cu_yaml)?;
35//! dir.write_to(std::path::Path::new("/tmp/lareira-hello-rio"))?;
36//! ```
37//!
38//! ## What this is NOT
39//!
40//! - Not a chart for the `caixa-operator` itself — that lives in
41//! `pleme-io/caixa/operator-chart/`.
42//! - Not a Helm CLI wrapper — emitting bytes only; consumers (`feira chart`,
43//! eventually) drive the I/O.
44//! - Not a renderer of K8s resources — `pleme-computeunit` library chart owns
45//! the templates that turn this values block into ComputeUnit + Service +
46//! ScaledObject + ConfigMap.
47
48#![allow(clippy::module_name_repetitions)]
49
50use std::collections::BTreeMap;
51use std::path::Path;
52
53use caixa_core::{Caixa, MappingExt, lareira_chart_name};
54use serde::{Deserialize, Serialize};
55use thiserror::Error;
56
57/// Errors caixa-helm can raise.
58#[derive(Debug, Error)]
59pub enum Error {
60 /// The caixa's `:kind` doesn't match what `caixa-helm` targets
61 /// (this renderer only emits per-program `lareira-<nome>` charts
62 /// for `:kind Servico`). Lifted from a prior `NotAServico(CaixaKind)`
63 /// arm to wrap [`caixa_core::KindMismatch`] so the diagnostic
64 /// names the offending caixa's `:nome` (not just its kind),
65 /// shared verbatim with `caixa-flux` and `caixa-mesh`.
66 #[error("{0}")]
67 NotAServico(#[from] caixa_core::KindMismatch),
68 /// The caixa's `:servicos` list doesn't carry exactly one entry —
69 /// the V0 contract every Servico-kind caixa satisfies (one
70 /// ComputeUnit YAML pointer per Servico, matching the one Helm
71 /// chart this renderer emits). Lifted from a prior
72 /// `UnsupportedServicoCount(usize)` arm to wrap
73 /// [`caixa_core::ServicoCountMismatch`] so the diagnostic names
74 /// the offending caixa's `:nome` (not just the count), shared
75 /// verbatim with `caixa-flux` (the peer per-Servico renderer
76 /// running the same V0 invariant on the programs.yaml-entry axis).
77 #[error("{0}")]
78 UnsupportedServicoCount(#[from] caixa_core::ServicoCountMismatch),
79 #[error("computeunit yaml missing required field: {0}")]
80 MissingField(&'static str),
81 #[error("yaml: {0}")]
82 Yaml(#[from] serde_yaml::Error),
83 #[error("render: {0}")]
84 Render(#[from] caixa_core::RenderError),
85 #[error("io: {0}")]
86 Io(#[from] std::io::Error),
87}
88
89/// One file in the rendered chart — `(path, contents)` pair every
90/// [`render_chart_for_servico`]-rendered `lareira-<nome>` chart-tree
91/// leaf lands at (`Chart.yaml`, `values.yaml`, `README.md`).
92///
93/// Type-aliased to the canonical [`caixa_core::RenderedFile`] so the
94/// substrate-side "one rendered leaf artifact" shape lives at one
95/// struct definition across every per-target renderer — the peer
96/// [`caixa_flux::BundleFile`] alias resolves to the same canonical, so
97/// a future rebrand on either axis (a per-artifact hash / provenance
98/// field addition, a per-artifact write-mode discriminator once
99/// per-cluster-writer sandboxing lands) lands at one caixa-core `pub
100/// struct RenderedFile` edit and reaches both crates by construction.
101/// Prior to this lift both crates carried an inline `pub struct
102/// <Xxx>File { pub path: PathBuf, pub contents: String }` with
103/// identical `#[derive(Debug, Clone, PartialEq, Eq)]` shapes and no
104/// per-type impls; a future per-target renderer (`caixa-otel`, the
105/// future `mesh.pleme.io/v1alpha1/Aplicacao` CR materializer, the
106/// future per-Supervisor reconciler renderer) would have carried a
107/// third and fourth clone of the same record. Type aliases preserve
108/// every existing struct-literal construction site
109/// (`ChartFile { path, contents }`), every field-access site (`f.path`,
110/// `f.contents`), and every derive-fed navigator by construction —
111/// Rust type aliases inherit the aliased type's `#[derive]`-generated
112/// `Debug`/`Clone`/`PartialEq`/`Eq` impls with no per-alias glue.
113pub type ChartFile = caixa_core::RenderedFile;
114
115/// The rendered chart — a flat list of files, plus the chart name.
116#[derive(Debug, Clone, PartialEq, Eq)]
117pub struct ChartDir {
118 /// Chart name — e.g. `lareira-hello-rio`. Used as the output dir name.
119 pub name: String,
120 pub files: Vec<ChartFile>,
121}
122
123impl ChartDir {
124 /// Write every file to `<dest>/<self.name>/`. Creates parent dirs.
125 pub fn write_to(&self, dest: &Path) -> Result<(), Error> {
126 let root = dest.join(&self.name);
127 std::fs::create_dir_all(&root)?;
128 for f in &self.files {
129 let target = root.join(&f.path);
130 if let Some(parent) = target.parent() {
131 std::fs::create_dir_all(parent)?;
132 }
133 std::fs::write(&target, &f.contents)?;
134 }
135 Ok(())
136 }
137}
138
139/// Top-level `Chart.yaml` shape for a generated lareira-<name> chart.
140///
141/// Mirrors `helmworks/charts/lareira-hello-world/Chart.yaml` 1:1 in
142/// structural slots — versions, deps, keywords, maintainers.
143#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
144pub struct ChartYaml {
145 #[serde(rename = "apiVersion")]
146 pub api_version: String,
147 pub name: String,
148 pub description: String,
149 #[serde(rename = "type")]
150 pub chart_type: String,
151 pub version: String,
152 #[serde(rename = "appVersion")]
153 pub app_version: String,
154 #[serde(default, skip_serializing_if = "Vec::is_empty")]
155 pub keywords: Vec<String>,
156 #[serde(default, skip_serializing_if = "Vec::is_empty")]
157 pub maintainers: Vec<Maintainer>,
158 #[serde(default, skip_serializing_if = "Option::is_none")]
159 pub home: Option<String>,
160 pub dependencies: Vec<ChartDependency>,
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
164pub struct Maintainer {
165 pub name: String,
166 #[serde(default, skip_serializing_if = "Option::is_none")]
167 pub email: Option<String>,
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
171pub struct ChartDependency {
172 pub name: String,
173 pub version: String,
174 pub repository: String,
175 #[serde(default, skip_serializing_if = "Option::is_none")]
176 pub alias: Option<String>,
177}
178
179/// Repository for the `pleme-computeunit` library chart. Defaults to the
180/// helmworks file:// path used by lareira-* charts; consumers can override
181/// via `RenderOpts::library_repo` to point at the published OCI registry.
182pub const DEFAULT_LIBRARY_REPO: &str = "file://../pleme-computeunit";
183pub const DEFAULT_LIBRARY_VERSION: &str = "~0.1.0";
184/// Canonical Helm library-chart name every `lareira-<nome>` chart depends
185/// on — re-export of the lifted [`caixa_core::DEFAULT_LIBRARY_NAME`] so
186/// the load-bearing string lives in exactly one place across every
187/// caixa renderer (caixa-helm's `RenderOpts::library_name` default
188/// here + caixa-flux's `cluster_bundle` `helmrelease.yaml` wrap key).
189/// A future per-edition library-chart fork — every entry on the
190/// absorption-roadmap that names a per-cluster / per-namespace /
191/// per-tenant variant of the canonical library chart — reaches both
192/// consumers through one `&'static str` by construction. Same shape
193/// as the [`caixa_core::DEFAULT_NAMESPACE`] (a085b26) /
194/// [`caixa_core::DEFAULT_SERVICO_PORT`] (1e22add) lifts on the peer
195/// canonical-K8s-axis-constant surface.
196pub use caixa_core::DEFAULT_LIBRARY_NAME;
197
198/// Canonical Helm 3 `Chart.yaml` `apiVersion` every rendered
199/// `lareira-<nome>` chart declares. Re-export of the lifted
200/// [`caixa_core::HELM_CHART_API_VERSION`] so the Helm-side
201/// chart-schema apiVersion — the discriminator the Helm binary's
202/// chart-schema parser (`helm dependency build`, `helm lint`,
203/// `helm template`) consults to select the schema that reads the
204/// rendered Chart.yaml — lives in exactly one place across every
205/// caixa renderer. The single production-code call site consuming
206/// it is [`build_chart_yaml`]'s `api_version` field assignment; a
207/// drifted local `pub const HELM_CHART_API_VERSION: &str = "…"` at
208/// this crate (or any sibling per-chart-schema renderer the
209/// absorption roadmap acknowledges — the future per-Aplicacao
210/// library chart, the future per-cluster snapshot chart) would
211/// silently reroute the rendered Chart.yaml through a stale
212/// chart-schema parser at `helm template` time far from the
213/// rebrand commit's source, so the equality + `&'static` static-data
214/// identity pin
215/// (`helm_chart_api_version_re_export_points_at_caixa_core_canonical`)
216/// closes the drift footgun at caixa-helm build time. Same shape as
217/// the [`DEFAULT_LIBRARY_NAME`] / [`KUBE_KEY_SPEC`] re-exports on the
218/// sibling canonical-Helm-load-bearing-string / canonical-K8s-CR-key
219/// axes.
220pub use caixa_core::HELM_CHART_API_VERSION;
221
222/// Canonical Helm 3 `Chart.yaml` `type` field per-chart-kind
223/// discriminator scalar-value every rendered `lareira-<nome>` chart
224/// declares. Re-export of the lifted
225/// [`caixa_core::HELM_CHART_TYPE_APPLICATION`] so the Helm chart-schema
226/// per-chart-kind discriminator — the scalar Helm's per-release install-
227/// shape dispatch loop keys off to select the per-chart-kind install
228/// pathway — lives in exactly one place across every caixa renderer.
229/// The single production-code call site consuming it is
230/// [`build_chart_yaml`]'s `chart_type` field assignment (the sole
231/// emitter site the prior inline `"application".into()` literal sat at);
232/// a drifted local `pub const HELM_CHART_TYPE_APPLICATION: &str = "…"`
233/// at this crate (or any sibling per-chart renderer the absorption
234/// roadmap acknowledges — the future per-Aplicacao library chart, the
235/// future per-cluster snapshot chart) would surface as one of two
236/// silent failure modes at `helm install` time: a value outside the
237/// schema's admitted set (`{"application", "library"}`) that Helm's
238/// chart-schema parser silently treats as the default `application`
239/// shape (masking the schema violation with no process-log signal), or
240/// an accidental collapse onto the sibling `"library"` shape that Helm
241/// refuses to install directly ("Error: library charts cannot be
242/// installed") with no field naming the chart-kind-drift root cause.
243/// The equality + `&'static` static-data identity pin
244/// (`helm_chart_type_application_re_export_points_at_caixa_core_canonical`)
245/// closes the drift footgun at caixa-helm build time. Peer to the
246/// [`HELM_CHART_API_VERSION`] re-export on the sibling canonical-Helm-
247/// chart-schema-axis — completes the per-Chart.yaml `(apiVersion, type)`
248/// canonical-scalar-axis re-export pair every rendered `lareira-<nome>`
249/// chart declares at its top-level Chart.yaml body.
250pub use caixa_core::HELM_CHART_TYPE_APPLICATION;
251
252/// Canonical Helm 3 `Chart.yaml` `type` field per-chart-kind discriminator
253/// scalar-value the sibling library-chart shape lands on — re-export of
254/// the lifted [`caixa_core::HELM_CHART_TYPE_LIBRARY`] so the second and
255/// only other arm of the Helm chart-schema's closed set `{"application",
256/// "library"}` lives in exactly one place across every caixa renderer.
257/// No production emitter here consumes it today — the caixa-helm
258/// renderer emits per-Servico `application`-typed `lareira-<nome>`
259/// charts, and the sibling [`DEFAULT_LIBRARY_NAME`] `pleme-computeunit`
260/// library chart is out-of-tree at `pleme-io/helmworks` (not this
261/// crate's authority) — but every future substrate-side per-chart-kind
262/// classifier and every emitter for the future per-Aplicacao library
263/// chart the [`HELM_CHART_TYPE_APPLICATION`] docstring names as a
264/// trajectory item reads the same `&'static str` by construction.
265/// Peer to the [`HELM_CHART_TYPE_APPLICATION`] re-export on the sibling
266/// closed-set arm — completes the two-arm re-export pair of the Helm
267/// chart-schema's per-chart-kind axis at the caixa-helm surface so
268/// consumers reaching for either shape read from one canonical source
269/// per arm. The paired identity pins
270/// (`helm_chart_type_library_re_export_points_at_caixa_core_canonical`)
271/// close the drift footgun at caixa-helm build time.
272pub use caixa_core::HELM_CHART_TYPE_LIBRARY;
273
274/// Canonical Helm 3 `Chart.yaml` top-level YAML axis-key naming the
275/// per-chart-kind discriminator field — re-export of the lifted
276/// [`caixa_core::HELM_CHART_KEY_TYPE`] so the top-level per-chart-kind
277/// discriminator YAML key the sibling [`HELM_CHART_TYPE_APPLICATION`] /
278/// [`HELM_CHART_TYPE_LIBRARY`] axis-value re-exports carry the closed-
279/// set admitted scalars for lives in exactly one place across every
280/// caixa renderer. The production emitter today is [`ChartYaml`]'s
281/// `chart_type` field `#[serde(rename = "type")]` attribute — Rust's
282/// attribute grammar admits only string literals so the const cannot
283/// substitute for the literal syntactically, but the drift-detection
284/// pin at
285/// [`tests::chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
286/// round-trips a rendered `Chart.yaml` through
287/// `serde_yaml::from_str::<serde_yaml::Value>` and asserts the top-
288/// level `Mapping::get(HELM_CHART_KEY_TYPE)` resolves, closing the
289/// drift the attribute-literal-only grammar leaves silent (a future
290/// refactor that dropped the `#[serde(rename = "type")]` attribute
291/// would silently serialize the field as Rust's default snake_case
292/// `chart_type:`, which Helm's chart-schema parser silently ignores
293/// as an unknown top-level key, defaulting the per-chart-kind axis
294/// to `application` with no process-log drift-signal). Peer to the
295/// [`HELM_CHART_TYPE_APPLICATION`] / [`HELM_CHART_TYPE_LIBRARY`]
296/// re-exports on the sibling per-chart-kind axis-value canonical
297/// surface — completes the per-Chart.yaml per-chart-kind
298/// discriminator axis's `(key, value-set)` canonical re-export trio
299/// at the caixa-helm surface.
300pub use caixa_core::HELM_CHART_KEY_TYPE;
301
302/// Canonical Helm 3 `Chart.yaml` top-level YAML axis-key naming the
303/// per-chart underlying-application-version field — re-export of the
304/// lifted [`caixa_core::HELM_CHART_KEY_APP_VERSION`] so the top-level
305/// per-chart-app-version YAML key the [`ChartYaml`] `app_version`
306/// field's `#[serde(rename = "appVersion")]` attribute encodes lives
307/// in exactly one place across every caixa renderer. Rust's attribute
308/// grammar admits only string literals so the const cannot substitute
309/// for the literal syntactically, but the drift-detection pin at
310/// [`tests::chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
311/// round-trips a rendered `Chart.yaml` and asserts the top-level
312/// `Mapping::get(HELM_CHART_KEY_APP_VERSION)` resolves, closing the
313/// drift the attribute-literal-only grammar leaves silent (a future
314/// refactor that dropped the `#[serde(rename = "appVersion")]`
315/// attribute would silently serialize the field as Rust's default
316/// snake_case `app_version:`, which Helm's chart-schema parser
317/// silently drops from the parsed chart-metadata shape, and every
318/// downstream Artifact Hub / `helm search` per-chart index falls back
319/// to "no application version" for the rendered chart far from the
320/// drift site). Peer to [`HELM_CHART_KEY_TYPE`] on the sibling
321/// per-Chart.yaml top-level YAML axis-key re-export surface —
322/// completes the per-Chart.yaml top-level YAML axis-key re-export
323/// pair at the caixa-helm surface for the two serde-rename-literal-
324/// only axes on this crate's [`ChartYaml`] struct that Rust's
325/// attribute-argument grammar leaves un-substitutable syntactically
326/// (the third top-level axis-key `apiVersion` re-exports through
327/// [`HELM_CHART_KEY_API_VERSION`] below, whose byte-shape coincides
328/// with the sibling [`caixa_core::KUBE_KEY_API_VERSION`] by Helm's
329/// design decision to inherit the K8s CR top-level shape verbatim —
330/// the paired substrate-side
331/// [`caixa_core`-side
332/// `helm_chart_key_api_version_matches_kube_key_api_version`] pin
333/// makes the byte-shape coincidence load-bearing rather than
334/// accidental).
335pub use caixa_core::HELM_CHART_KEY_APP_VERSION;
336
337/// Canonical Helm 3 `Chart.yaml` top-level YAML axis-key naming the
338/// per-chart chart-schema-apiVersion field — re-export of the lifted
339/// [`caixa_core::HELM_CHART_KEY_API_VERSION`] so the top-level chart-
340/// schema-apiVersion YAML key the [`ChartYaml`] `api_version` field's
341/// `#[serde(rename = "apiVersion")]` attribute encodes lives in
342/// exactly one place across every caixa renderer. Rust's attribute
343/// grammar admits only string literals so the const cannot substitute
344/// for the literal syntactically, but the drift-detection pin at
345/// [`tests::chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version`]
346/// round-trips a rendered `Chart.yaml` and asserts the top-level
347/// `Mapping::get(HELM_CHART_KEY_API_VERSION)` resolves, closing the
348/// drift the attribute-literal-only grammar leaves silent (a future
349/// refactor that dropped the `#[serde(rename = "apiVersion")]`
350/// attribute would silently serialize the field as Rust's default
351/// snake_case `api_version:`, which Helm's chart-schema parser
352/// rejects at `helm lint` / `helm dependency build` / `helm template`
353/// time with an "apiVersion is required" error far from the drift
354/// site). Peer to [`HELM_CHART_KEY_TYPE`] / [`HELM_CHART_KEY_APP_VERSION`]
355/// on the sibling per-Chart.yaml top-level YAML axis-key re-export
356/// surface — completes the per-Chart.yaml top-level YAML axis-key
357/// re-export trio at the caixa-helm surface for the three serde-
358/// rename-literal-only axes on this crate's [`ChartYaml`] struct.
359pub use caixa_core::HELM_CHART_KEY_API_VERSION;
360
361/// Canonical Helm 3 `Chart.yaml` top-level YAML axis-key naming the
362/// per-chart dependency-list field — re-export of the lifted
363/// [`caixa_core::HELM_CHART_KEY_DEPENDENCIES`] so the load-bearing serde
364/// field-name at [`ChartYaml`]'s `dependencies` field (the parent
365/// list-container the already-re-exported per-`dependencies[]`-entry
366/// sub-mapping tetrad [`HELM_CHART_DEPENDENCY_KEY_NAME`] /
367/// [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
368/// [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
369/// [`HELM_CHART_DEPENDENCY_KEY_ALIAS`] mounts one level down under)
370/// lives in exactly one place across every caixa renderer. The Rust
371/// field name and the wire key coincide by default (no
372/// `#[serde(rename)]` attribute today), so the const doesn't substitute
373/// for the field-name syntactically at the struct definition, but the
374/// drift-detection pin at
375/// [`tests::chart_yaml_serializes_dependencies_axis_under_lifted_helm_chart_key_dependencies`]
376/// round-trips a rendered `Chart.yaml` through
377/// `serde_yaml::from_str::<serde_yaml::Value>` and asserts the top-
378/// level `Mapping::get(HELM_CHART_KEY_DEPENDENCIES)` resolves — closing
379/// the drift a future field rename (`dependencies` → `deps` /
380/// `chartDependencies`) or a `#[serde(rename_all = "camelCase")]`
381/// attribute addition on [`ChartYaml`] would otherwise leave silent
382/// (Helm's chart-schema parser silently drops the entire dep list from
383/// the parsed chart-metadata, `helm dependency build` finds no chart to
384/// vendor, and every rendered `lareira-<nome>` chart's install fails at
385/// apply time far from the drift site). Peer to
386/// [`HELM_CHART_KEY_TYPE`] / [`HELM_CHART_KEY_APP_VERSION`] /
387/// [`HELM_CHART_KEY_API_VERSION`] on the sibling per-Chart.yaml
388/// top-level YAML axis-key re-export surface — extends the per-
389/// Chart.yaml top-level YAML axis-key re-export trio at the caixa-helm
390/// surface onto the fourth top-level axis-key, the parent list-
391/// container whose per-entry sub-mapping tetrad is already re-exported
392/// under [`HELM_CHART_DEPENDENCY_KEY_*`].
393pub use caixa_core::HELM_CHART_KEY_DEPENDENCIES;
394
395/// Canonical Helm 3 `Chart.yaml` per-`dependencies[]`-entry sub-mapping
396/// YAML axis-key naming the per-dep chart-name field — re-export of the
397/// lifted [`caixa_core::HELM_CHART_DEPENDENCY_KEY_NAME`] so the load-
398/// bearing serde field-name at [`ChartDependency`]'s `name` field lives
399/// in exactly one place across every caixa renderer. Peer to
400/// [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
401/// [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
402/// [`HELM_CHART_DEPENDENCY_KEY_ALIAS`] on the sibling per-dep sub-key
403/// axes. The drift-detection round-trip pin at
404/// [`tests::chart_dependency_serializes_tetrad_under_lifted_helm_chart_dependency_keys`]
405/// serializes a fully-populated [`ChartDependency`] and asserts each of
406/// the four per-dep sub-mapping wire keys resolves — closing the drift
407/// a rename of the Rust field or a `#[serde(rename_all)]` attribute
408/// addition would otherwise leave silent.
409pub use caixa_core::HELM_CHART_DEPENDENCY_KEY_NAME;
410
411/// Canonical Helm 3 `Chart.yaml` per-`dependencies[]`-entry sub-mapping
412/// YAML axis-key naming the per-dep chart-version-constraint field —
413/// re-export of the lifted [`caixa_core::HELM_CHART_DEPENDENCY_KEY_VERSION`]
414/// so the load-bearing serde field-name at [`ChartDependency`]'s
415/// `version` field lives in exactly one place across every caixa
416/// renderer. Peer to [`HELM_CHART_DEPENDENCY_KEY_NAME`] on the sibling
417/// per-dep sub-key axes. See [`HELM_CHART_DEPENDENCY_KEY_NAME`] for the
418/// shared per-entry-sub-mapping lift rationale.
419pub use caixa_core::HELM_CHART_DEPENDENCY_KEY_VERSION;
420
421/// Canonical Helm 3 `Chart.yaml` per-`dependencies[]`-entry sub-mapping
422/// YAML axis-key naming the per-dep chart-registry URL field — re-export
423/// of the lifted [`caixa_core::HELM_CHART_DEPENDENCY_KEY_REPOSITORY`]
424/// so the load-bearing serde field-name at [`ChartDependency`]'s
425/// `repository` field lives in exactly one place across every caixa
426/// renderer. Peer to [`HELM_CHART_DEPENDENCY_KEY_NAME`] on the sibling
427/// per-dep sub-key axes.
428pub use caixa_core::HELM_CHART_DEPENDENCY_KEY_REPOSITORY;
429
430/// Canonical Helm 3 `Chart.yaml` per-`dependencies[]`-entry sub-mapping
431/// YAML axis-key naming the per-dep chart-alias override field —
432/// re-export of the lifted [`caixa_core::HELM_CHART_DEPENDENCY_KEY_ALIAS`]
433/// so the load-bearing serde field-name at [`ChartDependency`]'s
434/// `alias` field lives in exactly one place across every caixa
435/// renderer. Peer to [`HELM_CHART_DEPENDENCY_KEY_NAME`] on the sibling
436/// per-dep sub-key axes.
437pub use caixa_core::HELM_CHART_DEPENDENCY_KEY_ALIAS;
438
439/// Canonical Helm 3 per-chart-directory metadata-file filename every
440/// rendered `lareira-<nome>` chart carries at its top-level directory —
441/// re-export of the lifted [`caixa_core::HELM_CHART_YAML_FILENAME`] so
442/// the fixed lookup name Helm's chart-schema parser (`helm dependency
443/// build`, `helm lint`, `helm template`, `helm install`) consults at
444/// chart-open time to locate the per-chart schema-body scalars
445/// ([`HELM_CHART_API_VERSION`], [`HELM_CHART_TYPE_APPLICATION`], the
446/// name/version/dependencies fields) lives in exactly one place across
447/// every caixa renderer. The single production-code call site
448/// consuming it is [`render_chart_for_servico`]'s `ChartDir` assembly
449/// where the metadata file's per-`ChartFile` `path` axis is set (the
450/// sole emitter site the prior inline `PathBuf::from("Chart.yaml")`
451/// literal sat at); every test-side round-trip navigator that reaches
452/// into the rendered `ChartDir` by the metadata filename (the
453/// per-chart-metadata-field sweep tests +
454/// [`ChartDir::write_to`] post-write existence pin) now consults the
455/// same `&'static str`, so a rebrand of the Helm 3 metadata-file axis
456/// (any per-fork `Chartfile.yaml` / Helm 4 metadata-file rename the
457/// upstream packaging spec might adopt) lands at one const and reaches
458/// every consumer by construction. A drifted local `pub const
459/// HELM_CHART_YAML_FILENAME: &str = "…"` at this crate — the canonical
460/// drift footgun where a sibling local `pub const` could happen to
461/// carry the same string at the source while pointing at a different
462/// `&'static` allocation — surfaces as one of two silent failure modes
463/// at chart-consumption time: Helm's chart-schema parser refuses to
464/// open the rendered chart-directory ("Error: Chart.yaml file is
465/// missing") far from the drift commit, or the sibling
466/// [`caixa_flux::cluster_bundle`]'s future per-chart-directory
467/// resolver — a per-cluster snapshot bundle that re-lists the
468/// chart-dir contents by filename — silently returns `None` at
469/// cluster-side `feira app deploy` time. The equality + `&'static`
470/// static-data identity pin
471/// (`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`)
472/// closes the drift footgun at caixa-helm build time. Peer to the
473/// [`HELM_CHART_API_VERSION`] / [`HELM_CHART_TYPE_APPLICATION`]
474/// re-exports on the sibling canonical-Helm-chart-schema-body-axis
475/// surface — completes the per-`lareira-<nome>`-chart-directory
476/// `(filename, apiVersion, type)` canonical-scalar-axis re-export
477/// triple every rendered chart declares at its top-level metadata file.
478pub use caixa_core::HELM_CHART_YAML_FILENAME;
479
480/// Canonical Helm 3 per-chart-directory values-file filename every
481/// rendered `lareira-<nome>` chart carries at its top-level directory —
482/// re-export of the lifted [`caixa_core::HELM_VALUES_YAML_FILENAME`] so
483/// the fixed lookup name Helm's chart-schema parser (`helm dependency
484/// build`, `helm lint`, `helm template`, `helm install`) consults at
485/// chart-open time to locate the per-chart values block that
486/// [`HELM_VALUES_KEY_ENABLED`] toggles under its
487/// [`DEFAULT_LIBRARY_NAME`] wrap key lives in exactly one place across
488/// every caixa renderer. The single production-code call site
489/// consuming it is [`render_chart_for_servico`]'s `ChartDir` assembly
490/// where the values file's per-`ChartFile` `path` axis is set (the
491/// sole emitter site the prior inline `PathBuf::from("values.yaml")`
492/// literal sat at); every test-side round-trip navigator that reaches
493/// into the rendered `ChartDir` by the values filename (the
494/// per-chart-values-field sweep tests +
495/// [`ChartDir::write_to`] post-write existence pin) now consults the
496/// same `&'static str`, so a rebrand of the Helm 3 values-file axis
497/// (any per-fork `defaults.yaml` / Helm 4 values-file rename the
498/// upstream packaging spec might adopt) lands at one const and reaches
499/// every consumer by construction. A drifted local `pub const
500/// HELM_VALUES_YAML_FILENAME: &str = "…"` at this crate — the canonical
501/// drift footgun where a sibling local `pub const` could happen to
502/// carry the same string at the source while pointing at a different
503/// `&'static` allocation — surfaces as one of two silent failure modes
504/// at chart-consumption time: Helm's per-chart values-loader silently
505/// falls back to the empty values block (`helm template` emits the
506/// library chart under its admission-time defaults, the workload comes
507/// up disabled or without any per-Servico M2 overlay applied) far from
508/// the drift commit, or the sibling
509/// [`caixa_flux::cluster_bundle`]'s future per-chart-directory
510/// resolver — a per-cluster snapshot bundle that re-lists the
511/// chart-dir contents by filename to route per-cluster values overlays
512/// through the canonical values file — silently returns `None` at
513/// cluster-side `feira app deploy` time. The equality + `&'static`
514/// static-data identity pin
515/// (`helm_values_yaml_filename_re_export_points_at_caixa_core_canonical`)
516/// closes the drift footgun at caixa-helm build time. Peer to the
517/// [`HELM_CHART_YAML_FILENAME`] re-export on the sibling
518/// canonical-Helm-per-chart-directory-metadata-file-axis surface —
519/// completes the per-`lareira-<nome>`-chart-directory
520/// `(Chart.yaml, values.yaml)` canonical-per-chart-directory-filename-
521/// axis re-export pair every rendered chart declares as its two
522/// schema-load-bearing `ChartDir::files` entries.
523pub use caixa_core::HELM_VALUES_YAML_FILENAME;
524
525/// Canonical `lareira-<nome>` chart-directory human-facing readme
526/// filename every rendered chart carries at its top-level directory —
527/// re-export of the lifted [`caixa_core::HELM_CHART_README_FILENAME`] so
528/// the third leg of the canonical `{Chart.yaml, values.yaml, README.md}`
529/// per-`lareira-<nome>` chart-directory `ChartFile` triple lives in
530/// exactly one place across every caixa renderer. The single
531/// production-code call site consuming it is
532/// [`render_chart_for_servico`]'s `ChartDir` assembly where the readme
533/// file's per-`ChartFile` `path` axis is set (the sole emitter site the
534/// prior inline `"README.md"` string literal sat at); every test-side
535/// round-trip navigator that reaches into the rendered `ChartDir` by
536/// the readme filename (the [`render_chart_for_servico`] files-vec-
537/// membership pin + the [`ChartDir::write_to`] post-write existence
538/// pin — two sites) now consults the same `&'static str`. A drifted
539/// local `pub const HELM_CHART_README_FILENAME: &str = "…"` at this
540/// crate — the canonical drift footgun where a sibling local
541/// `pub const` could happen to carry the same string at the source
542/// while pointing at a different `&'static` allocation — surfaces as
543/// GitHub / Artifact Hub / any downstream per-chart README-surfacing
544/// UI silently falling back to "no README available" for the rendered
545/// `lareira-<nome>` chart far from the drift commit's source, with no
546/// field naming the readme-filename-drift root cause. The equality +
547/// `&'static` static-data identity pin
548/// (`helm_chart_readme_filename_re_export_points_at_caixa_core_canonical`)
549/// closes the drift footgun at caixa-helm build time. Peer to the
550/// [`HELM_CHART_YAML_FILENAME`] / [`HELM_VALUES_YAML_FILENAME`]
551/// re-exports on the sibling canonical-Helm-per-chart-directory-
552/// filename axes — completes the per-`lareira-<nome>`-chart-directory
553/// `(Chart.yaml, values.yaml, README.md)` canonical-per-chart-directory-
554/// filename-axis re-export triple every rendered chart declares as its
555/// three `ChartDir::files` entries.
556pub use caixa_core::HELM_CHART_README_FILENAME;
557
558/// Canonical K8s CR top-level `spec` key. Re-export of the canonical
559/// [`caixa_core::KUBE_KEY_SPEC`] so the per-kind body key lives in
560/// exactly one place across every caixa renderer — caixa-helm's
561/// `build_values_yaml` (the upstream ComputeUnit YAML's `spec.*` axis
562/// the rendered `lareira-<nome>` chart's values block re-routes
563/// through the library alias) now consults the same `&'static str` as
564/// the peer caixa-flux / caixa-mesh renderers' `KUBE_KEY_SPEC`
565/// re-exports. The prior inline `"spec"` literal at the production-
566/// code call site would have let a typo (e.g. `"Spec"`, `"specs"`,
567/// `"spec_"`) silently emit a values block that drops every typed
568/// ComputeUnit-side field (`module`, `trigger`, `capabilities`,
569/// `resources`, `serviceAccount`) at the rendered chart's landing
570/// site — the `Error::MissingField("spec")` diagnostic now threads
571/// the same `&'static str` through the diagnostic surface so the
572/// error message stays byte-identical to the key it failed to find.
573/// Same shape as the [`DEFAULT_LIBRARY_NAME`] re-export on the
574/// sibling canonical-Helm-load-bearing-string axis.
575pub use caixa_core::KUBE_KEY_SPEC;
576
577/// Canonical `pleme-computeunit` library-chart values-block enable-toggle
578/// key — re-export of the lifted [`caixa_core::HELM_VALUES_KEY_ENABLED`]
579/// so the values-block toggle every rendered `lareira-<nome>` chart's
580/// values.yaml carries under its [`DEFAULT_LIBRARY_NAME`] wrap key lives
581/// in exactly one place across every caixa renderer. The single
582/// production-code call site consuming it is [`build_values_yaml`]'s
583/// `block.insert(HELM_VALUES_KEY_ENABLED.to_string(), …)` (formerly an
584/// inline `"enabled".to_string()` literal at `caixa-helm/src/lib.rs:389`);
585/// the peer test-fixture navigators pinning the default-off round-trip
586/// (`values_yaml_wraps_under_pleme_computeunit_key`,
587/// `values_yaml_wrap_key_follows_library_name_override`) also consult the
588/// re-export so a rebrand of the library-chart's per-values enable-toggle
589/// axis lands at one const and reaches every consumer by construction.
590/// A drifted local `pub const HELM_VALUES_KEY_ENABLED: &str = "…"` (or
591/// any sibling per-renderer variant that inlined a stale
592/// `"enabled"` / `"enable"` / `"disabled"` literal) would silently emit
593/// a values block whose per-values enable-toggle lands under one key
594/// while [`caixa_flux::cluster_bundle`]'s `HelmRelease`
595/// `spec.values.<library>.enabled` per-cluster override lands under
596/// another — Helm's per-values merge treats them as sibling scalars, the
597/// enable-toggle the library chart's own template consults never sees the
598/// flip, and the workload silently comes up with the library chart's
599/// admission-time defaults instead of the per-cluster override the
600/// operator set. Same shape as the [`DEFAULT_LIBRARY_NAME`] /
601/// [`KUBE_KEY_SPEC`] / [`HELM_CHART_API_VERSION`] re-exports on the
602/// sibling canonical-Helm-load-bearing-string / canonical-K8s-CR-body-
603/// key / canonical-Helm-chart-schema-apiVersion axes.
604pub use caixa_core::HELM_VALUES_KEY_ENABLED;
605
606/// Canonical substrate-side default for the
607/// `values.<library>.enabled` scalar-value toggle every
608/// [`render_chart_for_servico`]-emitted standalone `lareira-<nome>`
609/// chart's `values.yaml` document seeds inside its per-caixa
610/// [`DEFAULT_LIBRARY_NAME`] wrap block to leave the paired
611/// [`DEFAULT_LIBRARY_NAME`] child chart opted-out at the per-cluster
612/// `helm template` / `helm install` apply step. Re-export of the
613/// canonical [`caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT`] so the
614/// substrate-side default the standalone per-chart path seeds under
615/// the sibling [`HELM_VALUES_KEY_ENABLED`] leaf-scalar-key lives in
616/// exactly one place across every caixa renderer. Consumed by
617/// [`RenderOpts::default`]'s `enabled_default` field seed (formerly
618/// an inline `false` scalar-value literal at
619/// `caixa-helm/src/lib.rs:700`); the peer test-fixture navigators
620/// pinning the default-off round-trip also consult the re-export so a
621/// rebrand of the per-values-block child-chart-enablement-toggle scalar
622/// on the standalone per-chart path lands at one const and reaches
623/// every consumer by construction. Semantically distinct from — and
624/// inverse of — the peer
625/// [`caixa_flux::CLUSTER_BUNDLE_LAREIRA_ENABLED_DEFAULT`] on the
626/// composition per-cluster-`HelmRelease` values-overlay path (which
627/// force-ons the child chart under the substrate-side composition
628/// path); the two peer scalar-value defaults name mirror-symmetric
629/// per-path child-chart-enablement-toggle-scalar-value defaults at the
630/// exact same `values.<library>.enabled` sub-block position on the
631/// standalone per-chart-`values.yaml` path (this re-export) and the
632/// composition per-cluster-`HelmRelease` values-overlay path (the peer
633/// re-export). Same shape as the [`DEFAULT_LIBRARY_NAME`] /
634/// [`KUBE_KEY_SPEC`] / [`HELM_VALUES_KEY_ENABLED`] re-exports on the
635/// sibling canonical-Helm-load-bearing-string / canonical-K8s-CR-body-
636/// key / canonical-Helm-per-values-block-enable-toggle-key axes. See
637/// [`caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT`] for the full lift
638/// rationale.
639pub use caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT;
640
641/// Local re-export of the canonical
642/// [`caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE`] — the
643/// `wasm.pleme.io/v1alpha1/ComputeUnit` CRD per-CR wasm-module-reference
644/// `spec.module` sub-block key every rendered `values.yaml`'s
645/// [`DEFAULT_LIBRARY_NAME`]-wrapped block carries so the
646/// `pleme-computeunit` library chart's per-Servico module-source axis
647/// binds to the exact source the caixa.lisp's `:servicos` fixture
648/// pins. Two per-values drift-detection navigators in this crate's
649/// test module (the canonical-wrap-key round-trip + the
650/// `library-name`-override wrap-key round-trip) now consult the same
651/// `&'static str` as the peer caixa-flux writer's per-Servico
652/// `programs[]`-entry module-source navigators. Same re-export shape
653/// as the peer [`HELM_VALUES_KEY_ENABLED`] / [`KUBE_KEY_SPEC`]
654/// surfaces on the sibling canonical-Helm-load-bearing-string /
655/// canonical-K8s-CR-body-key axes — extends the discipline the
656/// M2-typed-slot / K8s-CR key re-export families establish onto the
657/// substrate-side ComputeUnit-CRD per-`spec.*` sub-block axis. See
658/// [`caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE`] for the full lift
659/// rationale.
660pub use caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE;
661
662/// Local re-export of the canonical
663/// [`caixa_core::COMPUTEUNIT_SPEC_KEY_TRIGGER`] — the
664/// `wasm.pleme.io/v1alpha1/ComputeUnit` CRD per-CR invocation-shape
665/// `spec.trigger` sub-block key every rendered `values.yaml`'s
666/// [`DEFAULT_LIBRARY_NAME`]-wrapped block carries so the
667/// `pleme-computeunit` library chart's per-Servico
668/// `trigger.service.{port, paths, breathability}` routing binds to
669/// the exact axis the caixa.lisp's `:servicos` fixture pins. Peer of
670/// [`COMPUTEUNIT_SPEC_KEY_MODULE`] on the same ComputeUnit CRD
671/// per-`spec.*` sub-block axis — see
672/// [`caixa_core::COMPUTEUNIT_SPEC_KEY_TRIGGER`] for the full lift
673/// rationale.
674pub use caixa_core::COMPUTEUNIT_SPEC_KEY_TRIGGER;
675
676/// Local re-export of the canonical
677/// [`caixa_core::COMPUTEUNIT_SPEC_KEY_CAPABILITIES`] — the
678/// `wasm.pleme.io/v1alpha1/ComputeUnit` CRD per-CR WASI-capability-list
679/// `spec.capabilities` sub-block key every rendered `values.yaml`'s
680/// [`DEFAULT_LIBRARY_NAME`]-wrapped block carries so the
681/// `pleme-computeunit` library chart's per-Servico WASI-preview-2
682/// capability-token binding fires exactly against the axis the
683/// caixa.lisp's `:servicos` fixture pins. Peer of
684/// [`COMPUTEUNIT_SPEC_KEY_MODULE`] and [`COMPUTEUNIT_SPEC_KEY_TRIGGER`]
685/// on the same ComputeUnit CRD per-`spec.*` sub-block axis — completes
686/// the substrate-side ComputeUnit-CRD per-`spec.*` sub-block re-export
687/// triple in this crate. See
688/// [`caixa_core::COMPUTEUNIT_SPEC_KEY_CAPABILITIES`] for the full lift
689/// rationale.
690pub use caixa_core::COMPUTEUNIT_SPEC_KEY_CAPABILITIES;
691
692/// Local re-export of the canonical
693/// [`caixa_core::servico_spec_and_m2_overlay_entries`] — the composed
694/// per-Servico value-block splice helper this crate's
695/// [`build_values_yaml`] and the peer
696/// [`caixa_flux::programs_yaml_entry`] both now route their two-step
697/// `spec.*` field-splice + M2 typed-slot overlay through. The single
698/// production-code call site consuming it is [`build_values_yaml`]'s
699/// inner splice loop (formerly two hand-written for-loops chained
700/// around `string_keyed_entries` + `servico_m2_overlay`); re-exported
701/// so the shared composition contract lives in exactly one place
702/// across both per-Servico renderers — a future author reading
703/// `caixa_helm::build_values_yaml` finds the composition helper
704/// immediately without an extra `use caixa_core::…` line, and a
705/// rebrand of the composition axis (e.g. a swap of the `or_insert`
706/// precedence rule once per-Aplicacao operator overrides land)
707/// reaches both renderers through one canonical `&'static` function
708/// pointer. Same shape as the peer [`COMPUTEUNIT_SPEC_KEY_MODULE`] /
709/// [`COMPUTEUNIT_SPEC_KEY_TRIGGER`] / [`COMPUTEUNIT_SPEC_KEY_CAPABILITIES`]
710/// re-exports on the sibling canonical-ComputeUnit-CRD `spec.*` axis
711/// — extends the shared-composition discipline the per-`spec.*`
712/// sub-block re-export triple establishes onto the composed
713/// spec.*+M2 splice axis every per-Servico renderer navigates.
714pub use caixa_core::servico_spec_and_m2_overlay_entries;
715
716/// Knobs that don't come from the Caixa manifest.
717#[derive(Debug, Clone)]
718pub struct RenderOpts {
719 /// Where the library chart lives. Default = `file://../pleme-computeunit`.
720 pub library_repo: String,
721 pub library_version: String,
722 pub library_name: String,
723 /// Whether the rendered values block is `enabled: false` by default
724 /// (matching `lareira-hello-world` so cluster operators flip it on
725 /// per-cluster). Default: [`STANDALONE_LAREIRA_ENABLED_DEFAULT`]
726 /// (`false` — the substrate's chosen standalone per-chart
727 /// opt-out seed, inverse of the composition per-cluster-`HelmRelease`
728 /// values-overlay path's [`caixa_flux::CLUSTER_BUNDLE_LAREIRA_ENABLED_DEFAULT`]
729 /// force-on).
730 pub enabled_default: bool,
731}
732
733impl Default for RenderOpts {
734 fn default() -> Self {
735 Self {
736 library_repo: DEFAULT_LIBRARY_REPO.into(),
737 library_version: DEFAULT_LIBRARY_VERSION.into(),
738 library_name: DEFAULT_LIBRARY_NAME.into(),
739 enabled_default: STANDALONE_LAREIRA_ENABLED_DEFAULT,
740 }
741 }
742}
743
744/// Render a per-program lareira-<name> chart from a Caixa Servico + its
745/// loaded ComputeUnit YAML.
746///
747/// The ComputeUnit YAML is passed in as a `serde_yaml::Value` because the
748/// authoritative schema lives in the wasm-operator's CRD — we don't want
749/// caixa-helm to drift from that schema. It's enough that we can locate
750/// `spec` and pass it through.
751pub fn render_chart_for_servico(
752 caixa: &Caixa,
753 computeunit_yaml: &serde_yaml::Value,
754) -> Result<ChartDir, Error> {
755 render_chart_for_servico_with(caixa, computeunit_yaml, &RenderOpts::default())
756}
757
758/// `render_chart_for_servico` with explicit options.
759pub fn render_chart_for_servico_with(
760 caixa: &Caixa,
761 computeunit_yaml: &serde_yaml::Value,
762 opts: &RenderOpts,
763) -> Result<ChartDir, Error> {
764 caixa_core::require_v0_servico_shape::<Error>(caixa)?;
765
766 // Canonical typed `&str`-read of the per-`Caixa` `:nome`
767 // universal-axis DNS-1123-label caixa-identity scalar into
768 // the per-chart-directory `lareira-<nome>` identity composer.
769 // Peer of the sibling 4a363bf / 54bf2f3 `caixa.nome.clone()`
770 // converges on the outer-Caixa `:nome` `String`-carry axis
771 // in caixa-flux / caixa-mesh and the sibling eb912de
772 // `caixa.versao.clone()` converge on the co-resident
773 // `Caixa::versao` `String`-carry axis in this crate — this
774 // extends the "one typed dispatch on the substrate primitive,
775 // thin projections at each consumer" discipline onto the
776 // non-`.clone()` raw-field-access axis of `Caixa::nome` in
777 // caixa-helm.
778 let chart_name = lareira_chart_name(caixa.nome());
779 let chart_yaml = build_chart_yaml(caixa, &chart_name, opts);
780 let values_yaml = build_values_yaml(caixa, computeunit_yaml, opts)?;
781 let readme = build_readme(caixa, &chart_name);
782
783 // Each per-artifact leaf routes through the canonical
784 // [`caixa_core::RenderedFile::new`] `impl Into<PathBuf>` /
785 // `impl Into<String>` constructor (re-exported by the peer
786 // [`ChartFile`] alias since Rust inherent methods travel through
787 // type aliases to the aliased type at name resolution). The prior
788 // three inline `ChartFile { path: PathBuf::from(FILENAME_CONST),
789 // contents: <body> }` blocks each re-derived the same
790 // `PathBuf::from(&str)` wrap + the same two-field assembly — a
791 // byte-identical duplicate of the peer [`caixa_flux::cluster_bundle`]
792 // Flux v2 CR trio's three per-CR emit sites. Sweeping both trios
793 // onto [`RenderedFile::new`] collapses the six substrate-side
794 // per-artifact-construction sites onto one canonical constructor,
795 // so a future rebrand on the record shape (a per-artifact hash /
796 // provenance field addition, a per-artifact write-mode discriminator
797 // once per-cluster-writer sandboxing lands, the
798 // [`caixa_core::is_sandboxed_relative_path`] discipline the
799 // [`RenderedFile`] docstring acknowledges is not yet run at emit
800 // time) reaches every per-target renderer through one caixa-core
801 // edit instead of a coordinated six-site rewrite.
802 Ok(ChartDir {
803 name: chart_name,
804 files: vec![
805 ChartFile::new(
806 HELM_CHART_YAML_FILENAME,
807 serde_yaml::to_string(&chart_yaml)?,
808 ),
809 ChartFile::new(HELM_VALUES_YAML_FILENAME, values_yaml),
810 ChartFile::new(HELM_CHART_README_FILENAME, readme),
811 ],
812 })
813}
814
815fn build_chart_yaml(caixa: &Caixa, chart_name: &str, opts: &RenderOpts) -> ChartYaml {
816 let description = caixa
817 .descricao()
818 .map(str::to_owned)
819 .unwrap_or_else(|| format!("Generated chart for caixa Servico {}", caixa.nome()));
820 let keywords: Vec<String> = caixa
821 .etiquetas()
822 .iter()
823 .cloned()
824 .chain(
825 caixa_core::LAREIRA_CHART_KEYWORDS
826 .iter()
827 .copied()
828 .map(String::from),
829 )
830 .collect::<Vec<_>>()
831 .into_iter()
832 .collect::<std::collections::BTreeSet<_>>()
833 .into_iter()
834 .collect();
835 let maintainers = caixa
836 .autores()
837 .iter()
838 .map(|a| Maintainer {
839 name: a.clone(),
840 email: None,
841 })
842 .collect();
843 // Canonical typed `String`-carry of the per-`Caixa` `:versao`
844 // universal-axis SemVer-2 pinned-version scalar into the two
845 // per-`Chart.yaml` version-carrier fields Helm's chart-schema
846 // parser routes per-chart identity through — `Chart.yaml`'s
847 // top-level `version:` (the axis Helm's per-chart resolver keys
848 // per-release reconciliation off, the paired `HelmRelease`
849 // `spec.chart.spec.version` binds through, and every `helm
850 // template <chart>` / `helm install <release> <chart>` /
851 // `helm upgrade <release> <chart> --version` invocation names
852 // through) and `Chart.yaml`'s top-level `appVersion:` (the
853 // axis Helm chart-consumers key per-application-version
854 // documentation / release-note / OCI-tag / operator-side
855 // per-Caixa CR revision off), both routing through the typed
856 // [`caixa_core::Caixa::versao`] accessor's canonical
857 // `to_string()` extension of `&self.versao`. Peer of the
858 // sibling 4a363bf / 54bf2f3 `caixa.nome.clone()` converges
859 // on the outer-Caixa `:nome` `String`-carry axis in caixa-flux
860 // / caixa-mesh — this converges the last unlifted per-Caixa
861 // `.versao.clone()` raw-field `String`-carry axis in
862 // caixa-helm on the same "one typed dispatch per axis"
863 // discipline.
864 let versao = caixa.versao().to_string();
865 ChartYaml {
866 api_version: HELM_CHART_API_VERSION.into(),
867 name: chart_name.into(),
868 description,
869 chart_type: HELM_CHART_TYPE_APPLICATION.into(),
870 version: versao.clone(),
871 app_version: versao,
872 keywords,
873 maintainers,
874 home: caixa.repositorio().map(str::to_owned),
875 dependencies: vec![ChartDependency {
876 name: opts.library_name.clone(),
877 version: opts.library_version.clone(),
878 repository: opts.library_repo.clone(),
879 alias: None,
880 }],
881 }
882}
883
884fn build_values_yaml(
885 caixa: &Caixa,
886 computeunit_yaml: &serde_yaml::Value,
887 opts: &RenderOpts,
888) -> Result<String, Error> {
889 // The library chart consumes its values under the key matching its
890 // Helm chart `dependencies[].name` (Helm's per-dep alias convention
891 // — when no `alias:` is set on the dependency, values are scoped
892 // under the dependency's `name`). This renderer wires both axes
893 // through the same `opts.library_name`: the chart's dep `name:`
894 // (build_chart_yaml at line 277) and this site's values wrap key
895 // both consult one `&str`, so a future fork that overrides
896 // `RenderOpts::library_name` to point at `acme-computeunit` /
897 // `pleme-computeunit-mirror` / the future per-edition library name
898 // reaches both axes by construction. Until this lift landed the
899 // wrap key was hardcoded `"pleme-computeunit"` while the dep name
900 // followed `opts.library_name`, so an override silently emitted
901 // values keyed under one name (the literal) while the rendered
902 // Chart.yaml's dep was declared under another (the override) —
903 // Helm's per-dep values router would route nothing to the
904 // configured dependency at `helm template` / `helm install` time,
905 // and every typed value the values block carries (`enabled`,
906 // `module`, `trigger`, the M2 overlay's `:limits`/`:behavior`/
907 // `:upgrade-from`) would silently no-op at the rendered chart's
908 // landing site. The wrap key now reads from the same `&str` the
909 // dep name reads from, structurally closing the drift footgun
910 // peer with the [`caixa_core::DEFAULT_NAMESPACE`] /
911 // [`caixa_core::DEFAULT_SERVICO_PORT`] lifts on the sibling
912 // canonical-K8s-axis constants (where two production-code call
913 // sites of the same load-bearing value would drift apart on
914 // any rebrand without a shared source of truth).
915 let library_alias = opts.library_name.as_str();
916 let spec = computeunit_yaml
917 .get(KUBE_KEY_SPEC)
918 .ok_or(Error::MissingField(KUBE_KEY_SPEC))?;
919
920 // Prepend a comment header so the file is human-friendly.
921 let header = format!(
922 "# Auto-generated by caixa-helm from caixa.lisp + servicos/{nome}.computeunit.yaml.\n\
923 # Edits to this file are overwritten by `feira chart`.\n\
924 #\n\
925 # `{library_alias}:` is the alias under which the library chart\n\
926 # in pleme-io/helmworks/charts/{library_alias} consumes its values.\n\n",
927 nome = caixa.nome()
928 );
929
930 let mut block = BTreeMap::new();
931 block.insert(
932 HELM_VALUES_KEY_ENABLED.to_string(),
933 serde_yaml::Value::Bool(opts.enabled_default),
934 );
935 // Two-step per-Servico value-block splice — the `spec.*` field
936 // splice (module / trigger / capabilities / config / resources /
937 // serviceAccount) and the M2 typed-slot overlay (limits / behavior
938 // / upgradeFrom, `or_insert` semantics so `spec.*` wins on
939 // collision) now route through the canonical
940 // [`caixa_core::servico_spec_and_m2_overlay_entries`] composition
941 // helper — the two prior inline for-loops chained around
942 // `string_keyed_entries` + `servico_m2_overlay` this call site
943 // (and the peer [`caixa_flux::programs_yaml_entry`] site) each
944 // re-derived collapse onto one canonical composition, so a future
945 // change to the per-Servico splice / overlay shape (the M4 typed
946 // per-edge policy overlay slot addition MESH-COMPOSITION §III.2 #3
947 // acknowledges, a change to the precedence rule once per-Aplicacao
948 // operator overrides land, a canonicalization pass on the merged
949 // key set) reaches both renderers by construction instead of a
950 // coordinated two-file rewrite. See the helper's docstring for the
951 // full lift rationale. The target `BTreeMap` re-sorts by key on
952 // insert, so the final rendered values block stays byte-identical
953 // to the prior inline block's alphabetical shape.
954 for (k, v) in caixa_core::servico_spec_and_m2_overlay_entries(caixa, spec)? {
955 block.entry(k).or_insert(v);
956 }
957
958 let mut wrapped = serde_yaml::Mapping::new();
959 wrapped.insert_str_key(library_alias, serde_yaml::to_value(block)?);
960 let body = serde_yaml::to_string(&serde_yaml::Value::Mapping(wrapped))?;
961 Ok(format!("{header}{body}"))
962}
963
964fn build_readme(caixa: &Caixa, chart_name: &str) -> String {
965 let descricao = caixa
966 .descricao()
967 .map(str::to_owned)
968 .unwrap_or_else(|| format!("caixa Servico {}", caixa.nome()));
969 format!(
970 "# {chart_name}\n\
971 \n\
972 {descricao}\n\
973 \n\
974 ## Origin\n\
975 \n\
976 Generated by `caixa-helm` from `{repo}/caixa.lisp` v{versao}.\n\
977 Edits here are overwritten by `feira chart`.\n\
978 \n\
979 ## Install\n\
980 \n\
981 ```bash\n\
982 helm dependency build\n\
983 helm template {chart_name} . --values values.yaml\n\
984 ```\n\
985 \n\
986 ## License\n\
987 \n\
988 {license}.\n",
989 chart_name = chart_name,
990 descricao = descricao,
991 repo = caixa.repositorio().unwrap_or(caixa.nome()),
992 versao = caixa.versao(),
993 license = caixa.licenca().unwrap_or("MIT"),
994 )
995}
996
997#[cfg(test)]
998mod tests {
999 use super::*;
1000 use caixa_core::{
1001 Caixa, CaixaKind, M2_BEHAVIOR_KEY_ON_CALL, M2_BEHAVIOR_KEY_ON_INIT, M2_KEY_BEHAVIOR,
1002 M2_KEY_LIMITS, M2_KEY_UPGRADE_FROM, M2_LIMITS_KEY_CPU, M2_LIMITS_KEY_FUEL,
1003 M2_LIMITS_KEY_MEMORY, M2_LIMITS_KEY_WALL_CLOCK, kube_str,
1004 };
1005 use std::path::PathBuf;
1006
1007 fn sample_caixa() -> Caixa {
1008 Caixa {
1009 nome: "hello-rio".into(),
1010 versao: "0.1.0".into(),
1011 kind: CaixaKind::Servico,
1012 edicao: Some("2026".into()),
1013 descricao: Some("Canonical Rust→wasm32-wasip2 caixa Servico.".into()),
1014 repositorio: Some("github:pleme-io/hello-rio".into()),
1015 licenca: Some("MIT".into()),
1016 autores: vec!["pleme-io".into()],
1017 etiquetas: vec!["hello-world".into(), "wasm".into(), "rust".into()],
1018 deps: vec![],
1019 deps_dev: vec![],
1020 exe: vec![],
1021 bibliotecas: vec![],
1022 servicos: vec!["servicos/hello-rio.computeunit.yaml".into()],
1023 limits: None,
1024 behavior: None,
1025 upgrade_from: vec![],
1026 estrategia: None,
1027 max_restarts: None,
1028 restart_window: None,
1029 children: vec![],
1030 membros: vec![],
1031 contratos: vec![],
1032 politicas: None,
1033 placement: None,
1034 entrada: None,
1035 ci: None,
1036 }
1037 }
1038
1039 fn sample_cu_yaml() -> serde_yaml::Value {
1040 serde_yaml::from_str(
1041 r#"
1042apiVersion: wasm.pleme.io/v1alpha1
1043kind: ComputeUnit
1044metadata:
1045 name: hello-rio
1046spec:
1047 module:
1048 source: oci://ghcr.io/pleme-io/hello-rio:v0.1.0
1049 trigger:
1050 service:
1051 port: 8080
1052 paths: ["/", "/hello", "/healthz"]
1053 breathability:
1054 enabled: true
1055 minReplicas: 0
1056 maxReplicas: 5
1057 cooldownPeriod: 600
1058 capabilities:
1059 - http-in:0.0.0.0:8080
1060 - env
1061"#,
1062 )
1063 .unwrap()
1064 }
1065
1066 #[test]
1067 fn renders_three_files() {
1068 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1069 assert_eq!(dir.name, "lareira-hello-rio");
1070 let names: Vec<_> = dir
1071 .files
1072 .iter()
1073 .map(|f| f.path.to_string_lossy().to_string())
1074 .collect();
1075 assert!(names.contains(&HELM_CHART_YAML_FILENAME.to_string()));
1076 assert!(names.contains(&HELM_VALUES_YAML_FILENAME.to_string()));
1077 assert!(names.contains(&HELM_CHART_README_FILENAME.to_string()));
1078 }
1079
1080 #[test]
1081 fn chart_yaml_metadata_propagates() {
1082 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1083 let chart_file = dir
1084 .files
1085 .iter()
1086 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1087 .unwrap();
1088 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
1089 assert_eq!(chart.api_version, "v2");
1090 assert_eq!(chart.name, "lareira-hello-rio");
1091 assert_eq!(chart.version, "0.1.0");
1092 assert_eq!(chart.app_version, "0.1.0");
1093 assert_eq!(chart.dependencies.len(), 1);
1094 assert_eq!(chart.dependencies[0].name, DEFAULT_LIBRARY_NAME);
1095 assert!(chart.keywords.contains(&"caixa-servico".to_string()));
1096 assert!(chart.keywords.contains(&"hello-world".to_string()));
1097 assert_eq!(chart.maintainers[0].name, "pleme-io");
1098 }
1099
1100 #[test]
1101 fn chart_yaml_keywords_union_pins_every_lareira_chart_keywords_entry() {
1102 // Structural pin: `build_chart_yaml`'s substrate-fixed
1103 // chart-keyword union routes through the canonical
1104 // `caixa_core::LAREIRA_CHART_KEYWORDS` array — every rendered
1105 // `lareira-<nome>` chart's emitted `Chart.yaml` `keywords:`
1106 // sequence carries every substrate-fixed entry the array
1107 // declares. A future substrate-fixed keyword addition
1108 // (an `"opentelemetry"` entry once the caixa-otel collector-
1109 // pipeline chart lands, a `"lunatic"` entry once the wasm-
1110 // process-runtime marker lands, a `"gen_server"` entry once
1111 // the OTP-shape callback marker lands per the
1112 // [`caixa_core::behavior`] surface) that lands in the array
1113 // reaches this crate's production emit site by construction
1114 // through the shared `&[&str]` reference — a drift where the
1115 // production emit at `build_chart_yaml` re-inlines the pre-
1116 // lift `["lareira", "wasm", "tatara-lisp", "caixa-servico"]`
1117 // literal set (or drops a per-entry axis on a rebrand
1118 // sweep) fails this pin at caixa-helm build time rather than
1119 // surfacing as a `helm search hub caixa-servico` miss on the
1120 // Artifact Hub keyword-search index at chart-publish time
1121 // downstream. Peer to
1122 // [`chart_yaml_metadata_propagates`] on the
1123 // per-`Chart.yaml`-body-field propagation surface.
1124 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1125 let chart_file = dir
1126 .files
1127 .iter()
1128 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1129 .unwrap();
1130 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
1131 for keyword in caixa_core::LAREIRA_CHART_KEYWORDS {
1132 assert!(
1133 chart.keywords.contains(&(*keyword).to_string()),
1134 "rendered Chart.yaml keywords {:?} must contain the \
1135 substrate-fixed LAREIRA_CHART_KEYWORDS entry {keyword:?}",
1136 chart.keywords,
1137 );
1138 }
1139 }
1140
1141 #[test]
1142 fn values_yaml_wraps_under_pleme_computeunit_key() {
1143 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1144 let values = dir
1145 .files
1146 .iter()
1147 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1148 .unwrap();
1149 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1150 let cu_block = parsed
1151 .get(DEFAULT_LIBRARY_NAME)
1152 .expect("must wrap under DEFAULT_LIBRARY_NAME");
1153 assert_eq!(
1154 cu_block.get(HELM_VALUES_KEY_ENABLED),
1155 Some(&serde_yaml::Value::Bool(false))
1156 );
1157 assert!(cu_block.get(COMPUTEUNIT_SPEC_KEY_MODULE).is_some());
1158 assert!(cu_block.get(COMPUTEUNIT_SPEC_KEY_TRIGGER).is_some());
1159 assert!(cu_block.get(COMPUTEUNIT_SPEC_KEY_CAPABILITIES).is_some());
1160 }
1161
1162 #[test]
1163 fn values_yaml_wrap_key_follows_library_name_override() {
1164 // Pinning the canonical alignment between the Helm chart's
1165 // `dependencies[].name` axis (build_chart_yaml at line 277) and
1166 // the values block's wrap key (build_values_yaml at the
1167 // `wrapped.insert(...)` site): both consult the same
1168 // `opts.library_name`, so an override on either axis reaches the
1169 // other by construction. Helm's per-dep alias convention — when
1170 // no `alias:` is set on a dependency, values are scoped under
1171 // its `name:` — makes wrap-key drift a silent value-routing
1172 // no-op at `helm template` / `helm install` time, so the
1173 // structural pin is load-bearing.
1174 let opts = RenderOpts {
1175 library_name: "acme-computeunit".into(),
1176 ..RenderOpts::default()
1177 };
1178 let dir = render_chart_for_servico_with(&sample_caixa(), &sample_cu_yaml(), &opts).unwrap();
1179 let values = dir
1180 .files
1181 .iter()
1182 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1183 .unwrap();
1184 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1185 assert!(
1186 parsed.get("acme-computeunit").is_some(),
1187 "values wrap key must follow opts.library_name override \
1188 (got top-level keys: {keys:?})",
1189 keys = parsed
1190 .as_mapping()
1191 .map(|m| m
1192 .keys()
1193 .filter_map(|k| k.as_str().map(str::to_string))
1194 .collect::<Vec<_>>())
1195 .unwrap_or_default()
1196 );
1197 assert!(
1198 parsed.get(DEFAULT_LIBRARY_NAME).is_none(),
1199 "values wrap key must not retain the default `{DEFAULT_LIBRARY_NAME}` literal \
1200 when opts.library_name overrides it"
1201 );
1202 let cu_block = parsed.get("acme-computeunit").unwrap();
1203 assert_eq!(
1204 cu_block.get(HELM_VALUES_KEY_ENABLED),
1205 Some(&serde_yaml::Value::Bool(false))
1206 );
1207 assert!(cu_block.get(COMPUTEUNIT_SPEC_KEY_MODULE).is_some());
1208 assert!(cu_block.get(COMPUTEUNIT_SPEC_KEY_TRIGGER).is_some());
1209 assert!(cu_block.get(COMPUTEUNIT_SPEC_KEY_CAPABILITIES).is_some());
1210 }
1211
1212 #[test]
1213 fn values_yaml_wrap_key_matches_chart_dependency_name() {
1214 // The structural invariant the lift defends: every rendered
1215 // chart's values.yaml wrap key equals its Chart.yaml
1216 // `dependencies[0].name`. Sweeping the canonical default + a
1217 // typed override on the same axis pins the alignment across the
1218 // accepted set of `RenderOpts::library_name` values rather than
1219 // at a single canonical literal.
1220 for library_name in [DEFAULT_LIBRARY_NAME, "acme-computeunit", "fork-pleme-cu"] {
1221 let opts = RenderOpts {
1222 library_name: library_name.into(),
1223 ..RenderOpts::default()
1224 };
1225 let dir =
1226 render_chart_for_servico_with(&sample_caixa(), &sample_cu_yaml(), &opts).unwrap();
1227 let chart_file = dir
1228 .files
1229 .iter()
1230 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1231 .unwrap();
1232 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
1233 let dep_name = &chart.dependencies[0].name;
1234 let values = dir
1235 .files
1236 .iter()
1237 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1238 .unwrap();
1239 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1240 assert!(
1241 parsed.get(dep_name.as_str()).is_some(),
1242 "values.yaml wrap key must match Chart.yaml dependencies[0].name {dep_name:?} \
1243 (library_name = {library_name:?}); Helm's per-dep alias convention scopes \
1244 values under the dep's `name` when no `alias:` is set, so any drift between \
1245 the two axes silently routes the values block nowhere"
1246 );
1247 }
1248 }
1249
1250 #[test]
1251 fn values_yaml_header_comment_follows_library_name_override() {
1252 // The human-facing values.yaml header's `<library_alias>:` /
1253 // `pleme-io/helmworks/charts/<library_alias>` references both
1254 // resolve through `opts.library_name`, peer with the wrap key
1255 // itself, so an override leaves the header self-consistent
1256 // with the rendered structure rather than naming a drifted
1257 // default literal.
1258 let opts = RenderOpts {
1259 library_name: "acme-computeunit".into(),
1260 ..RenderOpts::default()
1261 };
1262 let dir = render_chart_for_servico_with(&sample_caixa(), &sample_cu_yaml(), &opts).unwrap();
1263 let values = dir
1264 .files
1265 .iter()
1266 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1267 .unwrap();
1268 assert!(
1269 values.contents.contains("`acme-computeunit:`"),
1270 "header must name the overriding library alias verbatim \
1271 (got: {contents:?})",
1272 contents = values.contents
1273 );
1274 assert!(
1275 values
1276 .contents
1277 .contains("pleme-io/helmworks/charts/acme-computeunit"),
1278 "header's helmworks path must follow the overriding library alias \
1279 (got: {contents:?})",
1280 contents = values.contents
1281 );
1282 assert!(
1283 !values.contents.contains("`pleme-computeunit:`"),
1284 "header must not retain the default library alias literal \
1285 when overridden (got: {contents:?})",
1286 contents = values.contents
1287 );
1288 }
1289
1290 #[test]
1291 fn refuses_non_servico() {
1292 let mut c = sample_caixa();
1293 c.kind = CaixaKind::Biblioteca;
1294 c.servicos = vec![];
1295 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1296 assert!(matches!(err, Error::NotAServico(_)));
1297 }
1298
1299 #[test]
1300 fn kind_mismatch_error_names_offending_caixa_nome() {
1301 // Pinning the lifted [`caixa_core::KindMismatch`] view's
1302 // load-bearing property: a kind-mismatched caixa surfaces a
1303 // diagnostic that *names the offending caixa* (`hello-rio`),
1304 // not just the rejected kind. Before the lift the renderer
1305 // raised `Error::NotAServico(CaixaKind::Biblioteca)` whose
1306 // Display said "caixa :kind must be Servico for caixa-helm
1307 // rendering, got Biblioteca" — the user had to grep their
1308 // source tree for which caixa.lisp triggered it. After the
1309 // lift the wrapped KindMismatch carries the `:nome`, the
1310 // renderer's `#[error("{0}")]` arm prints it through, and
1311 // the diagnostic is self-locating.
1312 let mut c = sample_caixa();
1313 c.kind = CaixaKind::Biblioteca;
1314 c.servicos = vec![];
1315 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1316 let msg = format!("{err}");
1317 assert!(
1318 msg.contains("hello-rio"),
1319 "kind-mismatch diagnostic must name the offending caixa nome \
1320 (got: {msg:?})"
1321 );
1322 assert!(
1323 msg.contains("Servico"),
1324 "diagnostic must name the expected kind (got: {msg:?})"
1325 );
1326 assert!(
1327 msg.contains("Biblioteca"),
1328 "diagnostic must name the actual kind (got: {msg:?})"
1329 );
1330 }
1331
1332 #[test]
1333 fn kind_mismatch_carries_typed_view_via_from_conversion() {
1334 // The renderer's `Error::NotAServico` variant wraps the typed
1335 // [`caixa_core::KindMismatch`] view via `#[from]`, so the `?`
1336 // operator at the call site converts without manual glue.
1337 // Pinning the typed payload (not just the variant) so a
1338 // future refactor can't silently switch the variant to a
1339 // raw-`CaixaKind` payload (which would regress the lift's
1340 // shared-shape contract with caixa-flux + caixa-mesh).
1341 let mut c = sample_caixa();
1342 c.kind = CaixaKind::Aplicacao;
1343 c.servicos = vec![];
1344 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1345 match err {
1346 Error::NotAServico(km) => {
1347 assert_eq!(km.nome, "hello-rio");
1348 assert_eq!(km.expected, CaixaKind::Servico);
1349 assert_eq!(km.actual, CaixaKind::Aplicacao);
1350 }
1351 other => panic!("expected Error::NotAServico, got {other:?}"),
1352 }
1353 }
1354
1355 #[test]
1356 fn servico_count_mismatch_carries_typed_view_with_nome() {
1357 // Peer to the [`KindMismatch`]-lift pin above on the V0
1358 // `:servicos`-singularity axis: a Servico-kind caixa whose
1359 // `:servicos` list is non-singleton fails
1360 // [`render_chart_for_servico`] with the renderer's
1361 // `Error::UnsupportedServicoCount` variant wrapping the typed
1362 // [`caixa_core::ServicoCountMismatch`] view (carrying the
1363 // offending caixa's `:nome` + the actual count). Before the
1364 // lift the variant carried only `usize` — the user had to grep
1365 // their source tree for which `caixa.lisp` triggered it; after
1366 // the lift the wrapped typed view names the offending caixa
1367 // verbatim. Pins both the variant routing (via `#[from]`) and
1368 // the typed payload so a future refactor can't silently switch
1369 // back to the raw-`usize` payload (which would regress the
1370 // shared-shape contract with caixa-flux on the peer
1371 // programs.yaml-entry path).
1372 let mut c = sample_caixa();
1373 c.servicos = vec![
1374 "servicos/hello-rio.computeunit.yaml".into(),
1375 "servicos/extra.computeunit.yaml".into(),
1376 ];
1377 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1378 match err {
1379 Error::UnsupportedServicoCount(scm) => {
1380 assert_eq!(scm.nome, "hello-rio");
1381 assert_eq!(scm.count, 2);
1382 }
1383 other => panic!("expected Error::UnsupportedServicoCount, got {other:?}"),
1384 }
1385 }
1386
1387 #[test]
1388 fn servico_count_mismatch_diagnostic_names_offending_caixa_nome() {
1389 // The renderer's `#[error("{0}")] UnsupportedServicoCount(
1390 // #[from] ServicoCountMismatch)` arm prints the typed view's
1391 // Display through verbatim, so the offending caixa's `:nome`
1392 // appears in the rendered diagnostic. Pinning the
1393 // self-locating property end-to-end (renderer entry-point →
1394 // typed view's Display → final diagnostic string) so a future
1395 // refactor that re-wraps the variant in a Display impl that
1396 // drops the `:nome` surfaces here as a test failure rather
1397 // than as silent fragmentation of the diagnostic. Peer to the
1398 // `kind_mismatch_error_names_offending_caixa_nome` test above
1399 // on the sibling V0 Servico-shape axis.
1400 let mut c = sample_caixa();
1401 c.servicos = vec![
1402 "servicos/hello-rio.computeunit.yaml".into(),
1403 "servicos/extra.computeunit.yaml".into(),
1404 ];
1405 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1406 let msg = format!("{err}");
1407 assert!(
1408 msg.contains("hello-rio"),
1409 ":servicos-count-mismatch diagnostic must name the offending caixa nome \
1410 (got: {msg:?})"
1411 );
1412 assert!(
1413 msg.contains("2"),
1414 "diagnostic must name the actual count (got: {msg:?})"
1415 );
1416 assert!(
1417 msg.contains(":servicos"),
1418 "diagnostic must name the offending field axis (got: {msg:?})"
1419 );
1420 }
1421
1422 #[test]
1423 fn limits_slot_propagates_into_values_block() {
1424 use caixa_core::LimitsSpec;
1425 use std::time::Duration;
1426 let mut c = sample_caixa();
1427 c.limits = Some(LimitsSpec {
1428 memory: Some(64 * 1024 * 1024),
1429 fuel: Some(1_000_000),
1430 wall_clock: Some(Duration::from_secs(30)),
1431 cpu: Some(500),
1432 });
1433 let dir = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap();
1434 let values = dir
1435 .files
1436 .iter()
1437 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1438 .unwrap();
1439 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1440 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1441 let limits = cu_block.get(M2_KEY_LIMITS).expect("limits must propagate");
1442 assert_eq!(kube_str(limits, M2_LIMITS_KEY_MEMORY), Some("64MiB"));
1443 assert_eq!(
1444 limits.get(M2_LIMITS_KEY_FUEL).and_then(|m| m.as_u64()),
1445 Some(1_000_000)
1446 );
1447 assert_eq!(kube_str(limits, M2_LIMITS_KEY_WALL_CLOCK), Some("30s"));
1448 assert_eq!(kube_str(limits, M2_LIMITS_KEY_CPU), Some("500m"));
1449 }
1450
1451 #[test]
1452 fn behavior_slot_propagates_into_values_block() {
1453 use caixa_core::BehaviorSpec;
1454 let mut c = sample_caixa();
1455 c.behavior = Some(BehaviorSpec {
1456 on_init: Some(PathBuf::from("lib/init.lisp")),
1457 on_call: Some(PathBuf::from("lib/handlers.lisp")),
1458 ..Default::default()
1459 });
1460 let dir = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap();
1461 let values = dir
1462 .files
1463 .iter()
1464 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1465 .unwrap();
1466 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1467 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1468 let behavior = cu_block
1469 .get(M2_KEY_BEHAVIOR)
1470 .expect("behavior must propagate");
1471 assert_eq!(
1472 behavior
1473 .get(M2_BEHAVIOR_KEY_ON_INIT)
1474 .and_then(|v| v.as_str()),
1475 Some("lib/init.lisp")
1476 );
1477 assert_eq!(
1478 behavior
1479 .get(M2_BEHAVIOR_KEY_ON_CALL)
1480 .and_then(|v| v.as_str()),
1481 Some("lib/handlers.lisp")
1482 );
1483 }
1484
1485 #[test]
1486 fn upgrade_from_slot_propagates_into_values_block() {
1487 use caixa_core::{UpgradeFromEntry, UpgradeInstruction};
1488 let mut c = sample_caixa();
1489 c.upgrade_from = vec![UpgradeFromEntry {
1490 from: "0.0.9".into(),
1491 instructions: vec![UpgradeInstruction::LoadModule {
1492 module: "hello-rio".into(),
1493 }],
1494 }];
1495 let dir = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap();
1496 let values = dir
1497 .files
1498 .iter()
1499 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1500 .unwrap();
1501 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1502 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1503 assert!(cu_block.get(M2_KEY_UPGRADE_FROM).is_some());
1504 }
1505
1506 #[test]
1507 fn empty_m2_slots_do_not_appear() {
1508 // Existing caixa with no M2 slots → values.yaml carries no
1509 // limits/behavior/upgradeFrom keys (forward-compat invariant).
1510 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1511 let values = dir
1512 .files
1513 .iter()
1514 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
1515 .unwrap();
1516 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
1517 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1518 assert!(cu_block.get(M2_KEY_LIMITS).is_none());
1519 assert!(cu_block.get(M2_KEY_BEHAVIOR).is_none());
1520 assert!(cu_block.get(M2_KEY_UPGRADE_FROM).is_none());
1521 }
1522
1523 #[test]
1524 fn write_to_creates_files() {
1525 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1526 let tmp = tempfile::tempdir().unwrap();
1527 dir.write_to(tmp.path()).unwrap();
1528 let chart_root = tmp.path().join("lareira-hello-rio");
1529 assert!(chart_root.join(HELM_CHART_YAML_FILENAME).exists());
1530 assert!(chart_root.join(HELM_VALUES_YAML_FILENAME).exists());
1531 assert!(chart_root.join(HELM_CHART_README_FILENAME).exists());
1532 }
1533
1534 #[test]
1535 fn default_library_name_re_export_points_at_caixa_core_canonical() {
1536 // The renderer's `pub const DEFAULT_LIBRARY_NAME` was lifted to a
1537 // re-export of [`caixa_core::DEFAULT_LIBRARY_NAME`] so the Helm
1538 // library-chart name lives in exactly one place across every
1539 // caixa renderer (caixa-helm's `RenderOpts::library_name`
1540 // default here + caixa-flux's `cluster_bundle` `helmrelease.yaml`
1541 // wrap key on the sibling deploy-path crate). Pin the equality
1542 // here so any local re-introduction of a sibling `pub const
1543 // DEFAULT_LIBRARY_NAME: &str = "…"` (the canonical drift footgun
1544 // the prior `DEFAULT_NAMESPACE` / `DEFAULT_SERVICO_PORT` lift
1545 // commits' bodies acknowledged as the recurring shape) is a
1546 // build-time test failure naming the offending drift, not a
1547 // silent apply-time wrap-key mismatch routing the per-cluster
1548 // `enabled: true` override nowhere on `helm template` /
1549 // `helm install`. Peer to
1550 // `caixa_flux::tests::default_library_name_re_export_points_at_caixa_core_canonical`
1551 // on the sibling renderer crate.
1552 caixa_core::assert_str_reexport_identity(
1553 "DEFAULT_LIBRARY_NAME",
1554 DEFAULT_LIBRARY_NAME,
1555 caixa_core::DEFAULT_LIBRARY_NAME,
1556 );
1557 }
1558
1559 #[test]
1560 fn kube_key_spec_re_export_points_at_caixa_core_canonical() {
1561 // The renderer's `KUBE_KEY_SPEC` was lifted from the production-
1562 // code inline `"spec"` literal at `build_values_yaml`'s
1563 // `computeunit_yaml.get("spec")` ComputeUnit-side spec read (+
1564 // its matching `Error::MissingField("spec")` diagnostic) to a
1565 // re-export of [`caixa_core::KUBE_KEY_SPEC`] so the canonical
1566 // K8s-CR top-level spec-axis string lives in exactly one place
1567 // across every caixa renderer. Pin the equality + static-data
1568 // identity here so any local re-introduction of a sibling
1569 // `pub const KUBE_KEY_SPEC: &str = "…"` (the canonical drift
1570 // footgun where a sibling local `pub const` could happen to
1571 // carry the same string at the source while pointing at a
1572 // different `&'static` allocation) is a build-time test
1573 // failure naming the offending drift. Peer to
1574 // [`default_library_name_re_export_points_at_caixa_core_canonical`]
1575 // on the sibling re-export axis +
1576 // `caixa_flux::tests::kube_key_spec_re_export_points_at_caixa_core_canonical`
1577 // / `caixa_mesh::tests::kube_key_spec_re_export_points_at_caixa_core_canonical`
1578 // on the sibling renderer crates.
1579 caixa_core::assert_str_reexport_identity(
1580 "KUBE_KEY_SPEC",
1581 KUBE_KEY_SPEC,
1582 caixa_core::KUBE_KEY_SPEC,
1583 );
1584 }
1585
1586 #[test]
1587 fn helm_chart_api_version_re_export_points_at_caixa_core_canonical() {
1588 // The renderer's `HELM_CHART_API_VERSION` was lifted from the
1589 // production-code inline `"v2".into()` literal at
1590 // [`build_chart_yaml`]'s `api_version` field assignment (formerly
1591 // `caixa-helm/src/lib.rs:298`) to a re-export of
1592 // [`caixa_core::HELM_CHART_API_VERSION`] so the Helm 3
1593 // chart-schema apiVersion the rendered Chart.yaml declares lives
1594 // in exactly one place across every caixa renderer. Pin the
1595 // equality + `&'static` static-data identity here so any local
1596 // re-introduction of a sibling `pub const HELM_CHART_API_VERSION:
1597 // &str = "…"` at this crate — the canonical drift footgun where
1598 // a sibling local `pub const` could happen to carry the same
1599 // string at the source while pointing at a different `&'static`
1600 // allocation — is a build-time test failure naming the offending
1601 // drift, not a silent chart-schema-parser reroute at
1602 // `helm template` time far from the drift site. Peer to
1603 // [`kube_key_spec_re_export_points_at_caixa_core_canonical`] /
1604 // [`default_library_name_re_export_points_at_caixa_core_canonical`]
1605 // on the sibling re-export axes.
1606 caixa_core::assert_str_reexport_identity(
1607 "HELM_CHART_API_VERSION",
1608 HELM_CHART_API_VERSION,
1609 caixa_core::HELM_CHART_API_VERSION,
1610 );
1611 }
1612
1613 #[test]
1614 fn chart_yaml_uses_lifted_helm_chart_api_version() {
1615 // Fail-before-pass-after pin on the production-code
1616 // substitution: [`build_chart_yaml`]'s `api_version` field
1617 // consults the lifted [`HELM_CHART_API_VERSION`] re-export at
1618 // its assignment site, so the rendered Chart.yaml's top-level
1619 // `apiVersion` axis is byte-identical to the canonical constant
1620 // by construction. Before the lift the field carried an inline
1621 // `"v2".into()` literal at [`build_chart_yaml`]; a future
1622 // refactor that accidentally reverted the substitution — or
1623 // any parallel per-renderer variant that inlined a stale
1624 // Helm 2 `"v1"` literal — would silently reroute the rendered
1625 // Chart.yaml through the wrong chart-schema parser at
1626 // `helm dependency build` / `helm template` time, so this pin
1627 // trips at caixa-helm build time. Peer to
1628 // `values_yaml_wrap_key_matches_chart_dependency_name` on the
1629 // sibling structural-cross-axis-invariant surface.
1630 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1631 let chart_file = dir
1632 .files
1633 .iter()
1634 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1635 .unwrap();
1636 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
1637 assert_eq!(
1638 chart.api_version, HELM_CHART_API_VERSION,
1639 "rendered Chart.yaml `apiVersion` must equal the lifted \
1640 HELM_CHART_API_VERSION verbatim — a drifted value silently \
1641 reroutes the rendered chart through the wrong Helm chart-schema \
1642 parser at `helm template` time"
1643 );
1644 }
1645
1646 #[test]
1647 fn helm_chart_type_application_re_export_points_at_caixa_core_canonical() {
1648 // The renderer's `HELM_CHART_TYPE_APPLICATION` was lifted from
1649 // the production-code inline `"application".into()` literal at
1650 // [`build_chart_yaml`]'s `chart_type` field assignment (formerly
1651 // `caixa-helm/src/lib.rs:354`) to a re-export of
1652 // [`caixa_core::HELM_CHART_TYPE_APPLICATION`] so the Helm 3
1653 // chart-schema per-chart-kind discriminator scalar-value the
1654 // rendered `lareira-<nome>` chart declares lives in exactly one
1655 // place across every caixa renderer. Pin the equality +
1656 // `&'static` static-data identity here so any local
1657 // re-introduction of a sibling `pub const
1658 // HELM_CHART_TYPE_APPLICATION: &str = "…"` at this crate — the
1659 // canonical drift footgun where a sibling local `pub const`
1660 // could happen to carry the same string at the source while
1661 // pointing at a different `&'static` allocation — is a
1662 // build-time test failure naming the offending drift, not a
1663 // silent per-release install-shape dispatch reroute at
1664 // `helm install` time far from the drift site. Peer to
1665 // [`helm_chart_api_version_re_export_points_at_caixa_core_canonical`]
1666 // on the sibling canonical-Helm-chart-schema-axis re-export
1667 // surface — completes the per-Chart.yaml `(apiVersion, type)`
1668 // canonical-scalar-axis re-export pair every rendered
1669 // `lareira-<nome>` chart declares at its top-level Chart.yaml
1670 // body.
1671 caixa_core::assert_str_reexport_identity(
1672 "HELM_CHART_TYPE_APPLICATION",
1673 HELM_CHART_TYPE_APPLICATION,
1674 caixa_core::HELM_CHART_TYPE_APPLICATION,
1675 );
1676 }
1677
1678 #[test]
1679 fn helm_chart_type_library_re_export_points_at_caixa_core_canonical() {
1680 // Re-export identity pin on the peer closed-set arm the
1681 // renderer's `HELM_CHART_TYPE_LIBRARY` alias resolves to. Peer
1682 // of `helm_chart_type_application_re_export_points_at_caixa_core_canonical`
1683 // on the sibling closed-set arm — the two pins together enshrine
1684 // the two-arm `{"application", "library"}` closed set at the
1685 // caixa-helm re-export surface as byte-identical `&'static`
1686 // static-data views onto the canonical caixa-core lifts, so any
1687 // local re-introduction of a sibling `pub const
1688 // HELM_CHART_TYPE_LIBRARY: &str = "…"` at this crate (the same
1689 // drift footgun the peer pin closes on the sibling arm) is a
1690 // build-time test failure naming the offending drift. The pin
1691 // also structurally forbids the two arms from converging on the
1692 // same `&'static` allocation — a future rebrand that
1693 // accidentally aliased `HELM_CHART_TYPE_LIBRARY` at the
1694 // [`caixa_core::HELM_CHART_TYPE_APPLICATION`] canonical would
1695 // pass this identity check but trip the caixa-core-side
1696 // `helm_chart_type_application_and_library_are_distinct` pin
1697 // paired to the two arms' distinctness contract.
1698 caixa_core::assert_str_reexport_identity(
1699 "HELM_CHART_TYPE_LIBRARY",
1700 HELM_CHART_TYPE_LIBRARY,
1701 caixa_core::HELM_CHART_TYPE_LIBRARY,
1702 );
1703 }
1704
1705 #[test]
1706 fn chart_yaml_uses_lifted_helm_chart_type_application() {
1707 // Fail-before-pass-after pin on the production-code substitution:
1708 // [`build_chart_yaml`]'s `chart_type` field consults the lifted
1709 // [`HELM_CHART_TYPE_APPLICATION`] re-export at its assignment
1710 // site, so the rendered Chart.yaml's top-level `type` axis is
1711 // byte-identical to the canonical constant by construction.
1712 // Before the lift the field carried an inline `"application".into()`
1713 // literal at [`build_chart_yaml`]; a future refactor that
1714 // accidentally reverted the substitution — or any parallel
1715 // per-renderer variant that inlined a `"library"` literal (the
1716 // sibling closed-set value from the Helm chart-schema's
1717 // per-chart-kind enum) — would silently reroute the rendered
1718 // Chart.yaml through the wrong per-release install-shape
1719 // dispatch at `helm install` time (Helm refuses to install a
1720 // `library` chart directly), so this pin trips at caixa-helm
1721 // build time. Peer to `chart_yaml_uses_lifted_helm_chart_api_version`
1722 // on the sibling per-Chart.yaml top-level `(apiVersion, type)`
1723 // canonical-scalar-axis pin pair — extends the per-Chart.yaml
1724 // top-level canonical-scalar-axis production-emit-pin
1725 // discipline from the `apiVersion` half onto the sibling `type`
1726 // half.
1727 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1728 let chart_file = dir
1729 .files
1730 .iter()
1731 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1732 .unwrap();
1733 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
1734 assert_eq!(
1735 chart.chart_type, HELM_CHART_TYPE_APPLICATION,
1736 "rendered Chart.yaml `type` must equal the lifted \
1737 HELM_CHART_TYPE_APPLICATION verbatim — a drifted value \
1738 silently reroutes the rendered chart through the wrong \
1739 per-release install-shape dispatch at `helm install` time \
1740 (Helm refuses to install a `library` chart directly, or \
1741 silently treats an unrecognized value as the default \
1742 `application` shape masking the schema violation)"
1743 );
1744 }
1745
1746 #[test]
1747 fn helm_chart_key_type_re_export_points_at_caixa_core_canonical() {
1748 // The renderer's `HELM_CHART_KEY_TYPE` was lifted from the
1749 // sole production-side inline `"type"` literal at [`ChartYaml`]'s
1750 // `chart_type` field `#[serde(rename = "type")]` attribute
1751 // (formerly `caixa-helm/src/lib.rs:149`) to a re-export of
1752 // [`caixa_core::HELM_CHART_KEY_TYPE`] so the Helm 3 top-level
1753 // per-chart-kind discriminator YAML axis-key lives in exactly
1754 // one place across every caixa renderer. Pin the equality +
1755 // `&'static` static-data identity here so any local
1756 // re-introduction of a sibling `pub const HELM_CHART_KEY_TYPE:
1757 // &str = "…"` at this crate — the canonical drift footgun
1758 // where a sibling local `pub const` could happen to carry the
1759 // same string at the source while pointing at a different
1760 // `&'static` allocation — is a build-time test failure naming
1761 // the offending drift, not a silent Helm-chart-schema-parser
1762 // per-chart-kind-defaulting reroute at `helm dependency build`
1763 // / `helm lint` / `helm template` / `helm install` time far
1764 // from the drift site. Peer to
1765 // [`helm_chart_type_application_re_export_points_at_caixa_core_canonical`]
1766 // / [`helm_chart_type_library_re_export_points_at_caixa_core_canonical`]
1767 // on the sibling per-chart-kind axis-value re-export surface —
1768 // completes the per-Chart.yaml per-chart-kind discriminator
1769 // axis's `(key, value-set)` canonical re-export trio at the
1770 // caixa-helm surface.
1771 caixa_core::assert_str_reexport_identity(
1772 "HELM_CHART_KEY_TYPE",
1773 HELM_CHART_KEY_TYPE,
1774 caixa_core::HELM_CHART_KEY_TYPE,
1775 );
1776 }
1777
1778 #[test]
1779 fn helm_chart_key_app_version_re_export_points_at_caixa_core_canonical() {
1780 // The renderer's `HELM_CHART_KEY_APP_VERSION` was lifted from
1781 // the sole production-side inline `"appVersion"` literal at
1782 // [`ChartYaml`]'s `app_version` field
1783 // `#[serde(rename = "appVersion")]` attribute (formerly
1784 // `caixa-helm/src/lib.rs:152`) to a re-export of
1785 // [`caixa_core::HELM_CHART_KEY_APP_VERSION`] so the Helm 3
1786 // top-level per-chart-app-version YAML axis-key lives in
1787 // exactly one place across every caixa renderer. Pin the
1788 // equality + `&'static` static-data identity here so any
1789 // local re-introduction of a sibling `pub const
1790 // HELM_CHART_KEY_APP_VERSION: &str = "…"` at this crate — the
1791 // canonical drift footgun where a sibling local `pub const`
1792 // could happen to carry the same string at the source while
1793 // pointing at a different `&'static` allocation — is a
1794 // build-time test failure naming the offending drift, not a
1795 // silent Helm-chart-schema-parser field-drop at every
1796 // downstream Artifact Hub / `helm search` chart-consumer far
1797 // from the drift site. Peer to
1798 // [`helm_chart_key_type_re_export_points_at_caixa_core_canonical`]
1799 // on the sibling per-Chart.yaml top-level YAML axis-key
1800 // re-export surface — completes the per-Chart.yaml top-level
1801 // YAML axis-key re-export pair at the caixa-helm surface for
1802 // the two serde-rename-literal-only axes.
1803 caixa_core::assert_str_reexport_identity(
1804 "HELM_CHART_KEY_APP_VERSION",
1805 HELM_CHART_KEY_APP_VERSION,
1806 caixa_core::HELM_CHART_KEY_APP_VERSION,
1807 );
1808 }
1809
1810 #[test]
1811 fn chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type() {
1812 // Fail-before-pass-after drift-detection pin on the
1813 // `#[serde(rename = "type")]` attribute at [`ChartYaml`]'s
1814 // `chart_type` field. Rust's attribute grammar admits only
1815 // string literals so the lifted [`HELM_CHART_KEY_TYPE`]
1816 // constant cannot substitute for the literal syntactically at
1817 // the attribute-argument site — a future refactor that
1818 // dropped the `#[serde(rename = "type")]` attribute (or
1819 // changed the target key to `"Type"` / `"kind"` /
1820 // `"chartType"`) would silently serialize the field under
1821 // Rust's default snake_case `chart_type:` key, which Helm's
1822 // chart-schema parser silently ignores as an unknown top-
1823 // level key, defaulting the per-chart-kind axis to
1824 // `application` with no process-log signal. This pin closes
1825 // the drift by round-tripping a rendered `Chart.yaml` through
1826 // `serde_yaml::from_str::<serde_yaml::Value>` and asserting
1827 // the top-level `Mapping::get(HELM_CHART_KEY_TYPE)` resolves
1828 // (rather than serializing through the [`ChartYaml`]-typed
1829 // deserializer that would silently absorb the rename drift
1830 // via `#[serde(default)]` fall-through at the struct-side).
1831 // Peer to
1832 // [`chart_yaml_uses_lifted_helm_chart_type_application`] on
1833 // the sibling per-Chart.yaml per-chart-kind axis-value
1834 // production-emit pin — the two pins together enforce the
1835 // full `(key, value)` production-emit pair at the caixa-helm
1836 // surface for the per-Chart.yaml per-chart-kind discriminator
1837 // axis.
1838 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1839 let chart_file = dir
1840 .files
1841 .iter()
1842 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1843 .unwrap();
1844 let doc: serde_yaml::Value = serde_yaml::from_str(&chart_file.contents).unwrap();
1845 let mapping = doc.as_mapping().expect(
1846 "rendered Chart.yaml must be a top-level YAML mapping per \
1847 the Helm 3 chart-schema shape",
1848 );
1849 assert!(
1850 mapping.contains_key(serde_yaml::Value::String(HELM_CHART_KEY_TYPE.to_string())),
1851 "rendered Chart.yaml must carry a top-level {HELM_CHART_KEY_TYPE:?} \
1852 axis-key — a drift on the `#[serde(rename = {HELM_CHART_KEY_TYPE:?})]` \
1853 attribute at ChartYaml's `chart_type` field silently reroutes the \
1854 per-chart-kind discriminator axis through Rust's default snake_case \
1855 serialization (`chart_type:`), which Helm's chart-schema parser \
1856 silently ignores as an unknown top-level key (defaulting the \
1857 per-chart-kind axis to `application` with no process-log signal)"
1858 );
1859 }
1860
1861 #[test]
1862 fn chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version() {
1863 // Fail-before-pass-after drift-detection pin on the
1864 // `#[serde(rename = "appVersion")]` attribute at [`ChartYaml`]'s
1865 // `app_version` field. Same attribute-literal-only-grammar
1866 // constraint the peer
1867 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1868 // pin closes on the sibling per-Chart.yaml top-level YAML
1869 // axis-key applies here: a future refactor that dropped the
1870 // `#[serde(rename = "appVersion")]` attribute (or changed the
1871 // target key to `"AppVersion"` / `"applicationVersion"` /
1872 // `"appversion"`) would silently serialize the field under
1873 // Rust's default snake_case `app_version:` key, which Helm's
1874 // chart-schema parser silently drops from the parsed
1875 // chart-metadata shape, and every downstream Artifact Hub /
1876 // `helm search` per-chart index falls back to "no application
1877 // version" for the rendered chart. This pin closes the drift
1878 // by round-tripping a rendered `Chart.yaml` through
1879 // `serde_yaml::from_str::<serde_yaml::Value>` (rather than
1880 // through the [`ChartYaml`]-typed deserializer that would
1881 // silently absorb the rename drift). Peer to
1882 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1883 // on the sibling per-Chart.yaml top-level YAML axis-key
1884 // serialization pin surface — completes the per-Chart.yaml
1885 // top-level YAML axis-key production-emit pin pair at the
1886 // caixa-helm surface for the two serde-rename-literal-only
1887 // axes.
1888 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1889 let chart_file = dir
1890 .files
1891 .iter()
1892 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1893 .unwrap();
1894 let doc: serde_yaml::Value = serde_yaml::from_str(&chart_file.contents).unwrap();
1895 let mapping = doc.as_mapping().expect(
1896 "rendered Chart.yaml must be a top-level YAML mapping per \
1897 the Helm 3 chart-schema shape",
1898 );
1899 assert!(
1900 mapping.contains_key(serde_yaml::Value::String(
1901 HELM_CHART_KEY_APP_VERSION.to_string()
1902 )),
1903 "rendered Chart.yaml must carry a top-level \
1904 {HELM_CHART_KEY_APP_VERSION:?} axis-key — a drift on the \
1905 `#[serde(rename = {HELM_CHART_KEY_APP_VERSION:?})]` attribute at \
1906 ChartYaml's `app_version` field silently reroutes the per-chart \
1907 underlying-application-version axis through Rust's default \
1908 snake_case serialization (`app_version:`), which Helm's \
1909 chart-schema parser silently drops from the parsed chart-metadata \
1910 shape (every downstream Artifact Hub / `helm search` per-chart \
1911 index falls back to \"no application version\" for the rendered \
1912 chart with no process-log signal at the substrate-side emitter site)"
1913 );
1914 }
1915
1916 #[test]
1917 fn chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version() {
1918 // Fail-before-pass-after drift-detection pin on the
1919 // `#[serde(rename = "apiVersion")]` attribute at [`ChartYaml`]'s
1920 // `api_version` field. Same attribute-literal-only-grammar
1921 // constraint the peer
1922 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1923 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
1924 // pins close on the sibling per-Chart.yaml top-level YAML
1925 // axis-keys applies here: a future refactor that dropped the
1926 // `#[serde(rename = "apiVersion")]` attribute (or changed the
1927 // target key to `"ApiVersion"` / `"apiversion"` /
1928 // `"schemaVersion"`) would silently serialize the field under
1929 // Rust's default snake_case `api_version:` key, which Helm's
1930 // chart-schema parser rejects at `helm lint` / `helm
1931 // dependency build` / `helm template` time with an "apiVersion
1932 // is required" error far from the drift site — every downstream
1933 // `lareira-<nome>` chart consumer drops with no field naming
1934 // the serde-rename-drift root cause. This pin closes the drift
1935 // by round-tripping a rendered `Chart.yaml` through
1936 // `serde_yaml::from_str::<serde_yaml::Value>` (rather than
1937 // through the [`ChartYaml`]-typed deserializer that would
1938 // silently absorb the rename drift via `#[serde(default)]`
1939 // fall-through at the struct-side). Peer to
1940 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1941 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
1942 // on the sibling per-Chart.yaml top-level YAML axis-key
1943 // serialization pin surface — completes the per-Chart.yaml
1944 // top-level YAML axis-key production-emit pin trio at the
1945 // caixa-helm surface for the three serde-rename-literal-only
1946 // axes.
1947 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1948 let chart_file = dir
1949 .files
1950 .iter()
1951 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
1952 .unwrap();
1953 let doc: serde_yaml::Value = serde_yaml::from_str(&chart_file.contents).unwrap();
1954 let mapping = doc.as_mapping().expect(
1955 "rendered Chart.yaml must be a top-level YAML mapping per \
1956 the Helm 3 chart-schema shape",
1957 );
1958 assert!(
1959 mapping.contains_key(serde_yaml::Value::String(
1960 HELM_CHART_KEY_API_VERSION.to_string()
1961 )),
1962 "rendered Chart.yaml must carry a top-level \
1963 {HELM_CHART_KEY_API_VERSION:?} axis-key — a drift on the \
1964 `#[serde(rename = {HELM_CHART_KEY_API_VERSION:?})]` attribute at \
1965 ChartYaml's `api_version` field silently reroutes the per-chart \
1966 chart-schema-apiVersion axis through Rust's default snake_case \
1967 serialization (`api_version:`), which Helm's chart-schema parser \
1968 rejects at `helm lint` / `helm template` time with an \"apiVersion \
1969 is required\" error far from the drift site"
1970 );
1971 }
1972
1973 #[test]
1974 fn chart_dependency_serializes_tetrad_under_lifted_helm_chart_dependency_keys() {
1975 // Fail-before-pass-after drift-detection pin on the per-
1976 // `dependencies[]`-entry sub-mapping serde field-name tetrad
1977 // at [`ChartDependency`]. The four fields are identity-mapped
1978 // to their target wire keys today (no `#[serde(rename)]` or
1979 // `#[serde(rename_all)]` attribute on the struct), so a drift
1980 // would surface as one of two shapes: a rename of the Rust
1981 // field (`pub name` → `pub nome`) that silently rebrands the
1982 // wire key, or a `#[serde(rename_all = "camelCase")]` attribute
1983 // addition that stays a no-op on the four lowercase-identity
1984 // fields today but silently activates on a future field
1985 // addition (e.g. an `import_values: Option<Vec<String>>` axis
1986 // matching Helm 3's per-dep `import-values` sub-key). Either
1987 // shape silently reroutes the per-dep sub-mapping through a
1988 // Helm-per-dep-resolver drop at `helm dependency build` time
1989 // far from the drift site (Helm silently drops the drifted
1990 // per-dep sub-mapping field and the per-dep resolver falls
1991 // back to the parsed-shape defaults). This pin closes the
1992 // drift by serializing a fully-populated [`ChartDependency`]
1993 // (`alias` set to a non-`None` value so the
1994 // `#[serde(skip_serializing_if = "Option::is_none")]`
1995 // attribute doesn't elide the axis from the emitted YAML)
1996 // through `serde_yaml::to_value` and asserting each of the
1997 // four per-dep sub-mapping wire keys resolves via
1998 // `Mapping::get(HELM_CHART_DEPENDENCY_KEY_*)`. Peer to
1999 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
2000 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
2001 // / [`chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version`]
2002 // on the sibling per-Chart.yaml top-level serde-rename-literal-
2003 // only axis-key drift-detection pin trio (cc44e4b / d29bc23) —
2004 // extends the drift-detection discipline from the per-Chart.yaml
2005 // top-level serde-rename-literal axes onto the per-
2006 // `dependencies[]`-entry sub-mapping serde-field-name tetrad.
2007 let dep = ChartDependency {
2008 name: "pleme-computeunit".into(),
2009 version: "~0.1.0".into(),
2010 repository: "file://../pleme-computeunit".into(),
2011 alias: Some("acme-alias".into()),
2012 };
2013 let doc = serde_yaml::to_value(&dep).unwrap();
2014 let mapping = doc.as_mapping().expect(
2015 "ChartDependency must serialize to a top-level YAML mapping per \
2016 the Helm 3 per-dep sub-mapping shape",
2017 );
2018 for key in [
2019 HELM_CHART_DEPENDENCY_KEY_NAME,
2020 HELM_CHART_DEPENDENCY_KEY_VERSION,
2021 HELM_CHART_DEPENDENCY_KEY_REPOSITORY,
2022 HELM_CHART_DEPENDENCY_KEY_ALIAS,
2023 ] {
2024 assert!(
2025 mapping.contains_key(serde_yaml::Value::String(key.to_string())),
2026 "serialized ChartDependency must carry a top-level {key:?} \
2027 axis-key — a drift on the `ChartDependency` struct's serde \
2028 field-name (a Rust-side rename, an added \
2029 `#[serde(rename_all)]` attribute, an added `#[serde(rename)]` \
2030 per-field override) silently reroutes the per-dep sub-mapping \
2031 through a Helm-per-dep-resolver drop at `helm dependency \
2032 build` time far from the drift site (Helm silently drops the \
2033 drifted per-dep sub-mapping field and the per-dep resolver \
2034 falls back to the parsed-shape defaults); the emitted mapping \
2035 keys are {keys:?}",
2036 keys = mapping
2037 .keys()
2038 .filter_map(|k| k.as_str().map(str::to_string))
2039 .collect::<Vec<_>>()
2040 );
2041 }
2042 }
2043
2044 #[test]
2045 fn chart_yaml_serializes_dependencies_axis_under_lifted_helm_chart_key_dependencies() {
2046 // Fail-before-pass-after drift-detection pin on the top-level
2047 // per-chart dependency-list YAML axis-key at [`ChartYaml`]'s
2048 // `dependencies` field. The Rust field name and the emitted
2049 // wire key coincide by default today (no `#[serde(rename)]`
2050 // attribute on the field, no `#[serde(rename_all = "…")]`
2051 // attribute on the struct — so serde emits `dependencies:`
2052 // verbatim as the top-level list-container YAML key). A future
2053 // hostile refactor could silently rebrand the wire key in
2054 // three shapes:
2055 //
2056 // - a rename of the Rust field itself (`pub dependencies:
2057 // Vec<ChartDependency>` → `pub deps: Vec<ChartDependency>`
2058 // / `pub chart_dependencies: …`), which serde would then
2059 // serialize as `deps:` / `chart_dependencies:` verbatim;
2060 // - an added `#[serde(rename_all = "camelCase")]` /
2061 // `"snake_case"` / `"kebab-case"` attribute on the struct
2062 // itself — a no-op on the four identity-mapped top-level
2063 // lowercase keys (`name` / `description` / `version` /
2064 // `dependencies`) today but silently activates on a future
2065 // multi-word field addition (e.g. an `icon_url` axis
2066 // matching Helm 3's per-chart `icon:` future-schema slot);
2067 // - an added `#[serde(rename = "deps")]` per-field override
2068 // at the site of the `dependencies` field.
2069 //
2070 // Under any of the three shapes Helm's chart-schema parser
2071 // silently drops the entire per-chart dep list from the
2072 // parsed chart-metadata (unknown top-level YAML keys silently
2073 // ignored per the Helm 3 chart-schema fallthrough), `helm
2074 // dependency build` finds no chart to vendor, and every
2075 // rendered `lareira-<nome>` chart's install fails with
2076 // `template: no template ... associated with template ...`
2077 // far from the drift site with no field naming the top-level-
2078 // list-key-drift root cause. This pin closes the drift by
2079 // round-tripping a rendered `Chart.yaml` through
2080 // `serde_yaml::from_str::<serde_yaml::Value>` and asserting
2081 // the top-level `Mapping::get(HELM_CHART_KEY_DEPENDENCIES)`
2082 // resolves — rather than through the [`ChartYaml`]-typed
2083 // deserializer that would silently absorb any of the three
2084 // drift shapes via `#[serde(default)]` fall-through at the
2085 // struct-side. Peer to
2086 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
2087 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
2088 // / [`chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version`]
2089 // on the sibling per-Chart.yaml top-level YAML axis-key
2090 // serialization pin surface (d29bc23, cc44e4b) — extends the
2091 // per-Chart.yaml top-level YAML axis-key production-emit pin
2092 // trio those closed onto the fourth top-level axis-key, the
2093 // parent list-container the already-lifted per-
2094 // `dependencies[]`-entry sub-mapping tetrad
2095 // [`HELM_CHART_DEPENDENCY_KEY_NAME`] /
2096 // [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
2097 // [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
2098 // [`HELM_CHART_DEPENDENCY_KEY_ALIAS`] mounts one level down.
2099 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
2100 let chart_file = dir
2101 .files
2102 .iter()
2103 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
2104 .unwrap();
2105 let doc: serde_yaml::Value = serde_yaml::from_str(&chart_file.contents).unwrap();
2106 let mapping = doc.as_mapping().expect(
2107 "rendered Chart.yaml must be a top-level YAML mapping per \
2108 the Helm 3 chart-schema shape",
2109 );
2110 assert!(
2111 mapping.contains_key(serde_yaml::Value::String(
2112 HELM_CHART_KEY_DEPENDENCIES.to_string()
2113 )),
2114 "rendered Chart.yaml must carry a top-level \
2115 {HELM_CHART_KEY_DEPENDENCIES:?} axis-key — a drift on the \
2116 `ChartYaml.dependencies` field's serde field-name (a Rust-side \
2117 rename to `deps` / `chart_dependencies`, an added \
2118 `#[serde(rename_all)]` attribute on the enclosing struct, an \
2119 added `#[serde(rename)]` per-field override) silently reroutes \
2120 the per-chart dependency-list axis through an unrecognized \
2121 top-level YAML key (`deps:` / `chartDependencies:` / \
2122 `chart_dependencies:`), which Helm's chart-schema parser \
2123 silently drops from the parsed chart-metadata shape (every \
2124 rendered `lareira-<nome>` chart's install fails with \
2125 `template: no template ... associated with template ...` at \
2126 `helm dependency build` / `helm template` time far from the \
2127 drift site with no field naming the top-level-list-key-drift \
2128 root cause); the emitted top-level mapping keys are {keys:?}",
2129 keys = mapping
2130 .keys()
2131 .filter_map(|k| k.as_str().map(str::to_string))
2132 .collect::<Vec<_>>()
2133 );
2134 }
2135
2136 #[test]
2137 fn helm_chart_key_dependencies_re_export_points_at_caixa_core_canonical() {
2138 // The renderer's [`HELM_CHART_KEY_DEPENDENCIES`] was lifted onto
2139 // a re-export of [`caixa_core::HELM_CHART_KEY_DEPENDENCIES`] so
2140 // the Helm 3 per-Chart.yaml top-level dependency-list-container
2141 // YAML axis-key — the parent whose per-`dependencies[]`-entry
2142 // sub-mapping tetrad [`HELM_CHART_DEPENDENCY_KEY_NAME`] /
2143 // [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
2144 // [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
2145 // [`HELM_CHART_DEPENDENCY_KEY_ALIAS`] mounts one level down —
2146 // lives in exactly one place across every caixa renderer. Pin
2147 // the equality + `&'static` static-data identity here so any
2148 // local re-introduction of a sibling `pub const
2149 // HELM_CHART_KEY_DEPENDENCIES: &str = "…"` at this crate — the
2150 // canonical drift footgun where a sibling local `pub const`
2151 // could happen to carry the same string at the source while
2152 // pointing at a different `&'static` allocation — is a build-
2153 // time test failure naming the offending drift, not a silent
2154 // per-Chart.yaml top-level-list-key reroute at `helm dependency
2155 // build` / `helm lint` / `helm template` time far from the
2156 // drift site. Peer to
2157 // [`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`]
2158 // and every other `helm_chart_*_re_export_points_at_caixa_core_canonical`
2159 // pin on the sibling canonical-Helm-chart-schema-body-axis
2160 // re-export surface — extends the per-Chart.yaml top-level
2161 // YAML axis-key re-export identity discipline onto the fourth
2162 // top-level axis-key at the caixa-helm surface.
2163 caixa_core::assert_str_reexport_identity(
2164 "HELM_CHART_KEY_DEPENDENCIES",
2165 HELM_CHART_KEY_DEPENDENCIES,
2166 caixa_core::HELM_CHART_KEY_DEPENDENCIES,
2167 );
2168 }
2169
2170 #[test]
2171 fn render_opts_default_library_name_follows_lifted_constant() {
2172 // [`RenderOpts::default()`] sets `library_name` from
2173 // [`DEFAULT_LIBRARY_NAME`]; pin that the lift preserves the
2174 // default-knob value bit-for-bit. A future refactor that
2175 // detaches `RenderOpts::default()` from the lifted constant —
2176 // accidentally re-introducing an inline `"pleme-computeunit"`
2177 // literal in the impl — would silently break the shared-shape
2178 // contract with caixa-flux (which uses the same constant
2179 // directly for its `helmrelease.yaml` wrap key); this test
2180 // surfaces the regression at build time rather than at
2181 // apply time as a silent values-routing no-op.
2182 let opts = RenderOpts::default();
2183 assert_eq!(opts.library_name, caixa_core::DEFAULT_LIBRARY_NAME);
2184 assert_eq!(opts.library_name, "pleme-computeunit");
2185 }
2186
2187 #[test]
2188 fn helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical() {
2189 // The renderer's `HELM_CHART_YAML_FILENAME` was lifted from the
2190 // seven production + test-side inline `"Chart.yaml"` /
2191 // `PathBuf::from("Chart.yaml")` / `chart_root.join("Chart.yaml")`
2192 // literals across [`render_chart_for_servico`]'s `ChartDir`
2193 // metadata-file `path` emit site + every test-side round-trip
2194 // navigator that reaches into the rendered `ChartDir` by the
2195 // metadata filename to a re-export of
2196 // [`caixa_core::HELM_CHART_YAML_FILENAME`] so the Helm 3
2197 // per-chart-directory metadata-file filename lives in exactly one
2198 // place across every caixa renderer. Pin the equality +
2199 // `&'static` static-data identity here so any local
2200 // re-introduction of a sibling `pub const
2201 // HELM_CHART_YAML_FILENAME: &str = "…"` at this crate — the
2202 // canonical drift footgun where a sibling local `pub const` could
2203 // happen to carry the same string at the source while pointing
2204 // at a different `&'static` allocation — is a build-time test
2205 // failure naming the offending drift, not a silent
2206 // Helm-chart-schema-parser "Chart.yaml file is missing" reroute
2207 // at `helm dependency build` / `helm lint` / `helm template` /
2208 // `helm install` time far from the drift site. Peer to
2209 // [`helm_chart_api_version_re_export_points_at_caixa_core_canonical`]
2210 // / [`helm_chart_type_application_re_export_points_at_caixa_core_canonical`]
2211 // on the sibling canonical-Helm-chart-schema-body-axis re-export
2212 // surfaces — completes the per-`lareira-<nome>`-chart-directory
2213 // `(filename, apiVersion, type)` canonical-scalar-axis re-export
2214 // triple every rendered chart declares at its top-level metadata
2215 // file.
2216 caixa_core::assert_str_reexport_identity(
2217 "HELM_CHART_YAML_FILENAME",
2218 HELM_CHART_YAML_FILENAME,
2219 caixa_core::HELM_CHART_YAML_FILENAME,
2220 );
2221 }
2222
2223 #[test]
2224 fn helm_values_yaml_filename_re_export_points_at_caixa_core_canonical() {
2225 // The renderer's `HELM_VALUES_YAML_FILENAME` was lifted from the
2226 // twelve production + test-side inline `"values.yaml"` /
2227 // `PathBuf::from("values.yaml")` / `chart_root.join("values.yaml")`
2228 // literals across [`render_chart_for_servico`]'s `ChartDir`
2229 // values-file `path` emit site + every test-side round-trip
2230 // navigator that reaches into the rendered `ChartDir` by the
2231 // values filename to a re-export of
2232 // [`caixa_core::HELM_VALUES_YAML_FILENAME`] so the Helm 3
2233 // per-chart-directory values-file filename lives in exactly one
2234 // place across every caixa renderer. Pin the equality +
2235 // `&'static` static-data identity here so any local
2236 // re-introduction of a sibling `pub const
2237 // HELM_VALUES_YAML_FILENAME: &str = "…"` at this crate — the
2238 // canonical drift footgun where a sibling local `pub const` could
2239 // happen to carry the same string at the source while pointing
2240 // at a different `&'static` allocation — is a build-time test
2241 // failure naming the offending drift, not a silent
2242 // Helm-per-chart-values-loader fall-through to the empty values
2243 // block at `helm template` / `helm install` time far from the
2244 // drift site (where the workload silently comes up under the
2245 // library chart's admission-time defaults with no per-Servico
2246 // M2 overlay applied). Peer to
2247 // [`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`]
2248 // on the sibling canonical-Helm-per-chart-directory-metadata-file-
2249 // axis re-export surface — completes the
2250 // per-`lareira-<nome>`-chart-directory `(Chart.yaml, values.yaml)`
2251 // canonical-per-chart-directory-filename-axis re-export pair
2252 // every rendered chart declares as its two schema-load-bearing
2253 // `ChartDir::files` entries.
2254 caixa_core::assert_str_reexport_identity(
2255 "HELM_VALUES_YAML_FILENAME",
2256 HELM_VALUES_YAML_FILENAME,
2257 caixa_core::HELM_VALUES_YAML_FILENAME,
2258 );
2259 }
2260
2261 #[test]
2262 fn helm_chart_readme_filename_re_export_points_at_caixa_core_canonical() {
2263 // The renderer's `HELM_CHART_README_FILENAME` was lifted from the
2264 // three production + test-side inline `"README.md"` literals
2265 // across [`render_chart_for_servico`]'s `ChartDir` readme-file
2266 // `path` emit site + every test-side round-trip navigator that
2267 // reaches into the rendered `ChartDir` by the readme filename
2268 // (the [`renders_three_files`] files-vec-membership pin + the
2269 // [`ChartDir::write_to`] post-write existence pin) to a
2270 // re-export of [`caixa_core::HELM_CHART_README_FILENAME`] so the
2271 // per-`lareira-<nome>` chart-directory human-facing readme
2272 // filename lives in exactly one place across every caixa
2273 // renderer. Pin the equality + `&'static` static-data identity
2274 // here so any local re-introduction of a sibling `pub const
2275 // HELM_CHART_README_FILENAME: &str = "…"` at this crate — the
2276 // canonical drift footgun where a sibling local `pub const`
2277 // could happen to carry the same string at the source while
2278 // pointing at a different `&'static` allocation — is a build-
2279 // time test failure naming the offending drift, not a silent
2280 // GitHub / Artifact Hub / any per-chart README-surfacing UI
2281 // fall-through to "no README available" at chart-consumption
2282 // time far from the drift site. Peer to
2283 // [`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`]
2284 // / [`helm_values_yaml_filename_re_export_points_at_caixa_core_canonical`]
2285 // on the sibling canonical-Helm-per-chart-directory-filename
2286 // axis re-export surfaces — completes the
2287 // per-`lareira-<nome>`-chart-directory `(Chart.yaml,
2288 // values.yaml, README.md)` canonical-per-chart-directory-
2289 // filename-axis re-export triple every rendered chart declares
2290 // as its three `ChartDir::files` entries.
2291 caixa_core::assert_str_reexport_identity(
2292 "HELM_CHART_README_FILENAME",
2293 HELM_CHART_README_FILENAME,
2294 caixa_core::HELM_CHART_README_FILENAME,
2295 );
2296 }
2297
2298 #[test]
2299 fn helm_values_key_enabled_re_export_points_at_caixa_core_canonical() {
2300 // The renderer's `HELM_VALUES_KEY_ENABLED` was lifted from the
2301 // production-code inline `"enabled".to_string()` literal at
2302 // [`build_values_yaml`]'s
2303 // `block.insert("enabled".to_string(), Value::Bool(…))` values-
2304 // block-toggle insert (formerly `caixa-helm/src/lib.rs:389`) plus
2305 // its two test-side round-trip navigators
2306 // (`values_yaml_wraps_under_pleme_computeunit_key`,
2307 // `values_yaml_wrap_key_follows_library_name_override`) to a
2308 // re-export of [`caixa_core::HELM_VALUES_KEY_ENABLED`] so the
2309 // canonical `pleme-computeunit` library-chart values-block
2310 // enable-toggle key lives in exactly one place across every
2311 // caixa renderer. Pin the equality + `&'static` static-data
2312 // identity here so any local re-introduction of a sibling
2313 // `pub const HELM_VALUES_KEY_ENABLED: &str = "…"` at this crate
2314 // — the canonical drift footgun where a sibling local
2315 // `pub const` could happen to carry the same string at the
2316 // source while pointing at a different `&'static` allocation —
2317 // is a build-time test failure naming the offending drift, not
2318 // a silent per-values enable-toggle reroute at `helm template` /
2319 // `helm install` time far from the drift site (where the
2320 // workload silently comes up with the library chart's
2321 // admission-time defaults instead of the per-cluster override
2322 // the operator set). Peer to
2323 // [`helm_chart_api_version_re_export_points_at_caixa_core_canonical`]
2324 // / [`kube_key_spec_re_export_points_at_caixa_core_canonical`] /
2325 // [`default_library_name_re_export_points_at_caixa_core_canonical`]
2326 // on the sibling re-export axes +
2327 // `caixa_flux::tests::helm_values_key_enabled_re_export_points_at_caixa_core_canonical`
2328 // on the peer bundle-path renderer crate.
2329 caixa_core::assert_str_reexport_identity(
2330 "HELM_VALUES_KEY_ENABLED",
2331 HELM_VALUES_KEY_ENABLED,
2332 caixa_core::HELM_VALUES_KEY_ENABLED,
2333 );
2334 }
2335
2336 #[test]
2337 fn values_yaml_enable_toggle_key_pins_lifted_helm_values_key_enabled() {
2338 // Fail-before-pass-after pin on the production-code substitution:
2339 // [`build_values_yaml`]'s `block.insert(…, Value::Bool(…))`
2340 // consults the lifted [`HELM_VALUES_KEY_ENABLED`] re-export at
2341 // its insert site, so the rendered `values.yaml`'s per-values
2342 // enable-toggle axis is byte-identical to the canonical constant
2343 // by construction. Before the lift the field carried an inline
2344 // `"enabled".to_string()` literal; a future refactor that
2345 // accidentally reverted the substitution — or any parallel per-
2346 // renderer variant that inlined a stale `"enable"` /
2347 // `"disabled"` literal — would silently emit a values block
2348 // whose per-values enable-toggle lands under one key while
2349 // [`caixa_flux::cluster_bundle`]'s `HelmRelease`
2350 // `spec.values.<library>.enabled` per-cluster override lands
2351 // under another, so this pin trips at caixa-helm build time.
2352 // Peer to `chart_yaml_uses_lifted_helm_chart_api_version` on the
2353 // sibling structural-cross-axis-invariant surface — both close
2354 // the drift between a rendered-value navigator's `.get(…)` /
2355 // struct-field read on the constant and the production-code
2356 // emit site that consumes the same constant.
2357 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
2358 let values = dir
2359 .files
2360 .iter()
2361 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
2362 .unwrap();
2363 let parsed: serde_yaml::Value = serde_yaml::from_str(&values.contents).unwrap();
2364 let cu_block = parsed
2365 .get(DEFAULT_LIBRARY_NAME)
2366 .expect("must wrap under DEFAULT_LIBRARY_NAME");
2367 assert_eq!(
2368 cu_block.get(HELM_VALUES_KEY_ENABLED),
2369 Some(&serde_yaml::Value::Bool(false)),
2370 "rendered values.yaml `{DEFAULT_LIBRARY_NAME}.{HELM_VALUES_KEY_ENABLED}` must \
2371 equal the default-off toggle the lifted HELM_VALUES_KEY_ENABLED axis carries — \
2372 a drifted enable-toggle key silently splits the per-values enable-flip across \
2373 two sibling scalar names on the caixa-helm / caixa-flux consumer split"
2374 );
2375 }
2376
2377 #[test]
2378 fn computeunit_spec_key_module_re_export_points_at_caixa_core_canonical() {
2379 // The renderer's `COMPUTEUNIT_SPEC_KEY_MODULE` was lifted from
2380 // the two inline `"module"` test-side call sites in this crate
2381 // (`values_yaml_wraps_under_pleme_computeunit_key`'s per-values
2382 // module-block present-check + the peer navigator on the
2383 // `library_name`-override wrap-key axis
2384 // `values_yaml_wrap_key_follows_library_name_override`) — every
2385 // per-Servico ComputeUnit CRD `spec.module` sub-block readback
2386 // in this crate now navigates through the same `&'static str`
2387 // re-exported to a re-export of
2388 // [`caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE`] so the canonical
2389 // ComputeUnit-CRD per-`spec.*` wasm-module-reference axis lives
2390 // in exactly one place across every caixa renderer. Pin the
2391 // equality + static-data identity here so any local re-
2392 // introduction of a sibling `pub const COMPUTEUNIT_SPEC_KEY_MODULE:
2393 // &str = "…"` at this crate is a build-time test failure naming
2394 // the offending drift, not a silent per-Servico wasm-runtime-
2395 // binding drop at cluster-apply time. Peer to
2396 // [`helm_values_key_enabled_re_export_points_at_caixa_core_canonical`]
2397 // /
2398 // [`kube_key_spec_re_export_points_at_caixa_core_canonical`]
2399 // on the sibling canonical-Helm-load-bearing-string /
2400 // canonical-K8s-CR-body-key re-export axes +
2401 // `caixa_flux::tests::computeunit_spec_key_module_re_export_points_at_caixa_core_canonical`
2402 // on the peer per-Servico renderer crate.
2403 caixa_core::assert_str_reexport_identity(
2404 "COMPUTEUNIT_SPEC_KEY_MODULE",
2405 COMPUTEUNIT_SPEC_KEY_MODULE,
2406 caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE,
2407 );
2408 }
2409
2410 #[test]
2411 fn computeunit_spec_key_trigger_re_export_points_at_caixa_core_canonical() {
2412 // Peer to
2413 // [`computeunit_spec_key_module_re_export_points_at_caixa_core_canonical`]
2414 // on the same ComputeUnit-CRD per-`spec.*` sub-block re-export
2415 // surface — pins the per-Servico invocation-shape sub-block
2416 // key's identity on the same trajectory.
2417 caixa_core::assert_str_reexport_identity(
2418 "COMPUTEUNIT_SPEC_KEY_TRIGGER",
2419 COMPUTEUNIT_SPEC_KEY_TRIGGER,
2420 caixa_core::COMPUTEUNIT_SPEC_KEY_TRIGGER,
2421 );
2422 }
2423
2424 #[test]
2425 fn computeunit_spec_key_capabilities_re_export_points_at_caixa_core_canonical() {
2426 // Peer to
2427 // [`computeunit_spec_key_module_re_export_points_at_caixa_core_canonical`]
2428 // and
2429 // [`computeunit_spec_key_trigger_re_export_points_at_caixa_core_canonical`]
2430 // on the same ComputeUnit-CRD per-`spec.*` sub-block re-export
2431 // surface — completes the substrate-side ComputeUnit-CRD
2432 // per-`spec.*` sub-block re-export triple in this crate on the
2433 // WASI-capability-token-list axis.
2434 caixa_core::assert_str_reexport_identity(
2435 "COMPUTEUNIT_SPEC_KEY_CAPABILITIES",
2436 COMPUTEUNIT_SPEC_KEY_CAPABILITIES,
2437 caixa_core::COMPUTEUNIT_SPEC_KEY_CAPABILITIES,
2438 );
2439 }
2440
2441 #[test]
2442 fn chart_file_alias_resolves_to_caixa_core_rendered_file() {
2443 // Type-alias identity pin: the [`ChartFile`] alias at this
2444 // crate's boundary resolves to the canonical
2445 // [`caixa_core::RenderedFile`] the substrate-side "one rendered
2446 // leaf artifact" shape lives at. `let _: ChartFile = <a
2447 // RenderedFile>` type-checks *iff* [`ChartFile`] is the aliased
2448 // canonical (not a sibling pub-struct re-declaration that
2449 // happens to carry the same field pair — that would compile
2450 // past the struct-literal navigators below but fail this
2451 // assignment). A drifted local `pub struct ChartFile { pub
2452 // path: PathBuf, pub contents: String }` at this crate — the
2453 // canonical drift footgun that would carry the same field pair
2454 // at the source while pointing at a different struct
2455 // definition — trips this pin at caixa-helm build time rather
2456 // than surfacing as a downstream `caixa_core::RenderedFile`
2457 // consumer refusing a `ChartFile`-shaped value at type-check
2458 // time far from the drift commit. Peer to the sibling
2459 // [`caixa_flux::BundleFile`]-alias-identity pin on the same
2460 // per-target-renderer canonical [`caixa_core::RenderedFile`]
2461 // re-export surface — both crates' per-artifact leaf type now
2462 // resolves through the same canonical struct definition, so a
2463 // future rebrand on the record shape lands at one caixa-core
2464 // edit and reaches both consumers by construction.
2465 let canonical: caixa_core::RenderedFile = caixa_core::RenderedFile {
2466 path: PathBuf::from(HELM_CHART_YAML_FILENAME),
2467 contents: String::new(),
2468 };
2469 let aliased: ChartFile = canonical.clone();
2470 assert_eq!(aliased, canonical);
2471 // Struct-literal construction still resolves through the alias
2472 // — the pre-lift `ChartFile { path, contents }` shape at every
2473 // production emit site (three sites in
2474 // `render_chart_for_servico_with`'s `ChartDir::files` assembly)
2475 // continues to compile, and the derive tuple travels through
2476 // the alias so downstream `ChartDir::files.iter().find(|f|
2477 // f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))`
2478 // navigators keep matching by `PartialEq` on `PathBuf`.
2479 let via_alias = ChartFile {
2480 path: PathBuf::from(HELM_VALUES_YAML_FILENAME),
2481 contents: format!("{DEFAULT_LIBRARY_NAME}:\n enabled: false\n"),
2482 };
2483 assert_eq!(via_alias.path.to_string_lossy(), HELM_VALUES_YAML_FILENAME);
2484 }
2485
2486 #[test]
2487 fn chart_file_new_constructor_travels_through_alias_to_canonical() {
2488 // Inherent-method-through-alias pin: the canonical
2489 // [`caixa_core::RenderedFile::new`] `impl Into<PathBuf>` /
2490 // `impl Into<String>` constructor every per-artifact leaf in
2491 // [`render_chart_for_servico_with`] now routes through
2492 // resolves at `ChartFile::new(…)` — Rust inherent methods
2493 // travel through a `pub type ChartFile = caixa_core::RenderedFile`
2494 // alias to the aliased canonical at name resolution, so a
2495 // drifted local `pub struct ChartFile { pub path: PathBuf, pub
2496 // contents: String }` at this crate would carry the field
2497 // pair the sibling type-alias-identity pin above still
2498 // accepts (both records share `pub path` / `pub contents`
2499 // shape) while dropping the constructor — the six sweep sites
2500 // in [`render_chart_for_servico_with`] would stop compiling
2501 // and the failing calls would name `ChartFile` directly,
2502 // making the drift-source unambiguous. This test pins the
2503 // constructor's per-alias reachability + the byte-identical
2504 // record shape against a `HELM_CHART_YAML_FILENAME`-keyed
2505 // probe so the pin fires at caixa-helm build time.
2506 let via_alias_new: ChartFile = ChartFile::new(HELM_CHART_YAML_FILENAME, "apiVersion: v2\n");
2507 let via_canonical_new = caixa_core::RenderedFile::new(
2508 HELM_CHART_YAML_FILENAME,
2509 String::from("apiVersion: v2\n"),
2510 );
2511 assert_eq!(via_alias_new, via_canonical_new);
2512 assert_eq!(via_alias_new.path, PathBuf::from(HELM_CHART_YAML_FILENAME));
2513 assert_eq!(via_alias_new.contents, "apiVersion: v2\n");
2514 }
2515
2516 #[test]
2517 fn render_opts_default_library_version_follows_lifted_constant() {
2518 // Peer of [`render_opts_default_library_name_follows_lifted_constant`]
2519 // (which pins the same alignment on the sibling
2520 // [`RenderOpts::library_name`] / [`DEFAULT_LIBRARY_NAME`] axis). The
2521 // [`RenderOpts::default()`] impl sets `library_version` from
2522 // [`DEFAULT_LIBRARY_VERSION`]; a future refactor that detached the
2523 // default-knob from the lifted constant — accidentally re-inlining
2524 // `"~0.1.0"` in the impl body — would silently split the value the
2525 // default knob threads into every rendered `Chart.yaml`
2526 // `dependencies[0].version` axis from the const the const's callers
2527 // (and this crate's future per-`DEFAULT_LIBRARY_VERSION` drift pins)
2528 // read. The two `Chart.yaml`-dep `(name, version)` scalar-axes now
2529 // share the same "default-knob follows lifted constant, byte for
2530 // byte" pin discipline the peer library-name axis carries.
2531 let opts = RenderOpts::default();
2532 assert_eq!(opts.library_version, DEFAULT_LIBRARY_VERSION);
2533 assert_eq!(opts.library_version, "~0.1.0");
2534 }
2535
2536 #[test]
2537 fn render_opts_default_enabled_default_follows_lifted_constant() {
2538 // Peer of [`render_opts_default_library_name_follows_lifted_constant`]
2539 // /
2540 // [`render_opts_default_library_version_follows_lifted_constant`]
2541 // / [`render_opts_default_library_repo_follows_lifted_constant`] —
2542 // the fourth leg of the [`RenderOpts::default()`]-body
2543 // default-knob-follows-lifted-constant quartet. The
2544 // [`RenderOpts::default()`] impl seeds `enabled_default` from
2545 // [`STANDALONE_LAREIRA_ENABLED_DEFAULT`]; every rendered
2546 // `lareira-<nome>` chart's `values.yaml` under-`<library>.enabled`
2547 // scalar reads through this knob, so a future refactor that
2548 // detached the default-knob from the lifted constant —
2549 // accidentally re-inlining `false` in the impl body — would
2550 // silently split the `bool` the default seed writes from the
2551 // const the drift-detection pin
2552 // [`standalone_lareira_enabled_default_pins_canonical_value`]
2553 // (in caixa-core) reads. The rendered values block would then
2554 // carry one `bool` at the emit site while the const-consuming
2555 // sibling test-fixture navigators (this crate's future per-
2556 // `STANDALONE_LAREIRA_ENABLED_DEFAULT` drift pins) read another,
2557 // and the substrate's chosen mirror-symmetric standalone /
2558 // composition per-values-block child-chart-enablement-toggle-
2559 // scalar-value default pair would silently disagree on the
2560 // standalone-path half. Peer with the sibling
2561 // `caixa_flux::tests::cluster_bundle_lareira_enabled_default_re_export_matches_caixa_core_canonical_value`
2562 // pin on the composition-path half of the same
2563 // [`HELM_VALUES_KEY_ENABLED`] scalar-axis pair.
2564 let opts = RenderOpts::default();
2565 assert_eq!(opts.enabled_default, STANDALONE_LAREIRA_ENABLED_DEFAULT);
2566 assert!(!opts.enabled_default);
2567 }
2568
2569 #[test]
2570 fn standalone_lareira_enabled_default_re_export_matches_caixa_core_canonical_value() {
2571 // The renderer's `STANDALONE_LAREIRA_ENABLED_DEFAULT` was lifted
2572 // from the [`RenderOpts::default()`] impl-body inline `false`
2573 // scalar-value literal at `caixa-helm/src/lib.rs:700` to a
2574 // re-export of [`caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT`]
2575 // so the substrate-side default the standalone per-chart path
2576 // seeds under the sibling [`HELM_VALUES_KEY_ENABLED`]
2577 // leaf-scalar-key lives in exactly one place across every caixa
2578 // renderer (this crate's standalone per-chart path + the peer
2579 // `caixa_flux::cluster_bundle`'s composition per-cluster-
2580 // `HelmRelease` values-overlay path, which reads through the
2581 // inverse [`caixa_flux::CLUSTER_BUNDLE_LAREIRA_ENABLED_DEFAULT`]
2582 // re-export). Pin the equality here so any local re-introduction
2583 // of a sibling `pub const STANDALONE_LAREIRA_ENABLED_DEFAULT:
2584 // bool = …` at this crate (the canonical drift footgun the peer
2585 // `CLUSTER_BUNDLE_LAREIRA_ENABLED_DEFAULT` re-export identity
2586 // pin's rationale names as the recurring shape) is a build-time
2587 // test failure naming the offending drift, not a silent
2588 // apply-time toggle-mismatch routing the standalone per-chart
2589 // `values.<library>.enabled` seed onto one substrate-side
2590 // opt-out convention while the peer composition-path override
2591 // routes onto another. Peer to the sibling
2592 // `caixa_flux::tests::cluster_bundle_lareira_enabled_default_re_export_matches_caixa_core_canonical_value`
2593 // on the composition-path half of the same
2594 // [`HELM_VALUES_KEY_ENABLED`] scalar-axis pair — the two
2595 // per-path re-export identity pins together lock the two peer
2596 // scalar-value defaults' per-crate re-exports onto their shared
2597 // caixa-core canonical.
2598 assert_eq!(
2599 STANDALONE_LAREIRA_ENABLED_DEFAULT,
2600 caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT,
2601 "STANDALONE_LAREIRA_ENABLED_DEFAULT re-export must remain the \
2602 same `bool` as its caixa-core canonical — a drifted local \
2603 `pub const STANDALONE_LAREIRA_ENABLED_DEFAULT: bool = …` at \
2604 caixa-helm would silently split the substrate's chosen \
2605 standalone per-chart opt-out seed from the peer \
2606 composition-path force-on inversion the caixa-core canonical \
2607 encodes."
2608 );
2609 assert!(
2610 !STANDALONE_LAREIRA_ENABLED_DEFAULT,
2611 "STANDALONE_LAREIRA_ENABLED_DEFAULT must remain `false` — the \
2612 standalone per-chart path is the substrate-side opt-out path \
2613 where cluster operators must opt each caixa in per-cluster, \
2614 inverse of the composition per-cluster-HelmRelease values-\
2615 overlay path's opt-in force-on."
2616 );
2617 }
2618
2619 #[test]
2620 fn render_opts_default_library_repo_follows_lifted_constant() {
2621 // Peer of [`render_opts_default_library_name_follows_lifted_constant`]
2622 // /
2623 // [`render_opts_default_library_version_follows_lifted_constant`] —
2624 // the third leg of the per-`Chart.yaml`-dep
2625 // `(repository, name, version)` default-knob triple. The
2626 // [`RenderOpts::default()`] impl seeds `library_repo` from
2627 // [`DEFAULT_LIBRARY_REPO`]; every rendered `lareira-<nome>` chart's
2628 // `Chart.yaml` `dependencies[0].repository` field reads through
2629 // this knob, so a future refactor that detached the default-knob
2630 // from the lifted constant — re-inlining
2631 // `"file://../pleme-computeunit"` in the impl body — would silently
2632 // split the URL the default seed writes from the const the
2633 // drift-detection pin below
2634 // ([`default_library_repo_ends_with_lifted_default_library_name`])
2635 // reads.
2636 let opts = RenderOpts::default();
2637 assert_eq!(opts.library_repo, DEFAULT_LIBRARY_REPO);
2638 assert_eq!(opts.library_repo, "file://../pleme-computeunit");
2639 }
2640
2641 #[test]
2642 fn default_library_version_parses_as_valid_semver_requirement() {
2643 // Structural pin: [`DEFAULT_LIBRARY_VERSION`] carries a Cargo-shaped
2644 // semver-requirement string that lands verbatim in every rendered
2645 // `lareira-<nome>` chart's `Chart.yaml` `dependencies[0].version`
2646 // field. Helm 3's chart-schema parser (`helm dependency build`,
2647 // `helm lint`, `helm template`, `helm install`) validates the
2648 // scalar against the same `semver::VersionReq` grammar
2649 // [`caixa_core::parse_requirement`] wraps, and rejects a malformed
2650 // shape (`"~0.1.,0"` — paste-from-typography stray comma;
2651 // `"v0.1.0"` — accidental Zig-style publish-tag prefix leaking back
2652 // from [`caixa_core::DEFAULT_PUBLISH_TAG_PREFIX`] into the
2653 // requirement axis; `"0.1"` with a trailing sigil dropped by a
2654 // fat-fingered edit) with the load-bearing `Error: found operator
2655 // …, expected version` diagnostic surfacing at chart-consumption
2656 // time — far from the constant-drift commit's source, with no
2657 // field naming the offending caixa or the drifted default. Routing
2658 // through [`caixa_core::parse_requirement`] here — the same
2659 // requirement-parser entry-point every peer typed `:versao`
2660 // requirement slot (`:deps`, `:deps-dev`, `:membros`, `:children`)
2661 // routes through via
2662 // [`caixa_core::require_valid_versao_requirement`] — closes the
2663 // drift structurally at caixa-helm build time and pins the const's
2664 // accepted set to exactly the set the peer author-facing
2665 // requirement axes accept: any shape a caixa author cannot write
2666 // in `:deps :versao` is a shape the substrate cannot seed as the
2667 // library-chart-dep default. Peer of the sibling
2668 // [`default_library_repo_ends_with_lifted_default_library_name`]
2669 // structural pin on the co-resident `(name, version)` per-Chart.yaml
2670 // dep-scalar pair.
2671 caixa_core::parse_requirement(DEFAULT_LIBRARY_VERSION).unwrap_or_else(|e| {
2672 panic!(
2673 "DEFAULT_LIBRARY_VERSION {DEFAULT_LIBRARY_VERSION:?} must parse as a valid \
2674 semver::VersionReq — every rendered lareira-<nome> chart's Chart.yaml \
2675 dependencies[0].version axis lands this scalar verbatim, and Helm 3's \
2676 chart-schema parser rejects a malformed shape at chart-consumption time \
2677 far from the constant-drift commit's source: {e}",
2678 )
2679 });
2680 }
2681
2682 #[test]
2683 fn default_library_repo_ends_with_lifted_default_library_name() {
2684 // Structural cross-const coherence pin: [`DEFAULT_LIBRARY_REPO`]
2685 // embeds the [`DEFAULT_LIBRARY_NAME`] byte-string verbatim as its
2686 // trailing directory-name component (the canonical
2687 // `file://../<library-chart-name>` shape every sibling
2688 // `lareira-<nome>` chart's `Chart.yaml` `dependencies[0]` entry
2689 // consults for a two-axis `(name, repository)` per-dep tuple that
2690 // Helm's per-chart-dep resolver `(chart-source-scheme + chart-name)`
2691 // navigator round-trips). The two axes must stay coupled: the
2692 // library-chart-directory on disk (the repo's trailing component)
2693 // and the library-chart's declared `name:` in its own
2694 // [`DEFAULT_LIBRARY_NAME`]-published `Chart.yaml` are the same
2695 // load-bearing chart-name identity. Prior to this pin the two
2696 // consts were independently authored — a future substrate-side
2697 // library-chart rebrand (`pleme-computeunit` → `pleme-cu` on a
2698 // shorter-form migration, `pleme-computeunit` →
2699 // `caixa-computeunit` on a substrate-alignment migration, a
2700 // per-edition library-chart fork the [`DEFAULT_LIBRARY_NAME`]
2701 // docstring names as a trajectory item) on the
2702 // [`caixa_core::DEFAULT_LIBRARY_NAME`] canonical without a
2703 // coordinated edit on this crate's [`DEFAULT_LIBRARY_REPO`] would
2704 // silently emit rendered `Chart.yaml` documents whose
2705 // `dependencies[0].name` names the new chart while
2706 // `dependencies[0].repository` points at the old directory —
2707 // `helm dependency build` would refuse to resolve the dep ("chart
2708 // <new-name> not found in file://../<old-name>") at chart-
2709 // consumption time, far from the constant-rebrand commit's source,
2710 // with no field naming the two-axis coherence drift root cause.
2711 // Pinning the structural `ends_with(DEFAULT_LIBRARY_NAME)` invariant
2712 // here surfaces the drift as a caixa-helm build-time test failure
2713 // and forces the coordinated `(REPO, NAME)` edit to move together.
2714 // Peer of the sibling
2715 // [`default_library_version_parses_as_valid_semver_requirement`]
2716 // structural pin on the co-resident `(name, version)` per-Chart.yaml
2717 // dep-scalar pair — completes the `(repository, name, version)`
2718 // per-Chart.yaml-dep default-triple's structural pin surface.
2719 assert!(
2720 DEFAULT_LIBRARY_REPO.ends_with(DEFAULT_LIBRARY_NAME),
2721 "DEFAULT_LIBRARY_REPO {DEFAULT_LIBRARY_REPO:?} must terminate with the lifted \
2722 DEFAULT_LIBRARY_NAME {DEFAULT_LIBRARY_NAME:?} — the two-axis (repository, name) \
2723 per-Chart.yaml-dep tuple must resolve to the same library-chart identity on \
2724 disk, so a rebrand on either axis must move both",
2725 );
2726 }
2727
2728 #[test]
2729 fn chart_yaml_version_routes_through_caixa_versao_accessor() {
2730 // Fail-before-pass-after pin: the emit-side per-`Chart.yaml`
2731 // top-level `version:` scalar the [`build_chart_yaml`] fn
2732 // writes must derive from the typed
2733 // [`caixa_core::Caixa::versao`] accessor byte-for-byte.
2734 // Before this converge the emit site carried a raw
2735 // `caixa.versao.clone()` field access at
2736 // [`build_chart_yaml`]'s per-`Chart.yaml` version-field
2737 // insert position — one of the two production-code
2738 // `String`-carry sites of `Caixa::versao` on this fn's
2739 // emit path — and a future extension of the accessor
2740 // (a build-metadata canonicalization pass the CAIXA-SDLC
2741 // §I SemVer-2 pin acknowledges, an OCI-tag normalization
2742 // the M4 registry-alignment slot lands, a per-edition
2743 // pre-release-tag overlay the sibling `Caixa::edicao`
2744 // universal-axis 4-digit-ASCII-decimal-year scalar
2745 // dispatches through) that landed on the accessor but
2746 // not on this emit site would silently split the
2747 // per-`Chart.yaml` `version:` axis (the discriminator
2748 // Helm's per-chart resolver keys per-release
2749 // reconciliation off, the paired `HelmRelease`
2750 // `spec.chart.spec.version` binds through, and every
2751 // `helm template <chart>` / `helm install <release>
2752 // <chart>` / `helm upgrade <release> <chart>
2753 // --version` invocation names through) from every peer
2754 // read-side consumer of `Caixa::versao` (the
2755 // README-body `v{versao}` scalar at
2756 // [`build_readme`]:958 the paired `feira chart`
2757 // Nord-themed emit round-trips through, every peer
2758 // per-axis navigator via `Caixa::versao()`, the
2759 // `caixa_flux::programs_yaml_entry` per-entry
2760 // `versao:` scalar at caixa-flux/src/lib.rs:2031, the
2761 // `caixa_feira::cmd::publish` per-tag `caixa {nome} v{versao}`
2762 // git-tag scalar at caixa-feira/src/cmd/publish.rs:72).
2763 // Byte-equal today (the accessor is `&self.versao`);
2764 // the pin catches any future accessor extension whose
2765 // emit-side write regresses to the raw field. Peer to
2766 // [`chart_yaml_app_version_routes_through_caixa_versao_accessor`]
2767 // on the sibling per-`Chart.yaml` `appVersion:` axis.
2768 let caixa = sample_caixa();
2769 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2770 let chart_file = dir
2771 .files
2772 .iter()
2773 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
2774 .expect("Chart.yaml present");
2775 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
2776 assert_eq!(
2777 chart.version.as_str(),
2778 caixa.versao(),
2779 "Chart.yaml `version:` must derive from the typed \
2780 `caixa_core::Caixa::versao` accessor byte-for-byte — a regression \
2781 that re-inlines `caixa.versao.clone()` at the emit site silently \
2782 splits the per-`Chart.yaml` `version:` axis from every future \
2783 accessor extension (SemVer-2 build-metadata canonicalization, \
2784 OCI-tag normalization, per-edition pre-release-tag overlay) that \
2785 lands on the accessor",
2786 );
2787 }
2788
2789 #[test]
2790 fn chart_yaml_app_version_routes_through_caixa_versao_accessor() {
2791 // Fail-before-pass-after pin: the emit-side per-`Chart.yaml`
2792 // top-level `appVersion:` scalar the [`build_chart_yaml`] fn
2793 // writes must derive from the typed
2794 // [`caixa_core::Caixa::versao`] accessor byte-for-byte.
2795 // Same single-source `let versao = caixa.versao().to_string()`
2796 // binding as the peer `version:` sibling pin — this test
2797 // pins the derived `Chart.yaml` `appVersion:` axis (the
2798 // axis Helm chart-consumers key per-application-version
2799 // documentation / release-note / OCI-tag / operator-side
2800 // per-Caixa CR revision off). Peer to
2801 // [`chart_yaml_version_routes_through_caixa_versao_accessor`]
2802 // on the sibling per-`Chart.yaml` `version:` axis — the
2803 // two together pin every per-`Chart.yaml` version-carrier
2804 // field on the typed accessor.
2805 let caixa = sample_caixa();
2806 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2807 let chart_file = dir
2808 .files
2809 .iter()
2810 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
2811 .expect("Chart.yaml present");
2812 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
2813 assert_eq!(
2814 chart.app_version.as_str(),
2815 caixa.versao(),
2816 "Chart.yaml `appVersion:` must derive from the typed \
2817 `caixa_core::Caixa::versao` accessor byte-for-byte — a regression \
2818 that re-inlines `caixa.versao.clone()` at the emit site silently \
2819 splits the per-`Chart.yaml` `appVersion:` axis from every future \
2820 accessor extension (SemVer-2 build-metadata canonicalization, \
2821 OCI-tag normalization, per-edition pre-release-tag overlay) that \
2822 lands on the accessor",
2823 );
2824 }
2825
2826 #[test]
2827 fn chart_yaml_name_routes_through_caixa_nome_accessor() {
2828 // Emit-path pin: the per-`Chart.yaml` top-level `name:`
2829 // scalar the [`build_chart_yaml`] fn writes must derive
2830 // from the typed [`caixa_core::Caixa::nome`] accessor
2831 // byte-for-byte through the substrate-canonical
2832 // [`caixa_core::lareira_chart_name`] identity composer.
2833 // Before this converge the outer `lareira_chart_name(&caixa.nome)`
2834 // call at [`render_chart_for_servico_with`] carried a raw
2835 // `&caixa.nome` borrow-then-deref of the underlying `String`
2836 // field, bypassing the typed accessor. Peer of the sibling
2837 // eb912de `caixa.versao().to_string()` converge on the
2838 // co-resident `Caixa::versao` `String`-carry axis in this
2839 // crate and the sibling 4a363bf / 54bf2f3 `caixa.nome().to_string()`
2840 // converges on the outer-Caixa `:nome` `String`-carry axis
2841 // in caixa-flux / caixa-mesh — extends the "one typed
2842 // dispatch on the substrate primitive, thin projections at
2843 // each consumer" discipline onto the non-`.clone()` raw-
2844 // field-access axis of `Caixa::nome` in caixa-helm. Byte-
2845 // equal today (the accessor is `&self.nome`); the pin
2846 // catches any future accessor extension (a per-cluster
2847 // alias overlay, an M4 CR-materializer name rewrite, a
2848 // future `:nome-suffix` slot) whose emit-side write
2849 // regresses to the raw `&caixa.nome` field access.
2850 let caixa = sample_caixa();
2851 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2852 let chart_file = dir
2853 .files
2854 .iter()
2855 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
2856 .expect("Chart.yaml present");
2857 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
2858 assert_eq!(
2859 chart.name,
2860 caixa_core::lareira_chart_name(caixa.nome()),
2861 "Chart.yaml `name:` must derive from the typed \
2862 `caixa_core::Caixa::nome` accessor through \
2863 `caixa_core::lareira_chart_name` byte-for-byte — a regression \
2864 that re-inlines `lareira_chart_name(&caixa.nome)` at the emit \
2865 site silently splits the per-`Chart.yaml` `name:` axis from \
2866 every future accessor extension (per-cluster alias overlay, \
2867 M4 CR-materializer name rewrite, `:nome-suffix` slot) that \
2868 lands on the accessor",
2869 );
2870 }
2871
2872 #[test]
2873 fn chart_yaml_description_fallback_routes_through_caixa_nome_accessor() {
2874 // Emit-path pin: on a `:descricao`-null caixa the
2875 // [`build_chart_yaml`] `description:` fallback substitutes
2876 // `format!("Generated chart for caixa Servico {}", caixa.nome())`,
2877 // which must derive its terminal identity byte-string from the
2878 // typed [`caixa_core::Caixa::nome`] accessor. Before this
2879 // converge the fallback carried a raw `caixa.nome` Display of
2880 // the underlying `String` field, bypassing the typed accessor.
2881 // Byte-equal today; the pin catches any future accessor
2882 // extension whose fallback emit regresses to the raw field.
2883 let caixa = Caixa {
2884 descricao: None,
2885 ..sample_caixa()
2886 };
2887 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2888 let chart_file = dir
2889 .files
2890 .iter()
2891 .find(|f| f.path == PathBuf::from(HELM_CHART_YAML_FILENAME))
2892 .expect("Chart.yaml present");
2893 let chart: ChartYaml = serde_yaml::from_str(&chart_file.contents).unwrap();
2894 assert_eq!(
2895 chart.description,
2896 format!("Generated chart for caixa Servico {}", caixa.nome()),
2897 "Chart.yaml `description:` `:descricao`-null fallback must \
2898 derive from the typed `caixa_core::Caixa::nome` accessor \
2899 byte-for-byte — a regression that re-inlines \
2900 `format!(\"Generated chart for caixa Servico {{}}\", caixa.nome)` \
2901 at the emit site silently splits the per-`Chart.yaml` \
2902 `description:` axis from every future accessor extension \
2903 that lands on the accessor",
2904 );
2905 }
2906
2907 #[test]
2908 fn values_yaml_header_nome_routes_through_caixa_nome_accessor() {
2909 // Emit-path pin: the [`build_values_yaml`] `# Auto-generated
2910 // by caixa-helm from caixa.lisp + servicos/{nome}.computeunit.yaml.`
2911 // comment header carries the parent-caixa's `:nome` identity
2912 // byte-string verbatim through the typed
2913 // [`caixa_core::Caixa::nome`] accessor. Before this converge
2914 // the site carried a raw `nome = caixa.nome` Display of the
2915 // underlying `String` field, bypassing the typed accessor.
2916 // Byte-equal today; the pin catches any future accessor
2917 // extension whose header-emit regresses to the raw field.
2918 let caixa = sample_caixa();
2919 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2920 let values_file = dir
2921 .files
2922 .iter()
2923 .find(|f| f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))
2924 .expect("values.yaml present");
2925 let expected = format!("servicos/{}.computeunit.yaml", caixa.nome());
2926 assert!(
2927 values_file.contents.contains(&expected),
2928 "values.yaml header comment must carry the typed \
2929 `caixa_core::Caixa::nome` accessor's byte-string \
2930 ({expected:?}) verbatim — a regression that re-inlines \
2931 `caixa.nome` in the header format silently splits the \
2932 values.yaml provenance-annotation axis from every future \
2933 accessor extension that lands on the accessor. \
2934 Full contents:\n{contents}",
2935 contents = values_file.contents,
2936 );
2937 }
2938
2939 #[test]
2940 fn readme_descricao_fallback_routes_through_caixa_nome_accessor() {
2941 // Emit-path pin: on a `:descricao`-null caixa the
2942 // [`build_readme`] descricao-line fallback substitutes
2943 // `format!("caixa Servico {}", caixa.nome())`, which must
2944 // derive its terminal identity byte-string from the typed
2945 // [`caixa_core::Caixa::nome`] accessor. Before this converge
2946 // the fallback carried a raw `caixa.nome` Display of the
2947 // underlying `String` field, bypassing the typed accessor.
2948 // Byte-equal today; the pin catches any future accessor
2949 // extension whose fallback emit regresses to the raw field.
2950 let caixa = Caixa {
2951 descricao: None,
2952 ..sample_caixa()
2953 };
2954 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2955 let readme_file = dir
2956 .files
2957 .iter()
2958 .find(|f| f.path == PathBuf::from(HELM_CHART_README_FILENAME))
2959 .expect("README.md present");
2960 let expected = format!("caixa Servico {}", caixa.nome());
2961 assert!(
2962 readme_file.contents.contains(&expected),
2963 "README.md `:descricao`-null fallback must carry the typed \
2964 `caixa_core::Caixa::nome` accessor's byte-string ({expected:?}) \
2965 verbatim — a regression that re-inlines `format!(\"caixa \
2966 Servico {{}}\", caixa.nome)` at the emit site silently \
2967 splits the README fallback-descricao axis from every future \
2968 accessor extension. Full contents:\n{contents}",
2969 contents = readme_file.contents,
2970 );
2971 }
2972
2973 #[test]
2974 fn readme_body_version_routes_through_caixa_versao_accessor() {
2975 // Emit-path pin: the per-`README.md` `Origin` line the
2976 // [`build_readme`] fn writes carries the terminal
2977 // `v{versao}` scalar the `feira chart` Nord-themed emit
2978 // round-trips through — that scalar must derive from the
2979 // typed [`caixa_core::Caixa::versao`] accessor byte-for-byte.
2980 // Before this converge the emit site carried a raw
2981 // `caixa.versao` `Display` field-access, bypassing the
2982 // typed accessor. Sibling of the 162e2e2 (caixa-flux) /
2983 // 980c059 (caixa-mesh) / 22461ef (caixa-helm) `Caixa::nome`
2984 // Display-axis converges — this closes the co-resident
2985 // `Caixa::versao` Display-axis in caixa-helm the eb912de
2986 // `caixa.versao().to_string()` `String`-carry converge
2987 // left open on the read-only Display-borrow arm. Byte-equal
2988 // today (the accessor is `&self.versao`); the pin catches
2989 // any future accessor extension (SemVer-2 build-metadata
2990 // canonicalization, OCI-tag normalization, per-edition
2991 // pre-release-tag overlay) whose emit-side Display regresses
2992 // to the raw field.
2993 let caixa = sample_caixa();
2994 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2995 let readme_file = dir
2996 .files
2997 .iter()
2998 .find(|f| f.path == PathBuf::from(HELM_CHART_README_FILENAME))
2999 .expect("README.md present");
3000 let expected = format!("caixa.lisp` v{}.", caixa.versao());
3001 assert!(
3002 readme_file.contents.contains(&expected),
3003 "README.md `Origin`-line `v{{versao}}` scalar must derive from \
3004 the typed `caixa_core::Caixa::versao` accessor byte-for-byte \
3005 ({expected:?}) — a regression that re-inlines `caixa.versao` \
3006 in the format silently splits the README origin-line version \
3007 axis from every future accessor extension (SemVer-2 \
3008 build-metadata canonicalization, OCI-tag normalization, \
3009 per-edition pre-release-tag overlay) that lands on the \
3010 accessor. Full contents:\n{contents}",
3011 contents = readme_file.contents,
3012 );
3013 }
3014
3015 #[test]
3016 fn readme_repositorio_fallback_routes_through_caixa_nome_accessor() {
3017 // Emit-path pin: on a `:repositorio`-null caixa the
3018 // [`build_readme`] `repo` interpolation falls back to
3019 // `caixa.nome()`, which must derive from the typed
3020 // [`caixa_core::Caixa::nome`] accessor. Before this converge
3021 // the fallback carried a raw `caixa.nome.as_str()` on the
3022 // underlying `String` field, bypassing the typed accessor.
3023 // Byte-equal today; the pin catches any future accessor
3024 // extension whose fallback emit regresses to the raw field.
3025 let caixa = Caixa {
3026 repositorio: None,
3027 ..sample_caixa()
3028 };
3029 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
3030 let readme_file = dir
3031 .files
3032 .iter()
3033 .find(|f| f.path == PathBuf::from(HELM_CHART_README_FILENAME))
3034 .expect("README.md present");
3035 let expected = format!(
3036 "Generated by `caixa-helm` from `{}/caixa.lisp`",
3037 caixa.nome()
3038 );
3039 assert!(
3040 readme_file.contents.contains(&expected),
3041 "README.md `:repositorio`-null fallback must derive its \
3042 `repo` interpolation from the typed \
3043 `caixa_core::Caixa::nome` accessor byte-for-byte \
3044 ({expected:?}) — a regression that re-inlines \
3045 `caixa.nome.as_str()` at the emit site silently splits \
3046 the README origin-line repo axis from every future \
3047 accessor extension. Full contents:\n{contents}",
3048 contents = readme_file.contents,
3049 );
3050 }
3051}