diff --git a/.github/workflows/interop.yml b/.github/workflows/interop.yml index 8cfe5d49fa3..9c18e205314 100644 --- a/.github/workflows/interop.yml +++ b/.github/workflows/interop.yml @@ -82,6 +82,10 @@ jobs: run: nix develop --command bash -c "bun install --frozen-lockfile && bunx playwright install --with-deps chromium" shell: bash -leo pipefail {0} + - name: Harness regressions + run: nix develop --command just test harness + shell: bash -leo pipefail {0} + - name: Subscription termination interop run: nix develop --command just test bare-fin shell: bash -leo pipefail {0} diff --git a/quest/m1/README.md b/quest/m1/README.md index ba0b1d6e157..715d6fd881f 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -21,7 +21,6 @@ transport, benchmark tooling); worktrees isolate commits, not semantics. - [lite-07 count settle](/quest/m1/lite-count-settle.md) - moq-lite-07 subscribers stop waiting for a subscription's tail once SUBSCRIBE_END's stream count is reached - [Dropped sources](/quest/m1/dropped-sources.md) - track consumers see the producer's real error on every end path, never `Dropped` - [Track tail interop](/quest/m1/track-tail-interop.md) - a Rust publisher ending a track with a group in flight is read to its end by the JS subscriber, and the reverse, in `just test interop` -- [Interop flakes](/quest/m1/interop-flakes.md) - the interop harness passes with other runs sharing the machine - [Go cancel test](/quest/m1/go-origin-gc.md) - the Go request-cancel test keeps its origin alive, so the collector can't close it mid-test - [Worker socket count](/quest/m1/worker-socket-count.md) - the moq-tokio worker test counts only its own listener's sockets - [Signal.race cleanup](/quest/m1/signal-race.md) - `Signal.race` releases its signal listeners when its result loses a race diff --git a/quest/m1/interop-flakes.md b/quest/m1/interop-flakes.md deleted file mode 100644 index 679c0344cff..00000000000 --- a/quest/m1/interop-flakes.md +++ /dev/null @@ -1,23 +0,0 @@ -# [S] Interop harness runs clean in parallel - -## Goal - -`just test interop --all` passes reliably while other harness runs share the -machine. Two known flakes: concurrent Nix shells reserve the same port because -each keeps its reservations under its own `TMPDIR`, and the browser driver's -pause click is sometimes blocked by the canvas (`js -> js`). - -## Plan - -- Port reservations live under one root shared by every shell (not - `TMPDIR`), or ports come from the OS (bind to 0 and pass the result). Prefer - whichever removes the reservation file entirely. -- The pause control is driven in a way the canvas cannot intercept (an API or - keyboard path, or waiting for the element to be actionable), not a retry. -- Prove it by running two `--all` harnesses at once, several times. - -Public API: none. Wire: none. - -## Related - -- [#4181](https://github.com/moq-dev/moq/pull/4181) - where both flakes were seen diff --git a/test/README.md b/test/README.md index 5c4f994c433..0e9ad969f7b 100644 --- a/test/README.md +++ b/test/README.md @@ -21,7 +21,7 @@ Every run owns three things and touches nothing else. holding every log, generated config, and capture. `MOQ_TEST_RUNS` moves the root. **Reserved ports.** A port is claimed by creating a directory under -`$TMPDIR/moq-test-ports-` (`MOQ_TEST_PORTS`), held for the whole run, and +`/tmp/moq-test-ports-` (`MOQ_TEST_PORTS`), held for the whole run, and released on the way out. That reservation is the point: probing for a free port and then releasing it is a race, and two runs that probe at the same moment pick the same number. The walk starts at `MOQ_TEST_PORT_BASE` (4500). A reservation whose owner @@ -30,10 +30,12 @@ Replacement is serialized by `flock` on Linux or `lockf` on macOS, and the reservation records the owner's process start so a reused PID is not mistaken for the original run. -Both roots carry the user id because `TMPDIR` is usually unset on Linux: a fixed -name in a world-writable `/tmp` belongs to whoever ran first, and everyone else -would fail to create anything under it. Two worktrees still share, since they run -as the same user, which is what makes the reservations mean anything. +The reservation root ignores `TMPDIR`: Nix shells have private temporary +directories but share the host's ports. The user id avoids ownership conflicts in +world-writable `/tmp`. An override via `MOQ_TEST_PORTS` must be the same for every +run sharing the network. The root must belong to the current user and cannot be +a symlink; new roots are private. Runs by different users still need disjoint +ports. The reservation settles contention between harness runs, not with the rest of the machine, so each harness still refuses a port something unrelated is already diff --git a/test/interop/clients/js/driver.ts b/test/interop/clients/js/driver.ts index efa0c1ecd47..b04fceca212 100644 --- a/test/interop/clients/js/driver.ts +++ b/test/interop/clients/js/driver.ts @@ -22,6 +22,7 @@ import { type PlayerState, POLL_INTERVAL_MS, pageUrl, + pause, readPlayerState, SELECTORS, serve, @@ -88,7 +89,12 @@ const browser = await launch([ let code = 1; try { - const [page, errors] = await open(browser, pageUrl(server.origin, role, { url, broadcast }), role, role === "subscribe"); + const [page, errors] = await open( + browser, + pageUrl(server.origin, role, { url, broadcast }), + role, + role === "subscribe", + ); if (role === "subscribe") await waitForWatch(page); if (role === "publish") { @@ -129,10 +135,7 @@ try { }); } - // The chrome auto-hides while playing. Pointer activity reveals the real - // control, then the click must flow through the public player API. - await page.dispatchEvent(SELECTORS.ui, "pointermove"); - await page.locator(SELECTORS.ui).locator(SELECTORS.pauseControl).click(); + await pause(page); await waitForState(page, errors, { deadline: interactionDeadline, description: "paused player UI", diff --git a/test/interop/clients/js/harness.browser.ts b/test/interop/clients/js/harness.browser.ts new file mode 100644 index 00000000000..ec07edd3780 --- /dev/null +++ b/test/interop/clients/js/harness.browser.ts @@ -0,0 +1,24 @@ +import { expect, test } from "bun:test"; +import { launch, pause } from "./harness"; + +test("pause activates its button when a canvas intercepts pointer input", async () => { + const browser = await launch(); + try { + const page = await browser.newPage(); + await page.setContent(` + + + `); + await pause(page); + expect(await page.locator("body").getAttribute("data-paused")).toBe("true"); + } finally { + await browser.close(); + } +}); diff --git a/test/interop/clients/js/harness.ts b/test/interop/clients/js/harness.ts index 019d4a003f5..4a7dd6ed161 100644 --- a/test/interop/clients/js/harness.ts +++ b/test/interop/clients/js/harness.ts @@ -63,6 +63,12 @@ export const SELECTORS = { fixture: "#fixture", } as const; +/** Activate the player's pause button without depending on pointer hit testing. */ +export async function pause(page: Page): Promise { + // Enter focuses and activates the real button even when the chrome auto-hides. + await page.locator(SELECTORS.ui).locator(SELECTORS.pauseControl).press("Enter"); +} + /** How often a wait re-reads the page. */ export const POLL_INTERVAL_MS = 100; diff --git a/test/interop/clients/js/media.ts b/test/interop/clients/js/media.ts index 6ac033f31b2..787b00665e3 100644 --- a/test/interop/clients/js/media.ts +++ b/test/interop/clients/js/media.ts @@ -30,6 +30,7 @@ import { type PlayerState, POLL_INTERVAL_MS, pageUrl, + pause, readFixtureState, readPlayerState, SELECTORS, @@ -526,9 +527,7 @@ try { // ── pause and resume ───────────────────────────────────────────────────── if (wants("pause")) { console.error("=== pause and resume ==="); - // The chrome auto-hides while playing; pointer activity reveals the real control. - await player.dispatchEvent(SELECTORS.ui, "pointermove"); - await player.locator(SELECTORS.ui).locator(SELECTORS.pauseControl).click(); + await pause(player); await waitForState(player, playerErrors, { deadline: Date.now() + SETTLE_MS, assertion: "pause takes effect", diff --git a/test/interop/clients/js/tsconfig.json b/test/interop/clients/js/tsconfig.json index a02418e9625..af3d0a2b272 100644 --- a/test/interop/clients/js/tsconfig.json +++ b/test/interop/clients/js/tsconfig.json @@ -3,5 +3,13 @@ "compilerOptions": { "types": ["bun", "vite/client"] }, - "include": ["driver.ts", "harness.ts", "media.ts", "src", "vite.config.ts", "../../../../js/common/worklet.d.ts"] + "include": [ + "driver.ts", + "harness.ts", + "harness.browser.ts", + "media.ts", + "src", + "vite.config.ts", + "../../../../js/common/worklet.d.ts" + ] } diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 5400c55be44..66688c1922b 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -256,7 +256,7 @@ prepare_go() { } echo "building go client (workspace moq-go via uniffi-bindgen-go)..." local staged ffi_pkg wrapper_pkg src="$HARNESS_RUN/go-client" - if ! staged=$(bash "$WORKSPACE/go/scripts/stage.sh" 2>"$HARNESS_RUN/go-stage.log"); then + if ! staged=$(bash "$WORKSPACE/go/scripts/stage.sh" --output "$HARNESS_RUN/go-stage" 2>"$HARNESS_RUN/go-stage.log"); then mark_broken go "go/scripts/stage.sh failed" sed 's/^/ /' "$HARNESS_RUN/go-stage.log" >&2 || true return diff --git a/test/justfile b/test/justfile index 5cb8ba23426..a9a777d3301 100644 --- a/test/justfile +++ b/test/justfile @@ -22,6 +22,12 @@ set working-directory := '.' default: @just --justfile {{ justfile() }} --list test +# Port isolation across private temp roots and keyboard activation under a canvas. +# The browser check is not `*.test.ts`: plain `bun test` runs lack Playwright Chromium. +harness: + ./lib/harness.test.sh + bun test ./interop/clients/js/harness.browser.ts + # Cross-language media interop test, built from this checkout. Stands up a # relay and runs the publisher x subscriber matrix. Default: rust only (fast # sanity check). `interop --all` runs the full matrix: rust + python + go + diff --git a/test/lib/harness.sh b/test/lib/harness.sh index 7180d384c5d..7cd50c85e9e 100644 --- a/test/lib/harness.sh +++ b/test/lib/harness.sh @@ -105,13 +105,11 @@ harness_begin() { # Where port reservations live. Shared across worktrees on purpose: the point is # that a run in one worktree cannot hand out a port another already took. # -# The default is suffixed with the user id, like the run root. On Linux TMPDIR is -# usually unset, so both would land in a world-writable /tmp under a fixed name -# owned by whoever ran first: a second user's `mkdir` would then fail for every -# port and the walk would report the whole range taken with nothing reserved. Two -# worktrees still share, because they run as the same user. +# Nix shells give TMPDIR a private directory, but their sockets still share the +# host network. Keep claims in /tmp regardless of each shell's scratch root. +# The user id avoids ownership conflicts with another user's harnesses. harness_port_root() { - local root="${MOQ_TEST_PORTS:-${TMPDIR:-/tmp}}" + local root="${MOQ_TEST_PORTS:-/tmp}" root="${root%/}" [[ -n "${MOQ_TEST_PORTS:-}" ]] || root="$root/moq-test-ports-$(id -u)" echo "$root" @@ -146,7 +144,13 @@ harness_port() { local label="$1" wanted="${2:-}" local root port last status root=$(harness_port_root) - mkdir -p "$root" + # Only the reservation root needs private permissions, not its parents. + # shellcheck disable=SC2174 + mkdir -m 700 -p "$root" + if [[ -L "$root" || ! -O "$root" ]]; then + echo "error: port reservation root must be owned by this user and not a symlink: $root" >&2 + return 2 + fi if [[ -n "$wanted" ]]; then harness_valid_port "$wanted" || { diff --git a/test/lib/harness.test.sh b/test/lib/harness.test.sh new file mode 100755 index 00000000000..e1bb411478d --- /dev/null +++ b/test/lib/harness.test.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Independent shells must reserve different ports even with private temp roots. +set -euo pipefail + +lib=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +scratch=$(mktemp -d) +owner="" +trap '[[ -z "$owner" ]] || { kill "$owner" 2>/dev/null || true; wait "$owner" 2>/dev/null || true; }; rm -rf "$scratch"' EXIT +mkdir "$scratch/one" "$scratch/two" +mkfifo "$scratch/ready" "$scratch/release" +export MOQ_TEST_RUNS="$scratch/runs" +unset MOQ_TEST_PORTS + +TMPDIR="$scratch/one" bash -euo pipefail -c ' + source "$1/harness.sh" + harness_begin ports >&2 + harness_port first + printf "%s\n" "$HARNESS_PORT" >"$2/ready" + read -r _ <"$2/release" +' bash "$lib" "$scratch" & +owner=$! +read -r first <"$scratch/ready" +TMPDIR="$scratch/two" bash -euo pipefail -c ' + source "$1/harness.sh" + harness_begin ports >&2 + harness_port second + if [[ "$HARNESS_PORT" == "$2" ]]; then + echo "FAIL: separate TMPDIR shells both reserved $2" >&2 + exit 1 + fi + if harness_port pinned "$2"; then + echo "FAIL: pinned port ignored another shell reservation" >&2 + exit 1 + fi +' bash "$lib" "$first" +printf 'done\n' >"$scratch/release" +wait "$owner" +owner="" +# Refuse an unexpected owner-controlled target under the predictable root. +ln -s "$scratch/one" "$scratch/ports-link" +MOQ_TEST_PORTS="$scratch/ports-link" bash -euo pipefail -c ' + source "$1/harness.sh" + harness_begin ports >&2 + if harness_port symlink; then + echo "FAIL: accepted a symlink reservation root" >&2 + exit 1 + else + status=$? + [[ "$status" == 2 ]] + fi +' bash "$lib" +echo "cross-shell port reservations passed"