Something went wrong. Try again.
Shuttle runs GitLab CI pipelines for Tangled repositories on an ordinary GitLab runner, and publishes the job logs to the repository owner's tangled.org/dracoblue.de/shuttle
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337#!/usr/bin/env bash# End-to-end runner. One compose stack, then each e2e/<feature> directory.# Pushes only to the local knot, and only to refs/heads/e2e-<feature>.set -euo pipefailcd "$(dirname "$0")/.."export PATH="$HOME/.local/go/bin:$PATH"export GIT_TERMINAL_PROMPT=0config_dir="$HOME/.config/shuttle-test"env_file="$config_dir/.env"db_path="$config_dir/shuttle.db"work_dir=$(mktemp -d)export SHUTTLE_DB_DIR="$config_dir" COMPOSE_PROJECT_NAME=shuttleexport SHUTTLE_UID="$(id -u)" SHUTTLE_GID="$(id -g)"if [[ "$*" == "artifacts" ]]; then export SHUTTLE_BLOB_LIMIT=65536; fishuttle_log="$work_dir/shuttle.log"volumes_before="$work_dir/volumes.before"docker volume ls -q | sort >"$volumes_before"# Pinned official Alpine. e2e/*/.gitlab-ci.yml uses this same digest.alpine='alpine@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6'cleanup(){ status=$? docker compose logs shuttle >"$work_dir/shuttle.final" 2>&1 || true docker compose logs runner >"$work_dir/runner.final" 2>&1 || true docker compose down --volumes >/dev/null 2>&1 || true docker volume ls -q | sort >"$work_dir/volumes.after" || true comm -13 "$volumes_before" "$work_dir/volumes.after" >"$work_dir/volumes.new" || true while IFS= read -r volume; do [[ -n "$volume" ]] || continue if [[ "$(docker volume inspect -f '{{ index .Labels "com.gitlab.gitlab-runner.type" }}' "$volume" 2>/dev/null || true)" == "cache" ]]; then docker volume rm "$volume" >/dev/null || true echo "removed runner cache volume $volume" fi done <"$work_dir/volumes.new" if [[ $status -ne 0 ]]; then sed -n '1,260p' "$work_dir/shuttle.final" >&2 || true sed -n '1,260p' "$work_dir/runner.final" >&2 || true fi rm -rf "$work_dir" exit "$status"}trap cleanup EXIT INT TERM[[ -f "$env_file" ]] || { echo "missing $env_file" >&2; exit 1; }set -a# shellcheck disable=SC1090source "$env_file"set +a: "${SHUTTLE_TEST_REPO_DID:?missing SHUTTLE_TEST_REPO_DID}": "${SHUTTLE_TEST_HANDLE:?missing SHUTTLE_TEST_HANDLE}": "${KNOT_MASTER_KEY:?missing KNOT_MASTER_KEY}"export SHUTTLE_DB="$db_path": "${SHUTTLE_TEST_DID:=did:plc:tdw3iqyznnma3t2ylthfpyd5}": "${SHUTTLE_TEST_PDS:=https://auriporia.us-west.host.bsky.network}"if [[ "$SHUTTLE_TEST_DID" != "did:plc:tdw3iqyznnma3t2ylthfpyd5" ]]; then echo "refusing to use any account other than the test account" >&2 exit 1fi
features=()if [[ $# -eq 0 ]]; then shopt -s nullglob for d in e2e/*/; do features+=("$(basename "$d")") doneelse features=("$@")fiif [[ ${#features[@]} -eq 0 ]]; then echo "no features under e2e/" >&2 exit 1fifor feature in "${features[@]}"; do if [[ ! "$feature" =~ ^[a-z0-9][a-z0-9-]*$ ]] || [[ ! -f "e2e/$feature/.gitlab-ci.yml" || ! -f "e2e/$feature/expect.yml" ]]; then echo "unknown feature: $feature" >&2 exit 1 fidone
count_jobs() { awk ' /^[^ #[:space:]].*:[[:space:]]*$/ { if (seen && !absent) count++; seen=1; absent=0; next } seen && /^[[:space:]]+absent:[[:space:]]*true[[:space:]]*$/ { absent=1 } END { if (seen && !absent) count++; print count+0 } ' "$1"}
# Newest trace records whose commit is $1, one JSON object per line.# listRecords returns newest first by default; reverse=true would return the# oldest first, and with hundreds of records on the test account the fresh# ones would fall behind the page limit (seen on 2026-10-07 at ~700 records).collect_records() { local sha=$1 dest=$2 local cursor="" page="" pages=0 : >"$dest" while [[ $pages -lt 8 ]]; do local -a args args=(curl -fsS --get "$SHUTTLE_TEST_PDS/xrpc/com.atproto.repo.listRecords" --data-urlencode "repo=$SHUTTLE_TEST_DID" --data-urlencode "collection=net.dracoblue.shuttle.trace" --data-urlencode "limit=100") if [[ -n "$cursor" ]]; then args+=(--data-urlencode "cursor=$cursor") fi page=$("${args[@]}") || return 1 local hits hits=$(jq -c --arg sha "$sha" '.records[]? | select(.value.sha == $sha)' <<<"$page") || return 1 [[ -n "$hits" ]] && printf '%s\n' "$hits" >>"$dest" cursor=$(jq -r '.cursor // empty' <<<"$page") || return 1 pages=$((pages + 1)) # Newest first: once this commit's records were seen and a page has none, # older pages cannot hold more of them. if [[ -z "$cursor" ]] || { [[ -s "$dest" ]] && [[ -z "$hits" ]]; }; then break fi done # Explicit: a while loop returns the status of its last body command, and # `[[ -z "$cursor" ]] && break` is 1 whenever the PDS still hands out a # cursor after the last page we read. That turned every lookup into a # failure once the test account held more than ~700 records. return 0}
run_push() { set -euo pipefail local feature=$1 run=$2 expect_file=$3 config_file=$4 local expect_n case_dir repo_dir sha dest raw uniq name record_name file_name attempt uri n i cid expect_n=$(count_jobs "$expect_file") case_dir="$work_dir/$feature/run-$run" repo_dir="$work_dir/repo" mkdir -p "$case_dir/records" "$case_dir/blobs" cp "$expect_file" "$case_dir/expect.yml" cp "$config_file" "$repo_dir/.gitlab-ci.yml" if [[ -d "e2e/$feature/files-$run" ]]; then cp -R "e2e/$feature/files-$run/." "$repo_dir/" fi git -C "$repo_dir" add -A # A new SHA every run, even when the tree matches main. git -C "$repo_dir" commit -q --allow-empty -m "e2e $feature run $run" sha=$(git -C "$repo_dir" rev-parse HEAD) dest="refs/heads/e2e-$feature" if [[ "$dest" == "refs/heads/main" || "$dest" != refs/heads/e2e-* ]]; then echo "refusing to push $dest" >&2 return 1 fi local ssh_command="ssh -i $config_dir/id_ed25519 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=$config_dir/known_hosts -p 2222" GIT_SSH_COMMAND="$ssh_command" git -C "$repo_dir" push --force -q \ "ssh://${SHUTTLE_TEST_HANDLE}@127.0.0.1:2222/${SHUTTLE_TEST_REPO_DID}" \ "HEAD:${dest}" echo "pushed $dest $sha" raw="$case_dir/raw.jsonl" uniq="$case_dir/uniq.jsonl" local found=0 local pipeline_status="" pipeline_status=$(awk '/^[[:space:]]+pipelineStatus:/ { print $2; exit }' "$expect_file") if [[ -n "$pipeline_status" ]]; then sleep 8; fi for _ in $(seq 1 180); do if collect_records "$sha" "$raw"; then jq -s -c 'unique_by(.uri)[]' "$raw" >"$uniq" found=$(grep -c . "$uniq" || true) if [[ "$found" -ge "$expect_n" ]]; then break fi fi sleep 2 done if [[ "$found" -lt "$expect_n" ]]; then echo "timed out waiting for $expect_n trace records for $sha (saw $found)" >&2 return 1 fi while IFS= read -r line; do name=$(jq -er '.value.jobName' <<<"$line") attempt=$(jq -er '.value.attempt // 1' <<<"$line") record_name="$name" if [[ "$attempt" -gt 1 ]]; then record_name="$name@$attempt"; fi file_name=$(jq -rn --arg value "$record_name" '$value | @uri') uri=$(jq -er '.uri' <<<"$line") if [[ -z "$name" || "$name" == "." || "$name" == ".." || "$file_name" == */* ]]; then echo "refusing job name" >&2 return 1 fi if [[ -e "$case_dir/records/$file_name.json" ]]; then echo "duplicate trace for job $record_name" >&2 return 1 fi jq '.value' <<<"$line" >"$case_dir/records/$file_name.json" : >"$case_dir/blobs/$file_name.txt" n=$(jq -er '.parts | length' "$case_dir/records/$file_name.json") for ((i = 0; i < n; i++)); do cid=$(jq -er --argjson i "$i" '.parts[$i].blob.ref["$link"]' "$case_dir/records/$file_name.json") curl -fsS --get "$SHUTTLE_TEST_PDS/xrpc/com.atproto.sync.getBlob" \ --data-urlencode "did=$SHUTTLE_TEST_DID" \ --data-urlencode "cid=$cid" >>"$case_dir/blobs/$file_name.txt" done echo "record $uri job=$name attempt=$attempt" done <"$uniq" local show="" tries for tries in $(seq 1 30); do if show=$(docker compose exec -T shuttle /usr/local/bin/shuttle run show --sha "$sha"); then [[ -n "$show" ]] && break fi show="" sleep 1 done if [[ -z "$show" ]]; then echo "run show failed for $sha" >&2 return 1 fi printf '%s\n' "$show" >"$case_dir/runs.txt" echo "run show:" printf '%s\n' "$show" if [[ -n "$pipeline_status" ]]; then grep -F "status=$pipeline_status" <<<"$show" >/dev/null || { echo "pipeline status is not $pipeline_status" >&2; return 1; } docker compose logs shuttle 2>&1 | grep -F "pipeline $pipeline_status repo=${SHUTTLE_TEST_REPO_DID} ref=$dest sha=$sha" >/dev/null || { echo "missing pipeline $pipeline_status log for $sha" >&2; return 1; } fi SHUTTLE_GREEN_VALIDATE_ONLY=1 \ SHUTTLE_E2E_DIR="$case_dir" \ SHUTTLE_E2E_SHA="$sha" \ SHUTTLE_E2E_REF="$dest" \ go test -v -count=1 -tags green -run TestE2EExpect ./cmd/shuttle if [[ "$feature" == artifacts ]]; then local artifact_page artifact_line artifact_record part_dir part_name part_sha part_size whole_sha assembled artifact_page=$(curl -fsS --get "$SHUTTLE_TEST_PDS/xrpc/com.atproto.repo.listRecords" --data-urlencode "repo=$SHUTTLE_TEST_DID" --data-urlencode "collection=net.dracoblue.shuttle.artifact" --data-urlencode "limit=100") artifact_line=$(jq -ce --arg sha "$sha" '.records[] | select(.value.sha==$sha)' <<<"$artifact_page" | head -n1) artifact_record="$case_dir/artifact.json"; jq '.value' <<<"$artifact_line" >"$artifact_record" part_dir="$case_dir/artifact-parts"; mkdir -p "$part_dir" while IFS=$'\t' read -r part_name cid part_sha part_size; do [[ "$part_name" != */* && -n "$part_name" ]] || { echo "unsafe artifact part name" >&2; return 1; } curl -fsS --get "$SHUTTLE_TEST_PDS/xrpc/com.atproto.sync.getBlob" --data-urlencode "did=$SHUTTLE_TEST_DID" --data-urlencode "cid=$cid" >"$part_dir/$part_name" [[ "$(wc -c <"$part_dir/$part_name")" == "$part_size" ]] || { echo "artifact part size mismatch" >&2; return 1; } [[ "$(sha256sum "$part_dir/$part_name" | awk '{print $1}')" == "$part_sha" ]] || { echo "artifact part sha256 mismatch" >&2; return 1; } done < <(jq -r '.parts[] | [.name,.blob.ref["$link"],.sha256,.size] | @tsv' "$artifact_record") assembled="$case_dir/artifact.zip"; : >"$assembled" while IFS= read -r part_name; do cat "$part_dir/$part_name" >>"$assembled"; done < <(jq -r '.parts[].name' "$artifact_record") whole_sha=$(jq -r '.sha256' "$artifact_record") [[ "$(sha256sum "$assembled" | awk '{print $1}')" == "$whole_sha" ]] || { echo "artifact whole sha256 mismatch" >&2; return 1; } [[ "$(jq '.parts|length' "$artifact_record")" -ge 2 ]] || { echo "artifact was not split" >&2; return 1; } jq -er '.parts[0].name | endswith(".001")' "$artifact_record" >/dev/null echo "artifact record $(jq -r '.uri' <<<"$artifact_line")" fi}
run_feature() { set -euo pipefail local feature=$1 repo_dir="$work_dir/repo" main_sha config_file main_sha=$(git -C "$repo_dir" rev-parse main) git -C "$repo_dir" checkout -q -f -B "e2e-$feature" "$main_sha" run_push "$feature" 1 "e2e/$feature/expect.yml" "e2e/$feature/.gitlab-ci.yml" if [[ -f "e2e/$feature/expect-2.yml" ]]; then config_file="e2e/$feature/.gitlab-ci.yml" [[ ! -f "e2e/$feature/.gitlab-ci-2.yml" ]] || config_file="e2e/$feature/.gitlab-ci-2.yml" run_push "$feature" 2 "e2e/$feature/expect-2.yml" "$config_file" fi}
grant_status=$(go run ./cmd/shuttle grant status --check)printf '%s\n' "$grant_status"if ! grep -F "DID: $SHUTTLE_TEST_DID" <<<"$grant_status" >/dev/null || grep -F "State: needs-login" <<<"$grant_status" >/dev/null || ! grep -F "repo:net.dracoblue.shuttle.artifact?action=create&action=delete" <<<"$grant_status" >/dev/null; then SHUTTLE_GREEN_LOGIN_ONLY=1 AGENT_BROWSER_ARGS=--no-sandbox go test -v -count=1 -tags green ./cmd/shuttlefigo run ./cmd/shuttle grant enable "$SHUTTLE_TEST_DID" >/dev/nullif ! docker volume inspect shuttle_knot-data >/dev/null 2>&1; then docker volume create --label shuttle.dev=knot shuttle_knot-data >/dev/nullfiif ! docker run --rm --label shuttle.spike=green -v shuttle_knot-data:/data "$alpine" test -f /data/state/ssh_host_ed25519_key; then seed=$(mktemp -d) ssh-keygen -q -t ed25519 -N '' -f "$seed/key" docker run --rm --label shuttle.spike=green -v shuttle_knot-data:/data -v "$seed:/seed:ro" "$alpine" sh -c 'mkdir -p /data/state /data/repos /data/lfs;cp /seed/key* /data/state/;chown -R 1000:1000 /data;chmod 600 /data/state/key;mv /data/state/key /data/state/ssh_host_ed25519_key;mv /data/state/key.pub /data/state/ssh_host_ed25519_key.pub' shred -u "$seed/key" unlink "$seed/key.pub" rmdir "$seed"fidocker compose up -d knotfor _ in $(seq 1 100); do curl -fsS -H 'Host: knot.example.org' http://127.0.0.1:5555/.well-known/did.json >/dev/null 2>&1 && break sleep .2donescripts/knot-setup.shdocker compose build shuttlerunner_token=$(docker compose run --rm --no-deps shuttle runner create)docker compose up -d shuttlefor _ in $(seq 1 100); do curl -sS -o /dev/null http://127.0.0.1:8080/api/v4/jobs/request && break sleep .2donereconciled=0for _ in $(seq 1 90); do if docker compose logs shuttle 2>&1 | grep -F "reconcile done repo=${SHUTTLE_TEST_REPO_DID}" >/dev/null; then reconciled=1 break fi sleep 1done[[ "$reconciled" == 1 ]] || { echo "timed out waiting for reconcile done" >&2; exit 1; }# GitLab Runner adds service aliases to user-defined network endpoints# (executors/docker/docker.go networkConfig). Keeping shuttle_default therefore# provides service DNS aliases while preserving access to the local knot.docker compose run --rm --no-deps runner register --non-interactive --url http://shuttle:8080/ --token "$runner_token" --executor docker --docker-image "$alpine" --docker-network-mode shuttle_default --docker-container-labels shuttle.spike=green >/dev/nullrunner_token=# gitlab-runner defaults to concurrent = 1, which runs jobs one after another# whatever Shuttle enqueues. With 4, jobs of one stage really overlap, and the# stages e2e's `after:` checks prove Shuttle's gating instead of the runner's.docker compose run --rm --no-deps --entrypoint sh runner -c 'sed -i "s/^concurrent = .*/concurrent = 4/" /etc/gitlab-runner/config.toml && grep -q "^concurrent = 4" /etc/gitlab-runner/config.toml'docker compose up -d runner
repo_dir="$work_dir/repo"git clone -q "http://127.0.0.1:5555/${SHUTTLE_TEST_REPO_DID}" "$repo_dir"git -C "$repo_dir" checkout -q -B maingit -C "$repo_dir" config user.name 'Shuttle Test'git -C "$repo_dir" config user.email shuttle@example.invalidecho "main $(git -C "$repo_dir" rev-parse HEAD) (read only)"
failed=0results=()for feature in "${features[@]}"; do echo "=== e2e/$feature ===" set +e ( set -euo pipefail run_feature "$feature" ) feature_status=$? set -e if [[ "$feature_status" -eq 0 ]]; then results+=("PASS $feature") echo "PASS $feature" else results+=("FAIL $feature") echo "FAIL $feature" failed=1 fidoneecho "---"printf '%s\n' "${results[@]}"docker compose logs shuttle >"$shuttle_log"if [[ "$failed" -ne 0 ]]; then exit 1fi