#!/usr/bin/env bash # Phase 3 interop gate: seed each fixture torrent with libtorrent and download # it with the from-scratch naut_leech, asserting a byte-identical content tree. # Skips (exit 77 = ctest SKIP) if python libtorrent is unavailable. set -u ROOT="$(cd "$(dirname "$0")/../.." && pwd)" LEECH="${1:-$ROOT/build/naut_leech}" SEEDER="$ROOT/tests/integration/seeder.py" DATA="$ROOT/tests/fixtures/data" python3 -c 'import libtorrent' 2>/dev/null || { echo "SKIP: python libtorrent not available"; exit 77; } [ -x "$LEECH" ] || { echo "FAIL: $LEECH not built"; exit 1; } fail=0 run_one() { local tor="$1" cmp="$2" local out; out="$(mktemp -d /tmp/naut_interop.XXXXXX)" local log; log="$(mktemp /tmp/naut_seed.XXXXXX)" python3 "$SEEDER" "$ROOT/tests/fixtures/$tor" "$DATA" > "$log" 2>&1 & local seed=$! local port="" for _ in $(seq 1 100); do port=$(grep -oP 'PORT \K[0-9]+' "$log" 2>/dev/null); [ -n "$port" ] && break; sleep 0.1; done if [ -z "$port" ]; then echo "FAIL[$tor]: seeder did not start"; cat "$log"; kill "$seed" 2>/dev/null; fail=1; rm -rf "$out" "$log"; return; fi if timeout 30 "$LEECH" "$ROOT/tests/fixtures/$tor" "$out" 127.0.0.1 "$port" 2>&1 | grep -q "COMPLETE"; then if diff -r "$out/$cmp" "$DATA/$cmp" >/dev/null; then echo "PASS[$tor]: byte-identical content tree" else echo "FAIL[$tor]: content mismatch"; fail=1 fi else echo "FAIL[$tor]: download did not complete"; fail=1 fi kill "$seed" 2>/dev/null; rm -rf "$out" "$log" } run_one single_v1.torrent single.bin run_one multi_v1.torrent multi run_one hybrid.torrent multi exit $fail