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};
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 // Route the per-`ChartDir.name` `lareira-<nome>` chart-identity
767 // composer through the substrate-canonical
768 // [`caixa_core::Caixa::lareira_chart_name`] resolved-chart-name
769 // dispatch rather than the two-step
770 // [`caixa_core::lareira_chart_name`]-of-[`caixa_core::Caixa::nome`]
771 // open-coded compose — the load-bearing per-Servico Helm chart
772 // identity now reaches through exactly one typed dispatch on the
773 // substrate primitive. Peer of the sibling
774 // [`Caixa::canonical_git_url`] (124f864) / [`Caixa::publish_tag`]
775 // (07e05b8) resolved-composers on the paired per-`Caixa` published-
776 // artifact-identity axis — every substrate-side consumer that
777 // resolves "which chart does this caixa publish under?" now travels
778 // through one accessor rather than a per-caller two-step compose.
779 // Pinned by the drift-detection test
780 // [`chart_dir_name_routes_through_caixa_lareira_chart_name_accessor`]
781 // in the tests module.
782 let chart_name = caixa.lareira_chart_name();
783 let chart_yaml = build_chart_yaml(caixa, &chart_name, opts);
784 let values_yaml = build_values_yaml(caixa, computeunit_yaml, opts)?;
785 let readme = build_readme(caixa, &chart_name);
786
787 // Each per-artifact leaf routes through the canonical
788 // [`caixa_core::RenderedFile::new`] `impl Into<PathBuf>` /
789 // `impl Into<String>` constructor (re-exported by the peer
790 // [`ChartFile`] alias since Rust inherent methods travel through
791 // type aliases to the aliased type at name resolution). The prior
792 // three inline `ChartFile { path: PathBuf::from(FILENAME_CONST),
793 // contents: <body> }` blocks each re-derived the same
794 // `PathBuf::from(&str)` wrap + the same two-field assembly — a
795 // byte-identical duplicate of the peer [`caixa_flux::cluster_bundle`]
796 // Flux v2 CR trio's three per-CR emit sites. Sweeping both trios
797 // onto [`RenderedFile::new`] collapses the six substrate-side
798 // per-artifact-construction sites onto one canonical constructor,
799 // so a future rebrand on the record shape (a per-artifact hash /
800 // provenance field addition, a per-artifact write-mode discriminator
801 // once per-cluster-writer sandboxing lands, the
802 // [`caixa_core::is_sandboxed_relative_path`] discipline the
803 // [`RenderedFile`] docstring acknowledges is not yet run at emit
804 // time) reaches every per-target renderer through one caixa-core
805 // edit instead of a coordinated six-site rewrite.
806 Ok(ChartDir {
807 name: chart_name,
808 files: vec![
809 ChartFile::new(
810 HELM_CHART_YAML_FILENAME,
811 serde_yaml::to_string(&chart_yaml)?,
812 ),
813 ChartFile::new(HELM_VALUES_YAML_FILENAME, values_yaml),
814 ChartFile::new(HELM_CHART_README_FILENAME, readme),
815 ],
816 })
817}
818
819fn build_chart_yaml(caixa: &Caixa, chart_name: &str, opts: &RenderOpts) -> ChartYaml {
820 let description = caixa
821 .descricao()
822 .map(str::to_owned)
823 .unwrap_or_else(|| format!("Generated chart for caixa Servico {}", caixa.nome()));
824 let keywords: Vec<String> = caixa
825 .etiquetas()
826 .iter()
827 .cloned()
828 .chain(
829 caixa_core::LAREIRA_CHART_KEYWORDS
830 .iter()
831 .copied()
832 .map(String::from),
833 )
834 .collect::<Vec<_>>()
835 .into_iter()
836 .collect::<std::collections::BTreeSet<_>>()
837 .into_iter()
838 .collect();
839 let maintainers = caixa
840 .autores()
841 .iter()
842 .map(|a| Maintainer {
843 name: a.clone(),
844 email: None,
845 })
846 .collect();
847 // Canonical typed `String`-carry of the per-`Caixa` `:versao`
848 // universal-axis SemVer-2 pinned-version scalar into the two
849 // per-`Chart.yaml` version-carrier fields Helm's chart-schema
850 // parser routes per-chart identity through — `Chart.yaml`'s
851 // top-level `version:` (the axis Helm's per-chart resolver keys
852 // per-release reconciliation off, the paired `HelmRelease`
853 // `spec.chart.spec.version` binds through, and every `helm
854 // template <chart>` / `helm install <release> <chart>` /
855 // `helm upgrade <release> <chart> --version` invocation names
856 // through) and `Chart.yaml`'s top-level `appVersion:` (the
857 // axis Helm chart-consumers key per-application-version
858 // documentation / release-note / OCI-tag / operator-side
859 // per-Caixa CR revision off), both routing through the typed
860 // [`caixa_core::Caixa::versao`] accessor's canonical
861 // `to_string()` extension of `&self.versao`. Peer of the
862 // sibling 4a363bf / 54bf2f3 `caixa.nome.clone()` converges
863 // on the outer-Caixa `:nome` `String`-carry axis in caixa-flux
864 // / caixa-mesh — this converges the last unlifted per-Caixa
865 // `.versao.clone()` raw-field `String`-carry axis in
866 // caixa-helm on the same "one typed dispatch per axis"
867 // discipline.
868 let versao = caixa.versao().to_string();
869 ChartYaml {
870 api_version: HELM_CHART_API_VERSION.into(),
871 name: chart_name.into(),
872 description,
873 chart_type: HELM_CHART_TYPE_APPLICATION.into(),
874 version: versao.clone(),
875 app_version: versao,
876 keywords,
877 maintainers,
878 home: caixa.repositorio().map(str::to_owned),
879 dependencies: vec![ChartDependency {
880 name: opts.library_name.clone(),
881 version: opts.library_version.clone(),
882 repository: opts.library_repo.clone(),
883 alias: None,
884 }],
885 }
886}
887
888fn build_values_yaml(
889 caixa: &Caixa,
890 computeunit_yaml: &serde_yaml::Value,
891 opts: &RenderOpts,
892) -> Result<String, Error> {
893 // The library chart consumes its values under the key matching its
894 // Helm chart `dependencies[].name` (Helm's per-dep alias convention
895 // — when no `alias:` is set on the dependency, values are scoped
896 // under the dependency's `name`). This renderer wires both axes
897 // through the same `opts.library_name`: the chart's dep `name:`
898 // (build_chart_yaml at line 277) and this site's values wrap key
899 // both consult one `&str`, so a future fork that overrides
900 // `RenderOpts::library_name` to point at `acme-computeunit` /
901 // `pleme-computeunit-mirror` / the future per-edition library name
902 // reaches both axes by construction. Until this lift landed the
903 // wrap key was hardcoded `"pleme-computeunit"` while the dep name
904 // followed `opts.library_name`, so an override silently emitted
905 // values keyed under one name (the literal) while the rendered
906 // Chart.yaml's dep was declared under another (the override) —
907 // Helm's per-dep values router would route nothing to the
908 // configured dependency at `helm template` / `helm install` time,
909 // and every typed value the values block carries (`enabled`,
910 // `module`, `trigger`, the M2 overlay's `:limits`/`:behavior`/
911 // `:upgrade-from`) would silently no-op at the rendered chart's
912 // landing site. The wrap key now reads from the same `&str` the
913 // dep name reads from, structurally closing the drift footgun
914 // peer with the [`caixa_core::DEFAULT_NAMESPACE`] /
915 // [`caixa_core::DEFAULT_SERVICO_PORT`] lifts on the sibling
916 // canonical-K8s-axis constants (where two production-code call
917 // sites of the same load-bearing value would drift apart on
918 // any rebrand without a shared source of truth).
919 let library_alias = opts.library_name.as_str();
920 let spec = computeunit_yaml
921 .get(KUBE_KEY_SPEC)
922 .ok_or(Error::MissingField(KUBE_KEY_SPEC))?;
923
924 // Prepend a comment header so the file is human-friendly.
925 let header = format!(
926 "# Auto-generated by caixa-helm from caixa.lisp + servicos/{nome}.computeunit.yaml.\n\
927 # Edits to this file are overwritten by `feira chart`.\n\
928 #\n\
929 # `{library_alias}:` is the alias under which the library chart\n\
930 # in pleme-io/helmworks/charts/{library_alias} consumes its values.\n\n",
931 nome = caixa.nome()
932 );
933
934 let mut block = BTreeMap::new();
935 block.insert(
936 HELM_VALUES_KEY_ENABLED.to_string(),
937 serde_yaml::Value::Bool(opts.enabled_default),
938 );
939 // Two-step per-Servico value-block splice — the `spec.*` field
940 // splice (module / trigger / capabilities / config / resources /
941 // serviceAccount) and the M2 typed-slot overlay (limits / behavior
942 // / upgradeFrom, `or_insert` semantics so `spec.*` wins on
943 // collision) now route through the canonical
944 // [`caixa_core::servico_spec_and_m2_overlay_entries`] composition
945 // helper — the two prior inline for-loops chained around
946 // `string_keyed_entries` + `servico_m2_overlay` this call site
947 // (and the peer [`caixa_flux::programs_yaml_entry`] site) each
948 // re-derived collapse onto one canonical composition, so a future
949 // change to the per-Servico splice / overlay shape (the M4 typed
950 // per-edge policy overlay slot addition MESH-COMPOSITION §III.2 #3
951 // acknowledges, a change to the precedence rule once per-Aplicacao
952 // operator overrides land, a canonicalization pass on the merged
953 // key set) reaches both renderers by construction instead of a
954 // coordinated two-file rewrite. See the helper's docstring for the
955 // full lift rationale. The target `BTreeMap` re-sorts by key on
956 // insert, so the final rendered values block stays byte-identical
957 // to the prior inline block's alphabetical shape.
958 for (k, v) in caixa_core::servico_spec_and_m2_overlay_entries(caixa, spec)? {
959 block.entry(k).or_insert(v);
960 }
961
962 let mut wrapped = serde_yaml::Mapping::new();
963 wrapped.insert_str_key(library_alias, serde_yaml::to_value(block)?);
964 let body = serde_yaml::to_string(&serde_yaml::Value::Mapping(wrapped))?;
965 Ok(format!("{header}{body}"))
966}
967
968fn build_readme(caixa: &Caixa, chart_name: &str) -> String {
969 let descricao = caixa
970 .descricao()
971 .map(str::to_owned)
972 .unwrap_or_else(|| format!("caixa Servico {}", caixa.nome()));
973 // Route the per-`README.md` `## Origin` line's `{repo}` interpolation
974 // through the substrate-canonical [`caixa_core::Caixa::canonical_git_url`]
975 // resolved-git-URL composer (124f864) rather than the prior
976 // `caixa.repositorio().unwrap_or(caixa.nome())` two-arm inline fallback.
977 // The prior shape's `:repositorio`-null arm folded to `caixa.nome()`
978 // verbatim, so the rendered README's `## Origin` line emitted the
979 // meaningless `Generated by `caixa-helm` from `<nome>/caixa.lisp``
980 // scalar on every `:repositorio`-null caixa — a bare `<nome>` prefix
981 // that told a downstream reader nothing about where the caixa's
982 // source actually lives, and disagreed on that same axis with the
983 // sibling [`caixa_flux::ClusterBundleOpts::for_caixa`] `git_url`
984 // seed which had already routed through the resolved-URL composer
985 // and emitted the canonical `https://github.com/{DEFAULT_PLEME_GIT_ORG}/<nome>`
986 // pleme-org fallback on the same author-omitted-`:repositorio` case.
987 // The 124f864 commit body explicitly anticipated this converge (the
988 // "same accessor consumed by every renderer" convergence surface it
989 // called out as the live-behavior-correcting fold distinct from that
990 // commit's pure byte-preserving convergence). Post-lift the two
991 // renderers agree byte-for-byte on the resolved-URL substrate
992 // primitive on both arms, and the README's `## Origin` line names a
993 // concrete pleme-org URL on the fallback path.
994 format!(
995 "# {chart_name}\n\
996 \n\
997 {descricao}\n\
998 \n\
999 ## Origin\n\
1000 \n\
1001 Generated by `caixa-helm` from `{repo}/caixa.lisp` v{versao}.\n\
1002 Edits here are overwritten by `feira chart`.\n\
1003 \n\
1004 ## Install\n\
1005 \n\
1006 ```bash\n\
1007 helm dependency build\n\
1008 helm template {chart_name} . --values values.yaml\n\
1009 ```\n\
1010 \n\
1011 ## License\n\
1012 \n\
1013 {license}.\n",
1014 chart_name = chart_name,
1015 descricao = descricao,
1016 repo = caixa.canonical_git_url(),
1017 versao = caixa.versao(),
1018 license = caixa.licenca().unwrap_or("MIT"),
1019 )
1020}
1021
1022#[cfg(test)]
1023mod tests {
1024 use super::*;
1025 use caixa_core::{
1026 Caixa, CaixaKind, M2_BEHAVIOR_KEY_ON_CALL, M2_BEHAVIOR_KEY_ON_INIT, M2_KEY_BEHAVIOR,
1027 M2_KEY_LIMITS, M2_KEY_UPGRADE_FROM, M2_LIMITS_KEY_CPU, M2_LIMITS_KEY_FUEL,
1028 M2_LIMITS_KEY_MEMORY, M2_LIMITS_KEY_WALL_CLOCK, find_file_by_path, kube_has, kube_str,
1029 kube_u64, mapping_string_keys, parse_yaml_at_path, parse_yaml_at_path_as,
1030 };
1031 use std::path::PathBuf;
1032
1033 fn sample_caixa() -> Caixa {
1034 Caixa {
1035 nome: "hello-rio".into(),
1036 versao: "0.1.0".into(),
1037 kind: CaixaKind::Servico,
1038 edicao: Some("2026".into()),
1039 descricao: Some("Canonical Rust→wasm32-wasip2 caixa Servico.".into()),
1040 repositorio: Some("github:pleme-io/hello-rio".into()),
1041 licenca: Some("MIT".into()),
1042 autores: vec!["pleme-io".into()],
1043 etiquetas: vec!["hello-world".into(), "wasm".into(), "rust".into()],
1044 deps: vec![],
1045 deps_dev: vec![],
1046 exe: vec![],
1047 bibliotecas: vec![],
1048 servicos: vec!["servicos/hello-rio.computeunit.yaml".into()],
1049 limits: None,
1050 behavior: None,
1051 upgrade_from: vec![],
1052 estrategia: None,
1053 max_restarts: None,
1054 restart_window: None,
1055 children: vec![],
1056 membros: vec![],
1057 contratos: vec![],
1058 politicas: None,
1059 placement: None,
1060 entrada: None,
1061 ci: None,
1062 }
1063 }
1064
1065 fn sample_cu_yaml() -> serde_yaml::Value {
1066 serde_yaml::from_str(
1067 r#"
1068apiVersion: wasm.pleme.io/v1alpha1
1069kind: ComputeUnit
1070metadata:
1071 name: hello-rio
1072spec:
1073 module:
1074 source: oci://ghcr.io/pleme-io/hello-rio:v0.1.0
1075 trigger:
1076 service:
1077 port: 8080
1078 paths: ["/", "/hello", "/healthz"]
1079 breathability:
1080 enabled: true
1081 minReplicas: 0
1082 maxReplicas: 5
1083 cooldownPeriod: 600
1084 capabilities:
1085 - http-in:0.0.0.0:8080
1086 - env
1087"#,
1088 )
1089 .unwrap()
1090 }
1091
1092 #[test]
1093 fn renders_three_files() {
1094 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1095 assert_eq!(dir.name, "lareira-hello-rio");
1096 let names: Vec<_> = dir
1097 .files
1098 .iter()
1099 .map(|f| f.path.to_string_lossy().to_string())
1100 .collect();
1101 assert!(names.contains(&HELM_CHART_YAML_FILENAME.to_string()));
1102 assert!(names.contains(&HELM_VALUES_YAML_FILENAME.to_string()));
1103 assert!(names.contains(&HELM_CHART_README_FILENAME.to_string()));
1104 }
1105
1106 #[test]
1107 fn chart_yaml_metadata_propagates() {
1108 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1109 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
1110 assert_eq!(chart.api_version, "v2");
1111 assert_eq!(chart.name, "lareira-hello-rio");
1112 assert_eq!(chart.version, "0.1.0");
1113 assert_eq!(chart.app_version, "0.1.0");
1114 assert_eq!(chart.dependencies.len(), 1);
1115 assert_eq!(chart.dependencies[0].name, DEFAULT_LIBRARY_NAME);
1116 assert!(chart.keywords.contains(&"caixa-servico".to_string()));
1117 assert!(chart.keywords.contains(&"hello-world".to_string()));
1118 assert_eq!(chart.maintainers[0].name, "pleme-io");
1119 }
1120
1121 #[test]
1122 fn chart_yaml_keywords_union_pins_every_lareira_chart_keywords_entry() {
1123 // Structural pin: `build_chart_yaml`'s substrate-fixed
1124 // chart-keyword union routes through the canonical
1125 // `caixa_core::LAREIRA_CHART_KEYWORDS` array — every rendered
1126 // `lareira-<nome>` chart's emitted `Chart.yaml` `keywords:`
1127 // sequence carries every substrate-fixed entry the array
1128 // declares. A future substrate-fixed keyword addition
1129 // (an `"opentelemetry"` entry once the caixa-otel collector-
1130 // pipeline chart lands, a `"lunatic"` entry once the wasm-
1131 // process-runtime marker lands, a `"gen_server"` entry once
1132 // the OTP-shape callback marker lands per the
1133 // [`caixa_core::behavior`] surface) that lands in the array
1134 // reaches this crate's production emit site by construction
1135 // through the shared `&[&str]` reference — a drift where the
1136 // production emit at `build_chart_yaml` re-inlines the pre-
1137 // lift `["lareira", "wasm", "tatara-lisp", "caixa-servico"]`
1138 // literal set (or drops a per-entry axis on a rebrand
1139 // sweep) fails this pin at caixa-helm build time rather than
1140 // surfacing as a `helm search hub caixa-servico` miss on the
1141 // Artifact Hub keyword-search index at chart-publish time
1142 // downstream. Peer to
1143 // [`chart_yaml_metadata_propagates`] on the
1144 // per-`Chart.yaml`-body-field propagation surface.
1145 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1146 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
1147 for keyword in caixa_core::LAREIRA_CHART_KEYWORDS {
1148 assert!(
1149 chart.keywords.contains(&(*keyword).to_string()),
1150 "rendered Chart.yaml keywords {:?} must contain the \
1151 substrate-fixed LAREIRA_CHART_KEYWORDS entry {keyword:?}",
1152 chart.keywords,
1153 );
1154 }
1155 }
1156
1157 #[test]
1158 fn values_yaml_wraps_under_pleme_computeunit_key() {
1159 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1160 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1161 let cu_block = parsed
1162 .get(DEFAULT_LIBRARY_NAME)
1163 .expect("must wrap under DEFAULT_LIBRARY_NAME");
1164 assert_eq!(
1165 cu_block.get(HELM_VALUES_KEY_ENABLED),
1166 Some(&serde_yaml::Value::Bool(false))
1167 );
1168 assert!(kube_has(cu_block, COMPUTEUNIT_SPEC_KEY_MODULE));
1169 assert!(kube_has(cu_block, COMPUTEUNIT_SPEC_KEY_TRIGGER));
1170 assert!(kube_has(cu_block, COMPUTEUNIT_SPEC_KEY_CAPABILITIES));
1171 }
1172
1173 #[test]
1174 fn values_yaml_wrap_key_follows_library_name_override() {
1175 // Pinning the canonical alignment between the Helm chart's
1176 // `dependencies[].name` axis (build_chart_yaml at line 277) and
1177 // the values block's wrap key (build_values_yaml at the
1178 // `wrapped.insert(...)` site): both consult the same
1179 // `opts.library_name`, so an override on either axis reaches the
1180 // other by construction. Helm's per-dep alias convention — when
1181 // no `alias:` is set on a dependency, values are scoped under
1182 // its `name:` — makes wrap-key drift a silent value-routing
1183 // no-op at `helm template` / `helm install` time, so the
1184 // structural pin is load-bearing.
1185 let opts = RenderOpts {
1186 library_name: "acme-computeunit".into(),
1187 ..RenderOpts::default()
1188 };
1189 let dir = render_chart_for_servico_with(&sample_caixa(), &sample_cu_yaml(), &opts).unwrap();
1190 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1191 assert!(
1192 kube_has(&parsed, "acme-computeunit"),
1193 "values wrap key must follow opts.library_name override \
1194 (got top-level keys: {keys:?})",
1195 keys = parsed
1196 .as_mapping()
1197 .map(mapping_string_keys)
1198 .unwrap_or_default()
1199 );
1200 assert!(
1201 !kube_has(&parsed, DEFAULT_LIBRARY_NAME),
1202 "values wrap key must not retain the default `{DEFAULT_LIBRARY_NAME}` literal \
1203 when opts.library_name overrides it"
1204 );
1205 let cu_block = parsed.get("acme-computeunit").unwrap();
1206 assert_eq!(
1207 cu_block.get(HELM_VALUES_KEY_ENABLED),
1208 Some(&serde_yaml::Value::Bool(false))
1209 );
1210 assert!(kube_has(cu_block, COMPUTEUNIT_SPEC_KEY_MODULE));
1211 assert!(kube_has(cu_block, COMPUTEUNIT_SPEC_KEY_TRIGGER));
1212 assert!(kube_has(cu_block, COMPUTEUNIT_SPEC_KEY_CAPABILITIES));
1213 }
1214
1215 #[test]
1216 fn values_yaml_wrap_key_matches_chart_dependency_name() {
1217 // The structural invariant the lift defends: every rendered
1218 // chart's values.yaml wrap key equals its Chart.yaml
1219 // `dependencies[0].name`. Sweeping the canonical default + a
1220 // typed override on the same axis pins the alignment across the
1221 // accepted set of `RenderOpts::library_name` values rather than
1222 // at a single canonical literal.
1223 for library_name in [DEFAULT_LIBRARY_NAME, "acme-computeunit", "fork-pleme-cu"] {
1224 let opts = RenderOpts {
1225 library_name: library_name.into(),
1226 ..RenderOpts::default()
1227 };
1228 let dir =
1229 render_chart_for_servico_with(&sample_caixa(), &sample_cu_yaml(), &opts).unwrap();
1230 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
1231 let dep_name = &chart.dependencies[0].name;
1232 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1233 assert!(
1234 parsed.get(dep_name.as_str()).is_some(),
1235 "values.yaml wrap key must match Chart.yaml dependencies[0].name {dep_name:?} \
1236 (library_name = {library_name:?}); Helm's per-dep alias convention scopes \
1237 values under the dep's `name` when no `alias:` is set, so any drift between \
1238 the two axes silently routes the values block nowhere"
1239 );
1240 }
1241 }
1242
1243 #[test]
1244 fn values_yaml_header_comment_follows_library_name_override() {
1245 // The human-facing values.yaml header's `<library_alias>:` /
1246 // `pleme-io/helmworks/charts/<library_alias>` references both
1247 // resolve through `opts.library_name`, peer with the wrap key
1248 // itself, so an override leaves the header self-consistent
1249 // with the rendered structure rather than naming a drifted
1250 // default literal.
1251 let opts = RenderOpts {
1252 library_name: "acme-computeunit".into(),
1253 ..RenderOpts::default()
1254 };
1255 let dir = render_chart_for_servico_with(&sample_caixa(), &sample_cu_yaml(), &opts).unwrap();
1256 let values = find_file_by_path(&dir.files, HELM_VALUES_YAML_FILENAME).unwrap();
1257 assert!(
1258 values.contents.contains("`acme-computeunit:`"),
1259 "header must name the overriding library alias verbatim \
1260 (got: {contents:?})",
1261 contents = values.contents
1262 );
1263 assert!(
1264 values
1265 .contents
1266 .contains("pleme-io/helmworks/charts/acme-computeunit"),
1267 "header's helmworks path must follow the overriding library alias \
1268 (got: {contents:?})",
1269 contents = values.contents
1270 );
1271 assert!(
1272 !values.contents.contains("`pleme-computeunit:`"),
1273 "header must not retain the default library alias literal \
1274 when overridden (got: {contents:?})",
1275 contents = values.contents
1276 );
1277 }
1278
1279 #[test]
1280 fn refuses_non_servico() {
1281 let mut c = sample_caixa();
1282 c.kind = CaixaKind::Biblioteca;
1283 c.servicos = vec![];
1284 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1285 assert!(matches!(err, Error::NotAServico(_)));
1286 }
1287
1288 #[test]
1289 fn kind_mismatch_error_names_offending_caixa_nome() {
1290 // Pinning the lifted [`caixa_core::KindMismatch`] view's
1291 // load-bearing property: a kind-mismatched caixa surfaces a
1292 // diagnostic that *names the offending caixa* (`hello-rio`),
1293 // not just the rejected kind. Before the lift the renderer
1294 // raised `Error::NotAServico(CaixaKind::Biblioteca)` whose
1295 // Display said "caixa :kind must be Servico for caixa-helm
1296 // rendering, got Biblioteca" — the user had to grep their
1297 // source tree for which caixa.lisp triggered it. After the
1298 // lift the wrapped KindMismatch carries the `:nome`, the
1299 // renderer's `#[error("{0}")]` arm prints it through, and
1300 // the diagnostic is self-locating.
1301 let mut c = sample_caixa();
1302 c.kind = CaixaKind::Biblioteca;
1303 c.servicos = vec![];
1304 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1305 let msg = format!("{err}");
1306 assert!(
1307 msg.contains("hello-rio"),
1308 "kind-mismatch diagnostic must name the offending caixa nome \
1309 (got: {msg:?})"
1310 );
1311 assert!(
1312 msg.contains("Servico"),
1313 "diagnostic must name the expected kind (got: {msg:?})"
1314 );
1315 assert!(
1316 msg.contains("Biblioteca"),
1317 "diagnostic must name the actual kind (got: {msg:?})"
1318 );
1319 }
1320
1321 #[test]
1322 fn kind_mismatch_carries_typed_view_via_from_conversion() {
1323 // The renderer's `Error::NotAServico` variant wraps the typed
1324 // [`caixa_core::KindMismatch`] view via `#[from]`, so the `?`
1325 // operator at the call site converts without manual glue.
1326 // Pinning the typed payload (not just the variant) so a
1327 // future refactor can't silently switch the variant to a
1328 // raw-`CaixaKind` payload (which would regress the lift's
1329 // shared-shape contract with caixa-flux + caixa-mesh).
1330 let mut c = sample_caixa();
1331 c.kind = CaixaKind::Aplicacao;
1332 c.servicos = vec![];
1333 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1334 match err {
1335 Error::NotAServico(km) => {
1336 assert_eq!(km.nome, "hello-rio");
1337 assert_eq!(km.expected, CaixaKind::Servico);
1338 assert_eq!(km.actual, CaixaKind::Aplicacao);
1339 }
1340 other => panic!("expected Error::NotAServico, got {other:?}"),
1341 }
1342 }
1343
1344 #[test]
1345 fn servico_count_mismatch_carries_typed_view_with_nome() {
1346 // Peer to the [`KindMismatch`]-lift pin above on the V0
1347 // `:servicos`-singularity axis: a Servico-kind caixa whose
1348 // `:servicos` list is non-singleton fails
1349 // [`render_chart_for_servico`] with the renderer's
1350 // `Error::UnsupportedServicoCount` variant wrapping the typed
1351 // [`caixa_core::ServicoCountMismatch`] view (carrying the
1352 // offending caixa's `:nome` + the actual count). Before the
1353 // lift the variant carried only `usize` — the user had to grep
1354 // their source tree for which `caixa.lisp` triggered it; after
1355 // the lift the wrapped typed view names the offending caixa
1356 // verbatim. Pins both the variant routing (via `#[from]`) and
1357 // the typed payload so a future refactor can't silently switch
1358 // back to the raw-`usize` payload (which would regress the
1359 // shared-shape contract with caixa-flux on the peer
1360 // programs.yaml-entry path).
1361 let mut c = sample_caixa();
1362 c.servicos = vec![
1363 "servicos/hello-rio.computeunit.yaml".into(),
1364 "servicos/extra.computeunit.yaml".into(),
1365 ];
1366 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1367 match err {
1368 Error::UnsupportedServicoCount(scm) => {
1369 assert_eq!(scm.nome, "hello-rio");
1370 assert_eq!(scm.count, 2);
1371 }
1372 other => panic!("expected Error::UnsupportedServicoCount, got {other:?}"),
1373 }
1374 }
1375
1376 #[test]
1377 fn servico_count_mismatch_diagnostic_names_offending_caixa_nome() {
1378 // The renderer's `#[error("{0}")] UnsupportedServicoCount(
1379 // #[from] ServicoCountMismatch)` arm prints the typed view's
1380 // Display through verbatim, so the offending caixa's `:nome`
1381 // appears in the rendered diagnostic. Pinning the
1382 // self-locating property end-to-end (renderer entry-point →
1383 // typed view's Display → final diagnostic string) so a future
1384 // refactor that re-wraps the variant in a Display impl that
1385 // drops the `:nome` surfaces here as a test failure rather
1386 // than as silent fragmentation of the diagnostic. Peer to the
1387 // `kind_mismatch_error_names_offending_caixa_nome` test above
1388 // on the sibling V0 Servico-shape axis.
1389 let mut c = sample_caixa();
1390 c.servicos = vec![
1391 "servicos/hello-rio.computeunit.yaml".into(),
1392 "servicos/extra.computeunit.yaml".into(),
1393 ];
1394 let err = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap_err();
1395 let msg = format!("{err}");
1396 assert!(
1397 msg.contains("hello-rio"),
1398 ":servicos-count-mismatch diagnostic must name the offending caixa nome \
1399 (got: {msg:?})"
1400 );
1401 assert!(
1402 msg.contains("2"),
1403 "diagnostic must name the actual count (got: {msg:?})"
1404 );
1405 assert!(
1406 msg.contains(":servicos"),
1407 "diagnostic must name the offending field axis (got: {msg:?})"
1408 );
1409 }
1410
1411 #[test]
1412 fn limits_slot_propagates_into_values_block() {
1413 use caixa_core::LimitsSpec;
1414 use std::time::Duration;
1415 let mut c = sample_caixa();
1416 c.limits = Some(LimitsSpec {
1417 memory: Some(64 * 1024 * 1024),
1418 fuel: Some(1_000_000),
1419 wall_clock: Some(Duration::from_secs(30)),
1420 cpu: Some(500),
1421 });
1422 let dir = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap();
1423 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1424 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1425 let limits = cu_block.get(M2_KEY_LIMITS).expect("limits must propagate");
1426 assert_eq!(kube_str(limits, M2_LIMITS_KEY_MEMORY), Some("64MiB"));
1427 assert_eq!(kube_u64(limits, M2_LIMITS_KEY_FUEL), Some(1_000_000));
1428 assert_eq!(kube_str(limits, M2_LIMITS_KEY_WALL_CLOCK), Some("30s"));
1429 assert_eq!(kube_str(limits, M2_LIMITS_KEY_CPU), Some("500m"));
1430 }
1431
1432 #[test]
1433 fn behavior_slot_propagates_into_values_block() {
1434 use caixa_core::BehaviorSpec;
1435 let mut c = sample_caixa();
1436 c.behavior = Some(BehaviorSpec {
1437 on_init: Some(PathBuf::from("lib/init.lisp")),
1438 on_call: Some(PathBuf::from("lib/handlers.lisp")),
1439 ..Default::default()
1440 });
1441 let dir = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap();
1442 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1443 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1444 let behavior = cu_block
1445 .get(M2_KEY_BEHAVIOR)
1446 .expect("behavior must propagate");
1447 assert_eq!(
1448 kube_str(behavior, M2_BEHAVIOR_KEY_ON_INIT),
1449 Some("lib/init.lisp")
1450 );
1451 assert_eq!(
1452 kube_str(behavior, M2_BEHAVIOR_KEY_ON_CALL),
1453 Some("lib/handlers.lisp")
1454 );
1455 }
1456
1457 #[test]
1458 fn upgrade_from_slot_propagates_into_values_block() {
1459 use caixa_core::{UpgradeFromEntry, UpgradeInstruction};
1460 let mut c = sample_caixa();
1461 c.upgrade_from = vec![UpgradeFromEntry {
1462 from: "0.0.9".into(),
1463 instructions: vec![UpgradeInstruction::LoadModule {
1464 module: "hello-rio".into(),
1465 }],
1466 }];
1467 let dir = render_chart_for_servico(&c, &sample_cu_yaml()).unwrap();
1468 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1469 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1470 assert!(kube_has(cu_block, M2_KEY_UPGRADE_FROM));
1471 }
1472
1473 #[test]
1474 fn empty_m2_slots_do_not_appear() {
1475 // Existing caixa with no M2 slots → values.yaml carries no
1476 // limits/behavior/upgradeFrom keys (forward-compat invariant).
1477 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1478 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
1479 let cu_block = parsed.get(DEFAULT_LIBRARY_NAME).unwrap();
1480 assert!(!kube_has(cu_block, M2_KEY_LIMITS));
1481 assert!(!kube_has(cu_block, M2_KEY_BEHAVIOR));
1482 assert!(!kube_has(cu_block, M2_KEY_UPGRADE_FROM));
1483 }
1484
1485 #[test]
1486 fn write_to_creates_files() {
1487 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1488 let tmp = tempfile::tempdir().unwrap();
1489 dir.write_to(tmp.path()).unwrap();
1490 let chart_root = tmp.path().join("lareira-hello-rio");
1491 assert!(chart_root.join(HELM_CHART_YAML_FILENAME).exists());
1492 assert!(chart_root.join(HELM_VALUES_YAML_FILENAME).exists());
1493 assert!(chart_root.join(HELM_CHART_README_FILENAME).exists());
1494 }
1495
1496 #[test]
1497 fn default_library_name_re_export_points_at_caixa_core_canonical() {
1498 // The renderer's `pub const DEFAULT_LIBRARY_NAME` was lifted to a
1499 // re-export of [`caixa_core::DEFAULT_LIBRARY_NAME`] so the Helm
1500 // library-chart name lives in exactly one place across every
1501 // caixa renderer (caixa-helm's `RenderOpts::library_name`
1502 // default here + caixa-flux's `cluster_bundle` `helmrelease.yaml`
1503 // wrap key on the sibling deploy-path crate). Pin the equality
1504 // here so any local re-introduction of a sibling `pub const
1505 // DEFAULT_LIBRARY_NAME: &str = "…"` (the canonical drift footgun
1506 // the prior `DEFAULT_NAMESPACE` / `DEFAULT_SERVICO_PORT` lift
1507 // commits' bodies acknowledged as the recurring shape) is a
1508 // build-time test failure naming the offending drift, not a
1509 // silent apply-time wrap-key mismatch routing the per-cluster
1510 // `enabled: true` override nowhere on `helm template` /
1511 // `helm install`. Peer to
1512 // `caixa_flux::tests::default_library_name_re_export_points_at_caixa_core_canonical`
1513 // on the sibling renderer crate.
1514 caixa_core::assert_str_reexport_identity(
1515 "DEFAULT_LIBRARY_NAME",
1516 DEFAULT_LIBRARY_NAME,
1517 caixa_core::DEFAULT_LIBRARY_NAME,
1518 );
1519 }
1520
1521 #[test]
1522 fn kube_key_spec_re_export_points_at_caixa_core_canonical() {
1523 // The renderer's `KUBE_KEY_SPEC` was lifted from the production-
1524 // code inline `"spec"` literal at `build_values_yaml`'s
1525 // `computeunit_yaml.get("spec")` ComputeUnit-side spec read (+
1526 // its matching `Error::MissingField("spec")` diagnostic) to a
1527 // re-export of [`caixa_core::KUBE_KEY_SPEC`] so the canonical
1528 // K8s-CR top-level spec-axis string lives in exactly one place
1529 // across every caixa renderer. Pin the equality + static-data
1530 // identity here so any local re-introduction of a sibling
1531 // `pub const KUBE_KEY_SPEC: &str = "…"` (the canonical drift
1532 // footgun where a sibling local `pub const` could happen to
1533 // carry the same string at the source while pointing at a
1534 // different `&'static` allocation) is a build-time test
1535 // failure naming the offending drift. Peer to
1536 // [`default_library_name_re_export_points_at_caixa_core_canonical`]
1537 // on the sibling re-export axis +
1538 // `caixa_flux::tests::kube_key_spec_re_export_points_at_caixa_core_canonical`
1539 // / `caixa_mesh::tests::kube_key_spec_re_export_points_at_caixa_core_canonical`
1540 // on the sibling renderer crates.
1541 caixa_core::assert_str_reexport_identity(
1542 "KUBE_KEY_SPEC",
1543 KUBE_KEY_SPEC,
1544 caixa_core::KUBE_KEY_SPEC,
1545 );
1546 }
1547
1548 #[test]
1549 fn helm_chart_api_version_re_export_points_at_caixa_core_canonical() {
1550 // The renderer's `HELM_CHART_API_VERSION` was lifted from the
1551 // production-code inline `"v2".into()` literal at
1552 // [`build_chart_yaml`]'s `api_version` field assignment (formerly
1553 // `caixa-helm/src/lib.rs:298`) to a re-export of
1554 // [`caixa_core::HELM_CHART_API_VERSION`] so the Helm 3
1555 // chart-schema apiVersion the rendered Chart.yaml declares lives
1556 // in exactly one place across every caixa renderer. Pin the
1557 // equality + `&'static` static-data identity here so any local
1558 // re-introduction of a sibling `pub const HELM_CHART_API_VERSION:
1559 // &str = "…"` at this crate — the canonical drift footgun where
1560 // a sibling local `pub const` could happen to carry the same
1561 // string at the source while pointing at a different `&'static`
1562 // allocation — is a build-time test failure naming the offending
1563 // drift, not a silent chart-schema-parser reroute at
1564 // `helm template` time far from the drift site. Peer to
1565 // [`kube_key_spec_re_export_points_at_caixa_core_canonical`] /
1566 // [`default_library_name_re_export_points_at_caixa_core_canonical`]
1567 // on the sibling re-export axes.
1568 caixa_core::assert_str_reexport_identity(
1569 "HELM_CHART_API_VERSION",
1570 HELM_CHART_API_VERSION,
1571 caixa_core::HELM_CHART_API_VERSION,
1572 );
1573 }
1574
1575 #[test]
1576 fn chart_yaml_uses_lifted_helm_chart_api_version() {
1577 // Fail-before-pass-after pin on the production-code
1578 // substitution: [`build_chart_yaml`]'s `api_version` field
1579 // consults the lifted [`HELM_CHART_API_VERSION`] re-export at
1580 // its assignment site, so the rendered Chart.yaml's top-level
1581 // `apiVersion` axis is byte-identical to the canonical constant
1582 // by construction. Before the lift the field carried an inline
1583 // `"v2".into()` literal at [`build_chart_yaml`]; a future
1584 // refactor that accidentally reverted the substitution — or
1585 // any parallel per-renderer variant that inlined a stale
1586 // Helm 2 `"v1"` literal — would silently reroute the rendered
1587 // Chart.yaml through the wrong chart-schema parser at
1588 // `helm dependency build` / `helm template` time, so this pin
1589 // trips at caixa-helm build time. Peer to
1590 // `values_yaml_wrap_key_matches_chart_dependency_name` on the
1591 // sibling structural-cross-axis-invariant surface.
1592 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1593 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
1594 assert_eq!(
1595 chart.api_version, HELM_CHART_API_VERSION,
1596 "rendered Chart.yaml `apiVersion` must equal the lifted \
1597 HELM_CHART_API_VERSION verbatim — a drifted value silently \
1598 reroutes the rendered chart through the wrong Helm chart-schema \
1599 parser at `helm template` time"
1600 );
1601 }
1602
1603 #[test]
1604 fn helm_chart_type_application_re_export_points_at_caixa_core_canonical() {
1605 // The renderer's `HELM_CHART_TYPE_APPLICATION` was lifted from
1606 // the production-code inline `"application".into()` literal at
1607 // [`build_chart_yaml`]'s `chart_type` field assignment (formerly
1608 // `caixa-helm/src/lib.rs:354`) to a re-export of
1609 // [`caixa_core::HELM_CHART_TYPE_APPLICATION`] so the Helm 3
1610 // chart-schema per-chart-kind discriminator scalar-value the
1611 // rendered `lareira-<nome>` chart declares lives in exactly one
1612 // place across every caixa renderer. Pin the equality +
1613 // `&'static` static-data identity here so any local
1614 // re-introduction of a sibling `pub const
1615 // HELM_CHART_TYPE_APPLICATION: &str = "…"` at this crate — the
1616 // canonical drift footgun where a sibling local `pub const`
1617 // could happen to carry the same string at the source while
1618 // pointing at a different `&'static` allocation — is a
1619 // build-time test failure naming the offending drift, not a
1620 // silent per-release install-shape dispatch reroute at
1621 // `helm install` time far from the drift site. Peer to
1622 // [`helm_chart_api_version_re_export_points_at_caixa_core_canonical`]
1623 // on the sibling canonical-Helm-chart-schema-axis re-export
1624 // surface — completes the per-Chart.yaml `(apiVersion, type)`
1625 // canonical-scalar-axis re-export pair every rendered
1626 // `lareira-<nome>` chart declares at its top-level Chart.yaml
1627 // body.
1628 caixa_core::assert_str_reexport_identity(
1629 "HELM_CHART_TYPE_APPLICATION",
1630 HELM_CHART_TYPE_APPLICATION,
1631 caixa_core::HELM_CHART_TYPE_APPLICATION,
1632 );
1633 }
1634
1635 #[test]
1636 fn helm_chart_type_library_re_export_points_at_caixa_core_canonical() {
1637 // Re-export identity pin on the peer closed-set arm the
1638 // renderer's `HELM_CHART_TYPE_LIBRARY` alias resolves to. Peer
1639 // of `helm_chart_type_application_re_export_points_at_caixa_core_canonical`
1640 // on the sibling closed-set arm — the two pins together enshrine
1641 // the two-arm `{"application", "library"}` closed set at the
1642 // caixa-helm re-export surface as byte-identical `&'static`
1643 // static-data views onto the canonical caixa-core lifts, so any
1644 // local re-introduction of a sibling `pub const
1645 // HELM_CHART_TYPE_LIBRARY: &str = "…"` at this crate (the same
1646 // drift footgun the peer pin closes on the sibling arm) is a
1647 // build-time test failure naming the offending drift. The pin
1648 // also structurally forbids the two arms from converging on the
1649 // same `&'static` allocation — a future rebrand that
1650 // accidentally aliased `HELM_CHART_TYPE_LIBRARY` at the
1651 // [`caixa_core::HELM_CHART_TYPE_APPLICATION`] canonical would
1652 // pass this identity check but trip the caixa-core-side
1653 // `helm_chart_type_application_and_library_are_distinct` pin
1654 // paired to the two arms' distinctness contract.
1655 caixa_core::assert_str_reexport_identity(
1656 "HELM_CHART_TYPE_LIBRARY",
1657 HELM_CHART_TYPE_LIBRARY,
1658 caixa_core::HELM_CHART_TYPE_LIBRARY,
1659 );
1660 }
1661
1662 #[test]
1663 fn chart_yaml_uses_lifted_helm_chart_type_application() {
1664 // Fail-before-pass-after pin on the production-code substitution:
1665 // [`build_chart_yaml`]'s `chart_type` field consults the lifted
1666 // [`HELM_CHART_TYPE_APPLICATION`] re-export at its assignment
1667 // site, so the rendered Chart.yaml's top-level `type` axis is
1668 // byte-identical to the canonical constant by construction.
1669 // Before the lift the field carried an inline `"application".into()`
1670 // literal at [`build_chart_yaml`]; a future refactor that
1671 // accidentally reverted the substitution — or any parallel
1672 // per-renderer variant that inlined a `"library"` literal (the
1673 // sibling closed-set value from the Helm chart-schema's
1674 // per-chart-kind enum) — would silently reroute the rendered
1675 // Chart.yaml through the wrong per-release install-shape
1676 // dispatch at `helm install` time (Helm refuses to install a
1677 // `library` chart directly), so this pin trips at caixa-helm
1678 // build time. Peer to `chart_yaml_uses_lifted_helm_chart_api_version`
1679 // on the sibling per-Chart.yaml top-level `(apiVersion, type)`
1680 // canonical-scalar-axis pin pair — extends the per-Chart.yaml
1681 // top-level canonical-scalar-axis production-emit-pin
1682 // discipline from the `apiVersion` half onto the sibling `type`
1683 // half.
1684 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1685 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
1686 assert_eq!(
1687 chart.chart_type, HELM_CHART_TYPE_APPLICATION,
1688 "rendered Chart.yaml `type` must equal the lifted \
1689 HELM_CHART_TYPE_APPLICATION verbatim — a drifted value \
1690 silently reroutes the rendered chart through the wrong \
1691 per-release install-shape dispatch at `helm install` time \
1692 (Helm refuses to install a `library` chart directly, or \
1693 silently treats an unrecognized value as the default \
1694 `application` shape masking the schema violation)"
1695 );
1696 }
1697
1698 #[test]
1699 fn helm_chart_key_type_re_export_points_at_caixa_core_canonical() {
1700 // The renderer's `HELM_CHART_KEY_TYPE` was lifted from the
1701 // sole production-side inline `"type"` literal at [`ChartYaml`]'s
1702 // `chart_type` field `#[serde(rename = "type")]` attribute
1703 // (formerly `caixa-helm/src/lib.rs:149`) to a re-export of
1704 // [`caixa_core::HELM_CHART_KEY_TYPE`] so the Helm 3 top-level
1705 // per-chart-kind discriminator YAML axis-key lives in exactly
1706 // one place across every caixa renderer. Pin the equality +
1707 // `&'static` static-data identity here so any local
1708 // re-introduction of a sibling `pub const HELM_CHART_KEY_TYPE:
1709 // &str = "…"` at this crate — the canonical drift footgun
1710 // where a sibling local `pub const` could happen to carry the
1711 // same string at the source while pointing at a different
1712 // `&'static` allocation — is a build-time test failure naming
1713 // the offending drift, not a silent Helm-chart-schema-parser
1714 // per-chart-kind-defaulting reroute at `helm dependency build`
1715 // / `helm lint` / `helm template` / `helm install` time far
1716 // from the drift site. Peer to
1717 // [`helm_chart_type_application_re_export_points_at_caixa_core_canonical`]
1718 // / [`helm_chart_type_library_re_export_points_at_caixa_core_canonical`]
1719 // on the sibling per-chart-kind axis-value re-export surface —
1720 // completes the per-Chart.yaml per-chart-kind discriminator
1721 // axis's `(key, value-set)` canonical re-export trio at the
1722 // caixa-helm surface.
1723 caixa_core::assert_str_reexport_identity(
1724 "HELM_CHART_KEY_TYPE",
1725 HELM_CHART_KEY_TYPE,
1726 caixa_core::HELM_CHART_KEY_TYPE,
1727 );
1728 }
1729
1730 #[test]
1731 fn helm_chart_key_app_version_re_export_points_at_caixa_core_canonical() {
1732 // The renderer's `HELM_CHART_KEY_APP_VERSION` was lifted from
1733 // the sole production-side inline `"appVersion"` literal at
1734 // [`ChartYaml`]'s `app_version` field
1735 // `#[serde(rename = "appVersion")]` attribute (formerly
1736 // `caixa-helm/src/lib.rs:152`) to a re-export of
1737 // [`caixa_core::HELM_CHART_KEY_APP_VERSION`] so the Helm 3
1738 // top-level per-chart-app-version YAML axis-key lives in
1739 // exactly one place across every caixa renderer. Pin the
1740 // equality + `&'static` static-data identity here so any
1741 // local re-introduction of a sibling `pub const
1742 // HELM_CHART_KEY_APP_VERSION: &str = "…"` at this crate — the
1743 // canonical drift footgun where a sibling local `pub const`
1744 // could happen to carry the same string at the source while
1745 // pointing at a different `&'static` allocation — is a
1746 // build-time test failure naming the offending drift, not a
1747 // silent Helm-chart-schema-parser field-drop at every
1748 // downstream Artifact Hub / `helm search` chart-consumer far
1749 // from the drift site. Peer to
1750 // [`helm_chart_key_type_re_export_points_at_caixa_core_canonical`]
1751 // on the sibling per-Chart.yaml top-level YAML axis-key
1752 // re-export surface — completes the per-Chart.yaml top-level
1753 // YAML axis-key re-export pair at the caixa-helm surface for
1754 // the two serde-rename-literal-only axes.
1755 caixa_core::assert_str_reexport_identity(
1756 "HELM_CHART_KEY_APP_VERSION",
1757 HELM_CHART_KEY_APP_VERSION,
1758 caixa_core::HELM_CHART_KEY_APP_VERSION,
1759 );
1760 }
1761
1762 #[test]
1763 fn chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type() {
1764 // Fail-before-pass-after drift-detection pin on the
1765 // `#[serde(rename = "type")]` attribute at [`ChartYaml`]'s
1766 // `chart_type` field. Rust's attribute grammar admits only
1767 // string literals so the lifted [`HELM_CHART_KEY_TYPE`]
1768 // constant cannot substitute for the literal syntactically at
1769 // the attribute-argument site — a future refactor that
1770 // dropped the `#[serde(rename = "type")]` attribute (or
1771 // changed the target key to `"Type"` / `"kind"` /
1772 // `"chartType"`) would silently serialize the field under
1773 // Rust's default snake_case `chart_type:` key, which Helm's
1774 // chart-schema parser silently ignores as an unknown top-
1775 // level key, defaulting the per-chart-kind axis to
1776 // `application` with no process-log signal. This pin closes
1777 // the drift by round-tripping a rendered `Chart.yaml` through
1778 // `serde_yaml::from_str::<serde_yaml::Value>` and asserting
1779 // the top-level `Mapping::get(HELM_CHART_KEY_TYPE)` resolves
1780 // (rather than serializing through the [`ChartYaml`]-typed
1781 // deserializer that would silently absorb the rename drift
1782 // via `#[serde(default)]` fall-through at the struct-side).
1783 // Peer to
1784 // [`chart_yaml_uses_lifted_helm_chart_type_application`] on
1785 // the sibling per-Chart.yaml per-chart-kind axis-value
1786 // production-emit pin — the two pins together enforce the
1787 // full `(key, value)` production-emit pair at the caixa-helm
1788 // surface for the per-Chart.yaml per-chart-kind discriminator
1789 // axis.
1790 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1791 let doc = parse_yaml_at_path(&dir.files, HELM_CHART_YAML_FILENAME);
1792 let mapping = doc.as_mapping().expect(
1793 "rendered Chart.yaml must be a top-level YAML mapping per \
1794 the Helm 3 chart-schema shape",
1795 );
1796 assert!(
1797 kube_has(mapping, HELM_CHART_KEY_TYPE),
1798 "rendered Chart.yaml must carry a top-level {HELM_CHART_KEY_TYPE:?} \
1799 axis-key — a drift on the `#[serde(rename = {HELM_CHART_KEY_TYPE:?})]` \
1800 attribute at ChartYaml's `chart_type` field silently reroutes the \
1801 per-chart-kind discriminator axis through Rust's default snake_case \
1802 serialization (`chart_type:`), which Helm's chart-schema parser \
1803 silently ignores as an unknown top-level key (defaulting the \
1804 per-chart-kind axis to `application` with no process-log signal)"
1805 );
1806 }
1807
1808 #[test]
1809 fn chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version() {
1810 // Fail-before-pass-after drift-detection pin on the
1811 // `#[serde(rename = "appVersion")]` attribute at [`ChartYaml`]'s
1812 // `app_version` field. Same attribute-literal-only-grammar
1813 // constraint the peer
1814 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1815 // pin closes on the sibling per-Chart.yaml top-level YAML
1816 // axis-key applies here: a future refactor that dropped the
1817 // `#[serde(rename = "appVersion")]` attribute (or changed the
1818 // target key to `"AppVersion"` / `"applicationVersion"` /
1819 // `"appversion"`) would silently serialize the field under
1820 // Rust's default snake_case `app_version:` key, which Helm's
1821 // chart-schema parser silently drops from the parsed
1822 // chart-metadata shape, and every downstream Artifact Hub /
1823 // `helm search` per-chart index falls back to "no application
1824 // version" for the rendered chart. This pin closes the drift
1825 // by round-tripping a rendered `Chart.yaml` through
1826 // `serde_yaml::from_str::<serde_yaml::Value>` (rather than
1827 // through the [`ChartYaml`]-typed deserializer that would
1828 // silently absorb the rename drift). Peer to
1829 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1830 // on the sibling per-Chart.yaml top-level YAML axis-key
1831 // serialization pin surface — completes the per-Chart.yaml
1832 // top-level YAML axis-key production-emit pin pair at the
1833 // caixa-helm surface for the two serde-rename-literal-only
1834 // axes.
1835 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1836 let doc = parse_yaml_at_path(&dir.files, HELM_CHART_YAML_FILENAME);
1837 let mapping = doc.as_mapping().expect(
1838 "rendered Chart.yaml must be a top-level YAML mapping per \
1839 the Helm 3 chart-schema shape",
1840 );
1841 assert!(
1842 kube_has(mapping, HELM_CHART_KEY_APP_VERSION),
1843 "rendered Chart.yaml must carry a top-level \
1844 {HELM_CHART_KEY_APP_VERSION:?} axis-key — a drift on the \
1845 `#[serde(rename = {HELM_CHART_KEY_APP_VERSION:?})]` attribute at \
1846 ChartYaml's `app_version` field silently reroutes the per-chart \
1847 underlying-application-version axis through Rust's default \
1848 snake_case serialization (`app_version:`), which Helm's \
1849 chart-schema parser silently drops from the parsed chart-metadata \
1850 shape (every downstream Artifact Hub / `helm search` per-chart \
1851 index falls back to \"no application version\" for the rendered \
1852 chart with no process-log signal at the substrate-side emitter site)"
1853 );
1854 }
1855
1856 #[test]
1857 fn chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version() {
1858 // Fail-before-pass-after drift-detection pin on the
1859 // `#[serde(rename = "apiVersion")]` attribute at [`ChartYaml`]'s
1860 // `api_version` field. Same attribute-literal-only-grammar
1861 // constraint the peer
1862 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1863 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
1864 // pins close on the sibling per-Chart.yaml top-level YAML
1865 // axis-keys applies here: a future refactor that dropped the
1866 // `#[serde(rename = "apiVersion")]` attribute (or changed the
1867 // target key to `"ApiVersion"` / `"apiversion"` /
1868 // `"schemaVersion"`) would silently serialize the field under
1869 // Rust's default snake_case `api_version:` key, which Helm's
1870 // chart-schema parser rejects at `helm lint` / `helm
1871 // dependency build` / `helm template` time with an "apiVersion
1872 // is required" error far from the drift site — every downstream
1873 // `lareira-<nome>` chart consumer drops with no field naming
1874 // the serde-rename-drift root cause. This pin closes the drift
1875 // by round-tripping a rendered `Chart.yaml` through
1876 // `serde_yaml::from_str::<serde_yaml::Value>` (rather than
1877 // through the [`ChartYaml`]-typed deserializer that would
1878 // silently absorb the rename drift via `#[serde(default)]`
1879 // fall-through at the struct-side). Peer to
1880 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1881 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
1882 // on the sibling per-Chart.yaml top-level YAML axis-key
1883 // serialization pin surface — completes the per-Chart.yaml
1884 // top-level YAML axis-key production-emit pin trio at the
1885 // caixa-helm surface for the three serde-rename-literal-only
1886 // axes.
1887 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
1888 let doc = parse_yaml_at_path(&dir.files, HELM_CHART_YAML_FILENAME);
1889 let mapping = doc.as_mapping().expect(
1890 "rendered Chart.yaml must be a top-level YAML mapping per \
1891 the Helm 3 chart-schema shape",
1892 );
1893 assert!(
1894 kube_has(mapping, HELM_CHART_KEY_API_VERSION),
1895 "rendered Chart.yaml must carry a top-level \
1896 {HELM_CHART_KEY_API_VERSION:?} axis-key — a drift on the \
1897 `#[serde(rename = {HELM_CHART_KEY_API_VERSION:?})]` attribute at \
1898 ChartYaml's `api_version` field silently reroutes the per-chart \
1899 chart-schema-apiVersion axis through Rust's default snake_case \
1900 serialization (`api_version:`), which Helm's chart-schema parser \
1901 rejects at `helm lint` / `helm template` time with an \"apiVersion \
1902 is required\" error far from the drift site"
1903 );
1904 }
1905
1906 #[test]
1907 fn chart_dependency_serializes_tetrad_under_lifted_helm_chart_dependency_keys() {
1908 // Fail-before-pass-after drift-detection pin on the per-
1909 // `dependencies[]`-entry sub-mapping serde field-name tetrad
1910 // at [`ChartDependency`]. The four fields are identity-mapped
1911 // to their target wire keys today (no `#[serde(rename)]` or
1912 // `#[serde(rename_all)]` attribute on the struct), so a drift
1913 // would surface as one of two shapes: a rename of the Rust
1914 // field (`pub name` → `pub nome`) that silently rebrands the
1915 // wire key, or a `#[serde(rename_all = "camelCase")]` attribute
1916 // addition that stays a no-op on the four lowercase-identity
1917 // fields today but silently activates on a future field
1918 // addition (e.g. an `import_values: Option<Vec<String>>` axis
1919 // matching Helm 3's per-dep `import-values` sub-key). Either
1920 // shape silently reroutes the per-dep sub-mapping through a
1921 // Helm-per-dep-resolver drop at `helm dependency build` time
1922 // far from the drift site (Helm silently drops the drifted
1923 // per-dep sub-mapping field and the per-dep resolver falls
1924 // back to the parsed-shape defaults). This pin closes the
1925 // drift by serializing a fully-populated [`ChartDependency`]
1926 // (`alias` set to a non-`None` value so the
1927 // `#[serde(skip_serializing_if = "Option::is_none")]`
1928 // attribute doesn't elide the axis from the emitted YAML)
1929 // through `serde_yaml::to_value` and asserting each of the
1930 // four per-dep sub-mapping wire keys resolves via
1931 // `Mapping::get(HELM_CHART_DEPENDENCY_KEY_*)`. Peer to
1932 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
1933 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
1934 // / [`chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version`]
1935 // on the sibling per-Chart.yaml top-level serde-rename-literal-
1936 // only axis-key drift-detection pin trio (cc44e4b / d29bc23) —
1937 // extends the drift-detection discipline from the per-Chart.yaml
1938 // top-level serde-rename-literal axes onto the per-
1939 // `dependencies[]`-entry sub-mapping serde-field-name tetrad.
1940 let dep = ChartDependency {
1941 name: "pleme-computeunit".into(),
1942 version: "~0.1.0".into(),
1943 repository: "file://../pleme-computeunit".into(),
1944 alias: Some("acme-alias".into()),
1945 };
1946 let doc = serde_yaml::to_value(&dep).unwrap();
1947 let mapping = doc.as_mapping().expect(
1948 "ChartDependency must serialize to a top-level YAML mapping per \
1949 the Helm 3 per-dep sub-mapping shape",
1950 );
1951 for key in [
1952 HELM_CHART_DEPENDENCY_KEY_NAME,
1953 HELM_CHART_DEPENDENCY_KEY_VERSION,
1954 HELM_CHART_DEPENDENCY_KEY_REPOSITORY,
1955 HELM_CHART_DEPENDENCY_KEY_ALIAS,
1956 ] {
1957 assert!(
1958 kube_has(mapping, key),
1959 "serialized ChartDependency must carry a top-level {key:?} \
1960 axis-key — a drift on the `ChartDependency` struct's serde \
1961 field-name (a Rust-side rename, an added \
1962 `#[serde(rename_all)]` attribute, an added `#[serde(rename)]` \
1963 per-field override) silently reroutes the per-dep sub-mapping \
1964 through a Helm-per-dep-resolver drop at `helm dependency \
1965 build` time far from the drift site (Helm silently drops the \
1966 drifted per-dep sub-mapping field and the per-dep resolver \
1967 falls back to the parsed-shape defaults); the emitted mapping \
1968 keys are {keys:?}",
1969 keys = mapping_string_keys(mapping)
1970 );
1971 }
1972 }
1973
1974 #[test]
1975 fn chart_yaml_serializes_dependencies_axis_under_lifted_helm_chart_key_dependencies() {
1976 // Fail-before-pass-after drift-detection pin on the top-level
1977 // per-chart dependency-list YAML axis-key at [`ChartYaml`]'s
1978 // `dependencies` field. The Rust field name and the emitted
1979 // wire key coincide by default today (no `#[serde(rename)]`
1980 // attribute on the field, no `#[serde(rename_all = "…")]`
1981 // attribute on the struct — so serde emits `dependencies:`
1982 // verbatim as the top-level list-container YAML key). A future
1983 // hostile refactor could silently rebrand the wire key in
1984 // three shapes:
1985 //
1986 // - a rename of the Rust field itself (`pub dependencies:
1987 // Vec<ChartDependency>` → `pub deps: Vec<ChartDependency>`
1988 // / `pub chart_dependencies: …`), which serde would then
1989 // serialize as `deps:` / `chart_dependencies:` verbatim;
1990 // - an added `#[serde(rename_all = "camelCase")]` /
1991 // `"snake_case"` / `"kebab-case"` attribute on the struct
1992 // itself — a no-op on the four identity-mapped top-level
1993 // lowercase keys (`name` / `description` / `version` /
1994 // `dependencies`) today but silently activates on a future
1995 // multi-word field addition (e.g. an `icon_url` axis
1996 // matching Helm 3's per-chart `icon:` future-schema slot);
1997 // - an added `#[serde(rename = "deps")]` per-field override
1998 // at the site of the `dependencies` field.
1999 //
2000 // Under any of the three shapes Helm's chart-schema parser
2001 // silently drops the entire per-chart dep list from the
2002 // parsed chart-metadata (unknown top-level YAML keys silently
2003 // ignored per the Helm 3 chart-schema fallthrough), `helm
2004 // dependency build` finds no chart to vendor, and every
2005 // rendered `lareira-<nome>` chart's install fails with
2006 // `template: no template ... associated with template ...`
2007 // far from the drift site with no field naming the top-level-
2008 // list-key-drift root cause. This pin closes the drift by
2009 // round-tripping a rendered `Chart.yaml` through
2010 // `serde_yaml::from_str::<serde_yaml::Value>` and asserting
2011 // the top-level `Mapping::get(HELM_CHART_KEY_DEPENDENCIES)`
2012 // resolves — rather than through the [`ChartYaml`]-typed
2013 // deserializer that would silently absorb any of the three
2014 // drift shapes via `#[serde(default)]` fall-through at the
2015 // struct-side. Peer to
2016 // [`chart_yaml_serializes_type_axis_under_lifted_helm_chart_key_type`]
2017 // / [`chart_yaml_serializes_app_version_axis_under_lifted_helm_chart_key_app_version`]
2018 // / [`chart_yaml_serializes_api_version_axis_under_lifted_helm_chart_key_api_version`]
2019 // on the sibling per-Chart.yaml top-level YAML axis-key
2020 // serialization pin surface (d29bc23, cc44e4b) — extends the
2021 // per-Chart.yaml top-level YAML axis-key production-emit pin
2022 // trio those closed onto the fourth top-level axis-key, the
2023 // parent list-container the already-lifted per-
2024 // `dependencies[]`-entry sub-mapping tetrad
2025 // [`HELM_CHART_DEPENDENCY_KEY_NAME`] /
2026 // [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
2027 // [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
2028 // [`HELM_CHART_DEPENDENCY_KEY_ALIAS`] mounts one level down.
2029 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
2030 let doc = parse_yaml_at_path(&dir.files, HELM_CHART_YAML_FILENAME);
2031 let mapping = doc.as_mapping().expect(
2032 "rendered Chart.yaml must be a top-level YAML mapping per \
2033 the Helm 3 chart-schema shape",
2034 );
2035 assert!(
2036 kube_has(mapping, HELM_CHART_KEY_DEPENDENCIES),
2037 "rendered Chart.yaml must carry a top-level \
2038 {HELM_CHART_KEY_DEPENDENCIES:?} axis-key — a drift on the \
2039 `ChartYaml.dependencies` field's serde field-name (a Rust-side \
2040 rename to `deps` / `chart_dependencies`, an added \
2041 `#[serde(rename_all)]` attribute on the enclosing struct, an \
2042 added `#[serde(rename)]` per-field override) silently reroutes \
2043 the per-chart dependency-list axis through an unrecognized \
2044 top-level YAML key (`deps:` / `chartDependencies:` / \
2045 `chart_dependencies:`), which Helm's chart-schema parser \
2046 silently drops from the parsed chart-metadata shape (every \
2047 rendered `lareira-<nome>` chart's install fails with \
2048 `template: no template ... associated with template ...` at \
2049 `helm dependency build` / `helm template` time far from the \
2050 drift site with no field naming the top-level-list-key-drift \
2051 root cause); the emitted top-level mapping keys are {keys:?}",
2052 keys = mapping_string_keys(mapping)
2053 );
2054 }
2055
2056 #[test]
2057 fn helm_chart_key_dependencies_re_export_points_at_caixa_core_canonical() {
2058 // The renderer's [`HELM_CHART_KEY_DEPENDENCIES`] was lifted onto
2059 // a re-export of [`caixa_core::HELM_CHART_KEY_DEPENDENCIES`] so
2060 // the Helm 3 per-Chart.yaml top-level dependency-list-container
2061 // YAML axis-key — the parent whose per-`dependencies[]`-entry
2062 // sub-mapping tetrad [`HELM_CHART_DEPENDENCY_KEY_NAME`] /
2063 // [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
2064 // [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
2065 // [`HELM_CHART_DEPENDENCY_KEY_ALIAS`] mounts one level down —
2066 // lives in exactly one place across every caixa renderer. Pin
2067 // the equality + `&'static` static-data identity here so any
2068 // local re-introduction of a sibling `pub const
2069 // HELM_CHART_KEY_DEPENDENCIES: &str = "…"` at this crate — the
2070 // canonical drift footgun where a sibling local `pub const`
2071 // could happen to carry the same string at the source while
2072 // pointing at a different `&'static` allocation — is a build-
2073 // time test failure naming the offending drift, not a silent
2074 // per-Chart.yaml top-level-list-key reroute at `helm dependency
2075 // build` / `helm lint` / `helm template` time far from the
2076 // drift site. Peer to
2077 // [`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`]
2078 // and every other `helm_chart_*_re_export_points_at_caixa_core_canonical`
2079 // pin on the sibling canonical-Helm-chart-schema-body-axis
2080 // re-export surface — extends the per-Chart.yaml top-level
2081 // YAML axis-key re-export identity discipline onto the fourth
2082 // top-level axis-key at the caixa-helm surface.
2083 caixa_core::assert_str_reexport_identity(
2084 "HELM_CHART_KEY_DEPENDENCIES",
2085 HELM_CHART_KEY_DEPENDENCIES,
2086 caixa_core::HELM_CHART_KEY_DEPENDENCIES,
2087 );
2088 }
2089
2090 #[test]
2091 fn render_opts_default_library_name_follows_lifted_constant() {
2092 // [`RenderOpts::default()`] sets `library_name` from
2093 // [`DEFAULT_LIBRARY_NAME`]; pin that the lift preserves the
2094 // default-knob value bit-for-bit. A future refactor that
2095 // detaches `RenderOpts::default()` from the lifted constant —
2096 // accidentally re-introducing an inline `"pleme-computeunit"`
2097 // literal in the impl — would silently break the shared-shape
2098 // contract with caixa-flux (which uses the same constant
2099 // directly for its `helmrelease.yaml` wrap key); this test
2100 // surfaces the regression at build time rather than at
2101 // apply time as a silent values-routing no-op.
2102 let opts = RenderOpts::default();
2103 assert_eq!(opts.library_name, caixa_core::DEFAULT_LIBRARY_NAME);
2104 assert_eq!(opts.library_name, "pleme-computeunit");
2105 }
2106
2107 #[test]
2108 fn helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical() {
2109 // The renderer's `HELM_CHART_YAML_FILENAME` was lifted from the
2110 // seven production + test-side inline `"Chart.yaml"` /
2111 // `PathBuf::from("Chart.yaml")` / `chart_root.join("Chart.yaml")`
2112 // literals across [`render_chart_for_servico`]'s `ChartDir`
2113 // metadata-file `path` emit site + every test-side round-trip
2114 // navigator that reaches into the rendered `ChartDir` by the
2115 // metadata filename to a re-export of
2116 // [`caixa_core::HELM_CHART_YAML_FILENAME`] so the Helm 3
2117 // per-chart-directory metadata-file filename lives in exactly one
2118 // place across every caixa renderer. Pin the equality +
2119 // `&'static` static-data identity here so any local
2120 // re-introduction of a sibling `pub const
2121 // HELM_CHART_YAML_FILENAME: &str = "…"` at this crate — the
2122 // canonical drift footgun where a sibling local `pub const` could
2123 // happen to carry the same string at the source while pointing
2124 // at a different `&'static` allocation — is a build-time test
2125 // failure naming the offending drift, not a silent
2126 // Helm-chart-schema-parser "Chart.yaml file is missing" reroute
2127 // at `helm dependency build` / `helm lint` / `helm template` /
2128 // `helm install` time far from the drift site. Peer to
2129 // [`helm_chart_api_version_re_export_points_at_caixa_core_canonical`]
2130 // / [`helm_chart_type_application_re_export_points_at_caixa_core_canonical`]
2131 // on the sibling canonical-Helm-chart-schema-body-axis re-export
2132 // surfaces — completes the per-`lareira-<nome>`-chart-directory
2133 // `(filename, apiVersion, type)` canonical-scalar-axis re-export
2134 // triple every rendered chart declares at its top-level metadata
2135 // file.
2136 caixa_core::assert_str_reexport_identity(
2137 "HELM_CHART_YAML_FILENAME",
2138 HELM_CHART_YAML_FILENAME,
2139 caixa_core::HELM_CHART_YAML_FILENAME,
2140 );
2141 }
2142
2143 #[test]
2144 fn helm_values_yaml_filename_re_export_points_at_caixa_core_canonical() {
2145 // The renderer's `HELM_VALUES_YAML_FILENAME` was lifted from the
2146 // twelve production + test-side inline `"values.yaml"` /
2147 // `PathBuf::from("values.yaml")` / `chart_root.join("values.yaml")`
2148 // literals across [`render_chart_for_servico`]'s `ChartDir`
2149 // values-file `path` emit site + every test-side round-trip
2150 // navigator that reaches into the rendered `ChartDir` by the
2151 // values filename to a re-export of
2152 // [`caixa_core::HELM_VALUES_YAML_FILENAME`] so the Helm 3
2153 // per-chart-directory values-file filename lives in exactly one
2154 // place across every caixa renderer. Pin the equality +
2155 // `&'static` static-data identity here so any local
2156 // re-introduction of a sibling `pub const
2157 // HELM_VALUES_YAML_FILENAME: &str = "…"` at this crate — the
2158 // canonical drift footgun where a sibling local `pub const` could
2159 // happen to carry the same string at the source while pointing
2160 // at a different `&'static` allocation — is a build-time test
2161 // failure naming the offending drift, not a silent
2162 // Helm-per-chart-values-loader fall-through to the empty values
2163 // block at `helm template` / `helm install` time far from the
2164 // drift site (where the workload silently comes up under the
2165 // library chart's admission-time defaults with no per-Servico
2166 // M2 overlay applied). Peer to
2167 // [`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`]
2168 // on the sibling canonical-Helm-per-chart-directory-metadata-file-
2169 // axis re-export surface — completes the
2170 // per-`lareira-<nome>`-chart-directory `(Chart.yaml, values.yaml)`
2171 // canonical-per-chart-directory-filename-axis re-export pair
2172 // every rendered chart declares as its two schema-load-bearing
2173 // `ChartDir::files` entries.
2174 caixa_core::assert_str_reexport_identity(
2175 "HELM_VALUES_YAML_FILENAME",
2176 HELM_VALUES_YAML_FILENAME,
2177 caixa_core::HELM_VALUES_YAML_FILENAME,
2178 );
2179 }
2180
2181 #[test]
2182 fn helm_chart_readme_filename_re_export_points_at_caixa_core_canonical() {
2183 // The renderer's `HELM_CHART_README_FILENAME` was lifted from the
2184 // three production + test-side inline `"README.md"` literals
2185 // across [`render_chart_for_servico`]'s `ChartDir` readme-file
2186 // `path` emit site + every test-side round-trip navigator that
2187 // reaches into the rendered `ChartDir` by the readme filename
2188 // (the [`renders_three_files`] files-vec-membership pin + the
2189 // [`ChartDir::write_to`] post-write existence pin) to a
2190 // re-export of [`caixa_core::HELM_CHART_README_FILENAME`] so the
2191 // per-`lareira-<nome>` chart-directory human-facing readme
2192 // filename lives in exactly one place across every caixa
2193 // renderer. Pin the equality + `&'static` static-data identity
2194 // here so any local re-introduction of a sibling `pub const
2195 // HELM_CHART_README_FILENAME: &str = "…"` at this crate — the
2196 // canonical drift footgun where a sibling local `pub const`
2197 // could happen to carry the same string at the source while
2198 // pointing at a different `&'static` allocation — is a build-
2199 // time test failure naming the offending drift, not a silent
2200 // GitHub / Artifact Hub / any per-chart README-surfacing UI
2201 // fall-through to "no README available" at chart-consumption
2202 // time far from the drift site. Peer to
2203 // [`helm_chart_yaml_filename_re_export_points_at_caixa_core_canonical`]
2204 // / [`helm_values_yaml_filename_re_export_points_at_caixa_core_canonical`]
2205 // on the sibling canonical-Helm-per-chart-directory-filename
2206 // axis re-export surfaces — completes the
2207 // per-`lareira-<nome>`-chart-directory `(Chart.yaml,
2208 // values.yaml, README.md)` canonical-per-chart-directory-
2209 // filename-axis re-export triple every rendered chart declares
2210 // as its three `ChartDir::files` entries.
2211 caixa_core::assert_str_reexport_identity(
2212 "HELM_CHART_README_FILENAME",
2213 HELM_CHART_README_FILENAME,
2214 caixa_core::HELM_CHART_README_FILENAME,
2215 );
2216 }
2217
2218 #[test]
2219 fn helm_values_key_enabled_re_export_points_at_caixa_core_canonical() {
2220 // The renderer's `HELM_VALUES_KEY_ENABLED` was lifted from the
2221 // production-code inline `"enabled".to_string()` literal at
2222 // [`build_values_yaml`]'s
2223 // `block.insert("enabled".to_string(), Value::Bool(…))` values-
2224 // block-toggle insert (formerly `caixa-helm/src/lib.rs:389`) plus
2225 // its two test-side round-trip navigators
2226 // (`values_yaml_wraps_under_pleme_computeunit_key`,
2227 // `values_yaml_wrap_key_follows_library_name_override`) to a
2228 // re-export of [`caixa_core::HELM_VALUES_KEY_ENABLED`] so the
2229 // canonical `pleme-computeunit` library-chart values-block
2230 // enable-toggle key lives in exactly one place across every
2231 // caixa renderer. Pin the equality + `&'static` static-data
2232 // identity here so any local re-introduction of a sibling
2233 // `pub const HELM_VALUES_KEY_ENABLED: &str = "…"` at this crate
2234 // — the canonical drift footgun where a sibling local
2235 // `pub const` could happen to carry the same string at the
2236 // source while pointing at a different `&'static` allocation —
2237 // is a build-time test failure naming the offending drift, not
2238 // a silent per-values enable-toggle reroute at `helm template` /
2239 // `helm install` time far from the drift site (where the
2240 // workload silently comes up with the library chart's
2241 // admission-time defaults instead of the per-cluster override
2242 // the operator set). Peer to
2243 // [`helm_chart_api_version_re_export_points_at_caixa_core_canonical`]
2244 // / [`kube_key_spec_re_export_points_at_caixa_core_canonical`] /
2245 // [`default_library_name_re_export_points_at_caixa_core_canonical`]
2246 // on the sibling re-export axes +
2247 // `caixa_flux::tests::helm_values_key_enabled_re_export_points_at_caixa_core_canonical`
2248 // on the peer bundle-path renderer crate.
2249 caixa_core::assert_str_reexport_identity(
2250 "HELM_VALUES_KEY_ENABLED",
2251 HELM_VALUES_KEY_ENABLED,
2252 caixa_core::HELM_VALUES_KEY_ENABLED,
2253 );
2254 }
2255
2256 #[test]
2257 fn values_yaml_enable_toggle_key_pins_lifted_helm_values_key_enabled() {
2258 // Fail-before-pass-after pin on the production-code substitution:
2259 // [`build_values_yaml`]'s `block.insert(…, Value::Bool(…))`
2260 // consults the lifted [`HELM_VALUES_KEY_ENABLED`] re-export at
2261 // its insert site, so the rendered `values.yaml`'s per-values
2262 // enable-toggle axis is byte-identical to the canonical constant
2263 // by construction. Before the lift the field carried an inline
2264 // `"enabled".to_string()` literal; a future refactor that
2265 // accidentally reverted the substitution — or any parallel per-
2266 // renderer variant that inlined a stale `"enable"` /
2267 // `"disabled"` literal — would silently emit a values block
2268 // whose per-values enable-toggle lands under one key while
2269 // [`caixa_flux::cluster_bundle`]'s `HelmRelease`
2270 // `spec.values.<library>.enabled` per-cluster override lands
2271 // under another, so this pin trips at caixa-helm build time.
2272 // Peer to `chart_yaml_uses_lifted_helm_chart_api_version` on the
2273 // sibling structural-cross-axis-invariant surface — both close
2274 // the drift between a rendered-value navigator's `.get(…)` /
2275 // struct-field read on the constant and the production-code
2276 // emit site that consumes the same constant.
2277 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
2278 let parsed = parse_yaml_at_path(&dir.files, HELM_VALUES_YAML_FILENAME);
2279 let cu_block = parsed
2280 .get(DEFAULT_LIBRARY_NAME)
2281 .expect("must wrap under DEFAULT_LIBRARY_NAME");
2282 assert_eq!(
2283 cu_block.get(HELM_VALUES_KEY_ENABLED),
2284 Some(&serde_yaml::Value::Bool(false)),
2285 "rendered values.yaml `{DEFAULT_LIBRARY_NAME}.{HELM_VALUES_KEY_ENABLED}` must \
2286 equal the default-off toggle the lifted HELM_VALUES_KEY_ENABLED axis carries — \
2287 a drifted enable-toggle key silently splits the per-values enable-flip across \
2288 two sibling scalar names on the caixa-helm / caixa-flux consumer split"
2289 );
2290 }
2291
2292 #[test]
2293 fn computeunit_spec_key_module_re_export_points_at_caixa_core_canonical() {
2294 // The renderer's `COMPUTEUNIT_SPEC_KEY_MODULE` was lifted from
2295 // the two inline `"module"` test-side call sites in this crate
2296 // (`values_yaml_wraps_under_pleme_computeunit_key`'s per-values
2297 // module-block present-check + the peer navigator on the
2298 // `library_name`-override wrap-key axis
2299 // `values_yaml_wrap_key_follows_library_name_override`) — every
2300 // per-Servico ComputeUnit CRD `spec.module` sub-block readback
2301 // in this crate now navigates through the same `&'static str`
2302 // re-exported to a re-export of
2303 // [`caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE`] so the canonical
2304 // ComputeUnit-CRD per-`spec.*` wasm-module-reference axis lives
2305 // in exactly one place across every caixa renderer. Pin the
2306 // equality + static-data identity here so any local re-
2307 // introduction of a sibling `pub const COMPUTEUNIT_SPEC_KEY_MODULE:
2308 // &str = "…"` at this crate is a build-time test failure naming
2309 // the offending drift, not a silent per-Servico wasm-runtime-
2310 // binding drop at cluster-apply time. Peer to
2311 // [`helm_values_key_enabled_re_export_points_at_caixa_core_canonical`]
2312 // /
2313 // [`kube_key_spec_re_export_points_at_caixa_core_canonical`]
2314 // on the sibling canonical-Helm-load-bearing-string /
2315 // canonical-K8s-CR-body-key re-export axes +
2316 // `caixa_flux::tests::computeunit_spec_key_module_re_export_points_at_caixa_core_canonical`
2317 // on the peer per-Servico renderer crate.
2318 caixa_core::assert_str_reexport_identity(
2319 "COMPUTEUNIT_SPEC_KEY_MODULE",
2320 COMPUTEUNIT_SPEC_KEY_MODULE,
2321 caixa_core::COMPUTEUNIT_SPEC_KEY_MODULE,
2322 );
2323 }
2324
2325 #[test]
2326 fn computeunit_spec_key_trigger_re_export_points_at_caixa_core_canonical() {
2327 // Peer to
2328 // [`computeunit_spec_key_module_re_export_points_at_caixa_core_canonical`]
2329 // on the same ComputeUnit-CRD per-`spec.*` sub-block re-export
2330 // surface — pins the per-Servico invocation-shape sub-block
2331 // key's identity on the same trajectory.
2332 caixa_core::assert_str_reexport_identity(
2333 "COMPUTEUNIT_SPEC_KEY_TRIGGER",
2334 COMPUTEUNIT_SPEC_KEY_TRIGGER,
2335 caixa_core::COMPUTEUNIT_SPEC_KEY_TRIGGER,
2336 );
2337 }
2338
2339 #[test]
2340 fn computeunit_spec_key_capabilities_re_export_points_at_caixa_core_canonical() {
2341 // Peer to
2342 // [`computeunit_spec_key_module_re_export_points_at_caixa_core_canonical`]
2343 // and
2344 // [`computeunit_spec_key_trigger_re_export_points_at_caixa_core_canonical`]
2345 // on the same ComputeUnit-CRD per-`spec.*` sub-block re-export
2346 // surface — completes the substrate-side ComputeUnit-CRD
2347 // per-`spec.*` sub-block re-export triple in this crate on the
2348 // WASI-capability-token-list axis.
2349 caixa_core::assert_str_reexport_identity(
2350 "COMPUTEUNIT_SPEC_KEY_CAPABILITIES",
2351 COMPUTEUNIT_SPEC_KEY_CAPABILITIES,
2352 caixa_core::COMPUTEUNIT_SPEC_KEY_CAPABILITIES,
2353 );
2354 }
2355
2356 #[test]
2357 fn chart_file_alias_resolves_to_caixa_core_rendered_file() {
2358 // Type-alias identity pin: the [`ChartFile`] alias at this
2359 // crate's boundary resolves to the canonical
2360 // [`caixa_core::RenderedFile`] the substrate-side "one rendered
2361 // leaf artifact" shape lives at. `let _: ChartFile = <a
2362 // RenderedFile>` type-checks *iff* [`ChartFile`] is the aliased
2363 // canonical (not a sibling pub-struct re-declaration that
2364 // happens to carry the same field pair — that would compile
2365 // past the struct-literal navigators below but fail this
2366 // assignment). A drifted local `pub struct ChartFile { pub
2367 // path: PathBuf, pub contents: String }` at this crate — the
2368 // canonical drift footgun that would carry the same field pair
2369 // at the source while pointing at a different struct
2370 // definition — trips this pin at caixa-helm build time rather
2371 // than surfacing as a downstream `caixa_core::RenderedFile`
2372 // consumer refusing a `ChartFile`-shaped value at type-check
2373 // time far from the drift commit. Peer to the sibling
2374 // [`caixa_flux::BundleFile`]-alias-identity pin on the same
2375 // per-target-renderer canonical [`caixa_core::RenderedFile`]
2376 // re-export surface — both crates' per-artifact leaf type now
2377 // resolves through the same canonical struct definition, so a
2378 // future rebrand on the record shape lands at one caixa-core
2379 // edit and reaches both consumers by construction.
2380 let canonical: caixa_core::RenderedFile = caixa_core::RenderedFile {
2381 path: PathBuf::from(HELM_CHART_YAML_FILENAME),
2382 contents: String::new(),
2383 };
2384 let aliased: ChartFile = canonical.clone();
2385 assert_eq!(aliased, canonical);
2386 // Struct-literal construction still resolves through the alias
2387 // — the pre-lift `ChartFile { path, contents }` shape at every
2388 // production emit site (three sites in
2389 // `render_chart_for_servico_with`'s `ChartDir::files` assembly)
2390 // continues to compile, and the derive tuple travels through
2391 // the alias so downstream `ChartDir::files.iter().find(|f|
2392 // f.path == PathBuf::from(HELM_VALUES_YAML_FILENAME))`
2393 // navigators keep matching by `PartialEq` on `PathBuf`.
2394 let via_alias = ChartFile {
2395 path: PathBuf::from(HELM_VALUES_YAML_FILENAME),
2396 contents: format!("{DEFAULT_LIBRARY_NAME}:\n enabled: false\n"),
2397 };
2398 assert_eq!(via_alias.path.to_string_lossy(), HELM_VALUES_YAML_FILENAME);
2399 }
2400
2401 #[test]
2402 fn chart_file_new_constructor_travels_through_alias_to_canonical() {
2403 // Inherent-method-through-alias pin: the canonical
2404 // [`caixa_core::RenderedFile::new`] `impl Into<PathBuf>` /
2405 // `impl Into<String>` constructor every per-artifact leaf in
2406 // [`render_chart_for_servico_with`] now routes through
2407 // resolves at `ChartFile::new(…)` — Rust inherent methods
2408 // travel through a `pub type ChartFile = caixa_core::RenderedFile`
2409 // alias to the aliased canonical at name resolution, so a
2410 // drifted local `pub struct ChartFile { pub path: PathBuf, pub
2411 // contents: String }` at this crate would carry the field
2412 // pair the sibling type-alias-identity pin above still
2413 // accepts (both records share `pub path` / `pub contents`
2414 // shape) while dropping the constructor — the six sweep sites
2415 // in [`render_chart_for_servico_with`] would stop compiling
2416 // and the failing calls would name `ChartFile` directly,
2417 // making the drift-source unambiguous. This test pins the
2418 // constructor's per-alias reachability + the byte-identical
2419 // record shape against a `HELM_CHART_YAML_FILENAME`-keyed
2420 // probe so the pin fires at caixa-helm build time.
2421 let via_alias_new: ChartFile = ChartFile::new(HELM_CHART_YAML_FILENAME, "apiVersion: v2\n");
2422 let via_canonical_new = caixa_core::RenderedFile::new(
2423 HELM_CHART_YAML_FILENAME,
2424 String::from("apiVersion: v2\n"),
2425 );
2426 assert_eq!(via_alias_new, via_canonical_new);
2427 assert_eq!(via_alias_new.path, PathBuf::from(HELM_CHART_YAML_FILENAME));
2428 assert_eq!(via_alias_new.contents, "apiVersion: v2\n");
2429 }
2430
2431 #[test]
2432 fn render_opts_default_library_version_follows_lifted_constant() {
2433 // Peer of [`render_opts_default_library_name_follows_lifted_constant`]
2434 // (which pins the same alignment on the sibling
2435 // [`RenderOpts::library_name`] / [`DEFAULT_LIBRARY_NAME`] axis). The
2436 // [`RenderOpts::default()`] impl sets `library_version` from
2437 // [`DEFAULT_LIBRARY_VERSION`]; a future refactor that detached the
2438 // default-knob from the lifted constant — accidentally re-inlining
2439 // `"~0.1.0"` in the impl body — would silently split the value the
2440 // default knob threads into every rendered `Chart.yaml`
2441 // `dependencies[0].version` axis from the const the const's callers
2442 // (and this crate's future per-`DEFAULT_LIBRARY_VERSION` drift pins)
2443 // read. The two `Chart.yaml`-dep `(name, version)` scalar-axes now
2444 // share the same "default-knob follows lifted constant, byte for
2445 // byte" pin discipline the peer library-name axis carries.
2446 let opts = RenderOpts::default();
2447 assert_eq!(opts.library_version, DEFAULT_LIBRARY_VERSION);
2448 assert_eq!(opts.library_version, "~0.1.0");
2449 }
2450
2451 #[test]
2452 fn render_opts_default_enabled_default_follows_lifted_constant() {
2453 // Peer of [`render_opts_default_library_name_follows_lifted_constant`]
2454 // /
2455 // [`render_opts_default_library_version_follows_lifted_constant`]
2456 // / [`render_opts_default_library_repo_follows_lifted_constant`] —
2457 // the fourth leg of the [`RenderOpts::default()`]-body
2458 // default-knob-follows-lifted-constant quartet. The
2459 // [`RenderOpts::default()`] impl seeds `enabled_default` from
2460 // [`STANDALONE_LAREIRA_ENABLED_DEFAULT`]; every rendered
2461 // `lareira-<nome>` chart's `values.yaml` under-`<library>.enabled`
2462 // scalar reads through this knob, so a future refactor that
2463 // detached the default-knob from the lifted constant —
2464 // accidentally re-inlining `false` in the impl body — would
2465 // silently split the `bool` the default seed writes from the
2466 // const the drift-detection pin
2467 // [`standalone_lareira_enabled_default_pins_canonical_value`]
2468 // (in caixa-core) reads. The rendered values block would then
2469 // carry one `bool` at the emit site while the const-consuming
2470 // sibling test-fixture navigators (this crate's future per-
2471 // `STANDALONE_LAREIRA_ENABLED_DEFAULT` drift pins) read another,
2472 // and the substrate's chosen mirror-symmetric standalone /
2473 // composition per-values-block child-chart-enablement-toggle-
2474 // scalar-value default pair would silently disagree on the
2475 // standalone-path half. Peer with the sibling
2476 // `caixa_flux::tests::cluster_bundle_lareira_enabled_default_re_export_matches_caixa_core_canonical_value`
2477 // pin on the composition-path half of the same
2478 // [`HELM_VALUES_KEY_ENABLED`] scalar-axis pair.
2479 let opts = RenderOpts::default();
2480 assert_eq!(opts.enabled_default, STANDALONE_LAREIRA_ENABLED_DEFAULT);
2481 assert!(!opts.enabled_default);
2482 }
2483
2484 #[test]
2485 fn standalone_lareira_enabled_default_re_export_matches_caixa_core_canonical_value() {
2486 // The renderer's `STANDALONE_LAREIRA_ENABLED_DEFAULT` was lifted
2487 // from the [`RenderOpts::default()`] impl-body inline `false`
2488 // scalar-value literal at `caixa-helm/src/lib.rs:700` to a
2489 // re-export of [`caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT`]
2490 // so the substrate-side default the standalone per-chart path
2491 // seeds under the sibling [`HELM_VALUES_KEY_ENABLED`]
2492 // leaf-scalar-key lives in exactly one place across every caixa
2493 // renderer (this crate's standalone per-chart path + the peer
2494 // `caixa_flux::cluster_bundle`'s composition per-cluster-
2495 // `HelmRelease` values-overlay path, which reads through the
2496 // inverse [`caixa_flux::CLUSTER_BUNDLE_LAREIRA_ENABLED_DEFAULT`]
2497 // re-export). Pin the equality here so any local re-introduction
2498 // of a sibling `pub const STANDALONE_LAREIRA_ENABLED_DEFAULT:
2499 // bool = …` at this crate (the canonical drift footgun the peer
2500 // `CLUSTER_BUNDLE_LAREIRA_ENABLED_DEFAULT` re-export identity
2501 // pin's rationale names as the recurring shape) is a build-time
2502 // test failure naming the offending drift, not a silent
2503 // apply-time toggle-mismatch routing the standalone per-chart
2504 // `values.<library>.enabled` seed onto one substrate-side
2505 // opt-out convention while the peer composition-path override
2506 // routes onto another. Peer to the sibling
2507 // `caixa_flux::tests::cluster_bundle_lareira_enabled_default_re_export_matches_caixa_core_canonical_value`
2508 // on the composition-path half of the same
2509 // [`HELM_VALUES_KEY_ENABLED`] scalar-axis pair — the two
2510 // per-path re-export identity pins together lock the two peer
2511 // scalar-value defaults' per-crate re-exports onto their shared
2512 // caixa-core canonical.
2513 assert_eq!(
2514 STANDALONE_LAREIRA_ENABLED_DEFAULT,
2515 caixa_core::STANDALONE_LAREIRA_ENABLED_DEFAULT,
2516 "STANDALONE_LAREIRA_ENABLED_DEFAULT re-export must remain the \
2517 same `bool` as its caixa-core canonical — a drifted local \
2518 `pub const STANDALONE_LAREIRA_ENABLED_DEFAULT: bool = …` at \
2519 caixa-helm would silently split the substrate's chosen \
2520 standalone per-chart opt-out seed from the peer \
2521 composition-path force-on inversion the caixa-core canonical \
2522 encodes."
2523 );
2524 assert!(
2525 !STANDALONE_LAREIRA_ENABLED_DEFAULT,
2526 "STANDALONE_LAREIRA_ENABLED_DEFAULT must remain `false` — the \
2527 standalone per-chart path is the substrate-side opt-out path \
2528 where cluster operators must opt each caixa in per-cluster, \
2529 inverse of the composition per-cluster-HelmRelease values-\
2530 overlay path's opt-in force-on."
2531 );
2532 }
2533
2534 #[test]
2535 fn render_opts_default_library_repo_follows_lifted_constant() {
2536 // Peer of [`render_opts_default_library_name_follows_lifted_constant`]
2537 // /
2538 // [`render_opts_default_library_version_follows_lifted_constant`] —
2539 // the third leg of the per-`Chart.yaml`-dep
2540 // `(repository, name, version)` default-knob triple. The
2541 // [`RenderOpts::default()`] impl seeds `library_repo` from
2542 // [`DEFAULT_LIBRARY_REPO`]; every rendered `lareira-<nome>` chart's
2543 // `Chart.yaml` `dependencies[0].repository` field reads through
2544 // this knob, so a future refactor that detached the default-knob
2545 // from the lifted constant — re-inlining
2546 // `"file://../pleme-computeunit"` in the impl body — would silently
2547 // split the URL the default seed writes from the const the
2548 // drift-detection pin below
2549 // ([`default_library_repo_ends_with_lifted_default_library_name`])
2550 // reads.
2551 let opts = RenderOpts::default();
2552 assert_eq!(opts.library_repo, DEFAULT_LIBRARY_REPO);
2553 assert_eq!(opts.library_repo, "file://../pleme-computeunit");
2554 }
2555
2556 #[test]
2557 fn default_library_version_parses_as_valid_semver_requirement() {
2558 // Structural pin: [`DEFAULT_LIBRARY_VERSION`] carries a Cargo-shaped
2559 // semver-requirement string that lands verbatim in every rendered
2560 // `lareira-<nome>` chart's `Chart.yaml` `dependencies[0].version`
2561 // field. Helm 3's chart-schema parser (`helm dependency build`,
2562 // `helm lint`, `helm template`, `helm install`) validates the
2563 // scalar against the same `semver::VersionReq` grammar
2564 // [`caixa_core::parse_requirement`] wraps, and rejects a malformed
2565 // shape (`"~0.1.,0"` — paste-from-typography stray comma;
2566 // `"v0.1.0"` — accidental Zig-style publish-tag prefix leaking back
2567 // from [`caixa_core::DEFAULT_PUBLISH_TAG_PREFIX`] into the
2568 // requirement axis; `"0.1"` with a trailing sigil dropped by a
2569 // fat-fingered edit) with the load-bearing `Error: found operator
2570 // …, expected version` diagnostic surfacing at chart-consumption
2571 // time — far from the constant-drift commit's source, with no
2572 // field naming the offending caixa or the drifted default. Routing
2573 // through [`caixa_core::parse_requirement`] here — the same
2574 // requirement-parser entry-point every peer typed `:versao`
2575 // requirement slot (`:deps`, `:deps-dev`, `:membros`, `:children`)
2576 // routes through via
2577 // [`caixa_core::require_valid_versao_requirement`] — closes the
2578 // drift structurally at caixa-helm build time and pins the const's
2579 // accepted set to exactly the set the peer author-facing
2580 // requirement axes accept: any shape a caixa author cannot write
2581 // in `:deps :versao` is a shape the substrate cannot seed as the
2582 // library-chart-dep default. Peer of the sibling
2583 // [`default_library_repo_ends_with_lifted_default_library_name`]
2584 // structural pin on the co-resident `(name, version)` per-Chart.yaml
2585 // dep-scalar pair.
2586 caixa_core::parse_requirement(DEFAULT_LIBRARY_VERSION).unwrap_or_else(|e| {
2587 panic!(
2588 "DEFAULT_LIBRARY_VERSION {DEFAULT_LIBRARY_VERSION:?} must parse as a valid \
2589 semver::VersionReq — every rendered lareira-<nome> chart's Chart.yaml \
2590 dependencies[0].version axis lands this scalar verbatim, and Helm 3's \
2591 chart-schema parser rejects a malformed shape at chart-consumption time \
2592 far from the constant-drift commit's source: {e}",
2593 )
2594 });
2595 }
2596
2597 #[test]
2598 fn default_library_repo_ends_with_lifted_default_library_name() {
2599 // Structural cross-const coherence pin: [`DEFAULT_LIBRARY_REPO`]
2600 // embeds the [`DEFAULT_LIBRARY_NAME`] byte-string verbatim as its
2601 // trailing directory-name component (the canonical
2602 // `file://../<library-chart-name>` shape every sibling
2603 // `lareira-<nome>` chart's `Chart.yaml` `dependencies[0]` entry
2604 // consults for a two-axis `(name, repository)` per-dep tuple that
2605 // Helm's per-chart-dep resolver `(chart-source-scheme + chart-name)`
2606 // navigator round-trips). The two axes must stay coupled: the
2607 // library-chart-directory on disk (the repo's trailing component)
2608 // and the library-chart's declared `name:` in its own
2609 // [`DEFAULT_LIBRARY_NAME`]-published `Chart.yaml` are the same
2610 // load-bearing chart-name identity. Prior to this pin the two
2611 // consts were independently authored — a future substrate-side
2612 // library-chart rebrand (`pleme-computeunit` → `pleme-cu` on a
2613 // shorter-form migration, `pleme-computeunit` →
2614 // `caixa-computeunit` on a substrate-alignment migration, a
2615 // per-edition library-chart fork the [`DEFAULT_LIBRARY_NAME`]
2616 // docstring names as a trajectory item) on the
2617 // [`caixa_core::DEFAULT_LIBRARY_NAME`] canonical without a
2618 // coordinated edit on this crate's [`DEFAULT_LIBRARY_REPO`] would
2619 // silently emit rendered `Chart.yaml` documents whose
2620 // `dependencies[0].name` names the new chart while
2621 // `dependencies[0].repository` points at the old directory —
2622 // `helm dependency build` would refuse to resolve the dep ("chart
2623 // <new-name> not found in file://../<old-name>") at chart-
2624 // consumption time, far from the constant-rebrand commit's source,
2625 // with no field naming the two-axis coherence drift root cause.
2626 // Pinning the structural `ends_with(DEFAULT_LIBRARY_NAME)` invariant
2627 // here surfaces the drift as a caixa-helm build-time test failure
2628 // and forces the coordinated `(REPO, NAME)` edit to move together.
2629 // Peer of the sibling
2630 // [`default_library_version_parses_as_valid_semver_requirement`]
2631 // structural pin on the co-resident `(name, version)` per-Chart.yaml
2632 // dep-scalar pair — completes the `(repository, name, version)`
2633 // per-Chart.yaml-dep default-triple's structural pin surface.
2634 assert!(
2635 DEFAULT_LIBRARY_REPO.ends_with(DEFAULT_LIBRARY_NAME),
2636 "DEFAULT_LIBRARY_REPO {DEFAULT_LIBRARY_REPO:?} must terminate with the lifted \
2637 DEFAULT_LIBRARY_NAME {DEFAULT_LIBRARY_NAME:?} — the two-axis (repository, name) \
2638 per-Chart.yaml-dep tuple must resolve to the same library-chart identity on \
2639 disk, so a rebrand on either axis must move both",
2640 );
2641 }
2642
2643 #[test]
2644 fn chart_yaml_version_routes_through_caixa_versao_accessor() {
2645 // Fail-before-pass-after pin: the emit-side per-`Chart.yaml`
2646 // top-level `version:` scalar the [`build_chart_yaml`] fn
2647 // writes must derive from the typed
2648 // [`caixa_core::Caixa::versao`] accessor byte-for-byte.
2649 // Before this converge the emit site carried a raw
2650 // `caixa.versao.clone()` field access at
2651 // [`build_chart_yaml`]'s per-`Chart.yaml` version-field
2652 // insert position — one of the two production-code
2653 // `String`-carry sites of `Caixa::versao` on this fn's
2654 // emit path — and a future extension of the accessor
2655 // (a build-metadata canonicalization pass the CAIXA-SDLC
2656 // §I SemVer-2 pin acknowledges, an OCI-tag normalization
2657 // the M4 registry-alignment slot lands, a per-edition
2658 // pre-release-tag overlay the sibling `Caixa::edicao`
2659 // universal-axis 4-digit-ASCII-decimal-year scalar
2660 // dispatches through) that landed on the accessor but
2661 // not on this emit site would silently split the
2662 // per-`Chart.yaml` `version:` axis (the discriminator
2663 // Helm's per-chart resolver keys per-release
2664 // reconciliation off, the paired `HelmRelease`
2665 // `spec.chart.spec.version` binds through, and every
2666 // `helm template <chart>` / `helm install <release>
2667 // <chart>` / `helm upgrade <release> <chart>
2668 // --version` invocation names through) from every peer
2669 // read-side consumer of `Caixa::versao` (the
2670 // README-body `v{versao}` scalar at
2671 // [`build_readme`]:958 the paired `feira chart`
2672 // Nord-themed emit round-trips through, every peer
2673 // per-axis navigator via `Caixa::versao()`, the
2674 // `caixa_flux::programs_yaml_entry` per-entry
2675 // `versao:` scalar at caixa-flux/src/lib.rs:2031, the
2676 // `caixa_feira::cmd::publish` per-tag `caixa {nome} v{versao}`
2677 // git-tag scalar at caixa-feira/src/cmd/publish.rs:72).
2678 // Byte-equal today (the accessor is `&self.versao`);
2679 // the pin catches any future accessor extension whose
2680 // emit-side write regresses to the raw field. Peer to
2681 // [`chart_yaml_app_version_routes_through_caixa_versao_accessor`]
2682 // on the sibling per-`Chart.yaml` `appVersion:` axis.
2683 let caixa = sample_caixa();
2684 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2685 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
2686 assert_eq!(
2687 chart.version.as_str(),
2688 caixa.versao(),
2689 "Chart.yaml `version:` must derive from the typed \
2690 `caixa_core::Caixa::versao` accessor byte-for-byte — a regression \
2691 that re-inlines `caixa.versao.clone()` at the emit site silently \
2692 splits the per-`Chart.yaml` `version:` axis from every future \
2693 accessor extension (SemVer-2 build-metadata canonicalization, \
2694 OCI-tag normalization, per-edition pre-release-tag overlay) that \
2695 lands on the accessor",
2696 );
2697 }
2698
2699 #[test]
2700 fn chart_yaml_app_version_routes_through_caixa_versao_accessor() {
2701 // Fail-before-pass-after pin: the emit-side per-`Chart.yaml`
2702 // top-level `appVersion:` scalar the [`build_chart_yaml`] fn
2703 // writes must derive from the typed
2704 // [`caixa_core::Caixa::versao`] accessor byte-for-byte.
2705 // Same single-source `let versao = caixa.versao().to_string()`
2706 // binding as the peer `version:` sibling pin — this test
2707 // pins the derived `Chart.yaml` `appVersion:` axis (the
2708 // axis Helm chart-consumers key per-application-version
2709 // documentation / release-note / OCI-tag / operator-side
2710 // per-Caixa CR revision off). Peer to
2711 // [`chart_yaml_version_routes_through_caixa_versao_accessor`]
2712 // on the sibling per-`Chart.yaml` `version:` axis — the
2713 // two together pin every per-`Chart.yaml` version-carrier
2714 // field on the typed accessor.
2715 let caixa = sample_caixa();
2716 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2717 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
2718 assert_eq!(
2719 chart.app_version.as_str(),
2720 caixa.versao(),
2721 "Chart.yaml `appVersion:` must derive from the typed \
2722 `caixa_core::Caixa::versao` accessor byte-for-byte — a regression \
2723 that re-inlines `caixa.versao.clone()` at the emit site silently \
2724 splits the per-`Chart.yaml` `appVersion:` axis from every future \
2725 accessor extension (SemVer-2 build-metadata canonicalization, \
2726 OCI-tag normalization, per-edition pre-release-tag overlay) that \
2727 lands on the accessor",
2728 );
2729 }
2730
2731 #[test]
2732 fn chart_yaml_name_routes_through_caixa_nome_accessor() {
2733 // Emit-path pin: the per-`Chart.yaml` top-level `name:`
2734 // scalar the [`build_chart_yaml`] fn writes must derive
2735 // from the typed [`caixa_core::Caixa::nome`] accessor
2736 // byte-for-byte through the substrate-canonical
2737 // [`caixa_core::lareira_chart_name`] identity composer.
2738 // Before this converge the outer `lareira_chart_name(&caixa.nome)`
2739 // call at [`render_chart_for_servico_with`] carried a raw
2740 // `&caixa.nome` borrow-then-deref of the underlying `String`
2741 // field, bypassing the typed accessor. Peer of the sibling
2742 // eb912de `caixa.versao().to_string()` converge on the
2743 // co-resident `Caixa::versao` `String`-carry axis in this
2744 // crate and the sibling 4a363bf / 54bf2f3 `caixa.nome().to_string()`
2745 // converges on the outer-Caixa `:nome` `String`-carry axis
2746 // in caixa-flux / caixa-mesh — extends the "one typed
2747 // dispatch on the substrate primitive, thin projections at
2748 // each consumer" discipline onto the non-`.clone()` raw-
2749 // field-access axis of `Caixa::nome` in caixa-helm. Byte-
2750 // equal today (the accessor is `&self.nome`); the pin
2751 // catches any future accessor extension (a per-cluster
2752 // alias overlay, an M4 CR-materializer name rewrite, a
2753 // future `:nome-suffix` slot) whose emit-side write
2754 // regresses to the raw `&caixa.nome` field access.
2755 let caixa = sample_caixa();
2756 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2757 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
2758 assert_eq!(
2759 chart.name,
2760 caixa_core::lareira_chart_name(caixa.nome()),
2761 "Chart.yaml `name:` must derive from the typed \
2762 `caixa_core::Caixa::nome` accessor through \
2763 `caixa_core::lareira_chart_name` byte-for-byte — a regression \
2764 that re-inlines `lareira_chart_name(&caixa.nome)` at the emit \
2765 site silently splits the per-`Chart.yaml` `name:` axis from \
2766 every future accessor extension (per-cluster alias overlay, \
2767 M4 CR-materializer name rewrite, `:nome-suffix` slot) that \
2768 lands on the accessor",
2769 );
2770 }
2771
2772 #[test]
2773 fn chart_dir_name_routes_through_caixa_lareira_chart_name_accessor() {
2774 // Emit-path pin: the per-`ChartDir` top-level `name` axis the
2775 // [`render_chart_for_servico_with`] fn writes must derive from
2776 // the substrate-canonical
2777 // [`caixa_core::Caixa::lareira_chart_name`] resolved-chart-name
2778 // dispatch. Before this converge the outer `lareira_chart_name
2779 // (caixa.nome())` two-step compose at the emit site re-derived
2780 // the `LAREIRA_CHART_NAME_PREFIX + :nome` composition inline,
2781 // bypassing the substrate primitive's single-`&Caixa` dispatch.
2782 // Peer of the sibling [`Caixa::canonical_git_url`] (124f864) /
2783 // [`Caixa::publish_tag`] (07e05b8) resolved-composers'
2784 // paired-site convergence pins the sibling caixa-flux
2785 // [`cluster_bundle_opts_for_caixa_git_url_routes_through_canonical_git_url_accessor`]
2786 // + `_git_ref_routes_through_publish_tag_accessor` byte-parity
2787 // tests carry on the per-Servico-renderer emit surface. Byte-
2788 // equal today (the accessor is
2789 // `caixa_core::lareira_chart_name(self.nome())`); the pin
2790 // catches any future accessor extension (a per-cluster alias
2791 // overlay, an M4 CR-materializer name rewrite, a
2792 // `:nome-suffix` slot, the [`LAREIRA_CHART_NAME_PREFIX`]
2793 // rebrand once the chart-family scoping intent shifts) whose
2794 // emit-side write regresses to the two-step open-coded compose.
2795 let caixa = sample_caixa();
2796 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2797 assert_eq!(
2798 dir.name,
2799 caixa.lareira_chart_name(),
2800 "ChartDir.name must derive from the substrate-canonical \
2801 `caixa_core::Caixa::lareira_chart_name` accessor byte-for-\
2802 byte — a regression that re-inlines \
2803 `caixa_core::lareira_chart_name(caixa.nome())` at the emit \
2804 site silently splits the per-`ChartDir` `name` axis from \
2805 every future accessor extension (per-cluster alias overlay, \
2806 M4 CR-materializer name rewrite, `:nome-suffix` slot, \
2807 `LAREIRA_CHART_NAME_PREFIX` rebrand) that lands on the \
2808 accessor",
2809 );
2810 }
2811
2812 #[test]
2813 fn chart_yaml_description_fallback_routes_through_caixa_nome_accessor() {
2814 // Emit-path pin: on a `:descricao`-null caixa the
2815 // [`build_chart_yaml`] `description:` fallback substitutes
2816 // `format!("Generated chart for caixa Servico {}", caixa.nome())`,
2817 // which must derive its terminal identity byte-string from the
2818 // typed [`caixa_core::Caixa::nome`] accessor. Before this
2819 // converge the fallback carried a raw `caixa.nome` Display of
2820 // the underlying `String` field, bypassing the typed accessor.
2821 // Byte-equal today; the pin catches any future accessor
2822 // extension whose fallback emit regresses to the raw field.
2823 let caixa = Caixa {
2824 descricao: None,
2825 ..sample_caixa()
2826 };
2827 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2828 let chart: ChartYaml = parse_yaml_at_path_as(&dir.files, HELM_CHART_YAML_FILENAME);
2829 assert_eq!(
2830 chart.description,
2831 format!("Generated chart for caixa Servico {}", caixa.nome()),
2832 "Chart.yaml `description:` `:descricao`-null fallback must \
2833 derive from the typed `caixa_core::Caixa::nome` accessor \
2834 byte-for-byte — a regression that re-inlines \
2835 `format!(\"Generated chart for caixa Servico {{}}\", caixa.nome)` \
2836 at the emit site silently splits the per-`Chart.yaml` \
2837 `description:` axis from every future accessor extension \
2838 that lands on the accessor",
2839 );
2840 }
2841
2842 #[test]
2843 fn values_yaml_header_nome_routes_through_caixa_nome_accessor() {
2844 // Emit-path pin: the [`build_values_yaml`] `# Auto-generated
2845 // by caixa-helm from caixa.lisp + servicos/{nome}.computeunit.yaml.`
2846 // comment header carries the parent-caixa's `:nome` identity
2847 // byte-string verbatim through the typed
2848 // [`caixa_core::Caixa::nome`] accessor. Before this converge
2849 // the site carried a raw `nome = caixa.nome` Display of the
2850 // underlying `String` field, bypassing the typed accessor.
2851 // Byte-equal today; the pin catches any future accessor
2852 // extension whose header-emit regresses to the raw field.
2853 let caixa = sample_caixa();
2854 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2855 let values_file =
2856 find_file_by_path(&dir.files, HELM_VALUES_YAML_FILENAME).expect("values.yaml present");
2857 let expected = format!("servicos/{}.computeunit.yaml", caixa.nome());
2858 assert!(
2859 values_file.contents.contains(&expected),
2860 "values.yaml header comment must carry the typed \
2861 `caixa_core::Caixa::nome` accessor's byte-string \
2862 ({expected:?}) verbatim — a regression that re-inlines \
2863 `caixa.nome` in the header format silently splits the \
2864 values.yaml provenance-annotation axis from every future \
2865 accessor extension that lands on the accessor. \
2866 Full contents:\n{contents}",
2867 contents = values_file.contents,
2868 );
2869 }
2870
2871 #[test]
2872 fn readme_descricao_fallback_routes_through_caixa_nome_accessor() {
2873 // Emit-path pin: on a `:descricao`-null caixa the
2874 // [`build_readme`] descricao-line fallback substitutes
2875 // `format!("caixa Servico {}", caixa.nome())`, which must
2876 // derive its terminal identity byte-string from the typed
2877 // [`caixa_core::Caixa::nome`] accessor. Before this converge
2878 // the fallback carried a raw `caixa.nome` Display of the
2879 // underlying `String` field, bypassing the typed accessor.
2880 // Byte-equal today; the pin catches any future accessor
2881 // extension whose fallback emit regresses to the raw field.
2882 let caixa = Caixa {
2883 descricao: None,
2884 ..sample_caixa()
2885 };
2886 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2887 let readme_file =
2888 find_file_by_path(&dir.files, HELM_CHART_README_FILENAME).expect("README.md present");
2889 let expected = format!("caixa Servico {}", caixa.nome());
2890 assert!(
2891 readme_file.contents.contains(&expected),
2892 "README.md `:descricao`-null fallback must carry the typed \
2893 `caixa_core::Caixa::nome` accessor's byte-string ({expected:?}) \
2894 verbatim — a regression that re-inlines `format!(\"caixa \
2895 Servico {{}}\", caixa.nome)` at the emit site silently \
2896 splits the README fallback-descricao axis from every future \
2897 accessor extension. Full contents:\n{contents}",
2898 contents = readme_file.contents,
2899 );
2900 }
2901
2902 #[test]
2903 fn readme_body_version_routes_through_caixa_versao_accessor() {
2904 // Emit-path pin: the per-`README.md` `Origin` line the
2905 // [`build_readme`] fn writes carries the terminal
2906 // `v{versao}` scalar the `feira chart` Nord-themed emit
2907 // round-trips through — that scalar must derive from the
2908 // typed [`caixa_core::Caixa::versao`] accessor byte-for-byte.
2909 // Before this converge the emit site carried a raw
2910 // `caixa.versao` `Display` field-access, bypassing the
2911 // typed accessor. Sibling of the 162e2e2 (caixa-flux) /
2912 // 980c059 (caixa-mesh) / 22461ef (caixa-helm) `Caixa::nome`
2913 // Display-axis converges — this closes the co-resident
2914 // `Caixa::versao` Display-axis in caixa-helm the eb912de
2915 // `caixa.versao().to_string()` `String`-carry converge
2916 // left open on the read-only Display-borrow arm. Byte-equal
2917 // today (the accessor is `&self.versao`); the pin catches
2918 // any future accessor extension (SemVer-2 build-metadata
2919 // canonicalization, OCI-tag normalization, per-edition
2920 // pre-release-tag overlay) whose emit-side Display regresses
2921 // to the raw field.
2922 let caixa = sample_caixa();
2923 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
2924 let readme_file =
2925 find_file_by_path(&dir.files, HELM_CHART_README_FILENAME).expect("README.md present");
2926 let expected = format!("caixa.lisp` v{}.", caixa.versao());
2927 assert!(
2928 readme_file.contents.contains(&expected),
2929 "README.md `Origin`-line `v{{versao}}` scalar must derive from \
2930 the typed `caixa_core::Caixa::versao` accessor byte-for-byte \
2931 ({expected:?}) — a regression that re-inlines `caixa.versao` \
2932 in the format silently splits the README origin-line version \
2933 axis from every future accessor extension (SemVer-2 \
2934 build-metadata canonicalization, OCI-tag normalization, \
2935 per-edition pre-release-tag overlay) that lands on the \
2936 accessor. Full contents:\n{contents}",
2937 contents = readme_file.contents,
2938 );
2939 }
2940
2941 #[test]
2942 fn contains_key_bare_str_key_byte_equals_value_string_wrapped_form_across_swept_axis_keys() {
2943 // Per-crate fail-before-pass-after equivalence pin covering the
2944 // five test-side `assert!(mapping.contains_key(<KEY>))`
2945 // drift-detection sites that this commit swept off the
2946 // three-token `serde_yaml::Value::String(<KEY>.to_string())`
2947 // wrapped shape onto the shorter bare-`&str` form
2948 // ([`HELM_CHART_KEY_TYPE`] on the per-Chart.yaml top-level
2949 // chart-kind discriminator axis, [`HELM_CHART_KEY_APP_VERSION`]
2950 // on the underlying-application-version axis,
2951 // [`HELM_CHART_KEY_API_VERSION`] on the chart-schema-apiVersion
2952 // axis, the per-`dependencies[]`-entry tetrad iterator
2953 // ([`HELM_CHART_DEPENDENCY_KEY_NAME`] /
2954 // [`HELM_CHART_DEPENDENCY_KEY_VERSION`] /
2955 // [`HELM_CHART_DEPENDENCY_KEY_REPOSITORY`] /
2956 // [`HELM_CHART_DEPENDENCY_KEY_ALIAS`]), and
2957 // [`HELM_CHART_KEY_DEPENDENCIES`] on the top-level
2958 // dependency-list container axis).
2959 //
2960 // The equivalence is a serde_yaml crate-level property (the
2961 // `impl Index for str` and `impl Index for Value` paths both
2962 // route through the same `HashLikeValue(&str)` bucket lookup)
2963 // pinned at the caixa-core-side sibling
2964 // `mapping_get_bare_str_key_byte_equals_value_string_wrapped_form`'s
2965 // trailing `contains_key` parity block for the generic axis
2966 // (0e84fb9). This pin lifts the same equivalence to the
2967 // caixa-helm-side lifted axis-key set every swept site keys
2968 // off, so a future `serde_yaml` upgrade whose `Index for str`
2969 // path diverges from `Index for Value` for the specific
2970 // key-string byte-shape at any of the seven swept keys is a
2971 // caixa-helm-build-time failure naming the offending axis-key,
2972 // not a silent regression that would let the swept
2973 // `assert!(_.contains_key(K))` shape probes drift past the
2974 // emitter's [`MappingExt::insert_str_key`]-promoted key.
2975 //
2976 // Peer to the caixa-core-side
2977 // `mapping_get_bare_str_key_byte_equals_value_string_wrapped_form`
2978 // pin (0e84fb9) on the generic `contains_key` parity axis —
2979 // the two together partition the equivalence-pin surface
2980 // exactly on the axis-key set specificity: caixa-core-side pin
2981 // covers the generic KUBE_KEY_KIND / KUBE_KEY_SPEC probe;
2982 // this caixa-helm-side pin covers the seven Chart.yaml-shape
2983 // axis-keys the swept sites key off.
2984 let mut m = serde_yaml::Mapping::new();
2985 m.insert_string(HELM_CHART_KEY_TYPE, "application");
2986 m.insert_string(HELM_CHART_KEY_APP_VERSION, "1.0.0");
2987 m.insert_string(HELM_CHART_KEY_API_VERSION, "v2");
2988 m.insert_string(HELM_CHART_KEY_DEPENDENCIES, "placeholder");
2989 m.insert_string(HELM_CHART_DEPENDENCY_KEY_NAME, "pleme-computeunit");
2990 m.insert_string(HELM_CHART_DEPENDENCY_KEY_VERSION, "0.1.0");
2991 m.insert_string(
2992 HELM_CHART_DEPENDENCY_KEY_REPOSITORY,
2993 "oci://ghcr.io/pleme-io",
2994 );
2995 m.insert_string(HELM_CHART_DEPENDENCY_KEY_ALIAS, "cu");
2996 for key in [
2997 HELM_CHART_KEY_TYPE,
2998 HELM_CHART_KEY_APP_VERSION,
2999 HELM_CHART_KEY_API_VERSION,
3000 HELM_CHART_KEY_DEPENDENCIES,
3001 HELM_CHART_DEPENDENCY_KEY_NAME,
3002 HELM_CHART_DEPENDENCY_KEY_VERSION,
3003 HELM_CHART_DEPENDENCY_KEY_REPOSITORY,
3004 HELM_CHART_DEPENDENCY_KEY_ALIAS,
3005 ] {
3006 // Present-key path: both forms find the same insertion.
3007 assert_eq!(
3008 m.contains_key(key),
3009 m.contains_key(serde_yaml::Value::String(key.to_string())),
3010 "present-key mapping.contains_key({key:?}) via bare-&str must \
3011 byte-equal mapping.contains_key(Value::String({key:?}.to_string())) \
3012 — otherwise the swept `assert!(_.contains_key({key:?}))` sites \
3013 in this file drift silently past the emitter's `insert_str_key` \
3014 promotion at every downstream drift-detection pin call site"
3015 );
3016 }
3017 // Absent-key path: both forms return false on a key that was
3018 // never inserted (mirroring the peer caixa-core-side
3019 // KUBE_KEY_SPEC absent-key parity assertion).
3020 let absent = "this_key_never_appears_in_any_chart_yaml_axis";
3021 assert_eq!(
3022 m.contains_key(absent),
3023 m.contains_key(serde_yaml::Value::String(absent.to_string())),
3024 "absent-key mapping.contains_key(<bare-&str>) must byte-equal \
3025 absent-key mapping.contains_key(Value::String(<key>.to_string())) \
3026 — otherwise a future swept drift-detection pin's absent-key arm \
3027 could silently disagree between the two forms"
3028 );
3029 }
3030
3031 #[test]
3032 fn readme_repositorio_null_fallback_routes_through_canonical_git_url_accessor() {
3033 // Emit-path pin: on a `:repositorio`-null caixa the
3034 // [`build_readme`] `## Origin` line's `{repo}` interpolation must
3035 // derive from the substrate-canonical
3036 // [`caixa_core::Caixa::canonical_git_url`] resolved-git-URL
3037 // composer's None-arm fallback (`https://github.com/{DEFAULT_PLEME_GIT_ORG}/<nome>`)
3038 // rather than the prior `caixa.repositorio().unwrap_or(caixa.nome())`
3039 // two-arm inline whose fallback folded to the bare `<nome>` scalar
3040 // and emitted the meaningless `Generated by `caixa-helm` from
3041 // `<nome>/caixa.lisp`` line the 124f864 commit body explicitly
3042 // called out as the live-behavior-correcting converge surface
3043 // waiting on this lift. Fail-before-pass-after: the pre-lift
3044 // shape carried the bare `hello-rio/caixa.lisp` substring and
3045 // this pin asserts the post-lift canonical pleme-org URL substring
3046 // in its place, so a regression that re-inlines the raw two-arm
3047 // fallback at the emit site surfaces at caixa-helm build time on
3048 // this test's failure rather than at a downstream README-consuming
3049 // UI's "where does this caixa live?" broken-URL trail.
3050 let caixa = Caixa {
3051 repositorio: None,
3052 ..sample_caixa()
3053 };
3054 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
3055 let readme_file =
3056 find_file_by_path(&dir.files, HELM_CHART_README_FILENAME).expect("README.md present");
3057 let expected = format!(
3058 "Generated by `caixa-helm` from `{}/caixa.lisp`",
3059 caixa.canonical_git_url()
3060 );
3061 assert!(
3062 readme_file.contents.contains(&expected),
3063 "README.md `:repositorio`-null fallback must derive its \
3064 `repo` interpolation from the typed \
3065 `caixa_core::Caixa::canonical_git_url` resolved-git-URL \
3066 composer byte-for-byte ({expected:?}) — a regression that \
3067 re-inlines the prior `caixa.repositorio().unwrap_or(caixa.nome())` \
3068 two-arm fallback at the emit site silently regresses the \
3069 README origin-line repo axis to the meaningless bare `<nome>` \
3070 prefix and splits the caixa-helm README axis from the sibling \
3071 [`caixa_flux::ClusterBundleOpts::for_caixa`] `git_url` seed \
3072 which already resolves through the canonical composer. \
3073 Full contents:\n{contents}",
3074 contents = readme_file.contents,
3075 );
3076 }
3077
3078 #[test]
3079 fn readme_repositorio_null_fallback_no_longer_emits_bare_nome_prefix() {
3080 // Fail-before-pass-after regression guard: pins the negative arm
3081 // the sibling
3082 // [`readme_repositorio_null_fallback_routes_through_canonical_git_url_accessor`]
3083 // pin's positive arm implies — the pre-lift bare `<nome>/caixa.lisp`
3084 // substring (the shape the prior `caixa.repositorio().unwrap_or(caixa.nome())`
3085 // inline two-arm fallback emitted on every `:repositorio`-null
3086 // caixa) must NOT appear in the rendered README's `## Origin` line.
3087 // A regression that re-inlines the two-arm fallback at
3088 // [`build_readme`]'s emit site would satisfy the positive
3089 // canonical-composer substring check on the `Some(<full-URL>)`
3090 // arm and drop the fallback arm back to `<nome>/caixa.lisp`
3091 // silently — so an explicit negative-substring pin closes the
3092 // remaining converge surface the sibling positive pin does not
3093 // catch on its own.
3094 let caixa = Caixa {
3095 repositorio: None,
3096 ..sample_caixa()
3097 };
3098 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
3099 let readme_file =
3100 find_file_by_path(&dir.files, HELM_CHART_README_FILENAME).expect("README.md present");
3101 let regressed = format!(
3102 "Generated by `caixa-helm` from `{}/caixa.lisp`",
3103 caixa.nome()
3104 );
3105 assert!(
3106 !readme_file.contents.contains(®ressed),
3107 "README.md `:repositorio`-null fallback must NOT emit the \
3108 pre-lift bare `<nome>/caixa.lisp` prefix ({regressed:?}) — \
3109 the `caixa.repositorio().unwrap_or(caixa.nome())` two-arm \
3110 inline fallback was retired in favor of \
3111 `caixa.canonical_git_url()` so the fallback arm now names \
3112 the substrate-canonical pleme-org URL; a regression that \
3113 re-inlines the two-arm fallback at the emit site would \
3114 silently split this caixa-helm README axis from the sibling \
3115 [`caixa_flux::ClusterBundleOpts::for_caixa`] `git_url` seed. \
3116 Full contents:\n{contents}",
3117 contents = readme_file.contents,
3118 );
3119 }
3120
3121 #[test]
3122 fn readme_repositorio_declared_arm_routes_through_canonical_git_url_accessor() {
3123 // Emit-path pin (peer of the `:repositorio`-null fallback sibling):
3124 // on a `:repositorio`-declared caixa the [`build_readme`] `## Origin`
3125 // line's `{repo}` interpolation must also derive from the substrate-
3126 // canonical [`caixa_core::Caixa::canonical_git_url`] resolved-git-URL
3127 // composer — the Some-arm return byte-string is the author-declared
3128 // `:repositorio` verbatim, so the substring the rendered README
3129 // carries matches the composer output on both arms and the pair
3130 // of pins jointly pins the entire two-arm dispatch through one
3131 // canonical composer. A regression that split the emit site into
3132 // a Some-arm-only bypass through the raw
3133 // [`caixa_core::Caixa::repositorio`] accessor while leaving the
3134 // fallback arm routed through the canonical composer would
3135 // silently drift the two-arm shape and be caught here (the raw
3136 // accessor path bypasses any future extension of the resolved-URL
3137 // composer, e.g. a `github:` → `https://github.com/` canonicalization
3138 // pass or the per-cluster repo-mirror overlay the M4 CR materializer
3139 // will apply).
3140 let caixa = sample_caixa();
3141 assert!(
3142 caixa.repositorio().is_some(),
3143 "sample_caixa() must carry a `Some(...)` `:repositorio` for \
3144 the Some-arm to exercise the canonical composer's non-fallback \
3145 path — a future sample_caixa() edit that drops the field must \
3146 re-establish it here or the pin regresses to a no-op",
3147 );
3148 let dir = render_chart_for_servico(&caixa, &sample_cu_yaml()).unwrap();
3149 let readme_file =
3150 find_file_by_path(&dir.files, HELM_CHART_README_FILENAME).expect("README.md present");
3151 let expected = format!(
3152 "Generated by `caixa-helm` from `{}/caixa.lisp`",
3153 caixa.canonical_git_url()
3154 );
3155 assert!(
3156 readme_file.contents.contains(&expected),
3157 "README.md `:repositorio`-declared arm must derive its `repo` \
3158 interpolation from the typed `caixa_core::Caixa::canonical_git_url` \
3159 resolved-git-URL composer byte-for-byte ({expected:?}) so the \
3160 two-arm dispatch routes through one canonical composer end to \
3161 end. Full contents:\n{contents}",
3162 contents = readme_file.contents,
3163 );
3164 }
3165
3166 #[test]
3167 #[allow(clippy::cmp_owned)] // Deliberate: the pin reproduces the
3168 // prior owning-`PathBuf::from(...)` comparand byte-for-byte to
3169 // guarantee the lift's substitution is behavior-preserving on
3170 // exactly the shape the 26 converged caixa-helm callers previously
3171 // carried.
3172 fn find_file_by_path_matches_prior_inline_iter_find_pathbuf_from_shape() {
3173 // Per-crate byte-equivalence pin on the lifted
3174 // [`caixa_core::find_file_by_path`] navigator: for every leaf
3175 // the `render_chart_for_servico` `lareira-<nome>` chart-
3176 // directory emit writes ([`HELM_CHART_YAML_FILENAME`] /
3177 // [`HELM_VALUES_YAML_FILENAME`] /
3178 // [`HELM_CHART_README_FILENAME`]), the lifted navigator must
3179 // byte-equal the prior three-line inline
3180 // `dir.files.iter().find(|f| f.path ==
3181 // PathBuf::from(<FILENAME_CONST>))` combinator the 26 test-
3182 // side per-artifact readback sites previously carried. Mirrors
3183 // the sibling `caixa-flux`
3184 // `find_file_by_path_matches_prior_inline_iter_find_pathbuf_from_shape`
3185 // pin at the peer caller-crate altitude and the substrate-
3186 // level `find_file_by_path_matches_inline_iter_find_pathbuf_from_shape`
3187 // pin at the primitive definition — the three-arm closure
3188 // that closes the discipline the sibling `sequence_str_values`
3189 // / `kube_has` sweeps established.
3190 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
3191 for filename in [
3192 HELM_CHART_YAML_FILENAME,
3193 HELM_VALUES_YAML_FILENAME,
3194 HELM_CHART_README_FILENAME,
3195 ] {
3196 let via_helper = find_file_by_path(&dir.files, filename);
3197 let via_inline = dir.files.iter().find(|f| f.path == PathBuf::from(filename));
3198 assert_eq!(
3199 via_helper, via_inline,
3200 "find_file_by_path(&dir.files, {filename:?}) must \
3201 byte-equal the prior three-line `dir.files.iter()\
3202 .find(|f| f.path == PathBuf::from({filename:?}))` \
3203 combinator on every leaf the `lareira-<nome>` chart-\
3204 directory emit writes — otherwise the 26 routed per-\
3205 artifact readback sites regress silently on the \
3206 leaf-path axis",
3207 );
3208 }
3209 }
3210
3211 #[test]
3212 fn parse_yaml_at_path_matches_prior_inline_find_then_from_str_shape() {
3213 // Per-crate byte-equivalence pin on the lifted
3214 // [`caixa_core::parse_yaml_at_path`] composed navigator: for
3215 // every YAML leaf the `render_chart_for_servico` `lareira-
3216 // <nome>` chart-directory emit writes that the test-side
3217 // routed callers parse to a [`serde_yaml::Value`]
3218 // ([`HELM_CHART_YAML_FILENAME`] as `doc` /
3219 // [`HELM_VALUES_YAML_FILENAME`] as `parsed`), the lifted helper
3220 // must return a `Value` byte-equal to the prior two-step
3221 //
3222 // let f = find_file_by_path(&dir.files, <FILENAME>).unwrap();
3223 // let parsed: serde_yaml::Value =
3224 // serde_yaml::from_str(&f.contents).unwrap();
3225 //
3226 // the 12 test-side per-artifact YAML readback sites previously
3227 // carried. Mirrors the sibling `caixa-flux`
3228 // `parse_yaml_at_path_matches_prior_inline_find_then_from_str_shape`
3229 // pin at the peer caller-crate altitude and the substrate-
3230 // level `parse_yaml_at_path_matches_prior_inline_two_step_shape`
3231 // pin at the primitive definition — the three-arm closure that
3232 // closes the same discipline the sibling `find_file_by_path`
3233 // sweep established. [`HELM_CHART_README_FILENAME`] is
3234 // deliberately not swept: the routed callers only assert on its
3235 // raw-byte content, never parse it to YAML.
3236 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
3237 for filename in [HELM_CHART_YAML_FILENAME, HELM_VALUES_YAML_FILENAME] {
3238 let via_helper = parse_yaml_at_path(&dir.files, filename);
3239 let via_inline_file = find_file_by_path(&dir.files, filename).unwrap();
3240 let via_inline: serde_yaml::Value =
3241 serde_yaml::from_str(&via_inline_file.contents).unwrap();
3242 assert_eq!(
3243 via_helper, via_inline,
3244 "parse_yaml_at_path(&dir.files, {filename:?}) must \
3245 byte-equal the prior two-step `find_file_by_path(&dir.files, \
3246 {filename:?}).unwrap() + serde_yaml::from_str(&_.contents).unwrap()` \
3247 combinator on every YAML leaf the `lareira-<nome>` chart-\
3248 directory emit writes — otherwise the 12 routed per-\
3249 artifact YAML readback sites regress silently on the \
3250 parse-target axis",
3251 );
3252 }
3253 }
3254
3255 #[test]
3256 fn parse_yaml_at_path_as_matches_prior_inline_find_then_from_str_typed_shape() {
3257 // Per-crate byte-equivalence pin on the lifted
3258 // [`caixa_core::parse_yaml_at_path_as`] caller-typed composed
3259 // navigator: for the `Chart.yaml` YAML leaf the
3260 // `render_chart_for_servico` `lareira-<nome>` chart-directory
3261 // emit writes that the test-side routed callers parse to a
3262 // [`ChartYaml`]-typed body, the lifted helper must return a
3263 // `ChartYaml` byte-equal to the prior two-step
3264 //
3265 // let chart_file = find_file_by_path(&dir.files, HELM_CHART_YAML_FILENAME)
3266 // .unwrap(); // or .expect("Chart.yaml present")
3267 // let chart: ChartYaml =
3268 // serde_yaml::from_str(&chart_file.contents).unwrap();
3269 //
3270 // the 9 test-side per-`Chart.yaml`-typed-parse readback sites
3271 // previously carried. Mirrors the sibling
3272 // [`parse_yaml_at_path_matches_prior_inline_find_then_from_str_shape`]
3273 // untyped-Value-arity pin in this crate at the caller-typed-
3274 // arity peer, and the substrate-level
3275 // `parse_yaml_at_path_as_matches_prior_inline_typed_two_step_shape`
3276 // pin at the primitive definition — the three-arm closure
3277 // that closes the same discipline the sibling
3278 // [`parse_yaml_at_path`] sweep established. Only
3279 // [`HELM_CHART_YAML_FILENAME`] is swept: the routed
3280 // caller-typed-parse sites in this crate reach exclusively
3281 // through the `ChartYaml`-typed body at the `Chart.yaml`
3282 // leaf; [`HELM_VALUES_YAML_FILENAME`] carries no typed-mirror
3283 // struct in this crate (the routed callers navigate its
3284 // parsed [`serde_yaml::Value`] through `kube_*` / `mapping_*`
3285 // primitives), and [`HELM_CHART_README_FILENAME`] is not
3286 // parsed as YAML at all.
3287 let dir = render_chart_for_servico(&sample_caixa(), &sample_cu_yaml()).unwrap();
3288 let filename = HELM_CHART_YAML_FILENAME;
3289 let via_helper: ChartYaml = parse_yaml_at_path_as(&dir.files, filename);
3290 let via_inline_file = find_file_by_path(&dir.files, filename).unwrap();
3291 let via_inline: ChartYaml = serde_yaml::from_str(&via_inline_file.contents).unwrap();
3292 assert_eq!(
3293 via_helper, via_inline,
3294 "parse_yaml_at_path_as::<ChartYaml>(&dir.files, {filename:?}) \
3295 must byte-equal the prior two-step \
3296 `find_file_by_path(&dir.files, {filename:?}).unwrap() + \
3297 serde_yaml::from_str::<ChartYaml>(&_.contents).unwrap()` \
3298 combinator on the `Chart.yaml` YAML leaf — otherwise \
3299 the 9 routed per-artifact typed-parse readback sites \
3300 regress silently on the parse-target axis",
3301 );
3302 }
3303}