From b79652305fdfc12fffc77eee8d91447703f85b1a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 06:00:06 +0000 Subject: [PATCH] fix(turbo-package): pre-build, build and typecheck read their parameters (0.20.1) The verify job guarded each optional step on a key the template context does not have: {{if .preBuildCommand}} <- always empty {{.parameters.preBuildCommand}} <- where the value is orun renders job templates with .orun, .parameters and .env only, so every guard was false from 0.18.1 through 0.20.0. Pre-build printed "Skipping pre-build." on every component, which is where consumers keep their tests, and a declared buildCommand or typecheckCommand was ignored in favour of the default. The three guards now read .parameters.*. verify.sh gains the two checks that would have caught it: - every {{if}} / {{with}} in compositions/ must read .orun, .parameters or .env; - turbo-package is planned through the packed artifact with two fixture components, and the rendered steps must run the declared commands, or skip pre-build and use the defaults when none are declared. Each fails on its own against the 0.20.0 template. Consumers pin exact versions, so this changes nobody until they move their pin. Of the 26 baselines on stack-tectonic, every turbo-package job except lumen's is on quick-check, which plans none of the three steps: their plans are identical with and without this fix. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BfmHkwWeA1oPJGBNF3QSQH --- .../jobs/turbo-package-verify.yaml | 6 +- docs/verification.md | 29 ++++++- scripts/verify.sh | 81 +++++++++++++++++++ stack.yaml | 2 +- 4 files changed, 110 insertions(+), 8 deletions(-) diff --git a/compositions/turbo-package/jobs/turbo-package-verify.yaml b/compositions/turbo-package/jobs/turbo-package-verify.yaml index ae19da9..f0f6090 100644 --- a/compositions/turbo-package/jobs/turbo-package-verify.yaml +++ b/compositions/turbo-package/jobs/turbo-package-verify.yaml @@ -50,7 +50,7 @@ spec: capability: turbo-package.pre-build shell: bash run: | - {{if .preBuildCommand}} + {{if .parameters.preBuildCommand}} {{.parameters.preBuildCommand}} {{else}} echo "Skipping pre-build." @@ -66,11 +66,11 @@ spec: - id: build-package name: build-package capability: turbo-package.build - run: "{{if .buildCommand}}{{.parameters.buildCommand}}{{else}}pnpm exec turbo run build --filter=./{{end}}" + run: "{{if .parameters.buildCommand}}{{.parameters.buildCommand}}{{else}}pnpm exec turbo run build --filter=./{{end}}" onFailure: stop - id: typecheck-package name: typecheck-package capability: turbo-package.typecheck - run: "{{if .typecheckCommand}}{{.parameters.typecheckCommand}}{{else}}pnpm exec turbo run typecheck --filter=./{{end}}" + run: "{{if .parameters.typecheckCommand}}{{.parameters.typecheckCommand}}{{else}}pnpm exec turbo run typecheck --filter=./{{end}}" onFailure: stop diff --git a/docs/verification.md b/docs/verification.md index bf57e8a..62ebbd8 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -4,7 +4,7 @@ The catalog has one gate, `scripts/verify.sh`, and two workflows that run it. ## `scripts/verify.sh` -The script runs from the repository root and executes four stages in order. Any failure stops the run. +The script runs from the repository root and executes six stages in order. Any failure stops the run. ### 1. Structural validation of every composition contract @@ -18,7 +18,19 @@ For each `compositions/*/composition.yaml`: The run also fails if no composition directories are found at all, so an empty or mis-staged tree cannot pass silently. -### 2. Publish target resolution +### 2. Every template guard reads a namespace the job can see + +A job template is rendered with exactly three namespaces: `.orun`, `.parameters` and `.env`. A +condition on any other key is always false, so the step takes its `else` branch for every consumer +and nothing fails. Every `{{if ...}}` and `{{with ...}}` in `compositions/` must therefore read one of +those three. + +This is the bug that shipped in 0.18.1 through 0.20.0: `turbo-package` guarded pre-build, build and +typecheck on `.preBuildCommand`, `.buildCommand` and `.typecheckCommand`, so pre-build skipped every +component's tests and declared build and typecheck commands were ignored. Inside a `range` or `with` +block `.` is rebound; bind a variable there so this rule can still read the expression. + +### 3. Publish target resolution ```bash orun publish "ghcr.io/sourceplane/stack-tectonic:${stack_version}" \ @@ -28,13 +40,13 @@ orun publish "ghcr.io/sourceplane/stack-tectonic:${stack_version}" \ `stack_version` is read from `metadata.version` in `stack.yaml`. This resolves the manifest and the registry target without uploading anything. -### 3. Pack the shipped layers +### 4. Pack the shipped layers `orun pack` archives whatever root it is given, but `orun publish` ships only `stack.yaml`, `compositions/`, and `examples/`. The script stages exactly that subset into a temporary directory and packs it, so the artifact under test is the artifact consumers actually resolve. -### 4. Resolve the packed artifact back through a consumer intent +### 5. Resolve the packed artifact back through a consumer intent The script writes a throwaway `intent.yaml` pointing at the packed tarball with an `archive` composition source: @@ -55,6 +67,15 @@ resolve; it is no evidence the package is loadable. Packing and re-resolving exe path a consumer repository runs, so a composition Orun cannot load or export fails here instead of in a downstream repo after release. +### 6. Render `turbo-package` through the packed artifact + +Resolving proves a composition loads, not that it renders what a component declares. The script plans +two fixture components through the same packed artifact, one declaring `preBuildCommand`, +`buildCommand` and `typecheckCommand` and one declaring none, on the `verify` profile. It then checks +the rendered steps: the first must run its three commands, and the second must skip pre-build and use +the default `turbo run build` and `turbo run typecheck`. Every structural check passed on the releases +that skipped pre-build; this one would have failed them. + ## Verify workflow `.github/workflows/verify.yml` runs on every pull request and every push to `main`. It is a single diff --git a/scripts/verify.sh b/scripts/verify.sh index 716c6d2..64db414 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -35,6 +35,22 @@ done test "$expected" -gt 0 || { echo "verify: no compositions found" >&2; exit 1; } echo "verify: $expected composition contract(s) structurally valid" +# A job template sees exactly three namespaces: .orun, .parameters and .env +# (orun's planner builds no others). A condition on anything else is always +# false, so its step silently takes the else branch for every consumer. That is +# how turbo-package's pre-build skipped every component's tests from 0.18 to +# 0.20.0 while its lanes went green. Inside a range or with block `.` is +# rebound; use a variable there ({{ $x := ... }}) so this rule can see it. +bad_guards="$(grep -rnoE '\{\{-?[[:space:]]*(else[[:space:]]+)?(if|with)[[:space:]][^}]*' compositions \ + | grep -oE '^[^:]+:[0-9]+:|[[:space:](]\.[A-Za-z_][A-Za-z0-9_]*' \ + | awk '/^[^ (.]/{loc=$0; next} {key=$0; sub(/^[[:space:](]\./, "", key); if (key != "orun" && key != "parameters" && key != "env") print loc " ." key}')" +if [ -n "$bad_guards" ]; then + echo "verify: these guards read a key the template context does not have (it has .orun, .parameters, .env):" >&2 + echo "$bad_guards" >&2 + exit 1 +fi +echo "verify: every template guard reads .orun, .parameters or .env" + # Resolve the publish target and version without uploading. orun publish "ghcr.io/sourceplane/stack-tectonic:${stack_version}" \ --dry-run \ @@ -83,3 +99,68 @@ for contract in "$repo_root"/compositions/*/composition.yaml; do done echo "verify: all $expected composition(s) export from the packed artifact" + +# Render, not just resolve: plan a turbo-package component through the packed +# artifact and check its declared commands reach the steps. Structural checks +# passed every release that skipped pre-build; this one would have failed. +fixture="$work_dir/consumer" +mkdir -p "$fixture/packages/declared" "$fixture/packages/defaults" +cat > "$fixture/intent.yaml" < "$fixture/packages/$pkg/component.yaml" +done +(cd "$fixture" && orun plan --no-catalog-refresh --format json --output plan.json >/dev/null) + +step_run() { # + jq -r --arg j "$1" --arg s "$2" \ + '.jobs[] | select(.id | startswith($j + ".")) | .steps[] | select(.id == $s) | .run' \ + "$fixture/plan.json" +} +expect() { # + run="$(step_run "$1" "$2")" + case "$run" in + *"$3"*) ;; + *) echo "verify: turbo-package rendered $1/$2 as '$run', expected it to contain '$3'" >&2; exit 1 ;; + esac +} +expect declared pre-build "echo render-check-pre-build" +expect declared build-package "echo render-check-build" +expect declared typecheck-package "echo render-check-typecheck" +expect defaults pre-build 'echo "Skipping pre-build."' +expect defaults build-package "pnpm exec turbo run build --filter=./" +expect defaults typecheck-package "pnpm exec turbo run typecheck --filter=./" +echo "verify: turbo-package renders declared commands and falls back to its defaults" diff --git a/stack.yaml b/stack.yaml index 8c61e5d..29faaef 100644 --- a/stack.yaml +++ b/stack.yaml @@ -3,7 +3,7 @@ kind: Stack metadata: name: stack-tectonic title: Stack Tectonic - version: 0.20.0 + version: 0.20.1 description: Versioned OCI-hosted catalog of Cloudflare, Terraform and monorepo compositions for Sourceplane repositories. owner: sourceplane tags: