helm-schema-ir 0.0.4

Generate an accurate JSON schema for any helm chart
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
//! Assignment actions (`$x := …`, `$x = …`) and structural `set`
//! mutations: local bindings, truthiness reductions, member-host
//! conversions, and helper-scope set-call application.

//! Output-hole evaluation: expression holes evaluate through the existing
//! `AbstractValue` lattice (with bound-helper resolution) and lower into
//! fragment nodes; partial scalars combine per-segment arms with a bounded
//! cartesian product; inline `{{ if }}…{{ end }}` regions inside scalars
//! re-parse structurally and become guarded scalar arms.

use helm_schema_ast::{TemplateExpr, parse_expr_text};
use helm_schema_syntax::Span;

use crate::abstract_value::AbstractValue;
use crate::bound_value_analysis::parse_get_binding_from_exprs;
use crate::eval_effect::MemberHostConversion;
use crate::fragment_assignment::parse_helper_assignment_from_exprs;
use crate::fragment_expr_eval::FragmentEvalContext;
use crate::helper_meta::merge_rendered_row_meta;
use crate::{Guard, ValueKind};
use helm_schema_core::Predicate;

use super::eval::Interpreter;
use super::hole_effects::{RenderedDemotion, predicate_applies_to_flowing_path};

/// The values paths whose type an expression describes, preserving the
/// selection branches of a local that can hold one of several paths.
pub(super) fn type_descriptor_sources(
    expr: &TemplateExpr,
    interpreter: &Interpreter<'_>,
    output_meta: &std::collections::BTreeMap<String, crate::helper_meta::HelperOutputMeta>,
) -> Option<std::collections::BTreeMap<String, crate::helper_meta::HelperOutputMeta>> {
    let TemplateExpr::Call { function, args } = expr.deparen() else {
        return None;
    };
    let subject = helm_schema_ast::type_descriptor_call_subject(function, args)?.deparen();
    if !matches!(
        subject,
        TemplateExpr::Field(_) | TemplateExpr::Selector { .. } | TemplateExpr::Variable(_)
    ) {
        return None;
    }
    let paths = interpreter.value_path_context().paths_for_expr(subject);
    if paths.is_empty() {
        return None;
    }
    Some(
        paths
            .into_iter()
            .map(|path| {
                let meta = output_meta.get(&path).cloned().unwrap_or_default();
                (path, meta)
            })
            .collect(),
    )
}

/// Whether the expression's produced VALUE is derived text (a
/// stringification or string transform): the binding's runtime truthiness is
/// then the text's emptiness, which a surviving input value cannot witness.
pub(super) fn rhs_produces_derived_text(expr: &TemplateExpr) -> bool {
    let stage = match expr.deparen() {
        TemplateExpr::Pipeline(stages) => match stages.last() {
            Some(stage) => stage.deparen(),
            None => return false,
        },
        stage => stage,
    };
    let TemplateExpr::Call { function, .. } = stage else {
        return false;
    };
    helm_schema_ast::is_total_stringification_function(function)
        || helm_schema_ast::is_string_transform_function(function)
        || matches!(
            function.as_str(),
            "join" | "printf" | "print" | "println" | "cat"
        )
}

pub(super) fn self_preserving_nonempty_accumulation(expr: &TemplateExpr, variable: &str) -> bool {
    let TemplateExpr::Call { function, args } = expr.deparen() else {
        return false;
    };
    if args.len() < 2 {
        return false;
    }
    if function == "concat" {
        let keeps_self = args.iter().any(|arg| {
            matches!(
                arg.deparen(),
                TemplateExpr::Variable(name) if name.trim_start_matches('$') == variable
            )
        });
        let adds_nonempty_literal_list = args.iter().any(|arg| {
            matches!(
                arg.deparen(),
                TemplateExpr::Call { function, args }
                    if matches!(function.as_str(), "list" | "tuple") && !args.is_empty()
            )
        });
        return keeps_self && adds_nonempty_literal_list;
    }
    let Some((first, rest)) = args.split_first() else {
        return false;
    };
    let same_variable = matches!(
        first.deparen(),
        TemplateExpr::Variable(name) if name.trim_start_matches('$') == variable
    );
    same_variable
        && (matches!(
            function.as_str(),
            "append" | "mustAppend" | "prepend" | "mustPrepend"
        ) || function == "print"
            && rest.iter().any(|arg| {
                matches!(
                    arg.deparen(),
                    TemplateExpr::Literal(
                        helm_schema_ast::Literal::String(text)
                            | helm_schema_ast::Literal::RawString(text)
                    ) if !text.is_empty()
                )
            }))
}

/// Concretization of range-key equalities over one predicate scope: inside
/// `range $k, $v := .Values.p`, an `eq $k "name"` arm makes this iteration
/// the NAMED member, so `Range(p)` and the equality collapse into the
/// member's presence (`HasKey(p, name)` — a range visits present-nil
/// members exactly like `hasKey` observes them) and member wildcard paths
/// `p.*.rest` rebind to `p.name.rest`. Keys that spell path syntax (dots,
/// `*`) abstain — the rewrite would fabricate nested segments.
pub(super) struct RangeKeyConcretization {
    /// collection path → equated literal key.
    keyed: std::collections::BTreeMap<String, String>,
    /// (`p.*`, `p.*.`, `p.name`) per keyed collection.
    rewrites: Vec<(String, String, String)>,
}

impl RangeKeyConcretization {
    pub(super) fn from_conjuncts<'a>(conjuncts: impl Iterator<Item = &'a Predicate>) -> Self {
        let keyed: std::collections::BTreeMap<String, String> = conjuncts
            .filter_map(|predicate| match predicate {
                Predicate::Guard(crate::Guard::RangeKeyEquals { path, key })
                    if !key.contains('.') && !key.contains('*') =>
                {
                    Some((path.clone(), key.clone()))
                }
                _ => None,
            })
            .collect();
        let rewrites = keyed
            .iter()
            .map(|(path, key)| {
                (
                    format!("{path}.*"),
                    format!("{path}.*."),
                    helm_schema_core::append_value_path(path, key),
                )
            })
            .collect();
        Self { keyed, rewrites }
    }

    pub(super) fn is_empty(&self) -> bool {
        self.keyed.is_empty()
    }

    pub(super) fn apply(&self, predicate: &Predicate) -> Predicate {
        match predicate {
            Predicate::Guard(crate::Guard::Range { path }) if self.keyed.contains_key(path) => {
                Predicate::from(crate::Guard::HasKey {
                    path: path.clone(),
                    key: self.keyed.get(path).cloned().unwrap_or_default(),
                })
            }
            Predicate::Guard(crate::Guard::RangeKeyEquals { path, key })
                if self.keyed.get(path) == Some(key) =>
            {
                Predicate::from(crate::Guard::HasKey {
                    path: path.clone(),
                    key: key.clone(),
                })
            }
            predicate => predicate.clone().map_value_paths(&mut |path: &str| {
                for (member, member_prefix, concrete) in &self.rewrites {
                    if path == member {
                        return concrete.clone();
                    }
                    if let Some(rest) = path.strip_prefix(member_prefix.as_str()) {
                        return format!("{concrete}.{rest}");
                    }
                }
                path.to_string()
            }),
        }
    }
}

fn concretize_range_key_equalities(predicates: &[Predicate]) -> Vec<Predicate> {
    let concretization = RangeKeyConcretization::from_conjuncts(predicates.iter());
    if concretization.is_empty() {
        return predicates.to_vec();
    }
    let mut mapped: Vec<Predicate> = predicates
        .iter()
        .map(|predicate| concretization.apply(predicate))
        .collect();
    mapped.dedup();
    mapped
}

pub(super) fn or_predicates(left: Predicate, right: Predicate) -> Predicate {
    match (left, right) {
        (Predicate::True, _) | (_, Predicate::True) => Predicate::True,
        (Predicate::False, predicate) | (predicate, Predicate::False) => predicate,
        (left, right) if left == right => left,
        (Predicate::Or(mut left), Predicate::Or(right)) => {
            left.extend(right);
            left.sort();
            left.dedup();
            Predicate::Or(left)
        }
        (Predicate::Or(mut alternatives), predicate)
        | (predicate, Predicate::Or(mut alternatives)) => {
            alternatives.push(predicate);
            alternatives.sort();
            alternatives.dedup();
            Predicate::Or(alternatives)
        }
        (left, right) => Predicate::Or(vec![left, right]),
    }
}

impl Interpreter<'_> {
    /// Assignment actions: bind the local (fragment semantics), refresh its
    /// default/meta facts, and record the right-hand side's reads — the
    /// current pipeline walks assignment bodies in a no-render scope, so all
    /// of its claims are pathless.
    pub(super) fn eval_assignment_span(&mut self, span: Span) {
        let exprs = parse_expr_text(self.text(span));
        if exprs.is_empty() {
            return;
        }
        let previous_site = self.enter_hole_site(span);
        self.eval_assignment_exprs(&exprs);
        self.restore_site(previous_site);
    }

    /// Structural `set` mutations on local dict bindings (`set $ctx "k" v`,
    /// bare or assigned to `$_`) mutate the target local instead of binding
    /// output. Helper bodies rely on this for config-normalization chains;
    /// only the chart-default effects surface (the summary lane never
    /// claimed set-call operand reads).
    pub(super) fn record_dot_member_host_conversions(&mut self, exprs: &[TemplateExpr]) {
        if self.under_approximate_condition() {
            return;
        }
        let Some(target_path) = self
            .current_value_dot()
            .and_then(|value| value.unique_path())
        else {
            return;
        };
        if target_path.is_empty() {
            return;
        }

        let mut assignments = Vec::new();
        for expr in exprs {
            expr.walk(|node| {
                let TemplateExpr::Call { function, args } = node else {
                    return;
                };
                let [target, key, value] = args.as_slice() else {
                    return;
                };
                if function != "set" {
                    return;
                }
                let target_is_dot = match target.deparen() {
                    TemplateExpr::Field(path) => path.is_empty(),
                    TemplateExpr::Variable(variable) => variable.is_empty(),
                    _ => false,
                };
                if target_is_dot {
                    assignments.push((key.clone(), value.clone()));
                }
            });
        }

        for (key_expr, value_expr) in assignments {
            let (keys, assigns_object) = {
                let context = self.value_path_context();
                let keys = context
                    .with_body_fragment_value_expr(&key_expr)
                    .map(|value| value.strings())
                    .unwrap_or_default();
                let assigns_object = matches!(
                    context.with_body_fragment_value_expr(&value_expr),
                    Some(AbstractValue::Dict(_))
                );
                (keys, assigns_object)
            };
            if !assigns_object {
                continue;
            }
            for key in keys {
                let path = helm_schema_core::append_value_path(&target_path, &key);
                for predicate in &self.active_predicates {
                    let Predicate::Guard(Guard::TypeIs {
                        path: tested_path,
                        schema_type,
                    }) = predicate
                    else {
                        continue;
                    };
                    if tested_path != &path || schema_type == "object" {
                        continue;
                    }
                    let mut outer_predicates = self
                        .active_predicates
                        .iter()
                        .filter(|outer| *outer != predicate)
                        .cloned()
                        .collect::<Vec<_>>();
                    outer_predicates.sort();
                    outer_predicates.dedup();
                    self.member_host_conversions.insert(MemberHostConversion {
                        path: path.clone(),
                        input_kind: schema_type.clone(),
                        outer_predicates,
                    });
                }
            }
        }
    }

    pub(super) fn absorb_member_host_conversions(
        &mut self,
        conversions: &std::collections::BTreeSet<MemberHostConversion>,
    ) {
        for conversion in conversions {
            let mut outer_predicates = self.active_predicates.clone();
            outer_predicates.extend(conversion.outer_predicates.iter().cloned());
            if outer_predicates
                .iter()
                .any(Predicate::contains_approximation)
            {
                continue;
            }
            outer_predicates.sort();
            outer_predicates.dedup();
            self.member_host_conversions.insert(MemberHostConversion {
                path: conversion.path.clone(),
                input_kind: conversion.input_kind.clone(),
                outer_predicates,
            });
        }
    }

    pub(super) fn apply_helper_scope_set_mutations(&mut self, exprs: &[TemplateExpr]) -> bool {
        self.record_dot_member_host_conversions(exprs);
        if !self.helper_scope {
            return false;
        }
        let current_dot = self.current_dot_fragment();
        let mut seen = self.helper_seen.clone();
        if !crate::fragment_assignment::apply_local_set_mutations_from_exprs(
            exprs,
            &mut self.locals.fragment_values,
            current_dot.as_ref(),
            FragmentEvalContext::new(self.db),
            &mut seen,
        ) {
            return false;
        }
        let effects = crate::expr_eval::eval_helper_exprs_direct_effects(
            exprs,
            &self.root_bindings,
            self.current_value_dot().as_ref(),
        );
        self.chart_defaults_observed
            .extend(effects.chart_default_paths.iter().cloned());
        let mut chart_defaults = effects.chart_default_paths;
        self.locals.append_chart_value_defaults(&mut chart_defaults);
        true
    }

    /// `set $copy.Values KEY V` at DOCUMENT scope: replacing a values
    /// member of a context-copy local (`$copy := deepCopy .`) re-routes
    /// every later `with $copy` block onto the replaced member, so the
    /// mutation must reach the fragment binding (airflow's per-worker-set
    /// `set $globals.Values "workers" $workers`). Every other document
    /// set call keeps the read-only treatment below.
    fn apply_context_copy_value_mutations(&mut self, exprs: &[TemplateExpr]) {
        fn is_context_copy(binding: &AbstractValue) -> bool {
            match binding {
                AbstractValue::RootContext => true,
                AbstractValue::Overlay { fallback, .. } => is_context_copy(fallback),
                _ => false,
            }
        }

        let mut template_bindings = self.locals.range_member_values.clone();
        template_bindings.extend(
            self.locals
                .fragment_values
                .iter()
                .map(|(name, value)| (name.clone(), value.clone())),
        );
        let current_dot = self.current_dot_fragment();
        let env = crate::eval_env::EvalEnv::from_fragment_context(
            &template_bindings,
            current_dot.as_ref(),
        );
        for expr in exprs {
            let mutation_expr = match expr {
                TemplateExpr::VariableDefinition { value, .. }
                | TemplateExpr::Assignment { value, .. } => value.as_ref(),
                other => other,
            };
            let result = crate::expr_eval::eval_expr(mutation_expr, &env);
            for (name, entries) in &result.effects.local_set_mutations {
                if !entries.keys().all(|key| key == "Values") {
                    continue;
                }
                let Some(binding) = self.locals.fragment_values.get(name) else {
                    continue;
                };
                if !is_context_copy(binding) {
                    continue;
                }
                let updated = binding.clone().with_overlay_entries(entries.clone());
                self.locals.fragment_values.insert(name.clone(), updated);
            }
        }
    }

    #[expect(
        clippy::too_many_lines,
        reason = "keeping this semantic operation together makes its state transitions easier to audit"
    )]
    pub(super) fn eval_assignment_exprs(&mut self, exprs: &[TemplateExpr]) {
        if self.apply_helper_scope_set_mutations(exprs) {
            return;
        }
        self.apply_context_copy_value_mutations(exprs);
        if let Some(assignment) = parse_helper_assignment_from_exprs(exprs) {
            let rhs = std::slice::from_ref(&assignment.rhs_expr);
            self.record_required_subjects(rhs);
            let inlined_template_value = self.inline_static_template_value(rhs);
            let rhs_truthy_reduction = {
                let context = self.value_path_context();
                context
                    .condition_lowering_is_faithful(&assignment.rhs_expr)
                    .then(|| context.condition_predicate_expr(&assignment.rhs_expr))
            };
            let output_effects = self.value_path_context().expression_output_effects(rhs);
            let hole = self.eval_hole_exprs(rhs);
            // The binding is the hole value without widened members (an
            // unknown call result is influence, not a values-backed
            // fragment).
            let fragment_value = inlined_template_value
                .or_else(|| hole.value.clone().and_then(AbstractValue::without_widened));
            let previous_truthy_reduction = self
                .locals
                .truthy_reductions
                .get(&assignment.variable)
                .cloned();
            let truthy_reduction = match assignment.kind {
                crate::fragment_assignment::AssignmentKind::Declaration => rhs_truthy_reduction
                    .or_else(|| {
                        // A text-producing RHS (`$m := join "\n" $list`) keeps
                        // its INPUT value for attribution, but the binding's
                        // runtime truthiness is the produced text's emptiness,
                        // which that value cannot witness: a nonempty list can
                        // join to "". Abstain instead of reducing.
                        if rhs_produces_derived_text(&assignment.rhs_expr) {
                            return None;
                        }
                        fragment_value
                            .as_ref()
                            .and_then(AbstractValue::static_truthiness)
                            .map(|truthy| {
                                if truthy {
                                    Predicate::True
                                } else {
                                    Predicate::False
                                }
                            })
                    }),
                crate::fragment_assignment::AssignmentKind::Assignment
                    if self_preserving_nonempty_accumulation(
                        &assignment.rhs_expr,
                        &assignment.variable,
                    ) =>
                {
                    previous_truthy_reduction.map(|previous| {
                        let condition = Predicate::all(concretize_range_key_equalities(
                            &self.active_predicates,
                        ));
                        let exact = !condition.contains_approximation()
                            && condition.value_paths().iter().all(|path| {
                                !path.starts_with('$') && !path.split('.').any(|part| part == "*")
                            });
                        if exact {
                            or_predicates(previous, condition)
                        } else {
                            previous
                        }
                    })
                }
                // A plain reassignment's static truthiness is branch-local
                // state; the branch join unions it with the other arms'
                // reductions (`$shouldContinue = false` in a traversal's
                // kill-switch arm).
                crate::fragment_assignment::AssignmentKind::Assignment => rhs_truthy_reduction
                    .or_else(|| {
                        if rhs_produces_derived_text(&assignment.rhs_expr) {
                            return None;
                        }
                        fragment_value
                            .as_ref()
                            .and_then(AbstractValue::static_truthiness)
                            .map(|truthy| {
                                if truthy {
                                    Predicate::True
                                } else {
                                    Predicate::False
                                }
                            })
                    }),
            };
            let previous_fragment_value = self
                .locals
                .fragment_values
                .get(&assignment.variable)
                .cloned();
            // Helper bodies keep the prior binding when the right-hand side
            // resolves to nothing (the summary lane's rule): an unresolvable
            // re-assignment in one branch must not erase the other branches'
            // value at the join.
            if fragment_value.is_some() || !self.helper_scope {
                self.locals.bind_fragment_value(
                    assignment.kind,
                    assignment.variable.clone(),
                    fragment_value.clone(),
                );
            }
            // A guarded self-advance (`$x = index $x $k` reassigning `$x`
            // one member deeper while this step's `hasKey` presence guard
            // is active) marks the local so the branch join keeps the
            // advanced value: consumers stay a finite exact path, and
            // their facts carry the member's presence guard.
            if assignment.kind == crate::fragment_assignment::AssignmentKind::Assignment
                && let (
                    Some(AbstractValue::ValuesPath(parent)),
                    Some(AbstractValue::ValuesPath(child)),
                ) = (&previous_fragment_value, &fragment_value)
                && helm_schema_core::values_path_is_descendant(child, parent)
            {
                let presence = Predicate::from(crate::Guard::Absent {
                    path: child.clone(),
                })
                .negated();
                let guarded = self.active_predicates.iter().any(|active| match active {
                    Predicate::And(items) => items.contains(&presence),
                    other => other == &presence,
                });
                if guarded {
                    self.locals.mark_traversal_advance(&assignment.variable);
                }
            }
            if let Some(predicate) = truthy_reduction {
                self.locals
                    .truthy_reductions
                    .insert(assignment.variable.clone(), predicate);
            } else {
                self.locals.truthy_reductions.remove(&assignment.variable);
            }
            // `$tp := typeOf .Values.x` binds a TYPE DESCRIPTOR of the path:
            // later `eq $tp "string"` comparisons are type tests, never value
            // equalities, so remember the described path. Recorded after the
            // value binding, whose displacement clears every other domain.
            if let Some(sources) =
                type_descriptor_sources(&assignment.rhs_expr, self, &hole.effects.local_output_meta)
            {
                self.locals
                    .typeof_sources
                    .insert(assignment.variable.clone(), sources);
            }
            // `$replicas := int (default 1 .Values.x)` binds an INTEGER
            // COERCION of the path: comparisons on the local strengthen
            // through the raw-integer sound subsets exactly as the inline
            // cast expression would (jenkins' controller.replicas domain).
            let cast_source = self
                .value_path_context()
                .int_cast_operand(&assignment.rhs_expr);
            if let Some(source) = cast_source {
                self.locals
                    .int_cast_sources
                    .insert(assignment.variable.clone(), source);
            }
            // A Capabilities-defaulted version local keeps its subject
            // identity so `semverCompare` conditions on it evaluate the
            // policy version / override split (kube-prometheus-stack's
            // `$kubeTargetVersion` document gates).
            let kube_version_source = self
                .value_path_context()
                .kube_version_operand(&assignment.rhs_expr);
            if let Some(source) = kube_version_source {
                self.locals
                    .kube_version_sources
                    .insert(assignment.variable.clone(), source);
            }
            let mut output_meta = output_effects.local_output_meta.clone();
            merge_rendered_row_meta(&mut output_meta, &hole.effects.helper_rendered);
            if let Some(binding) = &fragment_value {
                for (path, meta) in binding.output_meta() {
                    output_meta.entry(path).or_default().merge(&meta);
                }
            }
            // A shape-erasing RHS (`$tag := … | toString`) rides the binding:
            // wherever the local renders, the splice exposes no input shape.
            for path in &hole.effects.shape_erased_paths {
                output_meta.entry(path.clone()).or_default().shape_erased = true;
            }
            for path in &hole.effects.stringified_paths {
                output_meta.entry(path.clone()).or_default().stringified = true;
            }
            for path in &hole.effects.yaml_serialized_paths {
                output_meta.entry(path.clone()).or_default().yaml_serialized = true;
            }
            // Likewise a derived-text RHS (`$port := include … .`): a later
            // consuming transform on the local operates on rendered text and
            // claims nothing about the underlying paths.
            for path in &hole.effects.derived_text_paths {
                output_meta.entry(path.clone()).or_default().derived_text = true;
            }
            // An omitting RHS (`$ctx = omit $ctx "runAsUser"`) rides the
            // binding: wherever the local renders the map, the removed
            // keys' sink typing must not bind. Retain guards start empty;
            // the branch join fills them where the omit provably did not
            // run.
            for (path, keys) in &hole.effects.omitted_map_keys {
                let meta = output_meta.entry(path.clone()).or_default();
                for key in keys {
                    meta.omitted_keys.insert(key.clone(), Vec::new());
                }
            }
            // A string-contracting RHS (`$name := .Values.x | trunc 63`)
            // also rides the binding: wherever the local renders, that row
            // requires a string input.
            for path in &hole.effects.string_contract_paths {
                output_meta.entry(path.clone()).or_default().string_contract = true;
            }
            for path in &hole.effects.json_serialized_paths {
                output_meta.entry(path.clone()).or_default().json_serialized = true;
            }
            // Eager helper arguments execute, but their rendered values are dependencies rather
            // than part of the assignment's value. Keep their runtime effects while preventing
            // their output metadata from riding the assigned local.
            let fragment_paths = fragment_value
                .as_ref()
                .map(AbstractValue::fragment_rendered_paths)
                .unwrap_or_default();
            let dependency_only_paths: std::collections::BTreeSet<&String> = hole
                .effects
                .helper_dependency_rendered
                .iter()
                .map(|row| &row.path)
                .filter(|path| !fragment_paths.contains(*path))
                .collect();
            output_meta.retain(|path, _| !dependency_only_paths.contains(path));
            // A `=` re-assignment under branch predicates keeps those
            // predicates on each flowing path's meta: the write-through
            // survives the branch join in the locals, so the conditions must
            // ride the meta to the render site. A truthiness condition about
            // a *different* flowing path describes a sibling's branch and
            // stays off this path's meta.
            if assignment.kind == crate::fragment_assignment::AssignmentKind::Assignment
                && !self.active_predicates.is_empty()
            {
                if let Some(binding) = &fragment_value {
                    for path in binding.fragment_rendered_paths() {
                        output_meta.entry(path).or_default();
                    }
                }
                let flowing: std::collections::BTreeSet<String> =
                    output_meta.keys().cloned().collect();
                for (path, meta) in &mut output_meta {
                    let site: std::collections::BTreeSet<Predicate> = self
                        .active_predicates
                        .iter()
                        .filter(|predicate| {
                            predicate_applies_to_flowing_path(predicate, path, &flowing)
                        })
                        .cloned()
                        .collect();
                    meta.conjoin_branches(&site);
                }
            }
            // Keep the (possibly empty) default and meta entries: the branch
            // join unions per-variable facts only for variables every outcome
            // still tracks, and a pre-branch binding without facts must not
            // erase a branch's recorded ones.
            self.locals
                .default_paths
                .insert(assignment.variable.clone(), output_effects.defaults.clone());
            self.locals
                .output_meta
                .insert(assignment.variable.clone(), output_meta);
            let demotion = if self.helper_scope {
                RenderedDemotion::Dependency
            } else {
                RenderedDemotion::Document
            };
            self.absorb_hole_effects(&hole.effects, demotion);
            // Inside helper bodies, direct expression paths ride the binding
            // and surface where the local renders; the summary lane never
            // claimed them at the assignment itself.
            if !self.helper_scope {
                let kind = if rhs.iter().any(TemplateExpr::renders_yaml_fragment) {
                    ValueKind::Fragment
                } else {
                    ValueKind::Scalar
                };
                self.push_effects_reads(&hole, kind);
            }
        }
        if let Some(get_binding) = parse_get_binding_from_exprs(exprs) {
            self.locals.apply_get_binding(get_binding);
        }
    }
}