From c33ec2348120b0afc4f435e35beded732a0edbe3 Mon Sep 17 00:00:00 2001 From: vijayakrishnans Date: Fri, 6 Nov 2026 13:15:22 +0000 Subject: [PATCH] 03-docs: render the deployment record without PyYAML The build box has python3 but not PyYAML, and render-deployment-docs.sh imported yaml outside its try block to read the public origin from intent.yaml. The import fails with exit 1 and no message, so a console build stops at 03-docs with its site live. blog-starter, astro-boilerplate and portfolio-starter-kit hit this first (sourceplane/blog-starter#9); this ports the same fix. The hook uses PyYAML when present and otherwise reads environments..env.SITE_URL by indentation. testing/render.test.sh runs it under a python3 with no third-party packages, and Baseline CI runs that test. Records risk VR-F. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/baseline.yml | 4 +- hooks/render-deployment-docs.sh | 36 +++++++++++-- .../risks-and-open-questions.md | 1 + testing/render.test.sh | 51 +++++++++++++++++++ 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100755 testing/render.test.sh diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml index 04d35b6..f970a00 100644 --- a/.github/workflows/baseline.yml +++ b/.github/workflows/baseline.yml @@ -41,11 +41,11 @@ jobs: # names a packageManager, and then fails on a runner with no pnpm. # This job installs nothing. package-manager-cache: false - - name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer) + - name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer, render) run: | set -euo pipefail python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml - for t in manifest phases coverage rebrand retouch bootstrap-defer; do + for t in manifest phases coverage rebrand retouch bootstrap-defer render; do echo "── $t" bash "testing/$t.test.sh" done diff --git a/hooks/render-deployment-docs.sh b/hooks/render-deployment-docs.sh index 0bbe21c..63de5bf 100644 --- a/hooks/render-deployment-docs.sh +++ b/hooks/render-deployment-docs.sh @@ -53,16 +53,46 @@ badge() { case "$1" in 2*|3*) echo "LIVE ($1)" ;; 000) echo "unreachable" ;; *) # The environment's public origin: SITE_URL from intent.yaml when set (a custom # domain the owner attached), else the workers.dev URL. +# STANDARD LIBRARY ONLY. The build box has python3 but not PyYAML, and an +# `import yaml` that fails ended this hook with exit 1 and no message: +# console builds reached 03-docs and stopped here, with the site live. +# PyYAML is used when present; otherwise the one key this needs is read by +# indentation: environments → → env → SITE_URL. site_url() { python3 - "$1" "https://${brand}-web-$1.${sub}.workers.dev" <<'PY' -import sys, yaml +import re, sys env, fallback = sys.argv[1], sys.argv[2] + +def by_indent(text): + path, want = [], ["environments", env, "env", "SITE_URL"] + for line in text.splitlines(): + if not line.strip() or line.lstrip().startswith("#"): + continue + m = re.match(r"^( *)([A-Za-z0-9_.-]+):(.*)$", line) + if not m: + continue + depth = len(m.group(1)) + while path and path[-1][0] >= depth: + path.pop() + path.append((depth, m.group(2))) + if [k for _, k in path] == want: + value = m.group(3).split(" #")[0].strip() + return value.strip("'\"") + return "" + +try: + text = open("intent.yaml").read() +except OSError: + text = "" try: - d = yaml.safe_load(open("intent.yaml")) or {} + import yaml + d = yaml.safe_load(text) or {} url = (((d.get("environments") or {}).get(env) or {}).get("env") or {}).get("SITE_URL") or "" +except ImportError: + url = by_indent(text) except Exception: url = "" -print(url.rstrip("/") or fallback) +print(str(url).rstrip("/") or fallback) PY } stage_url="$(site_url stage)"; prod_url="$(site_url prod)" diff --git a/specs/epics/vite-react-boilerplate/risks-and-open-questions.md b/specs/epics/vite-react-boilerplate/risks-and-open-questions.md index 14c8bbd..aa19366 100644 --- a/specs/epics/vite-react-boilerplate/risks-and-open-questions.md +++ b/specs/epics/vite-react-boilerplate/risks-and-open-questions.md @@ -7,3 +7,4 @@ | VR-C | The template's Vite 5 and React 18, not current majors | ACCEPTED | They build and run on Node 22 (spike: `~/orunbase/spikes/vite-react-boilerplate.md`). Moving to Vite 7 or React 19 is the owner's change, and the page's spec and the e2e tier would catch a behaviour it breaks | | VR-D | The tab's title is the site's name | ACCEPTED | The template's title is "Vite + React + TS"; the seam's default is the heading's "Vite + React", and the title reads it, so a product's tab carries its own name and nothing else | | VR-E | stack-tectonic 0.19.0, not 0.20.0 | ACCEPTED | 0.20.0's lane-shared install links each job's `node_modules` out of its tree; the siblings pin 0.19.0 for it and the app would save nothing | +| VR-F | 03-docs needs PyYAML the build box lacks | RESOLVED | `hooks/render-deployment-docs.sh` imported `yaml` to read the public origin from `intent.yaml`. The build box has python3 but not PyYAML, so the import failed with exit 1 and no message, and console builds stopped at 03-docs with the site live. Local and CLI runs had PyYAML and passed. blog-starter (BS-H), astro-boilerplate (AB-L) and portfolio-starter-kit (PK-L) hit it first (2026-11-06). The hook now uses PyYAML when present and reads that one key by indentation otherwise; `testing/render.test.sh` runs it under a python3 with no third-party packages | diff --git a/testing/render.test.sh b/testing/render.test.sh new file mode 100755 index 0000000..dcf4a1e --- /dev/null +++ b/testing/render.test.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# hooks/render-deployment-docs.sh runs in the build box, which has python3 but +# not PyYAML. Console builds that reached 03-docs stopped there on +# `import yaml`, with exit 1 and its site live. This runs the hook on a +# scaffolded tree under a python3 with no third-party packages, and checks it +# reads SITE_URL from intent.yaml the same way with and without PyYAML. +# Offline: the probes find nothing, which the record says as "unreachable". +set -euo pipefail +here="$(cd "$(dirname "$0")/.." && pwd)" +work="$(mktemp -d)"; trap 'rm -rf "$work"' EXIT + +python3 -m venv --without-pip "$work/bare" +if "$work/bare/bin/python3" -c 'import yaml' 2>/dev/null; then + echo "render.test.sh: the bare python3 still imports yaml — cannot test" >&2; exit 1 +fi + +site="$work/site"; mkdir -p "$site/.github/workflows" +mkdir -p "$site/.rebrand" +printf '{"reponame":"acme-notes","subdomain":"acme"}\n' > "$site/.rebrand/values.json" +printf '# Acme Notes\n\nA site.\n' > "$site/README.md" +printf 'jobs:\n lane:\n steps:\n - with:\n version: v2.78.4\n' > "$site/.github/workflows/ci.yml" +cat > "$site/intent.yaml" <<'YAML' +execution: + state: + workspace: ws_TEST0000 +environments: + stage: + env: + BASE_DOMAIN: acme.dev + prod: + # a custom domain + env: + SITE_URL: "https://acme.dev/" # trailing slash dropped +YAML + +fail=0 +for py in "$work/bare/bin" ""; do + label="${py:+without PyYAML}"; label="${label:-with the system python3}" + [ -n "$py" ] || python3 -c 'import yaml' 2>/dev/null || { echo " (skipped: system python3 has no PyYAML)"; continue; } + rm -f "$site/ai/context/deployment.md" + if ! (cd "$site" && PATH="${py:+$py:}$PATH" bash "$here/hooks/render-deployment-docs.sh" . ws_TEST0000 "$here" >/dev/null 2>"$work/err"); then + echo " ✕ $label: the hook failed"; sed 's/^/ /' "$work/err"; fail=1; continue + fi + rec="$site/ai/context/deployment.md" + grep -q 'stage `https://acme-notes-web-stage.acme.workers.dev`' "$rec" || { echo " ✕ $label: stage origin is not the workers.dev URL"; fail=1; } + grep -q 'prod `https://acme.dev`' "$rec" || { echo " ✕ $label: prod origin is not SITE_URL"; fail=1; } + grep -q '' "$site/README.md" || { echo " ✕ $label: README section missing"; fail=1; } + [ "$fail" = 0 ] && echo " $label: record rendered, SITE_URL read" +done +[ "$fail" = 0 ] || exit 1 +echo "render.test.sh: ok"