diff --git a/quest/m0/ci/README.md b/quest/m0/ci/README.md index be6e8b849aa..1cccfa89e08 100644 --- a/quest/m0/ci/README.md +++ b/quest/m0/ci/README.md @@ -167,6 +167,5 @@ The historical samples locate candidates; they are not controlled benchmarks. - [A jq error in the Rust selection fails the run](/quest/m0/ci/check-selection.md) - `just check`'s Rust selection fails the run when one of its jq filters errors, instead of selecting less - [The workspace-hack refuses trybuild edges and spares non-media builds](/quest/m0/ci/hakari-followups.md) - `hakari.py` refuses trybuild dev-dependency edges, and non-media Linux test builds stop needing libpipewire and libclang - [Pullfrog reviews finish inside their time limit](/quest/m0/ci/pullfrog-timeout.md) - A Pullfrog review of a large PR finishes instead of failing on the action's run limit -- [Long test runs keep their built binaries](/quest/m0/ci/shared-target.md) - A long `just test interop` or wire-compat run never fails because the binaries it built were removed from the shared Cargo target mid-run, such as by mbx pruning its managed build storage - [One nextest pin](/quest/m0/ci/nextest-pin.md) - cargo-nextest's version lives in one place - [The flake lane skips hosts that can't map user namespaces](/quest/m0/ci/userns-uid-map.md) - `check flake` skips instead of failing where `/proc/self/uid_map` is unwritable diff --git a/quest/m0/ci/shared-target.md b/quest/m0/ci/shared-target.md deleted file mode 100644 index ef1aeb814ba..00000000000 --- a/quest/m0/ci/shared-target.md +++ /dev/null @@ -1,33 +0,0 @@ -# [S] Long test runs keep their built binaries - -## Goal - -A long `just test interop` or wire-compat run never fails because the -binaries it built were removed from the shared Cargo target mid-run, such -as by mbx pruning its managed build storage. - -## Plan - -Decided 2026-10-31 (user, /quest-plan of the follow-ups from the 2026-10-31 /quest-complete run), from [moq-dev/moq#7211](https://github.com/moq-dev/moq/pull/7211). Milestone: ✅ m0 (user, "all recommended" for quests 1-8). - -- **Target removed mid-run**: the 2026-10-31 run reported the shared - `target/` deleted by mbx under long interop and wire-compat runs. mbx - links each checkout's target to managed storage that prunes itself - (`mbx gc` collects managed targets to fit its budget), and - `test/interop/interop.sh:578` (at be39188000) resolves `TARGET_BASE` - once, then runs `moq-relay`, `moq-cli`, its examples, and moq-c's library - from there for the whole matrix; `test/interop/compat.sh:72-73` does the - same. Confirm from mbx's logs or `mbx gc --dry-run` which collection - removes them. Then either copy everything the run loads from the target - into the run's own directory (`$HARNESS_RUN`) right after building, - which needs no mbx change: binaries, examples, moq-c's headers and - library, and any GStreamer plugin the matrix loads, with every consumer - pointed at the copies. Or use an mbx lease or pin if mbx offers one. - Prefer whichever keeps one rule for every long-running script. - -The one-off `Argument list too long` Cargo launch #7211 saw is fixed: -[moq-dev/moq#7594](https://github.com/moq-dev/moq/pull/7594) (merged) -traced it to mbx copying a PATH that grew with every nested dev shell and -dedupes PATH in `flake.nix`'s `shellHook`. - -Public API: none. Wire: none. diff --git a/test/README.md b/test/README.md index a1682039f98..32320d4f7d4 100644 --- a/test/README.md +++ b/test/README.md @@ -34,6 +34,11 @@ Every run owns three things and touches nothing else. holding every log, generated config, and capture. `HARNESS_RUNS` moves the root. Client builds go here too (the Python venv, the staged Go modules, the browser page), so two runs from one checkout never rebuild a client the other is running. +Interop and wire-compat also stage their Cargo executables, headers, static libraries, +and GStreamer plugin here immediately after building, as hard links or copies across +filesystems. Every later execution, link, and plugin load uses these run-owned paths, +so collecting shared Cargo output cannot remove an artifact a running matrix still +needs. Binary overrides are staged too, including nested wire-compat cells. **Reserved ports.** A port is claimed by creating a directory under `/tmp/moq-test-ports-` (`HARNESS_PORT_ROOT`), held for the whole run, and diff --git a/test/interop/compat.sh b/test/interop/compat.sh index 48d80b4e839..73e158e1369 100755 --- a/test/interop/compat.sh +++ b/test/interop/compat.sh @@ -70,7 +70,9 @@ release_binary moq-cli moq release_binary moq-relay moq-relay cargo build --locked -p moq-cli -p moq-relay TARGET=$(cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys;print(json.load(sys.stdin)["target_directory"])') -CURRENT="$TARGET/debug/moq" +harness_stage current/moq "$TARGET/debug/moq" +harness_stage current/moq-relay "$TARGET/debug/moq-relay" +CURRENT="$HARNESS_RUN/current/moq" RELEASED="$HARNESS_RUN/released/bin/moq" "$CURRENT" --help >"$HARNESS_RUN/current-help" "$RELEASED" --help >"$HARNESS_RUN/released-help" @@ -130,13 +132,14 @@ hang = $dependency bytes = "1" TOML cargo build --manifest-path "$HARNESS_RUN/hang-$source/Cargo.toml" --target-dir "$TARGET/compat-hang-$source" - "$TARGET/compat-hang-$source/debug/compat-container" encode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" + harness_stage "hang-$source/compat-container" "$TARGET/compat-hang-$source/debug/compat-container" + "$HARNESS_RUN/hang-$source/compat-container" encode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" done bun "$DIR/compat/client.ts" encode "$HARNESS_RUN/js-current.catalog" "$HARNESS_RUN/js-current.frame" bun "$HARNESS_RUN/js/client.ts" encode "$HARNESS_RUN/js-released.catalog" "$HARNESS_RUN/js-released.frame" for source in current released js-current js-released; do for consumer in current released; do - "$TARGET/compat-hang-$consumer/debug/compat-container" decode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" + "$HARNESS_RUN/hang-$consumer/compat-container" decode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" done bun "$DIR/compat/client.ts" decode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" bun "$HARNESS_RUN/js/client.ts" decode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" @@ -205,7 +208,7 @@ live_publisher() { # relay, and package set, and can never be covered by a planned break. while read -r source version <&3; do case "$source" in - current) relay="$TARGET/debug/moq-relay" pub="$CURRENT" js="$DIR/compat" ;; + current) relay="$HARNESS_RUN/current/moq-relay" pub="$CURRENT" js="$DIR/compat" ;; released) relay="$HARNESS_RUN/released/bin/moq-relay" pub="$RELEASED" js="$HARNESS_RUN/js" ;; *) echo "unknown media control source: $source" >&2 @@ -233,15 +236,15 @@ while read -r version <&3; do released_relay="$HARNESS_RUN/released/bin/moq-relay" # Each moq-net library states whether the draft has FETCH, so a FETCH cell that # fails is a failure, never a skip. Dropping a released capability fails too. - current_fetch=$("$TARGET/compat-hang-current/debug/compat-container" fetch-supported "$version") - released_fetch=$("$TARGET/compat-hang-released/debug/compat-container" fetch-supported "$version") + current_fetch=$("$HARNESS_RUN/hang-current/compat-container" fetch-supported "$version") + released_fetch=$("$HARNESS_RUN/hang-released/compat-container" fetch-supported "$version") cell fetch-capability "$version" both both fetch_kept "$released_fetch" "$current_fetch" if [[ "$released_fetch" != true || "$current_fetch" != true ]]; then echo "SKIP $version fetch and js-publish: no FETCH on this draft in both libraries" skipped=$((skipped + 8)) fi for relay_source in current released; do - if [[ "$relay_source" == current ]]; then relay="$TARGET/debug/moq-relay"; else relay="$released_relay"; fi + if [[ "$relay_source" == current ]]; then relay="$HARNESS_RUN/current/moq-relay"; else relay="$released_relay"; fi for source in current released; do # Each side's compat client, with its version-pinning transport beside it. if [[ "$source" == current ]]; then diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 42fbdf34eaa..dcf80847019 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -535,7 +535,8 @@ plan_pass() { } plan_cases -TARGET_BASE="" # cargo target dir (resolved in require_tools) +TARGET_BASE="" # cargo target dir (resolved in require_tools) +EXAMPLES="$HARNESS_RUN/examples" PY="" # python interpreter with the workspace moq build (set in prepare) C_INTEROP="" # compiled C client binary (set in prepare) GO_INTEROP="" # compiled Go client binary (set in prepare) @@ -586,28 +587,42 @@ require_tools() { # Build moq-relay + moq-cli from the workspace. The relay is the spine of the # test, so a failure here aborts rather than marking a single client broken. build_relay_cli() { + local flag=() build_examples=0 + [[ "$PROFILE" == "release" ]] && flag=(--release) if [[ -n "$RELAY" && -n "$MOQ" ]]; then [[ -x "$RELAY" && -x "$MOQ" ]] || { echo "override binaries are not executable" >&2 exit 1 } - return - fi - local flag=() - [[ "$PROFILE" == "release" ]] && flag=(--release) - echo "building moq-relay + moq-cli ($PROFILE)..." - # ${arr[@]+...} guard: bash 3.2 (macOS /bin/bash) errors on "${flag[@]}" for - # an empty (debug) array under `set -u`. - (cd "$WORKSPACE" && cargo build --locked ${flag[@]+"${flag[@]}"} -p moq-relay -p moq-cli) || { - echo "error: failed to build moq-relay / moq-cli" >&2 - exit 1 - } - if [[ "$MEDIA" -eq 0 ]]; then - (cd "$WORKSPACE" && cargo build --locked ${flag[@]+"${flag[@]}"} -p moq-cli --example interop-tail --example interop-catalog --example interop-audio --example interop-hls --example interop-control --example interop-goaway --example interop-goaway-client --example interop-finish) + else + build_examples=1 + echo "building moq-relay + moq-cli ($PROFILE)..." + # ${arr[@]+...} guard: bash 3.2 (macOS /bin/bash) errors on "${flag[@]}" for + # an empty (debug) array under `set -u`. + (cd "$WORKSPACE" && cargo build --locked ${flag[@]+"${flag[@]}"} -p moq-relay -p moq-cli) || { + echo "error: failed to build moq-relay / moq-cli" >&2 + exit 1 + } + [[ -n "$RELAY" ]] || RELAY="$TARGET_BASE/$PROFILE/moq-relay" + # The `moq-cli` crate ships its binary as `moq` (a `[[bin]]` override). + [[ -n "$MOQ" ]] || MOQ="$TARGET_BASE/$PROFILE/moq" + fi + harness_stage bin/moq-relay "$RELAY" + harness_stage bin/moq "$MOQ" + RELAY="$HARNESS_RUN/bin/moq-relay" + MOQ="$HARNESS_RUN/bin/moq" + if [[ -n "${INTEROP_SUB_MOQ:-}" ]]; then + harness_stage bin/moq-sub "$INTEROP_SUB_MOQ" + INTEROP_SUB_MOQ="$HARNESS_RUN/bin/moq-sub" + fi + if [[ "$build_examples" -eq 1 && "$MEDIA" -eq 0 ]]; then + local example args=() examples=(interop-tail interop-catalog interop-audio interop-hls interop-control interop-goaway interop-goaway-client interop-finish) + for example in "${examples[@]}"; do args+=(--example "$example"); done + (cd "$WORKSPACE" && cargo build --locked ${flag[@]+"${flag[@]}"} -p moq-cli "${args[@]}") + for example in "${examples[@]}"; do + harness_stage "examples/$example" "$TARGET_BASE/$PROFILE/examples/$example" + done fi - [[ -n "$RELAY" ]] || RELAY="$TARGET_BASE/$PROFILE/moq-relay" - # The `moq-cli` crate ships its binary as `moq` (a `[[bin]]` override). - [[ -n "$MOQ" ]] || MOQ="$TARGET_BASE/$PROFILE/moq" } # Build the workspace Python packages as wheels (maturin builds rs/moq-ffi, hatchling @@ -774,6 +789,8 @@ prepare_c() { mark_broken c "moq-c artifacts missing ($header / $lib)" return } + harness_stage c/include/moq.h "$header" + harness_stage c/libmoq.a "$lib" # cargo can't inject libmoq.a's native deps into an external link, so read # them from the same list moq-c.pc and CMake use. local native_libs @@ -790,7 +807,7 @@ prepare_c() { esac done <"$native_libs" C_INTEROP="$HARNESS_RUN/c-interop" - if ! "$cc" "$CLIENTS/c/subscribe.c" -I"$out_dir/include" -L"$TARGET_BASE/$PROFILE" -lmoq "${os_libs[@]}" -o "$C_INTEROP" >"$HARNESS_RUN/c-compile.log" 2>&1; then + if ! "$cc" "$CLIENTS/c/subscribe.c" -I"$HARNESS_RUN/c/include" "$HARNESS_RUN/c/libmoq.a" "${os_libs[@]}" -o "$C_INTEROP" >"$HARNESS_RUN/c-compile.log" 2>&1; then mark_broken c "cc compile failed" sed 's/^/ /' "$HARNESS_RUN/c-compile.log" >&2 || true fi @@ -819,7 +836,10 @@ prepare_gst() { sed 's/^/ /' "$HARNESS_RUN/gst-build.log" >&2 || true return fi - GST_PLUGIN_DIR="$TARGET_BASE/$PROFILE" + local extension=so + [[ "$(uname -s)" != Darwin ]] || extension=dylib + harness_stage "gst/libgstmoq.$extension" "$TARGET_BASE/$PROFILE/libgstmoq.$extension" + GST_PLUGIN_DIR="$HARNESS_RUN/gst" # Use the packaging smoke check's isolated discovery and factory assertions. if ! "$WORKSPACE/rs/moq-gst/smoke.sh" "$GST_PLUGIN_DIR" >"$HARNESS_RUN/gst-inspect.log" 2>&1; then mark_broken gst "moqsrc not exposed (plugin failed to load against this GStreamer)" @@ -1380,7 +1400,7 @@ PYCODE local n connect audio_pid="" audio_status=0 rust_connect "$url" if [[ "$AUDIO" -eq 1 ]]; then - timeout -k 3 "$TIMEOUT" "$TARGET_BASE/$PROFILE/examples/interop-audio" \ + timeout -k 3 "$TIMEOUT" "$EXAMPLES/interop-audio" \ "$url" "$broadcast" "$audio_out" "$AUDIO_MS" "$(cell_version rust)" & audio_pid=$! fi @@ -1610,7 +1630,7 @@ run_finish_client() { if [[ "$role" == publish ]]; then args+=(--finish-ack "$ack"); else args+=(--finish --frames 10); fi case "$lang/$role" in python/publish | go/publish | cpp/publish) args+=(--tone "$(publisher_tone "$lang")") ;; esac case "$lang" in - rust) timeout -k 3 "$limit" "$TARGET_BASE/$PROFILE/examples/interop-finish" "${args[@]}" ;; + rust) timeout -k 3 "$limit" "$EXAMPLES/interop-finish" "${args[@]}" ;; python) timeout -k 3 "$limit" "$PY" "$CLIENTS/python/interop.py" "${args[@]}" ;; go) timeout -k 3 "$limit" "$GO_INTEROP" "${args[@]}" ;; cpp) timeout -k 3 "$limit" "$CPP_INTEROP" "${args[@]}" ;; @@ -1830,7 +1850,7 @@ run_tail_client() { extra=("$version") fi case "$lang" in - rust) timeout -k 3 "$limit" "$TARGET_BASE/$PROFILE/examples/interop-tail" "$role" "$url" "$broadcast" ${extra[@]+"${extra[@]}"} ;; + rust) timeout -k 3 "$limit" "$EXAMPLES/interop-tail" "$role" "$url" "$broadcast" ${extra[@]+"${extra[@]}"} ;; js-native-node) (cd "$CLIENTS/js-native" && timeout -k 3 "$limit" node --import tsx tail.ts "$role" "$url" "$broadcast" ${extra[@]+"${extra[@]}"}) ;; js-native-bun) (cd "$CLIENTS/js-native" && timeout -k 3 "$limit" bun tail.ts "$role" "$url" "$broadcast" ${extra[@]+"${extra[@]}"}) ;; *) @@ -2247,12 +2267,12 @@ run_control_case() { local runtime="$1" kind="$2" version name="$2-$1" started=$SECONDS local cell=(case="$kind" publisher=rust subscriber="$runtime" log="$LOGS/$name.log") version=$(pinned_version) - local command=("$TARGET_BASE/$PROFILE/examples/interop-control" "$kind" "$version" "${runtime##*-}") + local command=("$EXAMPLES/interop-control" "$kind" "$version" "${runtime##*-}") case "$kind" in status) cell=(case="wire track status" publisher=rust subscriber="$runtime" log="$LOGS/$name.log") ;; - goaway) command=("$TARGET_BASE/$PROFILE/examples/interop-goaway" "$version" "${runtime##*-}") ;; + goaway) command=("$EXAMPLES/interop-goaway" "$version" "${runtime##*-}") ;; reverse-goaway) - command=("$TARGET_BASE/$PROFILE/examples/interop-goaway-client" "$version") + command=("$EXAMPLES/interop-goaway-client" "$version") cell=(case=goaway publisher="$runtime" subscriber=rust log="$LOGS/$name.log") ;; esac @@ -2283,7 +2303,7 @@ relay_inflated() { run_catalog_publisher() { local fifo="$1" shift - timeout -k 3 $((TIMEOUT * 2)) "$TARGET_BASE/$PROFILE/examples/interop-catalog" "$@" <"$fifo" 9>&- + timeout -k 3 $((TIMEOUT * 2)) "$EXAMPLES/interop-catalog" "$@" <"$fifo" 9>&- } # shellcheck disable=SC2329 # invoked indirectly via harness_spawn @@ -2359,7 +2379,7 @@ run_hls_publisher() { local fifo="$1" runtime="$2" shift 2 case "$runtime" in - rust) timeout -k 3 $((TIMEOUT * 2)) "$TARGET_BASE/$PROFILE/examples/interop-hls" publish "$@" <"$fifo" 9>&- ;; + rust) timeout -k 3 $((TIMEOUT * 2)) "$EXAMPLES/interop-hls" publish "$@" <"$fifo" 9>&- ;; js-native-node) (cd "$CLIENTS/js-native" && timeout -k 3 $((TIMEOUT * 2)) node --import tsx hls.ts "$@" <"$fifo" 9>&-) ;; js-native-bun) (cd "$CLIENTS/js-native" && timeout -k 3 $((TIMEOUT * 2)) bun hls.ts "$@" <"$fifo" 9>&-) ;; esac @@ -2383,7 +2403,7 @@ run_hls_records() { for publisher in rust "$runtime"; do harness_spawn "$name-$publisher-pub" "$LOGS/$name-$publisher-pub.log" run_hls_publisher "$fifo" "$publisher" "$(token_url --publish "$broadcast-$publisher/**")" "$broadcast-$publisher" pid="$HARNESS_PID" - harness_spawn "$name-$publisher-read" "$LOGS/$name-$publisher-read.log" timeout -k 3 "$TIMEOUT" "$TARGET_BASE/$PROFILE/examples/interop-hls" read "$(token_url --subscribe "$broadcast-$publisher/**")" "$broadcast-$publisher" + harness_spawn "$name-$publisher-read" "$LOGS/$name-$publisher-read.log" timeout -k 3 "$TIMEOUT" "$EXAMPLES/interop-hls" read "$(token_url --subscribe "$broadcast-$publisher/**")" "$broadcast-$publisher" harness_wait "$HARNESS_PID" || why="${why:-$publisher records unreadable}" printf 'clean end\n' >&9 harness_wait "$pid" || true diff --git a/test/interop/staging.test.py b/test/interop/staging.test.py new file mode 100644 index 00000000000..80d354ed7c0 --- /dev/null +++ b/test/interop/staging.test.py @@ -0,0 +1,263 @@ +#!/usr/bin/env python3 +"""Exercise setup and late consumers after collecting only owned build fixtures.""" + +import os +import re +import shlex +import shutil +import subprocess +import tempfile +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] + + +def executable(path, body): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("#!/usr/bin/env bash\nset -euo pipefail\n" + body) + path.chmod(0o755) + + +class Staging(unittest.TestCase): + def setUp(self): + (ROOT / ".tmp").mkdir(exist_ok=True) + self.temp = tempfile.TemporaryDirectory(dir=ROOT / ".tmp", prefix="staging-") + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + self.target = self.root / "shared target" + self.profile = self.target / "debug" + self.profile.mkdir(parents=True) + self.tools = self.root / "tools" + self.tools.mkdir() + self.env = {k: v for k, v in os.environ.items() if not k.startswith(("INTEROP_", "HARNESS_"))} + self.env.update( + PATH=f"{self.tools}:{os.environ['PATH']}", + GITHUB_ACTIONS="true", + BASH_ENV="", + CC="cc", + HARNESS_RUNS=str(self.root / "runs"), + FIXTURE_TARGET=str(self.target), + ) + self.env.pop("RELAY_BIN", None) + self.env.pop("CLI_BIN", None) + executable( + self.tools / "cargo", + """ +case "$1" in + metadata) printf '{"target_directory":"%s"}\n' "$FIXTURE_TARGET" ;; + install) + while [[ "$1" != --root ]]; do shift; done + mkdir -p "$2/bin" + cp "$FIXTURE_TARGET/debug/moq" "$2/bin/moq" + cp "$FIXTURE_TARGET/debug/moq-relay" "$2/bin/moq-relay" + ;; + build) + if [[ "$*" == *'--manifest-path'* ]]; then + while [[ "$1" != --target-dir ]]; do shift; done + mkdir -p "$2/debug" + cp "$FIXTURE_TARGET/adapter" "$2/debug/compat-container" + elif [[ "$*" == *'-p moq-c'* ]]; then + printf '{"reason":"build-script-executed","package_id":"/moq-c#0.0.0","out_dir":"%s/header"}\n' \ + "$FIXTURE_TARGET" + fi + ;; + *) exit 2 ;; +esac +""", + ) + for name in ("moq", "moq-relay"): + executable(self.profile / name, "echo owned-binary\n") + + def run_script(self, script, expected=0): + path = self.root / "run.sh" + path.write_text("set -euo pipefail\n" + script) + result = subprocess.run(["bash", str(path)], env=self.env, text=True, capture_output=True) + self.assertEqual(result.returncode, expected, result.stdout + result.stderr) + return result + + def test_interop_consumers_survive_collection(self): + source = (ROOT / "test/interop/interop.sh").read_text() + setup, runtime = source.split("# ── setup", 1) + setup = re.sub(r"^INTEROP_DIR=.*$", "INTEROP_DIR=" + shlex.quote(str(ROOT / "test/interop")), setup, flags=re.M) + for name in re.findall(r"\$EXAMPLES/(interop-[\w-]+)", runtime): + executable(self.profile / "examples" / name, "echo owned-example\n") + # Exercise dereferencing, including a symlink to a cache outside target. + cached = self.root / "cache" + cached.mkdir() + shutil.move(self.profile / "moq-relay", cached / "relay") + (self.profile / "moq-relay").symlink_to(cached / "relay") + clients = self.root / "clients/c" + clients.mkdir(parents=True) + (clients / "subscribe.c").write_text('#include "moq.h"\nint main(void) { return fixture() != 42; }\n') + header = self.target / "header/include" + header.mkdir(parents=True) + (header / "moq.h").write_text("int fixture(void);\n") + native = self.root / "fixture.c" + native.write_text("int fixture(void) { return 42; }\n") + subprocess.run(["cc", "-c", str(native), "-o", str(self.root / "fixture.o")], check=True) + subprocess.run(["ar", "rcs", str(self.profile / "libmoq.a"), str(self.root / "fixture.o")], check=True) + extension = "dylib" if os.uname().sysname == "Darwin" else "so" + subprocess.run( + ["cc", "-shared", "-fPIC", str(native), "-o", str(self.profile / f"libgstmoq.{extension}")], check=True + ) + # A stray shared moq library must never win over the staged staticlib. + (self.profile / f"libmoq.{extension}").write_text("invalid shared library") + executable(self.tools / "gst-launch-1.0", "exit 0\n") + executable( + self.tools / "gst-inspect-1.0", + """ +if [[ -n "${GST_PLUGIN_PATH_1_0:-}" ]]; then + python3 - "$GST_PLUGIN_PATH_1_0" <<'CHECK' +import ctypes, pathlib, sys +paths = list(pathlib.Path(sys.argv[1]).glob('libgstmoq.*')) +assert len(paths) == 1 +assert ctypes.CDLL(str(paths[0])).fixture() == 42 +CHECK +fi +printf ' moqsink: fixture\n moqsrc: fixture\n' +""", + ) + # Header and archive must survive collection before the C compiler reads them. + executable(self.tools / "cc", 'rm -rf "$FIXTURE_TARGET"\nexec ' + shlex.quote(shutil.which("cc")) + ' "$@"\n') + # Build C last, since its compiler deliberately collects this fixture target. + # Preserve the actual consumer expressions, so a leftover target path fails. + late_examples = "\n".join( + '"' + path + '"' + for path in sorted( + set(re.findall(r"\$(?:EXAMPLES|TARGET_BASE/\$PROFILE/examples)/interop-[\w-]+", runtime)) + ) + ) + self.run_script( + setup + + f""" +require_tools +build_relay_cli +prepare_gst +CLIENTS={shlex.quote(str(clients.parent))} +prepare_c +[[ -z "$BROKEN_LANGS" ]] +rm -rf {shlex.quote(str(cached))} +[[ ! -e "$TARGET_BASE" ]] +"$RELAY" +"$MOQ" +"$C_INTEROP" +GST_PLUGIN_PATH_1_0="$GST_PLUGIN_DIR" gst-inspect-1.0 moq +{late_examples} +""" + ) + self.assertEqual(list((self.root / "runs").iterdir()), []) + + def test_override_binaries_are_owned(self): + source = (ROOT / "test/interop/interop.sh").read_text().split("# ── setup", 1)[0] + source = re.sub( + r"^INTEROP_DIR=.*$", "INTEROP_DIR=" + shlex.quote(str(ROOT / "test/interop")), source, flags=re.M + ) + self.env.update( + RELAY_BIN=str(self.profile / "moq-relay"), + CLI_BIN=str(self.profile / "moq"), + INTEROP_SUB_MOQ=str(self.profile / "moq"), + ) + self.run_script( + source + + """ +require_tools +build_relay_cli +rm -rf "$TARGET_BASE" +"$RELAY" +"$MOQ" +"$INTEROP_SUB_MOQ" +""" + ) + + def test_wire_compat_adapters_and_current_binaries_are_owned(self): + executable(self.tools / "gh", "exit 1\n") + executable( + self.tools / "bun", + """ +if [[ "$*" == *'resolve.ts resolve'* ]]; then + printf '{"moq-cli":"0.1.0","moq-relay":"0.1.0","hang":"0.1.0"}' >"$3" +fi +""", + ) + executable( + self.target / "adapter", + """ +case "$1" in + encode) echo catalog >"$2"; echo frame >"$3" ;; + decode) [[ "$(cat "$2")" == catalog && "$(cat "$3")" == frame ]] ;; + fetch-supported) echo false ;; + *) exit 2 ;; +esac +""", + ) + source = (ROOT / "test/interop/compat.sh").read_text() + setup = source.split("# A separate package root", 1)[0] + setup = re.sub(r"^DIR=.*$", "DIR=" + shlex.quote(str(ROOT / "test/interop")), setup, flags=re.M) + adapters = source.split("# Exercise the actual hang library release", 1)[1].split( + 'bun "$DIR/compat/client.ts" encode', 1 + )[0] + self.run_script( + setup + + "# Exercise the actual hang library release" + + adapters + + """ +rm -rf "$TARGET" +"$CURRENT" --help +"$HARNESS_RUN/current/moq-relay" --help +for source in current released; do + "$HARNESS_RUN/hang-$source/compat-container" decode "$HARNESS_RUN/current.catalog" "$HARNESS_RUN/current.frame" + [[ "$("$HARNESS_RUN/hang-$source/compat-container" fetch-supported moq-lite-07)" == false ]] +done +""" + ) + + def test_nested_run_owns_links_after_parent_teardown(self): + binary = shlex.quote(str(self.profile / "moq")) + self.run_script( + f""" +source {shlex.quote(str(ROOT / "test/lib/harness.sh"))} +harness_begin parent +harness_stage bin/moq {binary} +parent="$HARNESS_RUN" +# Model the parent's lifetime ending before a child launches its next client. +HARNESS_RUN="$parent/child" +mkdir -p "$HARNESS_RUN" +harness_stage bin/moq "$parent/bin/moq" +[[ "$HARNESS_RUN/bin/moq" -ef "$parent/bin/moq" ]] +mv "$HARNESS_RUN" "$parent-saved-child" +rm -rf "$parent" "$FIXTURE_TARGET" +HARNESS_RUN="$parent-saved-child" +"$HARNESS_RUN/bin/moq" +""" + ) + self.assertEqual(list((self.root / "runs").iterdir()), []) + + def test_copy_when_hard_links_are_unavailable(self): + executable(self.tools / "ln", "exit 1\n") + self.run_script( + f""" +source {shlex.quote(str(ROOT / "test/lib/harness.sh"))} +harness_begin copy +harness_stage bin/moq "$FIXTURE_TARGET/debug/moq" +[[ ! "$HARNESS_RUN/bin/moq" -ef "$FIXTURE_TARGET/debug/moq" ]] +rm -rf "$FIXTURE_TARGET" +"$HARNESS_RUN/bin/moq" +""" + ) + + def test_missing_artifact_fails_and_keeps_evidence(self): + self.run_script( + f""" +source {shlex.quote(str(ROOT / "test/lib/harness.sh"))} +harness_begin missing +harness_stage bin/missing "$HARNESS_RUN/no-such-file" +echo should-not-run +""", + expected=1, + ) + self.assertEqual(len(list((self.root / "runs").iterdir())), 1) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/justfile b/test/justfile index a03400dbef0..0def7abf9b7 100644 --- a/test/justfile +++ b/test/justfile @@ -46,6 +46,7 @@ default: harness: ./lib/harness.test.sh ./interop/relay-log.test.sh + python3 interop/staging.test.py python3 ../rs/moq-gst/smoke.test.py python3 interop/report.test.py python3 interop/tone.test.py diff --git a/test/lib/harness.sh b/test/lib/harness.sh index 928d5f08dcb..21528845f6c 100644 --- a/test/lib/harness.sh +++ b/test/lib/harness.sh @@ -102,6 +102,19 @@ harness_begin() { echo "run: $HARNESS_RUN" } +# ── artifacts ─────────────────────────────────────────────────────────────── + +# Keep a build artifact in this run before another build or collection can +# unlink it. Dereference symlinks: ownership must not depend on the build cache. +# DEST is relative to HARNESS_RUN; callers use that path for every later load. +harness_stage() { + local dest="$HARNESS_RUN/$1" source="$2" + mkdir -p "$(dirname "$dest")" || return $? + # Nested compat cells retain their own names without copying the same large + # binary every time. A copy also supports run directories on another disk. + ln -L "$source" "$dest" 2>/dev/null || cp -L "$source" "$dest" +} + # ── endpoints ─────────────────────────────────────────────────────────────── # Where port reservations live. Shared across worktrees on purpose: the point is