diff --git a/.claude/skills/verify/SKILL.md b/.claude/skills/verify/SKILL.md index 4ab8fd4..e5ace0a 100644 --- a/.claude/skills/verify/SKILL.md +++ b/.claude/skills/verify/SKILL.md @@ -1,6 +1,6 @@ --- name: verify -description: Run vimmary's checks before committing — scripts/lint (gofmt, vet, golangci-lint, govulncheck, migration rules, script tests, frontend build) and scripts/test (race tests against Postgres + pgvector, frontend tests), scripts/e2e for startup, config, migration or Dockerfile changes. Triggers — "verifizier das", "läuft der build", "prüf ob das durchgeht", "run the checks", "verify before commit", "does this still build". Also reach for it after changing anything under internal/, web/ or migrations/. Not for running the app — that is the run skill. +description: Run vimmary's checks before committing — scripts/lint (gofmt, vet, golangci-lint, govulncheck, migration rules, script tests, frontend build) and scripts/test (race tests against Postgres + pgvector, frontend tests), scripts/e2e for startup, config, migration, Dockerfile or web/ changes. Triggers — "verifizier das", "läuft der build", "prüf ob das durchgeht", "run the checks", "verify before commit", "does this still build". Also reach for it after changing anything under internal/, web/ or migrations/. Not for running the app — that is the run skill. --- # Verify @@ -11,7 +11,8 @@ The checks are the entry scripts CI runs; run them from the repo root. scripts/setup # toolchain and npm dependencies, if the SessionStart hook has not run scripts/lint scripts/test -scripts/e2e # for a change to startup, config, migrations or the Dockerfile +scripts/e2e # for a change to startup, config, migrations, the Dockerfile or web/ +E2E_NATIVE=1 scripts/e2e # the same without the image, where docker build fails (cloud session) ``` - `scripts/test` starts `compose.test.yaml` (pgvector) when diff --git a/CLAUDE.md b/CLAUDE.md index 56b3545..ec4a56e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,7 +8,9 @@ Shorts and playlists are out of scope, and it never downloads podcast audio. `scripts/setup`, `scripts/test`, `scripts/lint` and `scripts/e2e` are the checks; CI, the hooks in `.claude/settings.json` and sessions call only these. Run `scripts/lint` and `scripts/test` before committing, `scripts/e2e` as well -for a change to startup, config, migrations or the Dockerfile. +for a change to startup, config, migrations, the Dockerfile or `web/`. Where +`docker build` fails (a cloud session), `E2E_NATIVE=1 scripts/e2e` runs it +without the image and without the upgrade test. ## Gotchas diff --git a/scripts/e2e b/scripts/e2e index 9c9b69a..0e1abba 100755 --- a/scripts/e2e +++ b/scripts/e2e @@ -18,6 +18,13 @@ # # E2E_UPGRADE=0 skips steps 1 and 3. # +# E2E_NATIVE=1 is for a machine that cannot build the image (a cloud session: +# docker build fails on the egress proxy's certificate). It builds the +# frontend and the binary, starts them against Postgres from +# compose.test.yaml with the fixtures, and runs the HTTP checks and the +# Playwright tests. There is no upgrade test; CI runs it. E2E_CONFIG replaces +# e2e/vimmary.yaml as the app's config (scripts/e2e-native_test.sh). +# # BUILD_SHA= scripts/e2e (default: git rev-parse HEAD) set -euo pipefail # shellcheck source=scripts/lib/common.sh @@ -69,6 +76,60 @@ if [[ -n "${E2E_BASE_URL:-}" ]]; then fi export BUILD_SHA="${BUILD_SHA:-$(git rev-parse HEAD)}" + +if [[ "${E2E_NATIVE:-0}" == 1 ]]; then + tmp=$(mktemp -d) + db=(docker compose --progress quiet -f compose.test.yaml -p "vimmary-e2e-native-$$") + app_pid="" + # shellcheck disable=SC2329 # invoked by the EXIT trap + native_cleanup() { + local status=$? + if [[ -n "$app_pid" ]]; then + kill "$app_pid" 2>/dev/null || true + wait "$app_pid" 2>/dev/null || true + fi + if [[ $status -ne 0 && -f "$tmp/vimmary.log" ]]; then + tail -n 80 "$tmp/vimmary.log" >&2 + fi + "${db[@]}" down -v --remove-orphans >/dev/null 2>&1 || true + rm -rf "$tmp" + exit "$status" + } + trap native_cleanup EXIT + + step "starting the database (compose.test.yaml)" + "${db[@]}" up -d --wait --quiet-pull + db_addr=$("${db[@]}" port db 5432) + + step "building the frontend and the binary" + ensure_npm_deps + (cd web && npm run build) >/dev/null + go build -ldflags "-X main.Version=${BUILD_SHA}" -o "$tmp/vimmary" ./cmd/vimmary + + # The loopback health listener is the container's; off here, so a second + # instance on this machine does not collide on 8081. + { cat "${E2E_CONFIG:-e2e/vimmary.yaml}"; echo 'health_addr: ""'; } >"$tmp/config.yaml" + port=$(python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])') + base_url="http://127.0.0.1:${port}" + + step "starting vimmary on ${base_url}" + VIMMARY_SERVER_HOST=127.0.0.1 VIMMARY_SERVER_PORT="$port" \ + VIMMARY_DB_HOST=127.0.0.1 VIMMARY_DB_PORT="${db_addr##*:}" VIMMARY_POSTGRES_PASSWORD=vimmary \ + "$tmp/vimmary" --config "$tmp/config.yaml" >"$tmp/vimmary.log" 2>&1 & + app_pid=$! + for _ in $(seq 1 120); do + curl -fsS --max-time 2 "$base_url/version" 2>/dev/null | grep -q "\"$BUILD_SHA\"" && break + kill -0 "$app_pid" 2>/dev/null || fail "vimmary exited during startup" + sleep 1 + done + expect_json "$base_url/version" ".build == \"$BUILD_SHA\" and .status == \"ok\"" "/version reports ${BUILD_SHA:0:12}" + http_checks "$base_url" + browser_tests "$base_url" + echo + echo "e2e ok (native): ${BUILD_SHA}" + exit 0 +fi + base_ref="${E2E_BASE_REF:-origin/main}" upgrade="${E2E_UPGRADE:-1}" project="vimmary-e2e-$$" diff --git a/scripts/e2e-native_test.sh b/scripts/e2e-native_test.sh new file mode 100755 index 0000000..75d0641 --- /dev/null +++ b/scripts/e2e-native_test.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Test for the failure path of E2E_NATIVE=1 scripts/e2e. Runs in the lint +# check. A config the app cannot parse makes it exit during startup; the run +# must fail, print the app's log and leave no database container behind. +# Without Docker it is skipped, except in CI. +set -uo pipefail +cd "$(dirname "$0")/.." || exit 1 +# shellcheck source=scripts/lib/common.sh +source scripts/lib/common.sh + +if ! docker info >/dev/null 2>&1; then + if is_ci; then + echo "FAIL e2e-native: Docker is not reachable" + exit 1 + fi + echo "skip e2e-native: Docker is not reachable" + exit 0 +fi + +dir=$(mktemp -d) +trap 'rm -r -- "$dir"' EXIT +sed 's/^seed_fixtures: true$/seed_fixtures: not-a-bool/' e2e/vimmary.yaml >"$dir/bad.yaml" + +out=$(E2E_NATIVE=1 E2E_CONFIG="$dir/bad.yaml" scripts/e2e 2>&1) +rc=$? +fail=0 +check() { # check + local name=$1; shift + if "$@"; then echo "ok e2e-native: $name"; else echo "FAIL e2e-native: $name"; fail=1; fi +} +left=$(docker ps -aq --filter name=vimmary-e2e-native-) +check "a broken config fails the run (exit $rc)" test "$rc" -ne 0 +check "the run names the early exit" grep -q 'vimmary exited during startup' <<<"$out" +check "the app log is printed" grep -q 'msg="startup failed"' <<<"$out" +check "no database container remains" test -z "$left" +if [[ $fail -ne 0 ]]; then + tail -n 30 <<<"$out" +fi +exit "$fail" diff --git a/scripts/lint b/scripts/lint index 6f5d786..85b3512 100755 --- a/scripts/lint +++ b/scripts/lint @@ -45,6 +45,7 @@ step "script tests" scripts/check-migrations_test.sh scripts/resolve-sha_test.sh scripts/renovate-only_test.sh +scripts/e2e-native_test.sh step "frontend type check and build" ensure_npm_deps