Skip to content

feat(helm): template-action-aware pinnability classifier (#1234) - #1887

Merged
lex00 merged 6 commits into
mainfrom
feat/1234-pinnability-classifier
Aug 24, 2026
Merged

lex00 merged 6 commits into
mainfrom
feat/1234-pinnability-classifier

Conversation

@lex00

@lex00 lex00 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Phase 1 of epic #1228: promote the survey harness's prototype classifier into the lexicon proper as lexicons/helm/src/pinnability/ — the production gate the pinned-render pipeline (#1235–#1240) calls before anything is pinned. Exported from the package entry and as the ./pinnability subpath; imports no generated artifacts, so the survey CI job still runs without a generation step.

Stacked on #1884 (feat/1228-survey-harness). Merge that first; this PR's own diff is the classifier promotion. If the base branch is gone, this rebases onto main.

What the promotion adds over the prototype

Template actions with structure, not just extraction. Actions are parsed with their enclosing control flow (if/else if/else, with including dot rebinding, range, define), so the classifier knows which gates enclose each construct. Lookup detection stays action-based — cert-manager's 52 textual hits classify as 0 (finding 9) — and matches only the function call, never a value named lookup* (grafana's persistence.lookupVolumeName, survey finding 2).

Subchart-recursive with per-instance effective values. Chart.yaml dependencies are walked with helm-style coalescing (child defaults < parent <alias-or-name> subtree < supplied values; globals propagate; null deletes). Aliased dependencies get their own value scope over the shared directory; condition:-disabled dependencies gate everything inside them; an unvendored dependency is a recorded warning, never a silent pass.

Values-aware reachability — the epic's core insight applied. Pinnability is a property of (chart, values):

  • A control-flow lookup whose enclosing gates (or short-circuited same-action and/or conjuncts) definitively evaluate false under the supplied values is a recorded conditional hazard (chart, path in root coordinates, gating value) — not a refusal. Flipping the value re-classifies the pair.
  • A reachable one refuses with file and line; an unprovable gate also refuses (not provably gated off) — unknown always degrades toward refusal, never toward pinning. The tri-state condition evaluator covers and/or/not/eq/ne/empty/default, parens, pipelines, literals, and .Values paths; everything else is UNKNOWN.
  • Value-position lookup stays a declared-input requirement (5 of 13 corpus charts; the reuse-existing-secret pattern), recorded in closedInputs.

