Files
zag/test/e2e.sh
T
Daniel Samson 4abc94f681
CI / test (pull_request) Successful in 3m20s
load levels: remove load levels from model, config, CLI, IPC, tests, docs
Completes issue #2 on top of the phase-1 strict single-job FIFO
scheduler. Removed:

- Job.load_level / Manifest.load_level / CreateOptions.load_level and
  the manifest.json loadLevel field (old manifests still parse: unknown
  fields are ignored)
- loadLevel in job JSON and <load_level> in XML output (field order
  shifts; old JSON still parses)
- the [load_levels] config section, service.max_concurrent_jobs,
  ZAG_LOAD_LEVELS_*/ZAG_LOADLEVELS_*/ZAG_SERVICE_MAX_CONCURRENT_JOBS
  env vars, loadlevel.zig / loadclass.zig and the default .load files

Friendly deprecation: old configs and environments still load fine.
config validate and config show report the removed settings as
non-fatal warnings (validate exit 1 stays reserved for real errors)
and the CLI/daemon logs them once at startup. --load-level is gone
from zag run; old IPC clients sending loadLevel are simply ignored.

e2e: wait_state is now portable to macOS bash 3.2 (it silently skipped
three checks before) and a serial-execution check asserts the second
job stays QUEUED while the first runs and both finish in FIFO order.
README and AGENTS.md document the deviation from barn.
2026-11-12 10:07:30 +00:00

