Skip to main content

parse_yaml_at_path

Function parse_yaml_at_path 

Source
pub fn parse_yaml_at_path(files: &[RenderedFile], path: &str) -> Value
Expand description

Locate the RenderedFile in files whose sandboxed relative RenderedFile::path byte-equals path, then parse its RenderedFile::contents as an untyped serde_yaml::Value YAML document. Panics on either short-circuit arm — the leaf is absent ({path} present) or the contents do not parse as YAML ({path} parses as YAML: {err}).

The composed peer to find_file_by_path — same &[RenderedFile]-container-side one-hop navigator, extended by the paired serde_yaml::from_str parse step every test-side per- artifact readback carried inline after the locate call. Every per-artifact readback across caixa-flux’s cluster_bundle Flux v2 CR-trio emit and caixa-helm’s render_chart_for_servico lareira-<nome> chart-directory emit previously carried the same four-line

let f = find_file_by_path(&files, <FILENAME>)
    .expect("<filename>.yaml present");
let parsed: serde_yaml::Value =
    serde_yaml::from_str(&f.contents).expect("<filename>.yaml parses as YAML");

combinator around a one-token semantic payload (the <FILENAME> filename constant — FLUX_HELMRELEASE_YAML_FILENAME / FLUX_GITREPOSITORY_YAML_FILENAME / FLUX_KUSTOMIZATION_YAML_FILENAME on the Flux v2 CR trio, HELM_CHART_YAML_FILENAME / HELM_VALUES_YAML_FILENAME on the lareira-<nome> chart-directory pair) around the two-hop locate- then-parse readback intent “read the parsed YAML at this leaf”. Every routed consumer now folds those four lines onto parse_yaml_at_path(&files, <FILENAME>) — the leaf-navigate + the parse step + the two .expect/.unwrap_or_else(|| panic!(...)) panics happen once inside the helper, the caller keeps its downstream continuation (kube_spec_field(&parsed, ...), kube_api_version_is(&parsed, ...), etc.) unchanged.

Panic messages are composed from the passed path verbatim — the missing-leaf arm produces "{path} present", the parse-failure arm produces "{path} parses as YAML: {err}". These match the canonical shape the routed test-side sites carried inline ("helmrelease.yaml present", "kustomization.yaml parses as YAML") where path is one of the substrate-canonical &'static str filename constants (FLUX_HELMRELEASE_YAML_FILENAME / FLUX_KUSTOMIZATION_YAML_FILENAME / FLUX_GITREPOSITORY_YAML_FILENAME / HELM_VALUES_YAML_FILENAME / HELM_CHART_YAML_FILENAME) — same panic prefix, and the parse-failure arm now includes the underlying serde_yaml::Error for far-easier root-cause naming than the prior .expect("<filename>.yaml parses as YAML") / .unwrap() shape (which either dropped the error verbatim or carried the canonical Result::unwrap() panic naming nothing).

Every future per-artifact YAML readback (a future caixa-mesh render_all_files per-multi-doc-emit split by leaf path, a future caixa-arch per-flake-file rendering that emits multiple .nix leaves the per-flake test walks by filename, a future caixa-teia per-tofu-manifest emit that carries main.tf / variables.tf / outputs.tf leaves the tofu-plan test walks by filename) reaches this same helper by construction, with no inline find_file_by_path(...).expect(...) + serde_yaml::from_str(...).expect(...) two-step and no drift surface on the parse-target, panic-message-composition, or filename-axis-key axes.