Open generated inputs (randAlphaNum, genCA, genSignedCert, ...) are detected statically and named, with the suppliable .Values path when the action carries one (harbor's core.secret/jobservice.secret/registry.secret cascade all resolve). Entries without a statically visible supply path are handed to the double-render localizer (#1236) by name. A generator behind a closed gate, or one whose value is already supplied, is dead and not an open input.

Capability reads (.Capabilities.KubeVersion / .APIVersions) are listed per occurrence in requiresProfile — the normal case (11 of 13 charts), not an error.

Verdict shape

{
  verdict: "deterministic" | "pinnable" | "unpinnable",
  requiresProfile: CapabilityRequirement[],   // per-occurrence file:line
  closedInputs: ClosedInput[],                // generated values, value-position lookups, supplied values
  hazards: ConditionalHazard[],               // gated-off control-flow lookups: (chart, file:line, gates)
  reasons: string[],                          // refusals first, specific per construct
  lookups: { controlFlow, valuePosition },    // raw findings for count/location surfaces
  warnings: string[]
}

The survey keeps its previous labels (deterministic-as-is, pinnable-with-closed-inputs) via a mapping so expected.txt diffs show only real reclassification.

Survey rewiring and expected.txt changes

The harness now consumes the promoted classifier; the prototype (test/survey/classify.ts) is deleted, with the routing/diff helpers promoted to src/pinnability/render-stream.ts (seeds for #1239/#1236). Full 13-chart survey re-run against helm v4.1.1. Two verdicts legitimately change, both by the reachability the promotion adds — the exact recovery the survey comment flagged as the open design question:

  • kube-prometheus-stack: unpinnable -> pinnable-with-closed-inputs, hazards=1. The bundled grafana's control-flow lookup (charts/grafana/templates/pvc.yaml:28) sits behind grafana.persistence.enabled, which the defaults leave false. The hazard records the gate.
  • grafana: unpinnable -> pinnable-with-closed-inputs, hazards=1. Same construct standalone: persistence.enabled defaults to false, so a default-values render never consults the cluster. (Its 4 unstable lines — the randAlphaNum admin password cascade — keep it pinnable-with-closed-inputs, now with the open input named.)

Every other row keeps its verdict and every count (caps, lookup-control/value, crds, unstable-lines) is unchanged; rows gain a hazards= column so gating drift fails the suite.

Tests

  • 37 colocated unit tests (src/pinnability/pinnability.test.ts): findings 9/10 regressions, condition evaluation and short-circuit reachability, coalescing/alias/condition/global handling, values-gated reachability (hazard vs refusal on a values flip, subchart gates in root coordinates, disabled deps, aliased instance left open refuses), generated-input detection and closure, capability listing.
  • New gated-lookup-fixture commits the kube-prometheus-stack shape offline (helm-only, no network): hazard under defaults, refusal when kid.persistence.enabled=true.
  • npx vitest run lexicons/helm: 572 passed, 15 skipped (network-gated).
  • CHANT_HELM_SURVEY=1 survey: 22/22, all 13 charts assert.
  • npm run build -w @intentius/chant-lexicon-helm, just build, just lint, npx tsx scripts/check-lexicons.ts: clean.

Closes #1234

lex00 added 4 commits August 24, 2026 16:31
…d conditional deps

A top-level-only CRD fixture passes even when subchart CRD routing is
broken (epic #1228 finding 10). This chart carries crds/ in the parent
AND in a subchart, includes the same subchart twice (plain + alias, so
the render emits duplicate CRD documents — finding 11), and a
conditional dependency disabled by default (finding 12). A comment in
the parent template deliberately mentions lookup as prose so a
text-matching classifier trips over it (finding 9).
loki 6.21.0 fails with default values (nil pointer on
loki.storage.bucketNames.chunks). A chart silently excluded from the
corpus reads as coverage it does not have, so charts that need values
ship them beside the corpus manifest and a chart that cannot render is
a harness failure, not an omission.
Phase 0 of epic #1228. A committed corpus of 13 real charts, pinned by
exact version in charts.txt, pulled at run time with an isolated helm
repo config and never vendored. Per chart the harness scans template
actions, renders twice with closed inputs (pinned kube version, values
file when the chart needs one), and classifies: deterministic-as-is,
pinnable-with-closed-inputs, or unpinnable — recording why.

Verdicts are asserted against expected.txt, not printed: any drift in
verdict, CRD routing, lookup counts, or render stability fails the
suite. The two prototype classifier bugs are fixed and regression-
pinned: lookup detection parses template actions rather than text
(finding 9 — cert-manager's 52 comment-prose hits classify as 0), and
CRD routing matches a crds/ path segment rather than prefix (finding 10
— subchart CRDs arrive as charts/<child>/crds/).

The upstream survey is network-gated on CHANT_HELM_SURVEY (run it with
'just helm-survey'; CI runs it path-scoped plus weekly via
helm-survey.yml). The fixture surveys — the umbrella chart plus a
control-flow-lookup and an open-generated-input fixture — need only a
helm binary and run offline in the normal suite.

The subchart-aware scan also surfaces a finding the prototype's
top-level-only grep missed: kube-prometheus-stack bundles grafana, so
its control-flow lookup (templates/pvc.yaml:28) refuses the umbrella
too under a purely static gate.
Promote the survey harness's prototype classifier into the lexicon proper
as src/pinnability — the production gate the pinned-render pipeline
(#1235-#1240) calls before anything is pinned.

What the promotion adds over the prototype:

- Template actions are parsed with control-flow structure (if/else-if/else,
  with, range, define), not just extracted — so the classifier knows which
  gates enclose each construct. Lookup detection stays action-based
  (finding 9: cert-manager's 52 textual hits classify as 0) and matches
  only the function call, never a value named lookup* (grafana's
  persistence.lookupVolumeName).
- Subchart-recursive with per-instance effective values: Chart.yaml
  dependencies are walked with helm-style coalescing (child defaults <
  parent subtree < supplied values, globals propagated), aliased
  dependencies get their own value scope over the shared directory, and
  condition:-disabled dependencies gate everything inside them.
- Values-aware reachability, the epic's core insight applied: a
  control-flow lookup whose enclosing gates (or short-circuited same-action
  conjuncts) definitively evaluate false under the supplied values is a
  recorded conditional hazard (chart, path, gating value) instead of a
  refusal — flipping the value re-classifies the (chart, values) pair. A
  reachable or unprovable one refuses with the file and line. Unknown
  always degrades toward refusal, never toward pinning.
- Open generated inputs (randAlphaNum, genCA, and friends) are detected
  statically and named, with the suppliable .Values path when the action
  carries one; the double-render localizer (#1236) confirms them
  dynamically.
- .Capabilities.* references are listed per occurrence as a
  requires-profile input — the normal case (11 of 13 corpus charts), not
  an error.

The verdict is a typed report: { verdict: deterministic | pinnable |
unpinnable, requiresProfile, closedInputs, hazards, reasons } with raw
lookup findings and scan warnings alongside.

The survey harness now consumes the promoted classifier; the prototype
(test/survey/classify.ts) is deleted. Two corpus verdicts legitimately
change, both by the reachability the promotion adds:

- kube-prometheus-stack: unpinnable -> pinnable-with-closed-inputs. The
  bundled grafana's control-flow lookup sits behind
  grafana.persistence.enabled, which the chart's defaults leave false; the
  hazard records the gate.
- grafana: unpinnable -> pinnable-with-closed-inputs. Same construct,
  standalone: persistence.enabled defaults to false, so a default-values
  render never consults the cluster.

Every other row keeps its verdict and counts; expected.txt rows gain a
hazards= column so gating drift fails the suite. A new
gated-lookup-fixture commits the kube-prometheus-stack shape offline.
@lex00
lex00 changed the base branch from feat/1228-survey-harness to main August 24, 2026 22:59
@lex00
lex00 merged commit 1664c5d into main Aug 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(helm): template-action-aware pinnability classifier

1 participant