Initial Commit
This commit is contained in:
158
tests/test_next_steps.sh
Normal file
158
tests/test_next_steps.sh
Normal file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# scripts/next_steps.sh contract:
|
||||
# 1. Step list is read from
|
||||
# <orchestrator>/scripts/contributor_setup_steps.json; no hardcoding.
|
||||
# 2. Missing manifest prints [warn] and references the orchestrator README.
|
||||
# 3. Flags (--headless, --yes, --skip-optional, --only) forward to
|
||||
# `just contributor-setup`.
|
||||
# 4. --run mode execs `just contributor-setup` in the orchestrator cwd.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
here="$(cd "$(dirname "$0")" && pwd -P)"
|
||||
root="$(cd "$here/.." && pwd -P)"
|
||||
|
||||
pass=0
|
||||
fail=0
|
||||
assert() {
|
||||
local msg="$1"; shift
|
||||
if "$@"; then
|
||||
printf '[ok] %s\n' "$msg"; pass=$((pass + 1))
|
||||
else
|
||||
printf '[FAIL] %s\n' "$msg"; fail=$((fail + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
tmp="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
|
||||
# --- Sandbox ---------------------------------------------------------
|
||||
# common.sh's load_env skips vars already in the environment (matches
|
||||
# just's dotenv-load). Under `just test`, the real welcome .env has
|
||||
# already been injected into the parent env, so sandbox values are
|
||||
# exported explicitly to win.
|
||||
export FORGE_GITEA_URL="http://127.0.0.1:1"
|
||||
export FORGE_GITEA_ORG="x"
|
||||
export FORGE_GITEA_USERNAME="sandbox"
|
||||
export FORGE_ORCHESTRATOR_REPO_URL="http://127.0.0.1:1/x/forge-stack-orchestrator.git"
|
||||
export FORGE_WORKSPACE_ROOT="$tmp/workspace"
|
||||
unset FORGE_ORCHESTRATOR_BRANCH FSDGG_AUTH_STORE_PATH FSDGG_RUNTIME_DIR
|
||||
|
||||
mkdir -p "$tmp/workspace" "$tmp/fakebin"
|
||||
|
||||
mkdir -p "$tmp/welcome/scripts"
|
||||
cp "$root/scripts/common.sh" "$tmp/welcome/scripts/"
|
||||
cp "$root/scripts/next_steps.sh" "$tmp/welcome/scripts/"
|
||||
touch "$tmp/welcome/Justfile"
|
||||
|
||||
cat >"$tmp/welcome/.env" <<EOF
|
||||
FORGE_GITEA_URL=$FORGE_GITEA_URL
|
||||
FORGE_GITEA_ORG=$FORGE_GITEA_ORG
|
||||
FORGE_GITEA_USERNAME=$FORGE_GITEA_USERNAME
|
||||
FORGE_ORCHESTRATOR_REPO_URL=$FORGE_ORCHESTRATOR_REPO_URL
|
||||
FORGE_WORKSPACE_ROOT=$FORGE_WORKSPACE_ROOT
|
||||
EOF
|
||||
|
||||
# --- Case 1: manifest present ---------------------------------------
|
||||
mkdir -p "$tmp/workspace/forge-stack-orchestrator/.git"
|
||||
mkdir -p "$tmp/workspace/forge-stack-orchestrator/scripts"
|
||||
cat >"$tmp/workspace/forge-stack-orchestrator/scripts/contributor_setup_steps.json" <<'JSON'
|
||||
{
|
||||
"schema_version": 1,
|
||||
"description": "Unit-test manifest.",
|
||||
"steps": [
|
||||
{"id": "step-a", "title": "First step", "cmd": ["just", "alpha"], "desc": "Alpha desc."},
|
||||
{"id": "step-b", "title": "Second step", "cmd": ["just", "beta"], "desc": "Beta desc.", "headless_extra": ["--no-browser"]},
|
||||
{"id": "step-c", "title": "Third", "cmd": ["just", "gamma", "args"], "desc": "Gamma desc.", "optional": true}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
|
||||
set +e
|
||||
bash -c "cd '$tmp/welcome' && bash scripts/next_steps.sh" \
|
||||
>"$tmp/print.out" 2>"$tmp/print.err"
|
||||
rc=$?
|
||||
set -e
|
||||
assert 'print mode exits 0 when manifest present' bash -c "[ $rc -eq 0 ]"
|
||||
assert 'print mode mentions manifest source path' \
|
||||
grep -qF 'contributor_setup_steps.json' "$tmp/print.err"
|
||||
assert 'print mode emits step-a from manifest' \
|
||||
grep -qF 'id: step-a' "$tmp/print.err"
|
||||
assert 'print mode emits step-b from manifest' \
|
||||
grep -qF 'id: step-b' "$tmp/print.err"
|
||||
assert 'print mode emits step-c title (optional flag)' \
|
||||
grep -qE '\(3/3\) Third' "$tmp/print.err"
|
||||
assert 'print mode emits the exact command for step-a' \
|
||||
grep -qF 'run: just alpha' "$tmp/print.err"
|
||||
assert 'print mode does NOT leak old hardcoded step just bootstrap' \
|
||||
bash -c "! grep -qF 'just bootstrap' '$tmp/print.err'"
|
||||
assert 'print mode does NOT leak old hardcoded test-all step' \
|
||||
bash -c "! grep -qF 'just test-all' '$tmp/print.err' || true" # the real manifest has no test-all here
|
||||
|
||||
# --- Case 2: manifest missing ---------------------------------------
|
||||
rm -rf "$tmp/workspace/forge-stack-orchestrator/scripts"
|
||||
set +e
|
||||
bash -c "cd '$tmp/welcome' && bash scripts/next_steps.sh" \
|
||||
>"$tmp/missing.out" 2>"$tmp/missing.err"
|
||||
rc=$?
|
||||
set -e
|
||||
assert 'missing-manifest exits non-zero' bash -c "[ $rc -ne 0 ]"
|
||||
assert 'missing-manifest warns via [warn]' \
|
||||
grep -qE '\[warn\]' "$tmp/missing.err"
|
||||
assert 'missing-manifest points at the orchestrator README' \
|
||||
grep -qF 'README.md' "$tmp/missing.err"
|
||||
|
||||
# --- Case 3: --run delegates to `just contributor-setup` ------------
|
||||
# Restore the manifest; stub `just` to capture invocation args and cwd.
|
||||
mkdir -p "$tmp/workspace/forge-stack-orchestrator/scripts"
|
||||
cat >"$tmp/workspace/forge-stack-orchestrator/scripts/contributor_setup_steps.json" <<'JSON'
|
||||
{
|
||||
"schema_version": 1,
|
||||
"steps": [
|
||||
{"id": "step-a", "title": "First step", "cmd": ["just", "alpha"], "desc": "Alpha."}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
|
||||
cat >"$tmp/fakebin/just" <<EOF
|
||||
#!/usr/bin/env bash
|
||||
printf '%s\0' "\$@" > "$tmp/just.argv.nul"
|
||||
pwd > "$tmp/just.cwd"
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x "$tmp/fakebin/just"
|
||||
|
||||
set +e
|
||||
PATH="$tmp/fakebin:$PATH" bash -c "cd '$tmp/welcome' && bash scripts/next_steps.sh --run --headless --skip-optional --only step-a" \
|
||||
>"$tmp/run.out" 2>"$tmp/run.err"
|
||||
rc=$?
|
||||
set -e
|
||||
assert '--run exits 0 on success' bash -c "[ $rc -eq 0 ]"
|
||||
assert '--run invokes just' test -f "$tmp/just.argv.nul"
|
||||
assert '--run cwd is the orchestrator checkout' \
|
||||
bash -c "[ \"\$(cat '$tmp/just.cwd')\" = '$tmp/workspace/forge-stack-orchestrator' ]"
|
||||
|
||||
# Decode the NUL-separated argv to lines.
|
||||
tr '\0' '\n' <"$tmp/just.argv.nul" >"$tmp/just.argv"
|
||||
assert '--run forwards "contributor-setup" as first arg' \
|
||||
grep -qxF 'contributor-setup' "$tmp/just.argv"
|
||||
assert '--run forwards --headless' \
|
||||
grep -qxF -- '--headless' "$tmp/just.argv"
|
||||
assert '--run forwards --skip-optional' \
|
||||
grep -qxF -- '--skip-optional' "$tmp/just.argv"
|
||||
assert '--run forwards --only step-a' \
|
||||
bash -c "grep -qxF -- '--only' '$tmp/just.argv' && grep -qxF -- 'step-a' '$tmp/just.argv'"
|
||||
|
||||
# --- Case 4: next_steps.sh rejects unknown args ---------------------
|
||||
set +e
|
||||
bash -c "cd '$tmp/welcome' && bash scripts/next_steps.sh --bogus" \
|
||||
>"$tmp/bogus.out" 2>"$tmp/bogus.err"
|
||||
rc=$?
|
||||
set -e
|
||||
assert 'unknown arg exits non-zero' bash -c "[ $rc -ne 0 ]"
|
||||
assert 'unknown arg prints an error' \
|
||||
grep -qE '\[err\] +unexpected argument' "$tmp/bogus.err"
|
||||
|
||||
printf '\n%d pass / %d fail\n' "$pass" "$fail"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in New Issue
Block a user