From d52da959bc416e09bc0f3e54994563bd80e19c64 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 25 Jul 2026 15:00:44 -0500 Subject: refactor(test): share runner and scenario contracts --- scripts/testing/run-maint-scenarios.sh | 65 +--------------------------------- 1 file changed, 1 insertion(+), 64 deletions(-) (limited to 'scripts/testing/run-maint-scenarios.sh') diff --git a/scripts/testing/run-maint-scenarios.sh b/scripts/testing/run-maint-scenarios.sh index 448f6d9..17481e9 100644 --- a/scripts/testing/run-maint-scenarios.sh +++ b/scripts/testing/run-maint-scenarios.sh @@ -35,6 +35,7 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" source "$SCRIPT_DIR/lib/logging.sh" source "$SCRIPT_DIR/lib/vm-utils.sh" +source "$SCRIPT_DIR/lib/maint-scenario.sh" SCENARIO_DIR="${MAINT_SCENARIO_DIR:-$SCRIPT_DIR/maint-scenarios}" MAINT_SRC="${MAINT_SRC:-$HOME/.dotfiles/maint/src/maint}" @@ -72,32 +73,6 @@ S_FILES=() S_NAMES=() S_DESCS=() S_GROUPS=() # Groups in first-appearance order. GROUP_ORDER=() -# Extract one declared var from a scenario file by sourcing it in a clean -# subshell. Scenario files must only define vars + functions; any top-level -# command fails here (no helpers exist), which is the contract. -_scenario_var() { # - bash -c 'set -eu; source "$1" || exit 9; eval "printf %s \"\${$2-}\""' \ - _probe "$1" "$2" 2>/dev/null -} - -_validate_scenario() { # -> fatal on contract violation - local f="$1" base probe_err - base=$(basename "$f") - probe_err=$(bash -c 'set -eu; source "$1" - : "${SCENARIO_DESC:?missing SCENARIO_DESC}" - : "${SCENARIO_GROUP:?missing SCENARIO_GROUP}" - : "${SCENARIO_PROFILES:?missing SCENARIO_PROFILES}" - for p in $SCENARIO_PROFILES; do - case "$p" in btrfs|zfs|any) ;; *) - echo "bad profile token: $p" >&2; exit 1 ;; - esac - done - declare -f scenario_break scenario_fix scenario_assert >/dev/null \ - || { echo "missing scenario_break/fix/assert" >&2; exit 1; }' \ - _probe "$f" 2>&1 >/dev/null) \ - || fatal "scenario contract violation in $base: $probe_err" -} - _profile_matches() { # -> 0 if scenario runs under $FS_PROFILE local p for p in $1; do @@ -283,44 +258,6 @@ import json; print(len(json.load(open('$RESULTS_DIR/bootstrap-status.json'))['me PASS=() FAIL=() -run_scenario() { # - local i="$1" name="${S_NAMES[$1]}" f="${S_FILES[$1]}" - section "Scenario: $name — ${S_DESCS[$1]}" - # Sourced in the runner's shell so break/fix/assert see the helpers; - # unset afterwards so the next scenario can't inherit stale functions. - # shellcheck disable=SC1090 - source "$f" - local ok=true - step "break" - if ! scenario_break; then - error "$name: break step failed" - ok=false - fi - if [ "$ok" = "true" ]; then - step "fix" - if ! scenario_fix; then - error "$name: fix step failed" - ok=false - fi - fi - if [ "$ok" = "true" ]; then - step "assert" - if ! scenario_assert; then - error "$name: post-state assertion failed" - ok=false - fi - fi - unset -f scenario_break scenario_fix scenario_assert - unset SCENARIO_DESC SCENARIO_GROUP SCENARIO_PROFILES - if [ "$ok" = "true" ]; then - success "PASS: $name" - PASS+=("$name") - else - error "FAIL: $name" - FAIL+=("$name") - fi -} - section "Preparing VM" stop_qemu 2>/dev/null || true step "Restoring clean-install snapshot" -- cgit v1.2.3