diff --git a/.github/justfile b/.github/justfile index 699ec0c3fa8..549ad23cfde 100644 --- a/.github/justfile +++ b/.github/justfile @@ -19,7 +19,7 @@ runner-vm-ci: # Build and test the persistent NixOS runner VM on x86_64 Linux. runner-vm: - nix build --no-link .#checks.x86_64-linux.github-runner-vm .#checks.x86_64-linux.github-runner-vm-image .#checks.x86_64-linux.github-runner-vm-config --print-build-logs + bash sh/local.sh nix build --no-link .#checks.x86_64-linux.github-runner-vm .#checks.x86_64-linux.github-runner-vm-image .#checks.x86_64-linux.github-runner-vm-config --print-build-logs # Lint GitHub Actions workflows, their alert coverage, and that every step runs a recipe. check: @@ -31,6 +31,7 @@ check: # Tests of repository tooling; every `just check` and `just ci` runs them. test: + python3 sh/local.test.py python3 test/smoke/runner.test.py python3 sh/coverage.test.py python3 sh/size/report.test.py diff --git a/README.md b/README.md index fcd5dad5d92..d8f13dad37f 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,21 @@ just check --all just fix --all ``` +Expensive checks and test launchers automatically enter `quest gate` locally, +including direct language recipes and fixture scripts. Admission waits for host +CPU load and available memory before builds or test timeout clocks start; +nested checks reuse that admission. Hosted GitHub Actions keeps its runner +scheduling. Rust builds still use the dev shell's mbx Cargo shim. + +`just check` and `just ci` run three module lanes at once, each admitted per +command; set `MOQ_CHECK_JOBS` to change that, or to 1 to run them in order. +Local nextest runs default to at most four test workers; set +`NEXTEST_TEST_THREADS` to override it. Bun workspace scripts run sequentially +locally, preserving dependency order, while CI keeps its workspace parallelism. +Selection and an empty JS selection do not wait for admission. For a build +outside these entrypoints, use `quest gate COMMAND [ARGS...]`; gate thresholds +come from the host and have no configuration. + PRs into `main` get no cloud CI until the merge queue, so run `just ci` before pushing. It runs what the queue runs, the same ground as `just check`, plus two settings: `MOQ_STRICT=1`, which turns a missing tool into an error instead of a skipped check, and `NEXTEST_PROFILE=ci`, which allows a longer hang timeout. See the [development guide](https://doc.moq.dev/setup/dev) and the [justfile](justfile) for more. diff --git a/bench/README.md b/bench/README.md index 57b07ac885c..61a13828c53 100644 --- a/bench/README.md +++ b/bench/README.md @@ -491,3 +491,23 @@ nix develop --command just gh benchmark-report gate target/bench/nightly/rust-be Each run's evidence directory keeps both builds' estimates (`criterion` and `criterion-base`), the confirmation rounds under `confirm/`, and the run's `paired.json`. + +## Local check capacity + +Prepare the same warm dependencies and artifacts in each isolated checkout, then +compare solo and concurrent suites with their actual worker counts: + +```bash +just bench-local --checkout "$PWD" --checkout /path/to/another/checkout \ + --workers 1 4 8 24 --samples 3 --cache warm -- \ + cargo nextest run --locked -p moq-net --lib +``` + +Each JSON record retains host load, configured workers and lanes, admission +delay, work wall time, total wall time, and child CPU time. Logs stay under each +checkout's `.scratch/local-bench/`. To compare Bun workspace fanout, repeat with +the same `bun run --filter=... test` command, then add `--sequential`. To compare +the module lanes `just check` runs at once, sweep `--jobs 1 3` over +`bash sh/dispatch.sh check BASE`, which is then admitted once as a whole. +Admission remains outside the suite's timeout clocks. Use separate checkouts to +avoid measuring Cargo's artifact lock instead of competing work. diff --git a/bench/local.py b/bench/local.py new file mode 100644 index 00000000000..2ad7f59dfce --- /dev/null +++ b/bench/local.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 +"""Compare suite fanout across isolated checkouts, separating admission from work.""" + +import argparse +import json +import os +from pathlib import Path +import subprocess +import signal +import sys +import time +import uuid + + +ROOT = Path(__file__).resolve().parents[1] + + +def main(): + if sys.argv[1:2] == ["--started"]: + started = time.monotonic() + result = subprocess.run(sys.argv[3:]) + Path(sys.argv[2]).write_text(json.dumps({"start": started, "end": time.monotonic()})) + sys.exit(result.returncode) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--checkout", action="append", type=Path, required=True) + parser.add_argument("--workers", nargs="+", type=int, required=True) + parser.add_argument("--jobs", nargs="+", type=int, help="MOQ_CHECK_JOBS lane counts to sweep") + parser.add_argument("--samples", type=int, default=3) + parser.add_argument("--cache", required=True, help="Describe the prepared cache state") + parser.add_argument("command", nargs=argparse.REMAINDER) + args = parser.parse_args() + command = args.command[1:] if args.command[:1] == ["--"] else args.command + if not command or args.samples < 1 or any(n < 1 for n in args.workers + (args.jobs or [])): + parser.error("a command, positive samples and positive worker and job counts are required") + if os.name != "posix": + parser.error("CPU accounting requires a POSIX host") + checkouts = [checkout.resolve() for checkout in args.checkout] + if not all(checkout.is_dir() for checkout in checkouts) or len(set(checkouts)) != len(checkouts): + parser.error("each checkout must be a distinct existing directory") + # Every checkout runs solo, so a concurrent run is compared against its own baseline. + groups = [[checkout] for checkout in checkouts] + ([checkouts] if len(checkouts) > 1 else []) + def cancel(number, _frame): + raise SystemExit(128 + number) + for number in (signal.SIGTERM, signal.SIGHUP): + signal.signal(number, cancel) + # Alternating the order spreads drift in host load or thermals over solo and concurrent runs. + for sample in range(args.samples): + for group in groups if sample % 2 == 0 else reversed(groups): + for workers, jobs in ((w, j) for w in args.workers for j in args.jobs or [None]): + processes = [] + load = os.getloadavg() + try: + for checkout in group: + directory = checkout / ".scratch/local-bench" + directory.mkdir(parents=True, exist_ok=True) + stem = directory / str(uuid.uuid4()) + stamp = stem.with_suffix(".started") + with stem.with_suffix(".log").open("w") as log: + env = dict(os.environ, NEXTEST_TEST_THREADS=str(workers)) + # Without --jobs, the record's null means sh/dispatch.sh's default. + env.pop("MOQ_CHECK_JOBS", None) + if jobs: + env["MOQ_CHECK_JOBS"] = str(jobs) + env.pop("QUEST_GATE_ADMITTED", None) + env.pop("MOQ_LOCAL_SUPERVISED", None) + env.pop("GITHUB_ACTIONS", None) + began = time.monotonic() + process = subprocess.Popen(["bash", str(ROOT / "sh/local.sh"), sys.executable, + str(Path(__file__).resolve()), "--started", str(stamp), + *command], cwd=checkout, env=env, stdout=log, stderr=log) + processes.append((process, began, stamp)) + results = [] + for process, began, stamp in processes: + _, status, usage = os.wait4(process.pid, 0) + process.returncode = os.waitstatus_to_exitcode(status) + if process.returncode: + raise RuntimeError(f"command failed ({process.returncode}); see {stamp.with_suffix('.log')}") + timing = json.loads(stamp.read_text()) + started, ended = timing["start"], timing["end"] + results.append({"admission_s": started - began, "work_s": ended - started, + "total_s": ended - began, "cpu_s": usage.ru_utime + usage.ru_stime}) + finally: + for process, _, _ in processes: + if process.returncode is None: + process.terminate() + process.wait() + print(json.dumps({"copies": len(group), "checkouts": [str(checkout) for checkout in group], + "nextest_workers": workers, "check_jobs": jobs, "sample": sample, + "cache": args.cache, "host_load": load, "command": command, + "runs": results}), flush=True) + + +if __name__ == "__main__": + main() diff --git a/js/justfile b/js/justfile index b5148be5616..fa79629f667 100644 --- a/js/justfile +++ b/js/justfile @@ -97,7 +97,7 @@ build: # Build browser/WASM bindings into @moq/wasm using the pinned wasm-bindgen toolchain. wasm PROFILE="wasm-release": - cargo build --locked -p moq-wasm --target wasm32-unknown-unknown --profile {{ PROFILE }} + bash ../sh/local.sh cargo build --locked -p moq-wasm --target wasm32-unknown-unknown --profile {{ PROFILE }} wasm-bindgen --target web --out-name moq --out-dir wasm/dist "${CARGO_TARGET_DIR:-../target}/wasm32-unknown-unknown/{{ if PROFILE == "dev" { "debug" } else { PROFILE } }}/moq_wasm.wasm" # Ensure the built public libraries can load without browser globals. diff --git a/justfile b/justfile index 6cd8b218f1e..e7c51037ea6 100644 --- a/justfile +++ b/justfile @@ -47,6 +47,11 @@ dev: bench $BASE="": bench/run.sh "$BASE" +# Compare admitted suites across checkouts and worker counts; see bench/README.md. +[positional-arguments] +bench-local *args: + python3 bench/local.py "$@" + # Benchmark selected wrappers against two Rust baselines on this machine. [positional-arguments] bench-ffi *runners: diff --git a/py/justfile b/py/justfile index e8895badecd..b465a0e983a 100644 --- a/py/justfile +++ b/py/justfile @@ -22,7 +22,7 @@ default: # keeps uv from fetching moq-ffi off PyPI; maturin just installed it locally. _develop *args: - cd .. && uv run --no-sync maturin develop --locked --uv {{ args }} + cd .. && bash sh/local.sh uv run --no-sync maturin develop --locked --uv {{ args }} uv pip install --no-deps -e moq-rs # Lint + format + editable build + pyright + doc samples + docs. `--no-install-workspace` @@ -60,7 +60,7 @@ fix: test: uv sync --locked --no-install-workspace just _develop {{ test_features }} - uv run --no-sync pytest moq-rs/tests/ moq-ffi/tests/ + bash ../sh/local.sh uv run --no-sync pytest moq-rs/tests/ moq-ffi/tests/ # Local dev build: editable install of moq-ffi (with the cdylib + uniffi @@ -72,7 +72,7 @@ build: # Run the binding benchmark's Python runner (see bench/README.md) on a release build. bench: uv sync --locked --no-install-workspace - cd .. && uv run --no-sync maturin develop --locked --uv --release + cd .. && bash sh/local.sh uv run --no-sync maturin develop --locked --uv --release uv pip install --no-deps -e moq-rs uv run --no-sync python moq-rs/benches/ffi.py diff --git a/quest/m0/ci/README.md b/quest/m0/ci/README.md index 7ecadcdfc1e..2f0da3af34e 100644 --- a/quest/m0/ci/README.md +++ b/quest/m0/ci/README.md @@ -89,8 +89,6 @@ The historical samples locate candidates; they are not controlled benchmarks. ## Required - [Require the release gate](/quest/m0/ci/release-gates.md) - condition: the next cut carries `release-gate.yml`; then release PRs require it -- [Share local check capacity](/quest/m0/ci/local-gate.md) - gate expensive phases and bound internal fanout -- [select.sh launcher path](/quest/m0/ci/select-launcher-path.md) - `sh/rs/select.sh` runs from a subdirectory by resolving its launcher before `cd` - [Build queue entries concurrently](/quest/m0/ci/queue-concurrency.md) - the queue builds two or more entries at once instead of one - [Check the bindings in separate lanes](/quest/m0/ci/ffi-lane.md) - py, kt, swift, go, carla, and cpp check concurrently instead of in one serial lane - [Measure nightly compiler levers](/quest/m0/ci/nightly-levers.md) - the parallel frontend and Cranelift, adopted only if the numbers beat their risks diff --git a/quest/m0/ci/ffi-lane.md b/quest/m0/ci/ffi-lane.md index 4c9a0924905..7b82ee8d6f7 100644 --- a/quest/m0/ci/ffi-lane.md +++ b/quest/m0/ci/ffi-lane.md @@ -32,7 +32,3 @@ than measure first or drop py's test features. fresh, which any concurrent Cargo build of moq-ffi would break. - Measure the full-run wall time and peak disk before and after on matched inputs: concurrent lanes add their temporary data together. - -## Related - -- [Share local check capacity](/quest/m0/ci/local-gate.md) - bounds the fanout these lanes add diff --git a/quest/m0/ci/local-gate.md b/quest/m0/ci/local-gate.md deleted file mode 100644 index 8533a2d8884..00000000000 --- a/quest/m0/ci/local-gate.md +++ /dev/null @@ -1,26 +0,0 @@ -# [M] Share local check capacity across worktrees - -## Goal - -Expensive local check and test phases enter `quest gate` automatically, sharing -one host/user budget with other worktrees and repositories. One admitted suite -also bounds its own worker fanout so it does not overwhelm the desktop. - -## Plan - -- Decided 2026-10-15: gate expensive commands, not agent sessions. Put admission - before expensive builds and fixture launch, outside test timeout clocks. - Keep hosted CI's existing runner/merge-queue behavior. -- Audit root and direct language/test entrypoints together. Nested invocation - must not deadlock or bypass the cap. Cheap selection and docs-only checks - should remain cheap. Verify cancellation leaves no owned workload running. -- Reuse mbx for Rust compilation. Measure nextest thread/group limits and Bun - workspace fanout for local runs, and the module lanes `sh/dispatch.sh` - runs at once (`MOQ_CHECK_JOBS`, which also bounds the sources - `sh/obs/compile.sh` checks at once); do not blindly enable mbx test scheduling - where queued time would consume nextest's timeout budget. -- Benchmark representative solo and concurrent checkouts, recording wall time, - CPU time, worker counts, cache state, and other host load. Compare total work - separately from admission delay. Choose defaults from those measurements. -- Explain direct invocation and configuration in existing developer docs. - Preserve selected tests and their failure behavior. diff --git a/quest/m0/ci/queue-concurrency.md b/quest/m0/ci/queue-concurrency.md index 8c337c27973..ff72eb2dd42 100644 --- a/quest/m0/ci/queue-concurrency.md +++ b/quest/m0/ci/queue-concurrency.md @@ -22,9 +22,7 @@ with a median entry of 135 s (p90 516 s) and 3 to 12 s of runner wait. - Concurrent entries share the local mbx store; confirm that is safe, or give each its own. - Measure merged PRs per hour and per-entry wall time before and after. +- Queue entries skip `quest gate`: `sh/local.sh` execs directly under GitHub + Actions, so the runner quota, not admission, has to keep entries apart. Public API: none. Wire: none. - -## Related - -- [Share local check capacity](/quest/m0/ci/local-gate.md) - admission for the same host diff --git a/quest/m0/ci/select-launcher-path.md b/quest/m0/ci/select-launcher-path.md deleted file mode 100644 index b1d826232ef..00000000000 --- a/quest/m0/ci/select-launcher-path.md +++ /dev/null @@ -1,16 +0,0 @@ -# [XS] select.sh resolves its launcher before cd - -## Goal - -`cd sh/rs && bash select.sh lint --all` runs the selected checks instead of -failing with `bash: ./../local.sh: No such file or directory`. - -## Plan - -[moq-dev/moq#6256](https://github.com/moq-dev/moq/pull/6256) re-execs -`sh/rs/select.sh` through `sh/local.sh` after changing to the repository -root, so a relative `$0` no longer resolves -([review thread](https://github.com/moq-dev/moq/pull/6256#discussion_r4366860705)). -Resolve both paths before the `cd`, or name them relative to the root. - -Public API: none. Wire: none. diff --git a/rs/justfile b/rs/justfile index aad3367e3c4..c502967f2aa 100644 --- a/rs/justfile +++ b/rs/justfile @@ -29,7 +29,7 @@ default: # Compile, lint, format-check, doc-check, and verify dependency hygiene. [positional-arguments] check *args: - cargo clippy --locked --all-targets "$@" -- -D warnings + bash sh/local.sh cargo clippy --locked --all-targets "$@" -- -D warnings just rs lint "$@" # `check` with clippy enforced by the `test` build. A selection can hold @@ -51,14 +51,14 @@ lint *args: cargo fmt --all --check # quinn-udp and quinn keep quinn's formatting; cargo fmt skips them (see moq-sock's lib.rs, moq-tokio's quic.rs). rustfmt --edition 2024 --check rs/moq-sock/src/udp/mod.rs rs/moq-tokio/src/quic/driver/mod.rs - RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps "$@" + RUSTDOCFLAGS="-D warnings" bash sh/local.sh cargo doc --locked --no-deps "$@" cargo shear cargo sort --workspace --check --no-format # Auto-fix clippy/format/shear/sort. [positional-arguments] fix *args: - cargo clippy --locked --fix --allow-staged --allow-dirty --all-targets "$@" + bash sh/local.sh cargo clippy --locked --fix --allow-staged --allow-dirty --all-targets "$@" cargo fmt --all rustfmt --edition 2024 rs/moq-sock/src/udp/mod.rs rs/moq-tokio/src/quic/driver/mod.rs cargo shear --fix @@ -123,13 +123,13 @@ uring *args: cargo test --locked -p moq-relay --test integration # Needs a second IPv6 address on lo, which the io_uring CI lanes add. bash sh/rs/nextest.sh cargo nextest run --locked -p moq-uring --test integration --run-ignored only -E 'test(=local_addr::a_v6_wildcard_answers_from_the_address_reached)' "$@" - cargo clippy --locked -p moq-uring -p moq-relay --features moq-relay/io-uring,moq-relay/qlog --all-targets "$@" -- -D warnings + bash sh/local.sh cargo clippy --locked -p moq-uring -p moq-relay --features moq-relay/io-uring,moq-relay/qlog --all-targets "$@" -- -D warnings bash sh/rs/nextest.sh cargo nextest run --locked -p moq-uring --features qlog --tests "$@" # Compile the io_uring relay path, off the default feature set. [positional-arguments] uring-check *args: - cargo clippy --locked -p moq-uring -p moq-relay --features moq-relay/io-uring --all-targets "$@" -- -D warnings + bash sh/local.sh cargo clippy --locked -p moq-uring -p moq-relay --features moq-relay/io-uring --all-targets "$@" -- -D warnings # The Apple-gated code in moq-video, moq-audio, and moq-sock, which # platform.yml compiles on a Mac runner alongside `windows`. @@ -148,7 +148,7 @@ macos-test: # Compile and lint the capture and playback features, which the default check skips. [positional-arguments] capture *args: - cargo clippy --locked -p moq-video -p moq-audio --all-targets --features moq-video/capture,moq-audio/capture,moq-audio/playback "$@" -- -D warnings + bash sh/local.sh cargo clippy --locked -p moq-video -p moq-audio --all-targets --features moq-video/capture,moq-audio/capture,moq-audio/playback "$@" -- -D warnings # The capture and playback tests drive synthetic devices, so they need no hardware. @@ -187,8 +187,8 @@ x11-bench-ci: # moq-ffi library links logcat: `Log::init` is silent on Android without it. [positional-arguments] android *args: - cargo ndk -t arm64-v8a --platform 26 check --locked -p moq-video --all-targets "$@" - cargo ndk -t arm64-v8a --platform 26 -o target/android-jni build --locked -p moq-ffi --features openh264 "$@" + bash sh/local.sh cargo ndk -t arm64-v8a --platform 26 check --locked -p moq-video --all-targets "$@" + bash sh/local.sh cargo ndk -t arm64-v8a --platform 26 -o target/android-jni build --locked -p moq-ffi --features openh264 "$@" nm -D --undefined-only target/android-jni/arm64-v8a/libmoq_ffi.so | grep -q __android_log_ # moq-wasm's crate root is `#![cfg(target_arch = "wasm32")]`, so only a wasm32 @@ -201,23 +201,23 @@ android *args: # Compile and lint the browser/WASM bindings, which the host-target check skips. [positional-arguments] wasm *args: - cargo clippy --locked -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock --target wasm32-unknown-unknown --lib "$@" -- -D warnings + bash sh/local.sh cargo clippy --locked -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock --target wasm32-unknown-unknown --lib "$@" -- -D warnings # Run the browser clock backend on the root devShell's Playwright Chromium, # with the runtime and with reads alone. wasm-test: - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" cargo test --locked -p moq-clock --lib --target wasm32-unknown-unknown - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" cargo test --locked -p moq-clock --lib --target wasm32-unknown-unknown --no-default-features + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" bash sh/local.sh cargo test --locked -p moq-clock --lib --target wasm32-unknown-unknown + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" bash sh/local.sh cargo test --locked -p moq-clock --lib --target wasm32-unknown-unknown --no-default-features # Auto-fix the browser/WASM bindings. [positional-arguments] wasm-fix *args: - cargo clippy --locked --fix --allow-staged --allow-dirty -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock --target wasm32-unknown-unknown --lib "$@" + bash sh/local.sh cargo clippy --locked --fix --allow-staged --allow-dirty -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock --target wasm32-unknown-unknown --lib "$@" cargo fmt -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock # Audit dependencies against deny.toml. Nightly: advisories land without a diff. audit: - cargo deny check --show-stats + bash sh/local.sh cargo deny check --show-stats # Verify relay startup validation without a QUIC backend. relay-minimal: @@ -240,18 +240,18 @@ features: just rs quic-features just rs tokio-features --all just rs media-features --all - cargo check --locked --workspace {{ no_fuzz }} --all-targets --no-default-features - cargo hack check --locked -p moq-tokio --each-feature --exclude-features _transport --features aws-lc-rs - cargo check --locked -p moq-relay --no-default-features + bash sh/local.sh cargo check --locked --workspace {{ no_fuzz }} --all-targets --no-default-features + bash sh/local.sh cargo hack check --locked -p moq-tokio --each-feature --exclude-features _transport --features aws-lc-rs + bash sh/local.sh cargo check --locked -p moq-relay --no-default-features just rs relay-minimal - cargo check --locked -p moq-cli --no-default-features + bash sh/local.sh cargo check --locked -p moq-cli --no-default-features just rs test -p moq-cli --no-default-features --features capture,websocket -E 'test(capture_window)' just rs test -p moq-cli --no-default-features --features capture,pipewire,websocket -E 'test(capture_window)' - cargo check --locked -p moq-bench --no-default-features - cargo check --locked -p moq-boy --no-default-features - cargo check --locked -p moq-hls -p moq-rtmp -p moq-rtc --no-default-features --all-targets - cargo clippy --locked --workspace {{ no_fuzz }} --all-targets --all-features -- -D warnings - RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace {{ no_fuzz }} --all-features --no-deps + bash sh/local.sh cargo check --locked -p moq-bench --no-default-features + bash sh/local.sh cargo check --locked -p moq-boy --no-default-features + bash sh/local.sh cargo check --locked -p moq-hls -p moq-rtmp -p moq-rtc --no-default-features --all-targets + bash sh/local.sh cargo clippy --locked --workspace {{ no_fuzz }} --all-targets --all-features -- -D warnings + RUSTDOCFLAGS="-D warnings" bash sh/local.sh cargo doc --locked --workspace {{ no_fuzz }} --all-features --no-deps bash sh/rs/nextest.sh cargo nextest run --locked --workspace {{ no_fuzz }} --all-targets --all-features # Compile and test the explicit-time model without async helpers or sessions. @@ -267,7 +267,7 @@ quic-features: echo "moq-quic must not depend on a native runtime" >&2 exit 1 fi - cargo clippy --locked -p moq-quic --all-targets --no-default-features -- -D warnings + bash sh/local.sh cargo clippy --locked -p moq-quic --all-targets --no-default-features -- -D warnings # Compile media boundaries (--all isolates every mode) and prove expensive # native/render dependencies are absent when their features are excluded. @@ -304,7 +304,7 @@ play *args: # Compile and run the `/// ```` examples, which nextest skips. [positional-arguments] doctest *args: - cargo test --locked --doc "$@" + bash sh/local.sh cargo test --locked --doc "$@" # `--cfg loom` swaps kio's primitives for loom's, so it rebuilds the world and # stays out of `check`. `--release` because a model check runs the body once @@ -391,26 +391,26 @@ coverage crate="workspace": # Build the default workspace members. build: - cargo build --locked + bash sh/local.sh cargo build --locked # Run the comparable epoll and io_uring UDP matrices. [positional-arguments] bench-udp *args: - cargo bench -p moq-uring --bench udp_tokio -- "$@" - cargo bench -p moq-uring --bench udp_uring -- "$@" + bash sh/local.sh cargo bench -p moq-uring --bench udp_tokio -- "$@" + bash sh/local.sh cargo bench -p moq-uring --bench udp_uring -- "$@" # Measure a QUIC echo through the io_uring worker, ablating receive # batching, GRO, and GSO one at a time. Linux 6.12+ (skips loudly otherwise). [positional-arguments] bench-echo *args: - cargo bench -p moq-uring --bench echo_quic -- "$@" + bash sh/local.sh cargo bench -p moq-uring --bench echo_quic -- "$@" # Measure a full moq-lite session (publisher to subscriber) through the # io_uring worker, same ablations and per-iteration unit as bench-echo. # Linux 6.12+ (skips loudly otherwise). [positional-arguments] bench-session *args: - cargo bench -p moq-uring --bench session_lite -- "$@" + bash sh/local.sh cargo bench -p moq-uring --bench session_lite -- "$@" # Create release PRs and publish crates via release-plz. release: @@ -468,17 +468,17 @@ bench-playback: # Sweep retained RTMP chunk-stream IDs independently of message and chunk sizes. [positional-arguments] bench-rtmp *args: - cargo bench --locked -p moq-rtmp --bench chunk_interleaving -- "$@" + bash sh/local.sh cargo bench --locked -p moq-rtmp --bench chunk_interleaving -- "$@" # Refresh one credential across unrelated sessions and held token counts. [positional-arguments] bench-relay-auth *args: - cargo bench --locked -p moq-relay --bench auth -- "$@" + bash sh/local.sh cargo bench --locked -p moq-relay --bench auth -- "$@" # One relay's stats tick, plus the decode and aggregate tables. `--test` runs each tick once; the tables ignore it and print every configuration. [positional-arguments] bench-stats *args: - cargo bench --locked -p moq-stats --features bench --bench producer_tick --bench decode --bench aggregate -- "$@" + bash sh/local.sh cargo bench --locked -p moq-stats --features bench --bench producer_tick --bench decode --bench aggregate -- "$@" # Sweep latency observations against writer count and report density. bench-latency: @@ -487,14 +487,14 @@ bench-latency: # Exact TS receiver scheduling across PID and queued-unit fanout. [positional-arguments] bench-ts-schedule *args: - cargo bench --locked -p moq-mux --bench ts_schedule -- "$@" + bash sh/local.sh cargo bench --locked -p moq-mux --bench ts_schedule -- "$@" # Sweep container export tracks and queued frames independently. [positional-arguments] bench-export *args: - cargo bench --locked -p moq-mux --bench export -- "$@" + bash sh/local.sh cargo bench --locked -p moq-mux --bench export -- "$@" # Requested-pad catalog gating and resolved EOS lookup across renditions x touched pads. [positional-arguments] bench-gst-catalog *args: - cargo bench -p moq-gst --bench catalog "$@" + bash sh/local.sh cargo bench -p moq-gst --bench catalog "$@" diff --git a/sh/coverage.test.py b/sh/coverage.test.py index 8ff5e20b0f8..8be259b43d0 100644 --- a/sh/coverage.test.py +++ b/sh/coverage.test.py @@ -18,7 +18,7 @@ def setUp(self): self.directory = tempfile.TemporaryDirectory() self.addCleanup(self.directory.cleanup) self.root = Path(self.directory.name) - for script in ("sh/js/coverage.py", "sh/rs/coverage.sh", "sh/rs/nextest.sh"): + for script in ("sh/js/coverage.py", "sh/rs/coverage.sh", "sh/rs/nextest.sh", "sh/local.sh"): target = self.root / script target.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(ROOT / script, target) @@ -44,7 +44,7 @@ def setUp(self): target.chmod(0o755) self.calls = self.root / "calls" self.env = dict(os.environ, PATH=f"{self.bin}:{os.environ['PATH']}", - COVERAGE_CALLS=str(self.calls), BASH_ENV="/dev/null", GITHUB_ACTIONS="") + COVERAGE_CALLS=str(self.calls), BASH_ENV="/dev/null", GITHUB_ACTIONS="", MOQ_LOCAL_SUPERVISED="1") def javascript(self, name="", fail=False): directories = ["js/first", "js/second", "js/empty"] diff --git a/sh/cpp/check.sh b/sh/cpp/check.sh index 87b20aa6249..17d5d27bcfe 100755 --- a/sh/cpp/check.sh +++ b/sh/cpp/check.sh @@ -7,6 +7,10 @@ # compiler on Unix; Windows uses MSVC. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + ffi_dir="" archive="" if [[ $# -gt 0 ]]; then diff --git a/sh/dart/check.sh b/sh/dart/check.sh index 46c85add991..1d047d4ef18 100755 --- a/sh/dart/check.sh +++ b/sh/dart/check.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + DART_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../dart" && pwd) ACTION=check diff --git a/sh/dispatch-query.test.py b/sh/dispatch-query.test.py index db82b7c4a6c..2b7b05c9786 100644 --- a/sh/dispatch-query.test.py +++ b/sh/dispatch-query.test.py @@ -22,13 +22,13 @@ def setUp(self): self.root = Path(self.temp.name) self.repo = self.root / "repo" (self.repo / "sh").mkdir(parents=True) - for script in ("dispatch.sh", "changed.sh"): + for script in ("dispatch.sh", "changed.sh", "local.sh"): shutil.copy(ROOT / "sh" / script, self.repo / "sh" / script) self.bin = self.root / "bin" self.bin.mkdir() for command in ("bash", "git", "sort", "mktemp", "rm", "grep"): (self.bin / command).symlink_to(shutil.which(command)) - self.env = dict(os.environ, PATH=str(self.bin), GIT_CONFIG_NOSYSTEM="1", + self.env = dict(os.environ, MOQ_LOCAL_SUPERVISED="1", PATH=str(self.bin), GIT_CONFIG_NOSYSTEM="1", GIT_CONFIG_GLOBAL=os.devnull, MOQ_STRICT="1") # The runner's own Actions variables would move the run's error # annotations to stdout and append to the real job summary. diff --git a/sh/dispatch.sh b/sh/dispatch.sh index a543ea6364a..8fd3e3f106f 100755 --- a/sh/dispatch.sh +++ b/sh/dispatch.sh @@ -46,7 +46,7 @@ else # These files hold the map and the recipes that call it, and match no # module, so a change to them would otherwise validate none of it. - if grep -qE '^(justfile|sh/(dispatch|changed)\.sh)$' "$changed"; then + if grep -qE '^(justfile|sh/(dispatch|changed)\.sh|sh/local\.(sh|ts))$' "$changed"; then echo "$action: root orchestration changed; running everything." >&2 all=1 fi @@ -64,7 +64,7 @@ declare -A scope=( [workers]='^(infra/|demo/pub/|sh/js/workers\.sh$)' [moq_sh]='^infra/moq-sh/' # sh/rs/select.sh widens to the whole workspace for inputs every crate shares. - [rs]='^(rs/|demo/carla/bridge/|sh/rs/|Cargo\.(toml|lock)$|rust-toolchain\.toml$|\.config/nextest\.toml$)' + [rs]='^(sh/local\.(sh|ts)$|rs/|demo/carla/bridge/|sh/rs/|Cargo\.(toml|lock)$|rust-toolchain\.toml$|\.config/nextest\.toml$)' [bench]='^bench/' # The CARLA demo's simulator worker and launchers. Its player is a JS # package and its GPU bridge a Rust crate, so those modules cover them. @@ -291,12 +291,12 @@ step() { check:rs) just rs lint-changed "$rs_list" ;; check:bench) python3 bench/compare.test.py - cargo check --locked --package moq-relay --package moq-bench --features moq-relay/io-uring + bash sh/local.sh cargo check --locked --package moq-relay --package moq-bench --features moq-relay/io-uring ;; check:quest) quest check ;; check:drill) just test drill-sensitivity --apply-only ;; check:obs_compile) just obs compile ;; - check:flake) nix flake check ;; + check:flake) bash sh/local.sh nix flake check ;; check:ts_paths) python3 sh/gh/ts-paths.py ;; check:markdown) bun install --frozen-lockfile diff --git a/sh/go/check.sh b/sh/go/check.sh index a96a6e82def..5989be580aa 100755 --- a/sh/go/check.sh +++ b/sh/go/check.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + # Local smoke check for the Go module. # # Stages the ffi + wrapper modules from this checkout (sh/go/stage.sh) and diff --git a/sh/js/workspace.py b/sh/js/workspace.py index b8d7845c5f1..3db2590a27d 100644 --- a/sh/js/workspace.py +++ b/sh/js/workspace.py @@ -138,7 +138,8 @@ def scripts(verb): filters = [f"--filter={name}" for name, package in packages.items() if verb in package["manifest"].get("scripts", {})] if filters: - command("bun", "run", *filters, "--elide-lines=0", verb) + concurrency = [] if os.environ.get("GITHUB_ACTIONS") == "true" else ["--sequential"] + command("bun", "run", *concurrency, *filters, "--elide-lines=0", verb) command("bun", "install", "--frozen-lockfile") if action == "test": @@ -205,6 +206,9 @@ def main(): if action == "plan": print(json.dumps(plan, default=sorted)) else: + if plan["packages"] and os.environ.get("GITHUB_ACTIONS") != "true" and os.environ.get("MOQ_LOCAL_SUPERVISED") != "1": + os.execvp("bash", ["bash", str(ROOT / "sh/local.sh"), + sys.executable, str(Path(__file__).resolve()), *sys.argv[1:]]) started = time.monotonic() run(action, plan) print(f"js: {action} finished in {time.monotonic() - started:.2f}s", flush=True) diff --git a/sh/js/workspace.test.py b/sh/js/workspace.test.py index ccfba76fb3c..58d018fa1eb 100644 --- a/sh/js/workspace.test.py +++ b/sh/js/workspace.test.py @@ -174,7 +174,7 @@ def test_cycles_terminate(self): self.assertEqual(set(self.plan(["js/view/src/index.ts"])["packages"]), {"@example/core", "@example/view", "docs"}) - def calls(self, paths, action="check"): + def calls(self, paths, action="check", github_actions=False): calls = [] self.configurations = [] def invoke(args, **kwargs): @@ -182,7 +182,8 @@ def invoke(args, **kwargs): if args[:2] == ("bunx", "tsc") and args[-1] != "test/tsconfig.json": self.configurations.append(json.loads(Path(args[-1]).read_text())) return type("Result", (), {"returncode": 1 if args[0] == "grep" else 0})() - with patch.object(selector, "ROOT", self.root), patch.object(selector.os, "chdir"), \ + with patch.dict(selector.os.environ, GITHUB_ACTIONS=str(github_actions).lower()), \ + patch.object(selector, "ROOT", self.root), patch.object(selector.os, "chdir"), \ patch.object(selector.subprocess, "run", side_effect=invoke), \ patch.object(selector.shutil, "which", return_value="tool"): selector.run(action, self.plan(paths)) @@ -191,7 +192,7 @@ def invoke(args, **kwargs): def test_executor_runs_only_selected_package_scripts_without_wasm(self): calls = self.calls(["doc/index.md"]) scripts = [c for c in calls if c[:2] == ["bun", "run"]] - self.assertEqual(scripts, [["bun", "run", "--filter=docs", "--elide-lines=0", action] + self.assertEqual(scripts, [["bun", "run", "--sequential", "--filter=docs", "--elide-lines=0", action] for action in ("check", "build")]) self.assertNotIn(["just", "js", "wasm", "dev"], calls) self.assertTrue(any(c[:2] == ["bunx", "tsc"] for c in calls)) @@ -225,7 +226,9 @@ def test_executor_builds_wasm_before_consumer_check(self): def test_tests_do_not_build_wasm_or_unselected_packages(self): calls = self.calls(["doc/index.md"], "test") - self.assertIn(["bun", "run", "--filter=docs", "--elide-lines=0", "test"], calls) + self.assertIn(["bun", "run", "--sequential", "--filter=docs", "--elide-lines=0", "test"], calls) + hosted = self.calls(["doc/index.md"], "test", github_actions=True) + self.assertIn(["bun", "run", "--filter=docs", "--elide-lines=0", "test"], hosted) self.assertFalse(any(c[0] == "just" for c in calls)) def test_owned_package_without_scripts_keeps_harness_check(self): diff --git a/sh/kt/check.sh b/sh/kt/check.sh index 4a4fe5568f2..eb5ac57f7cd 100644 --- a/sh/kt/check.sh +++ b/sh/kt/check.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + # Full check for the Kotlin packages: regenerate the bindings + native lib # (sh/kt/generate.sh), then run the raw-bindings and wrapper JVM tests. # diff --git a/sh/local.sh b/sh/local.sh new file mode 100755 index 00000000000..1e29e3d3e94 --- /dev/null +++ b/sh/local.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Admit a local suite once; cheap selection runs before calling this launcher. +set -euo pipefail + +if [[ $# == 0 ]]; then + echo 'usage: sh/local.sh COMMAND [ARGS...]' >&2 + exit 2 +fi +if [[ "${GITHUB_ACTIONS:-}" == true ]]; then + exec "$@" +fi +export NEXTEST_TEST_THREADS="${NEXTEST_TEST_THREADS-4}" +if [[ "${MOQ_LOCAL_SUPERVISED:-}" == 1 ]]; then + exec "$@" +fi +if [[ "${QUEST_GATE_ADMITTED:-}" == 1 ]]; then + exec bun --no-orphans "${BASH_SOURCE[0]%/*}/local.ts" "$@" +fi +exec quest gate bun --no-orphans "${BASH_SOURCE[0]%/*}/local.ts" "$@" diff --git a/sh/local.test.py b/sh/local.test.py new file mode 100644 index 00000000000..de4b03fdbfd --- /dev/null +++ b/sh/local.test.py @@ -0,0 +1,118 @@ +"""Admission must preserve failures and own the entire admitted command tree.""" + +import os +from pathlib import Path +import signal +import shutil +import subprocess +import sys +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +LAUNCHER = ROOT / "sh/local.sh" +SUPERVISOR = ROOT / "sh/local.ts" +BUN = shutil.which("bun") +BASH = shutil.which("bash") + + +class LocalGate(unittest.TestCase): + def env(self, **changes): + env = dict(os.environ) + for key in ("QUEST_GATE_ADMITTED", "MOQ_LOCAL_SUPERVISED", "GITHUB_ACTIONS", "NEXTEST_TEST_THREADS"): + env.pop(key, None) + env.update(changes) + return env + + def run_command(self, script, **changes): + return subprocess.run([BASH, str(LAUNCHER), sys.executable, "-c", script], + env=self.env(**changes), text=True, capture_output=True) + + def test_hosted_ci_bypasses_admission_and_worker_defaults(self): + result = self.run_command('import os; print(os.getenv("NEXTEST_TEST_THREADS")); exit(7)', + GITHUB_ACTIONS="true", PATH="") + self.assertEqual(result.returncode, 7, result.stderr) + self.assertEqual(result.stdout.strip(), "None") + + def test_nested_admission_preserves_failures_and_worker_override(self): + result = self.run_command('import os; print(os.environ["NEXTEST_TEST_THREADS"]); exit(9)', + MOQ_LOCAL_SUPERVISED="1", NEXTEST_TEST_THREADS="2", PATH="") + self.assertEqual(result.returncode, 9, result.stderr) + self.assertEqual(result.stdout.strip(), "2") + result = self.run_command('import os; print(os.environ["NEXTEST_TEST_THREADS"])', + MOQ_LOCAL_SUPERVISED="1", PATH="") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertLessEqual(int(result.stdout), 4) + self.assertGreater(int(result.stdout), 0) + + def test_admission_precedes_launch_and_nested_calls_skip_it(self): + with tempfile.TemporaryDirectory() as directory: + (Path(directory) / "bun").symlink_to(BUN) + quest = Path(directory) / "quest" + quest.write_text(f'#!{sys.executable}\n' + 'import os, sys\n' + 'assert sys.argv[1] == "gate"\n' + 'print("admitted", flush=True)\n' + 'os.environ["QUEST_GATE_ADMITTED"] = "1"\n' + 'os.execvp(sys.argv[2], sys.argv[2:])\n') + quest.chmod(0o755) + script = ('import subprocess, sys; print("outer", flush=True); ' + f'sys.exit(subprocess.call([{BASH!r}, {str(LAUNCHER)!r}, ' + 'sys.executable, "-c", "print(\'inner\'); exit(11)"]))') + result = self.run_command(script, PATH=directory) + self.assertEqual(result.returncode, 11, result.stderr) + self.assertEqual(result.stdout.splitlines(), ["admitted", "outer", "inner"]) + + def test_external_admission_keeps_descendant_supervision(self): + with tempfile.TemporaryDirectory() as directory: + (Path(directory) / "bun").symlink_to(BUN) + result = self.run_command('import os; print(os.environ["MOQ_LOCAL_SUPERVISED"])', + QUEST_GATE_ADMITTED="1", PATH=directory) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.strip(), "1") + + @unittest.skipUnless(os.name == "posix", "process groups require POSIX") + def test_cancellation_reaches_descendants_and_waits_for_cleanup(self): + # The grandchild inherits stdout; EOF proves no descendant holds it open. + script = """import signal, subprocess, sys +child = subprocess.Popen([sys.executable, "-c", "import signal; print('ready', flush=True); signal.pause()"]) +signal.pause() +""" + process = subprocess.Popen([BUN, "--no-orphans", str(SUPERVISOR), sys.executable, "-c", script], + env=self.env(QUEST_GATE_ADMITTED="1"), + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + try: + self.assertEqual(process.stdout.readline().strip(), "ready") + process.send_signal(signal.SIGTERM) + output, error = process.communicate() + self.assertEqual(process.returncode, 128 + signal.SIGTERM, error) + self.assertEqual(output.strip(), "") + finally: + if process.poll() is None: + process.kill() + process.wait() + + @unittest.skipUnless(sys.platform == "linux", "adopting orphans requires Linux") + def test_exit_reaches_descendants_orphaned_by_their_parent(self): + # The child exits first, so its grandchild reparents before the supervisor exits. + script = """import subprocess, sys +subprocess.Popen([sys.executable, "-c", "import signal; signal.pause()"]) +print("ready", flush=True) +sys.exit(5) +""" + process = subprocess.Popen([BUN, "--no-orphans", str(SUPERVISOR), sys.executable, "-c", script], + env=self.env(QUEST_GATE_ADMITTED="1"), + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + try: + output, error = process.communicate(timeout=30) + self.assertEqual(process.returncode, 5, error) + self.assertEqual(output.strip(), "ready") + finally: + if process.poll() is None: + process.kill() + process.wait() + + +if __name__ == "__main__": + unittest.main() diff --git a/sh/local.ts b/sh/local.ts new file mode 100644 index 00000000000..fdfc908ad37 --- /dev/null +++ b/sh/local.ts @@ -0,0 +1,31 @@ +// Bun's --no-orphans owns every descendant, including detached fixture groups. +import { dlopen, FFIType } from "bun:ffi"; +import { constants } from "node:os"; + +const command = Bun.argv.slice(2); +if (!command.length) throw new Error("usage: sh/local.ts COMMAND [ARGS...]"); + +// --no-orphans only reaches descendants still in this tree, and a grandchild whose parent +// exits first reparents out of it. Adopting orphans keeps them reachable on Linux. +if (process.platform === "linux") { + const PR_SET_CHILD_SUBREAPER = 36; + const libc = dlopen("libc.so.6", { prctl: { args: [FFIType.i32, FFIType.u64], returns: FFIType.i32 } }); + if (libc.symbols.prctl(PR_SET_CHILD_SUBREAPER, 1) !== 0) throw new Error("prctl(PR_SET_CHILD_SUBREAPER) failed"); +} + +const child = Bun.spawn(command, { + stdin: "inherit", + stdout: "inherit", + stderr: "inherit", + env: { ...process.env, MOQ_LOCAL_SUPERVISED: "1" }, +}); +// Forward cancellation and let the child clean up; once it exits, every survivor is ours. +let signaled: number | undefined; +for (const name of ["SIGINT", "SIGTERM", "SIGHUP"] as const) { + process.on(name, () => { + signaled ??= 128 + constants.signals[name]; + child.kill(name); + }); +} +const code = await child.exited; +process.exit(signaled ?? code); diff --git a/sh/obs/compile.sh b/sh/obs/compile.sh index 1da001fca25..d4ebb10926c 100755 --- a/sh/obs/compile.sh +++ b/sh/obs/compile.sh @@ -18,6 +18,10 @@ # only where obs.yml's path filter reaches; `just obs test` runs nightly. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$here/../../cpp/obs" diff --git a/sh/obs/test.sh b/sh/obs/test.sh index 40b3d72f2be..55e3ea752c4 100755 --- a/sh/obs/test.sh +++ b/sh/obs/test.sh @@ -9,6 +9,10 @@ # can't check. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$here/../../cpp/obs" diff --git a/sh/obs/unit.sh b/sh/obs/unit.sh index 50c4b0a215e..62704c05dee 100755 --- a/sh/obs/unit.sh +++ b/sh/obs/unit.sh @@ -5,6 +5,10 @@ # both run the same assertions. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$here/../../cpp/obs" mode=${1:-plain} diff --git a/sh/rs/c-tests.sh b/sh/rs/c-tests.sh index e0f4c01c4d4..873e69b93cb 100755 --- a/sh/rs/c-tests.sh +++ b/sh/rs/c-tests.sh @@ -6,6 +6,10 @@ # Unix only. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + cd "$(git rev-parse --show-toplevel)" cc="${CC:-cc}" diff --git a/sh/rs/gpu.sh b/sh/rs/gpu.sh index cf7899e1c4e..4ac870e4f41 100755 --- a/sh/rs/gpu.sh +++ b/sh/rs/gpu.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash # Hardware tests are opt-in; a detected GPU must have its driver and pass its tests. set -euo pipefail + +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi cd "$(git rev-parse --show-toplevel)" declare -A vendors=() diff --git a/sh/rs/media-features.sh b/sh/rs/media-features.sh index a2148513c26..70a73a7e20e 100755 --- a/sh/rs/media-features.sh +++ b/sh/rs/media-features.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + all=0 if [[ $# == 1 && $1 == --all ]]; then all=1 diff --git a/sh/rs/net-features.sh b/sh/rs/net-features.sh index f2be50fcf7c..605ac62c13a 100644 --- a/sh/rs/net-features.sh +++ b/sh/rs/net-features.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + # Build moq-net alone: a workspace build unifies its default features back in. # Normal dependencies exclude the simulation executor and bench-only Tokio. minimal=$(cargo tree --locked -p moq-net --no-default-features -e normal --prefix none) diff --git a/sh/rs/nextest.sh b/sh/rs/nextest.sh index b03650e7f12..79218b80726 100644 --- a/sh/rs/nextest.sh +++ b/sh/rs/nextest.sh @@ -10,4 +10,4 @@ if [[ "$(uname -s)" == Linux ]]; then ulimit -Sl "$(ulimit -Hl)" fi fi -exec "$@" +exec bash "$(dirname "$0")/../local.sh" "$@" diff --git a/sh/rs/select.sh b/sh/rs/select.sh index 5c2d4b20385..7e2357f26ee 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -20,7 +20,7 @@ select_packages() { echo ALL return fi - if [[ "$list" == --all ]] || grep -qE '^(Cargo\.(toml|lock)|rust-toolchain\.toml|rs/justfile|sh/rs/(select|platform|nextest)\.sh|\.config/nextest\.toml)$' "$list"; then + if [[ "$list" == --all ]] || grep -qE '^(sh/local\.(sh|ts)|Cargo\.(toml|lock)|rust-toolchain\.toml|rs/justfile|sh/rs/(select|platform|nextest)\.sh|\.config/nextest\.toml)$' "$list"; then echo ALL return fi @@ -113,6 +113,12 @@ case "$packages" in *) echo "rs: selecting $names" ;; esac +# Selection and empty crate sets stay outside admission. The paths are +# root-relative because the `cd` above invalidates a relative `$0`. +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash sh/local.sh bash sh/rs/select.sh "$@" +fi + # The `*-fuzz` crates need a nightly toolchain; only `just rs fuzz` compiles them. if [[ "$packages" == ALL ]]; then flags=(--workspace --exclude moq-net-fuzz --exclude moq-quic-fuzz) diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index aaa79b1abe9..dbe616522e4 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -22,7 +22,7 @@ def selected(self, *paths, action="lint", github_actions=False): just.chmod(0o755) changed = scratch / "changed" changed.write_text("\n".join(paths) + "\n") - env = dict(os.environ, PATH=f"{scratch}:{os.environ['PATH']}", + env = dict(os.environ, MOQ_LOCAL_SUPERVISED="1", PATH=f"{scratch}:{os.environ['PATH']}", SELECT_CALLS=str(calls), BASH_ENV=os.devnull, GITHUB_ACTIONS=str(github_actions).lower()) subprocess.run(["bash", "sh/rs/select.sh", action, str(changed)], @@ -108,7 +108,7 @@ def test_unexecuted_bench_is_not_compiled(self): (scratch / "benches/unexecuted.rs").write_text( 'compile_error!("nextest must not compile a benchmark it never runs");\nfn main() {}\n' ) - env = dict(os.environ, BASH_ENV=os.devnull, TMPDIR="/tmp", + env = dict(os.environ, MOQ_LOCAL_SUPERVISED="1", BASH_ENV=os.devnull, TMPDIR="/tmp", NEXTEST_PROFILE="default") result = subprocess.run( ["just", "rs", "test", "--manifest-path", str(scratch / "Cargo.toml")], @@ -125,7 +125,7 @@ def trace(self, owner, *args): cargo = scratch / "cargo" cargo.write_text(CARGO_STUB) cargo.chmod(0o755) - env = dict(os.environ, PATH=f"{scratch}:{os.environ['PATH']}", + env = dict(os.environ, MOQ_LOCAL_SUPERVISED="1", PATH=f"{scratch}:{os.environ['PATH']}", FEATURE_CALLS=str(calls), BASH_ENV=os.devnull) result = subprocess.run(["bash", f"sh/rs/{owner}-features.sh", *args], cwd=ROOT, env=env, capture_output=True, text=True) diff --git a/sh/rs/test-lints.test.py b/sh/rs/test-lints.test.py index e9c16c0802b..005dd6eff01 100644 --- a/sh/rs/test-lints.test.py +++ b/sh/rs/test-lints.test.py @@ -18,6 +18,7 @@ def test_clippy_warning_fails_test_build(self): (root / "rs").mkdir() (root / "sh" / "rs").mkdir(parents=True) (root / "src").mkdir() + shutil.copy(ROOT / "sh" / "local.sh", root / "sh" / "local.sh") (root / "justfile").write_text("mod rs\n") shutil.copy(ROOT / "rs" / "justfile", root / "rs" / "justfile") shutil.copy(ROOT / "sh" / "rs" / "nextest.sh", root / "sh" / "rs" / "nextest.sh") @@ -29,7 +30,7 @@ def test_clippy_warning_fails_test_build(self): '#[test]\nfn runs() { assert!(empty(&[])); }\n' ) toolchain = Path(shutil.which("clippy-driver")).parent - env = dict(os.environ, CARGO_TARGET_DIR=str(root / "target"), + env = dict(os.environ, MOQ_LOCAL_SUPERVISED="1", CARGO_TARGET_DIR=str(root / "target"), PATH=f"{toolchain}:{os.environ['PATH']}", NEXTEST_PROFILE="default") subprocess.run(["cargo", "generate-lockfile", "--offline"], cwd=root, diff --git a/sh/rs/tokio-features.sh b/sh/rs/tokio-features.sh index 44c60af47c7..18f09c24ed2 100755 --- a/sh/rs/tokio-features.sh +++ b/sh/rs/tokio-features.sh @@ -5,6 +5,10 @@ # through unification. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + all=0 if [[ $# == 1 && $1 == --all ]]; then all=1 diff --git a/sh/rs/uring.test.py b/sh/rs/uring.test.py index 207969b9b59..0646adfac3c 100644 --- a/sh/rs/uring.test.py +++ b/sh/rs/uring.test.py @@ -31,7 +31,7 @@ def test_selection_follows_shared_dependencies(self): cargo.write_text('#!/bin/sh\ncat "$TEST_METADATA"\n') cargo.chmod(0o755) changed = scratch / "changed" - env = dict(os.environ, PATH=f"{scratch}:{os.environ['PATH']}", + env = dict(os.environ, MOQ_LOCAL_SUPERVISED="1", PATH=f"{scratch}:{os.environ['PATH']}", SELECT_CALLS=str(calls), TEST_METADATA=str(fixture)) for path, passes in ( ("rs/moq-uring/src/worker.rs", True), ("rs/moq-relay/src/uring.rs", True), diff --git a/sh/swift/check.sh b/sh/swift/check.sh index a6032d13859..3dec50d406b 100755 --- a/sh/swift/check.sh +++ b/sh/swift/check.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + # Local smoke check for the Swift wrapper. Builds moq-ffi for the host # macOS target, lays out a local XCFramework, and runs `swift test`. # diff --git a/sh/swift/simulator.sh b/sh/swift/simulator.sh index 9b1621b8c2d..2244d2bbc3a 100755 --- a/sh/swift/simulator.sh +++ b/sh/swift/simulator.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" +fi + # The simulators have no hardware encoder, so the release build (rs/moq-ffi/build.sh) # turns on `openh264`; check the same feature set it ships. for target in aarch64-apple-ios-sim x86_64-apple-ios; do diff --git a/test/audio-quality/record.sh b/test/audio-quality/record.sh index 687856046f1..0817e4dfbfc 100755 --- a/test/audio-quality/record.sh +++ b/test/audio-quality/record.sh @@ -10,6 +10,10 @@ # replay budgets after. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + AQ_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$AQ_DIR/../.." && pwd) CLIENT="$AQ_DIR/clients/js" diff --git a/test/audio-quality/run.sh b/test/audio-quality/run.sh index bc3535d076b..8f012671281 100755 --- a/test/audio-quality/run.sh +++ b/test/audio-quality/run.sh @@ -7,6 +7,10 @@ # README.md for the profiles, the metric contract, and the void rules. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + AQ_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$AQ_DIR/../.." && pwd) CLIENT="$AQ_DIR/clients/js" diff --git a/test/drain/run.sh b/test/drain/run.sh index 52506c27fde..ac83b3a56b7 100755 --- a/test/drain/run.sh +++ b/test/drain/run.sh @@ -3,6 +3,10 @@ # migrates to relay B when A drains, without a dropped group. See README.md. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + DRAIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$DRAIN_DIR/../.." && pwd) diff --git a/test/ietf-conformance/run.sh b/test/ietf-conformance/run.sh index 517fae082a5..df3502a4b81 100755 --- a/test/ietf-conformance/run.sh +++ b/test/ietf-conformance/run.sh @@ -2,6 +2,10 @@ # Pinned upstream conformance under the relay profile, subgroup zero, one relay. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + CONFORMANCE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$CONFORMANCE_DIR/../.." && pwd) # shellcheck source-path=SCRIPTDIR source=../lib/harness.sh diff --git a/test/interop/compat.sh b/test/interop/compat.sh index 0ddef6d3350..17c12f84185 100755 --- a/test/interop/compat.sh +++ b/test/interop/compat.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash # Compare this checkout with registry releases using the existing interop drivers. set -euo pipefail + +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$DIR/../.." && pwd) # shellcheck source-path=SCRIPTDIR source=../lib/harness.sh diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 88e1d2826bc..7640eb58524 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -31,6 +31,10 @@ # version per pass, such as each even moq-transport draft (`--versions ietf`). set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + INTEROP_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$INTEROP_DIR/../.." && pwd) CLIENTS="$INTEROP_DIR/clients" diff --git a/test/justfile b/test/justfile index cda790b2459..8e8911e39a2 100644 --- a/test/justfile +++ b/test/justfile @@ -46,7 +46,7 @@ harness: python3 interop/tone.test.py cd .. && bun test {{ replace(harness_compat_tests, "\n", " ") }} cd .. && bun install --frozen-lockfile - cd interop/clients/js && bun test {{ replace(harness_browser_tests, "\n", " ") }} + cd interop/clients/js && bash ../../../../sh/local.sh bun test {{ replace(harness_browser_tests, "\n", " ") }} # Cross-language media interop test, built from this checkout. Stands up a # relay and runs the publisher x subscriber matrix. Default: rust only (fast @@ -241,16 +241,16 @@ wasm *args: video: cd .. && bun install --frozen-lockfile # A desktop display makes software Vulkan request unsupported window surfaces. - cd video && env -u DISPLAY -u WAYLAND_DISPLAY bun test ./renderer.browser.ts + cd video && bash ../../sh/local.sh env -u DISPLAY -u WAYLAND_DISPLAY bun test ./renderer.browser.ts # Optional publisher retention across Rust/JS sessions through a Rust relay. max-age: - cargo nextest run --locked -p moq-tokio --test integration -E 'test(/^max_age::/)' --run-ignored all + bash ../sh/local.sh cargo nextest run --locked -p moq-tokio --test integration -E 'test(/^max_age::/)' --run-ignored all # A JavaScript sender exhausts each native receiver's connection credit, which recovers. receive-credit: - cargo nextest run --locked -p moq-tokio --test integration -E 'test(/^receive_credit::javascript_/)' --run-ignored only - cargo nextest run --locked -p moq-uring --test integration -E 'test(/^receive_credit::javascript_/)' --run-ignored only + bash ../sh/local.sh cargo nextest run --locked -p moq-tokio --test integration -E 'test(/^receive_credit::javascript_/)' --run-ignored only + bash ../sh/local.sh cargo nextest run --locked -p moq-uring --test integration -E 'test(/^receive_credit::javascript_/)' --run-ignored only # Cross-language subscription termination over in-memory transports. bare-fin: @@ -258,7 +258,7 @@ bare-fin: # Explore JSON snapshot codec sequences with a fresh replayable seed. json-properties: - bash json-properties.sh + bash ../sh/local.sh bash json-properties.sh # The TypeScript qmux peer as client and server against the in-tree Rust qmux # interop examples, per draft. The manifest path names the in-tree crate, which @@ -273,7 +273,7 @@ qmux: # Complete MoQ SETUP and transfer a frame over a real browser data-channel pair. p2p: cd .. && bun install --frozen-lockfile - cd p2p && bun test ./transport.browser.ts + cd p2p && bash ../../sh/local.sh bun test ./transport.browser.ts # Retain complete backend assets, parity, and raw alternating browser samples. [positional-arguments] diff --git a/test/native-play/run.sh b/test/native-play/run.sh index 320734b03cd..5258f9678e3 100755 --- a/test/native-play/run.sh +++ b/test/native-play/run.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash # Hear the shipped headless player through a private, clocked null audio device. set -euo pipefail + +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi if [[ $(uname -s) != Linux ]]; then echo "native-play requires Linux ALSA/cpal and PulseAudio" >&2 exit 2 diff --git a/test/portrait/run.sh b/test/portrait/run.sh index d47b719f4e4..c1644c42f2c 100755 --- a/test/portrait/run.sh +++ b/test/portrait/run.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash # Publish a coded portrait, transcode a short-side rung, and paint it in Chromium. set -euo pipefail + +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$DIR/../.." && pwd) # shellcheck source-path=SCRIPTDIR source=../lib/harness.sh diff --git a/test/ts/eit-roundtrip.sh b/test/ts/eit-roundtrip.sh index 35f4da7e903..959efab0962 100755 --- a/test/ts/eit-roundtrip.sh +++ b/test/ts/eit-roundtrip.sh @@ -16,6 +16,10 @@ set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # shellcheck source-path=SCRIPTDIR source=../lib/harness.sh source "$DIR/../lib/harness.sh" diff --git a/test/ts/run.sh b/test/ts/run.sh index 58ded8b8552..3c6672ac16a 100755 --- a/test/ts/run.sh +++ b/test/ts/run.sh @@ -50,6 +50,10 @@ # see a cadence regression at all. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$DIR/../.." && pwd) diff --git a/test/wasm/run.sh b/test/wasm/run.sh index 18f4582d0ea..21cab5d7cd5 100755 --- a/test/wasm/run.sh +++ b/test/wasm/run.sh @@ -17,6 +17,10 @@ # so each case is also an interop check. See README.md. set -euo pipefail +if [[ "${GITHUB_ACTIONS:-}" != true && "${MOQ_LOCAL_SUPERVISED:-}" != 1 ]]; then + exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" +fi + WASM_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$WASM_DIR/../.." && pwd)