Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/interop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions quest/m1/interop-flakes.md

This file was deleted.

12 changes: 7 additions & 5 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<uid>` (`MOQ_TEST_PORTS`), held for the whole run, and
`/tmp/moq-test-ports-<uid>` (`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
Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions test/interop/clients/js/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
type PlayerState,
POLL_INTERVAL_MS,
pageUrl,
pause,
readPlayerState,
SELECTORS,
serve,
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions test/interop/clients/js/harness.browser.ts
Original file line number Diff line number Diff line change
@@ -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(`
<moq-watch-ui></moq-watch-ui>
<script>
const root = document.querySelector("moq-watch-ui").attachShadow({ mode: "open" });
root.innerHTML = \`<button class="control" aria-label="Pause">Pause</button>
<canvas style="position: fixed; inset: 0; width: 100%; height: 100%"></canvas>\`;
root.querySelector("button").addEventListener("click", () => {
document.body.dataset.paused = "true";
});
</script>
`);
await pause(page);
expect(await page.locator("body").getAttribute("data-paused")).toBe("true");
} finally {
await browser.close();
}
});
6 changes: 6 additions & 0 deletions test/interop/clients/js/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
// 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;

Expand Down
5 changes: 2 additions & 3 deletions test/interop/clients/js/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type PlayerState,
POLL_INTERVAL_MS,
pageUrl,
pause,
readFixtureState,
readPlayerState,
SELECTORS,
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion test/interop/clients/js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
2 changes: 1 addition & 1 deletion test/interop/interop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep Python staging isolated before closing the quest

When two full matrices run from the same checkout, this change isolates only Go: prepare_python still runs just py build, whose uv sync, maturin develop, and editable install concurrently rewrite the same $WORKSPACE/.venv and generated Python bindings. Those runs can therefore still clobber each other even though this commit deletes the concurrency quest; move the Python environment and generated output under HARNESS_RUN, or keep the quest open until that remaining work is tracked and tested.

AGENTS.md reference: quest/AGENTS.md:L97-L98

Useful? React with 👍 / 👎.

mark_broken go "go/scripts/stage.sh failed"
sed 's/^/ /' "$HARNESS_RUN/go-stage.log" >&2 || true
return
Expand Down
6 changes: 6 additions & 0 deletions test/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Install browser prerequisites in the harness recipe

In a clean checkout, just test harness reaches this command without installing workspace dependencies or Playwright Chromium, so it fails to resolve playwright or launch the configured Chromium channel. The preceding Playwright step in .github/workflows/interop.yml happens to prepare CI, but the newly advertised local recipe is not independently runnable; provision the same prerequisites here or invoke an existing setup path before the browser test.

Useful? React with 👍 / 👎.


# 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 +
Expand Down
18 changes: 11 additions & 7 deletions test/lib/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" || {
Expand Down
52 changes: 52 additions & 0 deletions test/lib/harness.test.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading