Artifact c519558b78281632158878c16d0ae9b5414d41e13f01780d87059a837c6bd055:
- File
test/test_remote_lifecycle.sh
— part of check-in
[11f47eadde]
at
2026-11-18 11:58:22
on branch trunk
— Record S0/S1 qualification groundwork before product code
Contract maps and pinned Pi reference, local C qualification fixtures, MC/DC and Fil-C remote lifecycle tooling, and the context transaction substrate probe. No product harness code yet. (user: dmestas, size: 6191) [annotate] [blame] [check-ins using]
#!/bin/sh # All transports are fake; the suite never contacts a host or needs privileges. set -eu ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) TEST_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/pi-c-remote-test.XXXXXX") trap 'rm -rf -- "$TEST_ROOT"' EXIT HUP INT TERM mkdir "$TEST_ROOT/bin" printf '#!/bin/sh\nprintf "unexpected transport\\n" >&2\nexit 99\n' > "$TEST_ROOT/bin/ssh" chmod +x "$TEST_ROOT/bin/ssh" PATH="$TEST_ROOT/bin:$PATH" export PATH RUN="$ROOT/tools/remote/run.sh" nonce=0123456789abcdef sh "$RUN" prepare "$TEST_ROOT/run" "$nonce" noop [ -f "$TEST_ROOT/run/manifest" ] grep -Fx 'host=hetzner-hel' "$TEST_ROOT/run/manifest" grep -Fx 'owner=pi-c-s0-0123456789abcdef-owner.service' "$TEST_ROOT/run/manifest" grep -Fx 'worker_seconds=300' "$TEST_ROOT/run/manifest" grep -Fx 'lease_seconds=600' "$TEST_ROOT/run/manifest" if sh "$RUN" prepare "$TEST_ROOT/bad" 'bad;echo unsafe' noop; then printf 'FAIL: unsafe nonce accepted\n' >&2 exit 1 fi if sh "$RUN" prepare "$TEST_ROOT/run" "$nonce" noop; then printf 'FAIL: local collision accepted\n' >&2 exit 1 fi printf 'remote lifecycle: manifest validation passed\n' # Execute the exact cleanup body locally, faking only Linux identity/stat output. printf '#!/bin/sh\nprintf "1000\\n"\n' > "$TEST_ROOT/bin/id" cat > "$TEST_ROOT/bin/stat" <<'STAT' #!/bin/sh set -eu [ "$1" = -c ] shift 2 [ "$1" != -- ] || shift path=$1 if [ "${BAD_OWNER:-}" = "$path" ]; then printf '0:0:700\n' exit fi mode=$(/usr/bin/stat -f '%Lp' "$path") printf '1000:1000:%s\n' "$mode" STAT chmod +x "$TEST_ROOT/bin/id" "$TEST_ROOT/bin/stat" TEST_ROOT=$(CDPATH='' cd -- "$TEST_ROOT" && pwd -P) home="$TEST_ROOT/home" mkdir -m 700 "$home" workspace="$home/.pi-c-s0-$nonce" CLEAN="$ROOT/tools/remote/cleanup.sh" sh "$CLEAN" "$home" "$workspace" "$nonce" mkdir -m 700 "$workspace" printf '%s\n' "$nonce" > "$workspace/.pi-c-owner" chmod 600 "$workspace/.pi-c-owner" printf 'evidence\n' > "$workspace/log" BAD_OWNER=$workspace export BAD_OWNER if sh "$CLEAN" "$home" "$workspace" "$nonce"; then exit 1; fi [ -f "$workspace/log" ] unset BAD_OWNER sh "$CLEAN" "$home" "$workspace" "$nonce" [ ! -e "$workspace" ] sh "$CLEAN" "$home" "$workspace" "$nonce" mkdir -m 700 "$TEST_ROOT/outside" ln -s "$TEST_ROOT/outside" "$workspace" if sh "$CLEAN" "$home" "$workspace" "$nonce"; then exit 1; fi [ -d "$TEST_ROOT/outside" ] rm "$workspace" mkdir -m 700 "$workspace" printf 'different\n' > "$workspace/.pi-c-owner" chmod 600 "$workspace/.pi-c-owner" if sh "$CLEAN" "$home" "$workspace" "$nonce"; then exit 1; fi [ -d "$workspace" ] printf 'remote lifecycle: cleanup refusal and idempotence passed\n' # A native compiler stands in only for the Fil-C invocation, not Fil-C safety evidence. mkdir "$TEST_ROOT/payload" cp -R "$ROOT/test" "$TEST_ROOT/payload/test" ( cd "$TEST_ROOT/payload" sh "$ROOT/tools/remote/payload.sh" filc "$(command -v cc)" > worker.log 2>&1 grep -Fx PASS result.txt grep -Fx 'qualification: 10 tests passed' worker.log grep -Fx 'oracle-mutant: 8 verdicts checked' worker.log grep -F 'replay: 7 files,' worker.log ) printf 'remote lifecycle: payload fixture interface passed (native stand-in only)\n' rm -rf "$workspace" FAKE_STATE="$TEST_ROOT/supervisor" FAKE_HOME=$home FAKE_WORKSPACE=$workspace FAKE_NONCE=$nonce FAKE_CLEANUP=$CLEAN export FAKE_STATE FAKE_HOME FAKE_WORKSPACE FAKE_NONCE FAKE_CLEANUP mkdir "$FAKE_STATE" FAKE_TOOLCHAIN="$TEST_ROOT/toolchain" FAKE_COMPILER="$TEST_ROOT/compiler" FAKE_ARCHIVE="$TEST_ROOT/archive" mkdir -p "$FAKE_TOOLCHAIN/pizfix/lib" printf 'fixture library\n' > "$FAKE_TOOLCHAIN/pizfix/lib/libc.so" printf '#!/bin/sh\necho fixture-compiler\n' > "$FAKE_COMPILER" chmod +x "$FAKE_COMPILER" printf 'fixture archive\n' > "$FAKE_ARCHIVE" FAKE_ARCHIVE_SHA=$(shasum -a 256 "$FAKE_ARCHIVE" | cut -d' ' -f1) FAKE_COMPILER_SHA=$(shasum -a 256 "$FAKE_COMPILER" | cut -d' ' -f1) export FAKE_TOOLCHAIN FAKE_COMPILER FAKE_ARCHIVE FAKE_ARCHIVE_SHA FAKE_COMPILER_SHA for tool in sudo systemd-run systemctl; do cp "$ROOT/test/remote/fake-supervisor.sh" "$TEST_ROOT/bin/$tool" chmod +x "$TEST_ROOT/bin/$tool" done cat > "$TEST_ROOT/host-entry.sh" <<'HOST' #!/bin/sh set -eu home=$FAKE_HOME toolchain=$FAKE_TOOLCHAIN compiler=$FAKE_COMPILER archive=$FAKE_ARCHIVE archive_sha=$FAKE_ARCHIVE_SHA compiler_sha=$FAKE_COMPILER_SHA runtime_libraries="$toolchain/pizfix/lib/libc.so" source_names=tools/remote/payload.sh uname() { case "$1" in -s) echo Linux ;; -m) echo x86_64 ;; *) return 1 ;; esac; } getent() { printf 'fixture:x:1000:1000:fixture:%s:/bin/sh\n' "$home"; } sha256sum() { shasum -a 256 "$@"; } cleanup_code=$(cat "$REMOTE_ROOT/tools/remote/cleanup.sh") . "$REMOTE_ROOT/tools/remote/host.sh" HOST REMOTE_ROOT=$ROOT export REMOTE_ROOT sh "$TEST_ROOT/host-entry.sh" start "$nonce" noop [ -d "$workspace" ] # Transient D-Bus exec properties preserve '%' literally, unlike unit-file text. if grep -F '%%s' "$FAKE_STATE/pi-c-s0-$nonce-owner.service.args" || grep -F '%%u' "$FAKE_STATE/pi-c-s0-$nonce-owner.service.args"; then printf 'FAIL: manager arguments would write literal format specifiers\n' >&2 exit 1 fi grep -Fx -- '--on-active=600s' "$FAKE_STATE/pi-c-s0-$nonce-cleanup.service.args" grep -Fx -- '--property=User=1000' "$FAKE_STATE/pi-c-s0-$nonce-owner.service.args" grep -Fx -- '--property=Group=1000' "$FAKE_STATE/pi-c-s0-$nonce-cleanup.service.args" grep -Fx -- '--property=RuntimeMaxSec=600s' "$FAKE_STATE/pi-c-s0-$nonce-owner.service.args" grep -Fx -- '--property=Conflicts=pi-c-s0-'"$nonce"'-owner.service pi-c-s0-'"$nonce"'-worker.service' \ "$FAKE_STATE/pi-c-s0-$nonce-cleanup.service.args" grep -F -- '--property=ExecStopPost=:/bin/sh -c ' \ "$FAKE_STATE/pi-c-s0-$nonce-owner.service.args" > /dev/null if sh "$TEST_ROOT/host-entry.sh" start "$nonce" noop; then exit 1; fi printf '%s\n' "$nonce" > "$workspace/.upload-complete" sh "$TEST_ROOT/host-entry.sh" work "$nonce" noop [ "$(/usr/bin/stat -f '%Lp' "$workspace/worker.log")" = 600 ] sh "$TEST_ROOT/host-entry.sh" teardown "$nonce" noop [ ! -e "$workspace" ] sh "$TEST_ROOT/host-entry.sh" teardown "$nonce" noop printf 'remote lifecycle: fake manager ordering and cleanup passed\n'