105 lines
5.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# End-to-end smoke test of the zag binary: offline mode, the daemon, IPC, kill/retry/clean.
# Usage: test/e2e.sh [path-to-zag] (default: zig-out/bin/zag)
set -u
ZAG=${1:-zig-out/bin/zag}
DIR=$(mktemp -d /tmp/zag-e2e.XXXXXX)
Z() { "$ZAG" --barn-dir "$DIR" "$@"; }
fails=0
pass() { printf 'ok %s\n' "$1"; }
fail() { printf 'FAIL %s\n' "$1"; fails=$((fails + 1)); }
check() { # check <name> <command...> (command must succeed)
local name=$1; shift
if "$@" >/dev/null 2>&1; then pass "$name"; else fail "$name"; fi
}
contains() { # contains <name> <needle> <haystack>
case $3 in *"$2"*) pass "$1" ;; *) fail "$1 (missing '$2' in: $3)" ;; esac
}
json_field() { printf '%s\n' "$2" | sed -n "s/.*\"$1\" : \"\{0,1\}\([^\",]*\)\"\{0,1\},\{0,1\}\$/\1/p" | head -1; }
wait_state() { # wait_state <id> <state> [seconds]
# ${2,,} would work on bash >= 4, but macOS ships bash 3.2
local lower i
lower=$(printf '%s' "$2" | tr '[:upper:]' '[:lower:]')
for ((i = 0; i < ${3:-100}; i++)); do
[[ $(json_field state "$(Z describe -o json "$1" --offline)") == "$lower" ]] && return 0
sleep 0.1
done
return 1
}
cleanup() { Z service stop --force >/dev/null 2>&1; rm -rf "$DIR"; }
trap cleanup EXIT
# --- basics -----------------------------------------------------------------------------
contains "version" "zag " "$("$ZAG" --version)"
contains "help lists commands" "describe" "$("$ZAG" --help)"
"$ZAG" frobnicate >/dev/null 2>&1; [[ $? -eq 2 ]] && pass "unknown command exits 2" || fail "unknown command exits 2"
# --- offline mode -----------------------------------------------------------------------
out=$(Z run --offline -o json -t demo sh -c 'echo hello; exit 0')
id=$(json_field id "$out")
contains "offline run succeeds" '"state" : "SUCCEEDED"' "$out"
contains "offline run tag" '"tag" : "demo"' "$out"
contains "describe --logs shows stdout" "hello" "$(Z describe --offline --logs "$id")"
contains "status table" "succeeded" "$(Z status --offline)"
contains "status json summary" '"succeeded" : 1' "$(Z status --offline -o json)"
contains "status xml" "<job>" "$(Z status --offline -o xml)"
contains "usage has samples" "samples" "$(Z usage "$id")"
contains "clean without selector removes nothing" "Cleaned 0 jobs." "$(Z clean --offline)"
contains "clean --all --dry-run lists the job" "Would clean 1 job" "$(Z clean --offline --all --dry-run)"
contains "clean --all removes it" "Cleaned 1 job" "$(Z clean --offline --all)"
contains "status empty" "No jobs found." "$(Z status --offline)"
# --- config -----------------------------------------------------------------------------
contains "config show --defaults" "retry_backoff_multiplier = 2.0" "$(Z config show --defaults)"
printf '[jobs]\nmax_retries = 0\nbogus = 1\n' >"$DIR/bad.conf"
Z config validate --file "$DIR/bad.conf" >/dev/null 2>&1; [[ $? -eq 1 ]] && pass "validate flags bad config" || fail "validate flags bad config"
printf '[jobs]\nmax_retries = 0\n' >"$DIR/good.conf"
contains "validate accepts good config" "Configuration is valid" "$(Z config validate --file "$DIR/good.conf")"
printf '[service]\nmax_concurrent_jobs = 4\n[load_levels]\nmax_high_jobs = 2\n' >"$DIR/deprecated.conf"
deprecated_out=$(Z config validate --file "$DIR/deprecated.conf" 2>&1); rc=$?
[[ $rc -eq 0 ]] && contains "validate warns on deprecated settings, exit 0" "deprecated" "$deprecated_out" || fail "validate warns on deprecated settings (rc=$rc)"
contains "install --show prints files" "zag.conf" "$(Z config install --show)"
# --- daemon -----------------------------------------------------------------------------
Z run echo hi >/dev/null 2>&1; [[ $? -eq 1 ]] && pass "run without service exits 1" || fail "run without service exits 1"
contains "service start" "Zag service started" "$(Z service start)"
contains "second start refused" "already running" "$(Z service start 2>&1)"
contains "service status running" "running" "$(Z service status)"
out=$(Z run -o json -t svc sh -c 'echo from-daemon')
sid=$(json_field id "$out")
contains "run over IPC is queued" '"state" : "QUEUED"' "$out"
wait_state "$sid" SUCCEEDED && pass "daemon runs the job" || fail "daemon runs the job"
out=$(Z run -o json sleep 60); kid=$(json_field id "$out")
wait_state "$kid" RUNNING && pass "sleeper is running" || fail "sleeper is running"
contains "kill reports canceled" "New state: canceled" "$(Z kill "$kid")"
wait_state "$kid" CANCELED && pass "killed job is canceled" || fail "killed job is canceled"
contains "kill a finished job fails" "not running" "$(Z kill "$kid" 2>&1)"
out=$(Z run -o json --max-retries 1 --retry-delay 1 sh -c 'exit 5'); rid=$(json_field id "$out")
sleep 4
desc=$(Z describe -o json "$rid" --offline)
contains "failed job retried once" '"retryCount" : 1' "$desc"
contains "failed job ended failed" '"state" : "failed"' "$desc"
out=$(Z run -o json --timeout 1 sleep 30); tid=$(json_field id "$out")
sleep 3
contains "timeout fails the job" '"exitCode" : "timeout"' "$(Z describe -o json "$tid" --offline)"
# Strict single-job FIFO: while the first job runs, the second stays queued, and both
# finish in creation order.
out=$(Z run -o json sleep 3); a1=$(json_field id "$out")
wait_state "$a1" RUNNING && pass "serial: first job is running" || fail "serial: first job is running"
out=$(Z run -o json sleep 1); b1=$(json_field id "$out")
contains "serial: second job stays queued" '"state" : "QUEUED"' "$out"
wait_state "$a1" SUCCEEDED && pass "serial: first job finishes first" || fail "serial: first job finishes first"
wait_state "$b1" SUCCEEDED && pass "serial: second job finishes second" || fail "serial: second job finishes second"
contains "service reload" "Configuration reloaded" "$(Z service reload)"
contains "clean via IPC" "Cleaned" "$(Z clean --all --include-failed)"
contains "service stop" "Zag service stopped" "$(Z service stop)"
contains "service status stopped" "stopped" "$(Z service status)"
if [[ $fails -eq 0 ]]; then echo "all e2e checks passed"; else echo "$fails e2e check(s) failed"; exit 1; fi