|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Runtime-isolation contract for the soak harness (#1696, follow-up to #1691). |
| 5 | +# |
| 6 | +# scripts/soak-test.sh must be the only client of the daemon it measures: it |
| 7 | +# asserts that a session crash and the final shutdown each stop "the daemon". |
| 8 | +# It used to claim isolation from interactive sessions through a private |
| 9 | +# CBM_CACHE_DIR, but only CBM_RUNTIME_DIR moves the daemon rendezvous |
| 10 | +# (docs/CONFIGURATION.md), so the soak shared the operator's account daemon |
| 11 | +# and either stopped it or was refused with a cache-root conflict. Drive the |
| 12 | +# harness with an environment-probe fixture and require that no product |
| 13 | +# process ever receives the caller's runtime or cache. |
| 14 | + |
| 15 | +ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 16 | +WORKDIR="$(mktemp -d)" |
| 17 | +trap 'rm -rf "$WORKDIR"' EXIT |
| 18 | + |
| 19 | +fail() { |
| 20 | + echo "FAIL: $*" >&2 |
| 21 | + exit 1 |
| 22 | +} |
| 23 | + |
| 24 | +normalize_path() { |
| 25 | + local path=${1%$'\r'} |
| 26 | + if command -v cygpath >/dev/null 2>&1; then |
| 27 | + cygpath -u "$path" 2>/dev/null && return 0 |
| 28 | + fi |
| 29 | + printf '%s\n' "${path//\\//}" |
| 30 | +} |
| 31 | + |
| 32 | +ENV_PROBE="$WORKDIR/environment-probe" |
| 33 | +cat > "$ENV_PROBE" <<'EOF' |
| 34 | +#!/usr/bin/env bash |
| 35 | +printf '%s\t%s\n' "${CBM_CACHE_DIR-}" "${CBM_RUNTIME_DIR-}" >> "$CBM_SOAK_ENV_PROBE" |
| 36 | +[[ "${1-} ${2-}" == "daemon status" ]] && exit 1 |
| 37 | +exit 0 |
| 38 | +EOF |
| 39 | +chmod +x "$ENV_PROBE" |
| 40 | + |
| 41 | +CALLER_CACHE="$WORKDIR/caller-cache" |
| 42 | +CALLER_RUNTIME="$WORKDIR/caller-runtime" |
| 43 | +ENV_LOG="$WORKDIR/environment.log" |
| 44 | +mkdir -p "$CALLER_CACHE" "$CALLER_RUNTIME" |
| 45 | + |
| 46 | +# The fixture exits as soon as it has recorded its environment, so the soak |
| 47 | +# fails at "server did not start"; only the environment it handed to the |
| 48 | +# product is under test here. RESULTS_DIR keeps the soak's metrics out of cwd. |
| 49 | +CBM_CACHE_DIR="$CALLER_CACHE" \ |
| 50 | +CBM_RUNTIME_DIR="$CALLER_RUNTIME" \ |
| 51 | +CBM_SOAK_ENV_PROBE="$ENV_LOG" \ |
| 52 | +RESULTS_DIR="$WORKDIR/results" \ |
| 53 | + "$ROOT/scripts/soak-test.sh" "$ENV_PROBE" 1 --skip-crash-test \ |
| 54 | + > "$WORKDIR/soak.out" 2>&1 || true |
| 55 | + |
| 56 | +[[ -s "$ENV_LOG" ]] || fail "soak-test did not execute the environment-probe fixture" |
| 57 | + |
| 58 | +CALLER_CACHE_NORMALIZED=$(normalize_path "$CALLER_CACHE") |
| 59 | +CALLER_RUNTIME_NORMALIZED=$(normalize_path "$CALLER_RUNTIME") |
| 60 | +private_root="" |
| 61 | +while IFS=$'\t' read -r child_cache_raw child_runtime_raw; do |
| 62 | + child_cache=$(normalize_path "$child_cache_raw") |
| 63 | + child_runtime=$(normalize_path "$child_runtime_raw") |
| 64 | + if [[ -z "$child_runtime" || "$child_runtime" == "$CALLER_RUNTIME_NORMALIZED" ]]; then |
| 65 | + fail "soak-test exposed the caller CBM_RUNTIME_DIR to a product process" |
| 66 | + fi |
| 67 | + if [[ -z "$child_cache" || "$child_cache" == "$CALLER_CACHE_NORMALIZED" ]]; then |
| 68 | + fail "soak-test exposed the caller CBM_CACHE_DIR to a product process" |
| 69 | + fi |
| 70 | + if [[ "${child_runtime%/*}" != "${child_cache%/*}" || |
| 71 | + "${child_runtime##*/}" != "runtime" || "${child_cache##*/}" != "cache" ]]; then |
| 72 | + fail "soak runtime/cache were not isolated beneath one private root" |
| 73 | + fi |
| 74 | + if [[ -n "$private_root" && "$private_root" != "${child_runtime%/*}" ]]; then |
| 75 | + fail "soak-test switched private roots mid-run" |
| 76 | + fi |
| 77 | + private_root="${child_runtime%/*}" |
| 78 | +done < "$ENV_LOG" |
| 79 | + |
| 80 | +[[ ! -e "$private_root" ]] || fail "soak-test left its private root behind: $private_root" |
| 81 | + |
| 82 | +echo "PASS: soak harness isolates its daemon runtime and cache from the caller" |
0 commit comments