Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compositions/turbo-package/jobs/turbo-package-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
29 changes: 25 additions & 4 deletions docs/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}" \
Expand All @@ -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:
Expand All @@ -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
Expand Down
81 changes: 81 additions & 0 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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" <<EOF
apiVersion: sourceplane.io/v1
kind: Intent
metadata:
name: stack-tectonic-render
compositions:
sources:
- name: stack-tectonic
kind: archive
path: $work_dir/stack.tgz
discovery:
roots:
- packages/
environments:
dev: {}
EOF
for pkg in declared defaults; do
{
echo "apiVersion: sourceplane.io/v1"
echo "kind: Component"
echo "metadata:"
echo " name: $pkg"
echo "spec:"
echo " type: turbo-package"
echo " subscribe:"
echo " environments:"
echo " - name: dev"
echo " profile: verify"
echo " parameters:"
echo " nodeVersion: \"20\""
echo " pnpmVersion: \"10.12.1\""
if [ "$pkg" = declared ]; then
echo " preBuildCommand: echo render-check-pre-build"
echo " buildCommand: echo render-check-build"
echo " typecheckCommand: echo render-check-typecheck"
fi
} > "$fixture/packages/$pkg/component.yaml"
done
(cd "$fixture" && orun plan --no-catalog-refresh --format json --output plan.json >/dev/null)

step_run() { # <job-id prefix> <step id>
jq -r --arg j "$1" --arg s "$2" \
'.jobs[] | select(.id | startswith($j + ".")) | .steps[] | select(.id == $s) | .run' \
"$fixture/plan.json"
}
expect() { # <job> <step> <text the rendered run must contain>
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"
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading