diff --git a/bun.lock b/bun.lock index c5ce21e30a..5132306ee1 100644 --- a/bun.lock +++ b/bun.lock @@ -526,7 +526,7 @@ "@moq/hang": "workspace:*", "@moq/json": "workspace:*", "@moq/net": "workspace:*", - "@moq/web-transport": "^0.1.5", + "@moq/web-transport": "^0.1.6", "@zod/mini": "^4.6.7", "zod": "^4.6.7", }, @@ -563,7 +563,7 @@ "name": "@moq/receive-credit-test", "dependencies": { "@moq/net": "workspace:*", - "@moq/web-transport": "^0.1.5", + "@moq/web-transport": "^0.1.6", }, }, "test/video": { @@ -926,17 +926,17 @@ "@moq/watch": ["@moq/watch@workspace:js/watch"], - "@moq/web-transport": ["@moq/web-transport@0.1.5", "", { "optionalDependencies": { "@moq/web-transport-darwin-arm64": "0.1.5", "@moq/web-transport-darwin-x64": "0.1.5", "@moq/web-transport-linux-arm64-gnu": "0.1.5", "@moq/web-transport-linux-x64-gnu": "0.1.5", "@moq/web-transport-win32-x64-msvc": "0.1.5" } }, "sha512-oqBQNIYS0GYKLSgfrVQIG5cwRArkCmujP7WV7SVlRDthq3GidiOzjONM0sOuqEypthNJctd9FyanWM6nCySqRw=="], + "@moq/web-transport": ["@moq/web-transport@0.1.6", "", { "optionalDependencies": { "@moq/web-transport-darwin-arm64": "0.1.6", "@moq/web-transport-darwin-x64": "0.1.6", "@moq/web-transport-linux-arm64-gnu": "0.1.6", "@moq/web-transport-linux-x64-gnu": "0.1.6", "@moq/web-transport-win32-x64-msvc": "0.1.6" } }, "sha512-ojNDQEO9EnTyaPgiqng9cll/JNh6eDAe6LS6zeEEx9ZVwKRikeb2wSFJA/hErrMmCmuE2YYmcXHPf0BIqcOASg=="], - "@moq/web-transport-darwin-arm64": ["@moq/web-transport-darwin-arm64@0.1.5", "", { "os": "darwin", "cpu": "arm64" }, "sha512-3E002DwvbU4zz0C7rr+ZFV81r8o/WCRqbhgFHN8PC44q6Yln8begu2rDfTfpJiFJq0MvhmkUzjsvy6eaTDmskQ=="], + "@moq/web-transport-darwin-arm64": ["@moq/web-transport-darwin-arm64@0.1.6", "", { "os": "darwin", "cpu": "arm64" }, "sha512-OQ+mYCvlXYoTN5qPqd91B+L6AHZ0P6MZNGrA5Y47bk/seoPZ2zyUYkJd/6vyNX6XXmLmNTZfvnjLedRxl6zefA=="], - "@moq/web-transport-darwin-x64": ["@moq/web-transport-darwin-x64@0.1.5", "", { "os": "darwin", "cpu": "x64" }, "sha512-U6FpabDrZoAAOg2YRpBgPKmcxGx5DafRu6rTD+IPbjz7BCPHT+mdBpPN709q1hHv+flT64bV2Enzi+q1s3JOiw=="], + "@moq/web-transport-darwin-x64": ["@moq/web-transport-darwin-x64@0.1.6", "", { "os": "darwin", "cpu": "x64" }, "sha512-W1yu5D/21jivvWtwdxIeZVyta4uaMByBNVRYCACZKCUMudyy8J7wmAgJPdloeHyjSIl6om6hsQHxKYIpANKnmA=="], - "@moq/web-transport-linux-arm64-gnu": ["@moq/web-transport-linux-arm64-gnu@0.1.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-R5ldf9T3NxItcYNhIfMsNXtwAwJRYFYEvGpw/j73Ha1o+FV2ldAuZEeb3QkANm5akS8xjQ6VZNNNQJ/wRo53Qg=="], + "@moq/web-transport-linux-arm64-gnu": ["@moq/web-transport-linux-arm64-gnu@0.1.6", "", { "os": "linux", "cpu": "arm64" }, "sha512-tCUVQudEaU7en7ltQLbDTEsGt73v9SIt0cACHZS4Ba8EFahTLifBCms7D+rvI7PsYBIEuK+oEisH5hJ1j2yd7A=="], - "@moq/web-transport-linux-x64-gnu": ["@moq/web-transport-linux-x64-gnu@0.1.5", "", { "os": "linux", "cpu": "x64" }, "sha512-+JNSJr5MtRp+SxiRp9xJIMovPZvtY1cR3X/tvQEqCH0T8gbV2Oc+FWau5AijsIfNuhWEDXedz7nyKteU+0/26Q=="], + "@moq/web-transport-linux-x64-gnu": ["@moq/web-transport-linux-x64-gnu@0.1.6", "", { "os": "linux", "cpu": "x64" }, "sha512-WfcaCW4WgymUPZ8MckKD2MLOI6Xdyswki4U8wnGTj8jvmM413ppb/Y2lkfolMoehfYr+F+sZELfdy/nBzZAmaQ=="], - "@moq/web-transport-win32-x64-msvc": ["@moq/web-transport-win32-x64-msvc@0.1.5", "", { "os": "win32", "cpu": "x64" }, "sha512-Njge/TQNY8uDFcnr884WUFQtvTw9qcUTjwBm14+wPZgkC7hlYeWbYhXdQFZ26OC4uZkkRMZVZAMa5kiaAAw8Og=="], + "@moq/web-transport-win32-x64-msvc": ["@moq/web-transport-win32-x64-msvc@0.1.6", "", { "os": "win32", "cpu": "x64" }, "sha512-V/4Euf+J+qcbedX5OfJlYzshvD+WedZVfLsQ3Hu3sXhLXDvbKjipC+MJAGWayKvK+n57fugVEr9SIJZj6BpAxQ=="], "@npmcli/config": ["@npmcli/config@8.3.4", "", { "dependencies": { "@npmcli/map-workspaces": "^3.0.2", "@npmcli/package-json": "^5.1.1", "ci-info": "^4.0.0", "ini": "^4.1.2", "nopt": "^7.2.1", "proc-log": "^4.2.0", "semver": "^7.3.5", "walk-up-path": "^3.0.1" } }, "sha512-01rtHedemDNhUXdicU7s+QYz/3JyV5Naj84cvdXGH4mgCdL+agmSYaLF4LUG4vMCLzhBO8YtS0gPpH1FGvbgAw=="], diff --git a/quest/m1/interop-coverage/README.md b/quest/m1/interop-coverage/README.md index 9e3e2800e4..7042e18393 100644 --- a/quest/m1/interop-coverage/README.md +++ b/quest/m1/interop-coverage/README.md @@ -46,7 +46,6 @@ coverage on `main` at `3ab6cbf81d`. - [JS namespace lifecycle](/quest/m1/interop-coverage/js-namespace-done.md) - the runner's moq-dev-js client moves to an `@moq/net` that withdraws namespaces by reset, so subscribe-namespace-lifecycle passes on Cloudflare draft-18 and aiomoqt - [JS subgroup data through imquic](/quest/m1/interop-coverage/js-imquic-objects.md) - the runner's moq-dev-js client moves to an `@moq/net` patch that writes data stream headers in one write, so data-subgroup-basic passes against imquic -- [Late join and FETCH](/quest/m1/interop-coverage/late-join.md) - a late subscriber gets the current group from object 0, and a standalone FETCH returns a past group exactly ## Related diff --git a/quest/m1/interop-coverage/late-join.md b/quest/m1/interop-coverage/late-join.md deleted file mode 100644 index 712de785b6..0000000000 --- a/quest/m1/interop-coverage/late-join.md +++ /dev/null @@ -1,25 +0,0 @@ -# [M] Interop covers late join and FETCH - -## Goal - -On the IETF matrix (`just test interop --versions ietf`), a -subscriber that joins mid-group receives the current group from object 0 -(a joining FETCH before draft 22, a fill from draft 22) and a standalone -FETCH of a past group returns exactly its objects, for Rust and JS -publishers and subscribers. - -## Plan - -Decided with the maintainer on 2026-10-21: an in-tree case, not proposed to -the runner's spec. - -This is the path the draft-22 public relay failures of 2026-10-21 hit: a -catalog written once is lost when a relay narrows a join to Next Object, and -the JS publisher refuses every FETCH. Publish a track whose first group -outlives the subscriber's arrival (a catalog written once, and a slow video -GOP) so the case cannot pass on timing. - -Decided 2026-10-27 (maintainer): this needs only the cached and joining half -of JavaScript FETCH, not the on-demand half that waits on JS ranges. - -Public API: none. Wire: none. diff --git a/quest/m1/next-object-cold-copy.md b/quest/m1/next-object-cold-copy.md index 02b0e6ccfb..6cd3e8e39a 100644 --- a/quest/m1/next-object-cold-copy.md +++ b/quest/m1/next-object-cold-copy.md @@ -20,7 +20,3 @@ with Next Object before any frame of `g` arrives. If it reproduces, keep the reported Object ID out of the reader's frame index, as JS does. Public API: none. Wire: none. - -## Related - -- [Interop covers late join and FETCH](/quest/m1/interop-coverage/late-join.md) - the cross-implementation late-join case diff --git a/quest/m2/ietf-headless-group.md b/quest/m2/ietf-headless-group.md index 4843481dfa..118ec72144 100644 --- a/quest/m2/ietf-headless-group.md +++ b/quest/m2/ietf-headless-group.md @@ -44,8 +44,3 @@ the mid-group stream arrives and after it. Both drop the group, and the subscription keeps delivering whole groups after it. Public API: none. Wire: none. - -## Related - -- [Late join and FETCH](/quest/m1/interop-coverage/late-join.md) - the - joining FETCH that normally supplies the head diff --git a/quest/m2/ietf-join-after-finish.md b/quest/m2/ietf-join-after-finish.md index f437f5da05..fa1f527107 100644 --- a/quest/m2/ietf-join-after-finish.md +++ b/quest/m2/ietf-join-after-finish.md @@ -78,4 +78,3 @@ refused. ## Related - [JS joining FETCH](/quest/m2/ietf-js-joining-fetch.md) - the JS publisher mirrors the bound settled here -- [Interop covers late join and FETCH](/quest/m1/interop-coverage/late-join.md) - the cross-implementation joining FETCH case diff --git a/test/interop/README.md b/test/interop/README.md index 3330a44337..21be1f8e3e 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -51,7 +51,22 @@ The normal run also checks a finite raw track through the relay. Its publisher announces end 4 before writing four 256 KiB groups; the reader verifies every byte, exactly groups 0 through 3, and a clean end at 4. Rust-to-Rust always runs. Selecting native JS adds both Rust-to-JS and JS-to-Rust under that runtime, so `--all` covers -Node and Bun. The current CLI also FETCHes group 0, verifies every byte, and closes under the relay idle-out check. `--tail` runs this FETCH round and the five finite-tail lanes. The wire-compat lanes, which swap in released relays and clients, skip them. +Node and Bun. The current CLI also FETCHes group 1 of a finished track from the Rust +publisher and each selected native JS runtime, requires exactly its three objects, each +with its own bytes, and closes under the relay idle-out check. + +A late-join lane runs Rust-to-Rust and Rust/Node/Bun in both directions. The publisher +writes the first two objects of group 0 before any subscriber exists and leaves the group +open. The subscriber joins at the latest group, as a player does, and reports once it has +read those two objects; only then does the harness release the rest of the group and +group 1. A join that skips the head cannot pass by racing the publisher. On +moq-transport a Rust subscriber, and the relay toward its publisher, recover the head +with a joining FETCH before draft 22 and a fill from it. A JS subscriber requests +neither: on draft 22 it subscribes from the current group's start, and before that the +Rust relay replays the group on the subscription. + +`--tail` runs the FETCH round, the late joins, and the five finite-tail lanes. The +wire-compat lanes, which swap in released relays and clients, skip them. The finite clients keep their session alive until the harness acknowledges the reader's complete clean end over stdin, so a lane tests delivery rather than @@ -184,8 +199,8 @@ delivers them as minted: a publisher is granted its exact broadcast, a subscribe relay. `auto`, the default, is everything above. Any other version pins every client in its pass to offer that version alone, and `ietf` expands to the even drafts `moq-transport-18` through `moq-transport-22`. A pinned pass keeps the -media cells, the relay close check, the CLI FETCH of group 0, and the finite -tails. The grant, refusal, close-code, and drop cases are moq-lite's and run in +media cells, the relay close check, the CLI FETCH round, the late joins, and the +finite tails. The grant, refusal, close-code, and drop cases are moq-lite's and run in `auto` alone. The relay logs the version each connection negotiated, so every round in a @@ -246,7 +261,7 @@ just test interop --all # Pick your own axes: just test interop --publishers rust,python --subscribers rust,c,js-native-bun -# CLI FETCH close and finite track tails only: Rust-to-Rust and Rust/Node/Bun in both directions. +# CLI FETCH close, late joins, and finite track tails only: Rust-to-Rust and Rust/Node/Bun in both directions. just test interop --tail # The full matrix once per even moq-transport draft (see moq-transport below). diff --git a/test/interop/clients/js-native/package.json b/test/interop/clients/js-native/package.json index 7eacad4b39..1b5d3e9be5 100644 --- a/test/interop/clients/js-native/package.json +++ b/test/interop/clients/js-native/package.json @@ -10,7 +10,7 @@ "@moq/hang": "workspace:*", "@moq/json": "workspace:*", "@moq/net": "workspace:*", - "@moq/web-transport": "^0.1.5", + "@moq/web-transport": "^0.1.6", "@zod/mini": "^4.6.7", "zod": "^4.6.7" }, diff --git a/test/interop/clients/js-native/tail.ts b/test/interop/clients/js-native/tail.ts index d630cde8cd..9fcc225e1e 100644 --- a/test/interop/clients/js-native/tail.ts +++ b/test/interop/clients/js-native/tail.ts @@ -4,7 +4,10 @@ * `drop` cuts group 1. `join` reads from whichever group the subscription starts at: a * moq-transport subscription starts at the largest group rather than at the range asked for, so * it must read a contiguous run of groups through the last one. `compress` publishes a compressed - * track with several frames, one empty, in each group. + * track with several frames, one empty, in each group. `cached` publishes every group before + * announcing, for a FETCH of a past group. `late` writes the head of group 0 before announcing and + * the rest only once the harness relays that the subscriber read it, so a join that skips the head + * stalls rather than racing the publisher. * * @module */ @@ -17,6 +20,9 @@ import { install } from "@moq/web-transport"; install(); const GROUPS = 4; const BYTES = 256 * 1024; +// The groups a `late` track publishes, and how many frames of group 0 precede the subscriber. +const LATE_GROUPS = 2; +const LATE_HEAD = 2; const [role, url, path, version, mode] = process.argv.slice(2); const drop = mode === "drop"; const compress = mode === "compress"; @@ -25,13 +31,55 @@ console.info = console.error; const join = mode === "join" || mode === "status"; const datagram = mode === "datagram"; const status = mode === "status"; +const cached = mode === "cached"; +const late = mode === "late"; if ( !url || !path || !["publish", "subscribe"].includes(role) || - ![undefined, "drop", "join", "compress", "datagram", "status"].includes(mode) + ![undefined, "drop", "join", "compress", "datagram", "status", "cached", "late"].includes(mode) ) { - throw new Error("usage: tail.ts publish|subscribe URL BROADCAST [VERSION [drop|join|compress|datagram|status]]"); + throw new Error( + "usage: tail.ts publish|subscribe URL BROADCAST [VERSION [drop|join|compress|datagram|status|cached|late]]", + ); +} + +/** + * The frames of each group. A compressed track spans several frames, one empty, per window. + * `cached` and `late` give every frame its own bytes, so a FETCH or join that drops, repeats, or + * reorders one fails. + */ +function frames(sequence: number): Uint8Array[] { + if (compress) + return [new Uint8Array(BYTES / 2).fill(sequence), new Uint8Array(0), new Uint8Array(BYTES / 2).fill(sequence)]; + if (cached || late) return [0, 1, 2].map((index) => new Uint8Array(BYTES / 4).fill(sequence * 16 + index)); + return [new Uint8Array(BYTES).fill(sequence)]; +} + +/** Publish every group, cutting group 1 for `drop`. The end precedes the last group's data. */ +function write(track: Moq.Track.Producer) { + track.finishAt({ group: GROUPS, frame: 0 }); + for (let sequence = 0; sequence < GROUPS; sequence++) { + const group = track.appendGroup(); + if (drop && sequence === 1) { + group.abort(new Error("cut")); + continue; + } + for (const payload of frames(sequence)) group.writeFrame({ payload }); + group.finish(); + } + track.finish(); +} + +/** Read one whole group, checking every frame's bytes, and report when the `late` head is in. */ +async function read(group: Moq.Group.Consumer) { + for (const [index, want] of frames(group.sequence).entries()) { + const frame = await group.readFrame(); + assert(frame, "short group"); + assert(Buffer.from(frame.payload).equals(want), `wrong frame ${index} in group ${group.sequence}`); + if (late && group.sequence === 0 && index + 1 === LATE_HEAD) process.stdout.write("late head\n"); + } + assert.equal(await group.readFrame(), undefined, "extra frame"); } const origin = new Moq.Origin.Producer(); @@ -46,10 +94,27 @@ try { const broadcastPublication = origin.createBroadcast(Moq.Path.from(path)); const broadcast = broadcastPublication.broadcast; const track = broadcast.createTrack("tail", { compress, ...(status ? { priority: 2 } : {}) }); + if (cached) write(track); + let head: Moq.Group.Producer | undefined; + if (late) { + head = track.appendGroup(); + for (const payload of frames(0).slice(0, LATE_HEAD)) head.writeFrame({ payload }); + } broadcastPublication.announce(); const lines = createInterface({ input: process.stdin }); const commands = lines[Symbol.asyncIterator](); - if (!status) { + if (head) { + assert.equal((await commands.next()).value, "late tail", "subscriber did not read the head"); + for (const payload of frames(0).slice(LATE_HEAD)) head.writeFrame({ payload }); + head.finish(); + for (let sequence = 1; sequence < LATE_GROUPS; sequence++) { + const group = track.appendGroup(); + for (const payload of frames(sequence)) group.writeFrame({ payload }); + group.finish(); + } + track.finish(); + track.close(); + } else if (!status && !cached) { const demand = track.demand(); while (demand.wanted.peek() === undefined) await demand.wanted.changed(); if (datagram) { @@ -58,20 +123,7 @@ try { track.appendDatagram(undefined, new Uint8Array(900).fill(sequence)); } } else { - // The end precedes the last group's data; the transport still has to drain it. - track.finishAt({ group: GROUPS, frame: 0 }); - for (let sequence = 0; sequence < GROUPS; sequence++) { - const group = track.appendGroup(); - if (drop && sequence === 1) { - group.abort(new Error("cut")); - continue; - } - for (const size of compress ? [BYTES / 2, 0, BYTES / 2] : [BYTES]) { - group.writeFrame({ payload: new Uint8Array(size).fill(sequence) }); - } - group.finish(); - } - track.finish(); + write(track); track.close(); } } @@ -91,9 +143,12 @@ try { await request.active.changed(); broadcast = request.active.peek(); } - const track = broadcast - .track("tail") - .subscribe({ maxDelay: Milli(drop ? 60_000 : 5000), groups: { start: { included: 0 } } }); + // `late` names no start, joining the latest group as a player does: group 0, whose + // head predates the subscription. + const track = broadcast.track("tail").subscribe({ + maxDelay: Milli(drop ? 60_000 : 5000), + ...(late ? {} : { groups: { start: { included: 0 } } }), + }); if (compress) assert.equal((await track.info()).compress, version === "moq-lite-07-wip"); const seen: number[] = []; try { @@ -113,22 +168,27 @@ try { process.stdout.write(`datagram ${sequence}\n`); } console.error("datagram clean groups=0,1,2,3 bytes=3600"); + } else if (late) { + for (let sequence = 0; sequence < LATE_GROUPS; sequence++) { + const group = await track.recvGroup(); + assert(group, "missing group"); + try { + assert.equal(group.sequence, sequence, "joined the wrong group"); + await read(group); + } finally { + group.close(); + } + } + assert.equal(await track.recvGroup(), undefined, "extra group"); + assert.deepEqual(await track.finished(), { group: LATE_GROUPS, frame: 0 }); + console.error("late join clean groups=0,1 frames=6"); } else { for (;;) { const group = await track.recvGroup(); if (!group) break; try { assert(group.sequence < GROUPS, `unexpected group ${group.sequence}`); - for (const size of compress ? [BYTES / 2, 0, BYTES / 2] : [BYTES]) { - const frame = await group.readFrame(); - assert(frame, "empty group"); - assert.equal(frame.payload.byteLength, size, "truncated group"); - assert( - frame.payload.every((byte) => byte === group.sequence), - "corrupt group", - ); - } - assert.equal(await group.readFrame(), undefined, "extra frame"); + await read(group); seen.push(group.sequence); } finally { group.close(); diff --git a/test/interop/clients/rust/tail.rs b/test/interop/clients/rust/tail.rs index 2f0f04f2e3..4761b98830 100644 --- a/test/interop/clients/rust/tail.rs +++ b/test/interop/clients/rust/tail.rs @@ -5,7 +5,9 @@ //! so it must read a contiguous run of groups through the last one. `cached` publishes every //! group before connecting, so a FETCH of a past group never races its write: moq-transport //! refuses a FETCH that starts past the largest group rather than waiting for it. `compress` -//! publishes a compressed track with several frames, one empty, in each group. +//! publishes a compressed track with several frames, one empty, in each group. `late` writes +//! the head of group 0 before connecting and the rest only once the harness relays that the +//! subscriber read it, so a join that skips the head stalls rather than racing the publisher. use std::time::Duration; use anyhow::{Context, ensure}; @@ -14,30 +16,59 @@ use tokio::io::AsyncBufReadExt; const GROUPS: u64 = 4; const BYTES: usize = 256 * 1024; +/// The groups a `late` track publishes, and how many frames of group 0 precede the subscriber. +const LATE_GROUPS: u64 = 2; +const LATE_HEAD: usize = 2; -/// Frame sizes in each group: a compressed track spans several frames, one empty, per window. -fn sizes(compress: bool) -> &'static [usize] { - if compress { &[BYTES / 2, 0, BYTES / 2] } else { &[BYTES] } +/// The frames of each group. A compressed track spans several frames, one empty, per window. +/// `cached` and `late` give every frame its own bytes, so a FETCH or join that drops, repeats, +/// or reorders one fails. +fn frames(sequence: u64, mode: Option<&str>) -> Vec> { + match mode { + Some("compress") => vec![ + vec![sequence as u8; BYTES / 2], + Vec::new(), + vec![sequence as u8; BYTES / 2], + ], + Some("cached" | "late") => (0..3) + .map(|index| vec![(sequence * 16 + index) as u8; BYTES / 4]) + .collect(), + _ => vec![vec![sequence as u8; BYTES]], + } } /// Publish every group, cutting group 1 for `drop`. -fn write(track: &mut moq_net::track::Producer, drop: bool, compress: bool) -> anyhow::Result<()> { +fn write(track: &mut moq_net::track::Producer, mode: Option<&str>) -> anyhow::Result<()> { // Declare the end before the final group's payload is even available. track.finish_at(moq_net::track::Position::group(GROUPS))?; for sequence in 0..GROUPS { let mut group = track.append_group()?; - if drop && sequence == 1 { + if mode == Some("drop") && sequence == 1 { group.abort(moq_net::Error::App(1))?; continue; } - for &size in sizes(compress) { - group.write_frame(moq_net::Timestamp::ZERO, vec![sequence as u8; size])?; + for frame in frames(sequence, mode) { + group.write_frame(moq_net::Timestamp::ZERO, frame)?; } group.finish()?; } Ok(()) } +/// Read one whole group, checking every frame's bytes, and report when the `late` head is in. +async fn read(group: &mut moq_net::group::Consumer, mode: Option<&str>) -> anyhow::Result<()> { + let sequence = group.sequence; + for (index, want) in frames(sequence, mode).iter().enumerate() { + let frame = group.read_frame().await?.context("short group")?; + ensure!(frame.payload[..] == want[..], "wrong frame {index} in group {sequence}"); + if mode == Some("late") && sequence == 0 && index + 1 == LATE_HEAD { + println!("late head"); + } + } + ensure!(group.read_frame().await?.is_none(), "extra frame in group {sequence}"); + Ok(()) +} + // Keep metadata acceptance and alias registration in one task turn, before the // subscriber acknowledges readiness to the harness. #[tokio::main(flavor = "current_thread")] @@ -45,14 +76,14 @@ async fn main() -> anyhow::Result<()> { let args: Vec<_> = std::env::args().collect(); ensure!( (4..=6).contains(&args.len()), - "usage: interop-tail publish|subscribe URL BROADCAST [VERSION [drop|join|cached|compress|datagram|status]]" + "usage: interop-tail publish|subscribe URL BROADCAST [VERSION [drop|join|cached|compress|datagram|status|late]]" ); let url: url::Url = args[2].parse()?; let mode = args.get(5).map(String::as_str); ensure!( matches!( mode, - None | Some("drop" | "join" | "cached" | "compress" | "datagram" | "status") + None | Some("drop" | "join" | "cached" | "compress" | "datagram" | "status" | "late") ), "unknown mode: {mode:?}" ); @@ -62,6 +93,7 @@ async fn main() -> anyhow::Result<()> { let compress = mode == Some("compress"); let datagram = mode == Some("datagram"); let status = mode == Some("status"); + let late = mode == Some("late"); let mut commands = tokio::io::BufReader::new(tokio::io::stdin()).lines(); let mut config = moq_tokio::connect::Config::default(); // An empty version offers the defaults, so a mode can follow it. @@ -83,7 +115,15 @@ async fn main() -> anyhow::Result<()> { )?; broadcast.announce(Default::default())?; if cached { - write(&mut track, drop, compress)?; + write(&mut track, mode)?; + } + let mut head = None; + if late { + let mut group = track.append_group()?; + for frame in frames(0, mode).into_iter().take(LATE_HEAD) { + group.write_frame(moq_net::Timestamp::ZERO, frame)?; + } + head = Some(group); } let session = client .clone() @@ -91,7 +131,24 @@ async fn main() -> anyhow::Result<()> { .connect(url) .established() .await?; - if !cached { + if let Some(mut group) = head { + ensure!( + commands.next_line().await?.as_deref() == Some("late tail"), + "subscriber did not read the head" + ); + for frame in frames(0, mode).into_iter().skip(LATE_HEAD) { + group.write_frame(moq_net::Timestamp::ZERO, frame)?; + } + group.finish()?; + for sequence in 1..LATE_GROUPS { + let mut group = track.append_group()?; + for frame in frames(sequence, mode) { + group.write_frame(moq_net::Timestamp::ZERO, frame)?; + } + group.finish()?; + } + track.finish()?; + } else if !cached { let mut demand = track.demand(); while demand.wanted_changed().await?.is_none() {} if datagram { @@ -105,7 +162,7 @@ async fn main() -> anyhow::Result<()> { track.append_datagram(None, vec![sequence as u8; 900])?; } } else { - write(&mut track, drop, compress)?; + write(&mut track, mode)?; } } // A finished track is not a drained transport. Keep the session alive @@ -142,6 +199,30 @@ async fn main() -> anyhow::Result<()> { client.close().await; return Ok(()); } + if late { + // No range: join the latest group as a player does, group 0, whose head predates + // the subscription. + let options = moq_net::track::Subscription::default().with_max_delay(Duration::from_secs(5)); + let mut track = remote.subscribe(Some(options)).await?; + for sequence in 0..LATE_GROUPS { + let mut group = track.recv_group().await?.context("missing group")?; + ensure!( + group.sequence == sequence, + "joined group {} for {sequence}", + group.sequence + ); + read(&mut group, mode).await?; + } + ensure!(track.recv_group().await?.is_none(), "extra group"); + ensure!( + track.finished().await? == moq_net::track::Position::group(LATE_GROUPS), + "wrong declared end" + ); + eprintln!("late join clean groups=0,1 frames=6"); + session.close().await?; + client.close().await; + return Ok(()); + } let options = moq_net::track::Subscription::default() .with_max_delay(Duration::from_secs(if drop { 60 } else { 5 })) .with_range(0..); @@ -174,15 +255,7 @@ async fn main() -> anyhow::Result<()> { while let Some(mut group) = track.recv_group().await? { let sequence = group.sequence; ensure!(sequence < GROUPS, "unexpected group {sequence}"); - for &size in sizes(compress) { - let frame = group.read_frame().await?.context("empty group")?; - ensure!(frame.payload.len() == size, "truncated group {sequence}"); - ensure!( - frame.payload.iter().all(|byte| *byte == sequence as u8), - "corrupt group {sequence}" - ); - } - ensure!(group.read_frame().await?.is_none(), "extra frame in group {sequence}"); + read(&mut group, mode).await?; seen.push(sequence); } seen.sort_unstable(); diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 7d0d8a41de..d2ef73bf28 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -448,9 +448,13 @@ plan_pass() { fi [[ "$FINISH_ONLY" -eq 0 ]] || return 0 record "not run" case="CLI FETCH" publisher=rust subscriber=rust + record "not run" case="late join" publisher=rust subscriber=rust record "not run" case=tail publisher=rust subscriber=rust for runtime in js-native-node js-native-bun; do needs "$runtime" || continue + record "not run" case="CLI FETCH" publisher="$runtime" subscriber=rust + record "not run" case="late join" publisher=rust subscriber="$runtime" + record "not run" case="late join" publisher="$runtime" subscriber=rust record "not run" case=tail publisher=rust subscriber="$runtime" record "not run" case=tail publisher="$runtime" subscriber=rust if [[ "$VERSION" == moq-transport-* ]]; then @@ -1910,37 +1914,103 @@ run_tail_pair() { rm "$fifo" } -# Exercise this checkout's CLI FETCH under the same relay close check as live readers. +# A late joiner. The publisher writes group 0's head before any subscriber exists and the rest only +# once the subscriber reports reading that head, so only a join from object 0 passes (a joining +# FETCH, a draft-22 fill, or a moq-lite group), never one that merely outran the publisher. +run_late_pair() { + local pub="$1" sub="$2" pid subscriber_pid started=$SECONDS from version head="" + local name="late-$1-$2" fifo="$LOGS/late-ack" heads="$LOGS/late-head" broadcast="late-$1-$2-$$-$RANDOM" + local cell=(case="late join" publisher="$pub" subscriber="$sub" log="$LOGS/$name-sub.log") + version=$(pinned_version) + if is_broken "$pub" || is_broken "$sub"; then + echo " FAIL late join $pub -> $sub (client unavailable)" + record fail "${cell[@]}" detail="client unavailable" + overall=1 + return + fi + mkfifo "$fifo" "$heads" + exec 9<>"$fifo" + from=$(relay_next_line) + harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_tail_publisher "$fifo" "$pub" publish "$broadcast" "$(token_url --publish "$(publish_grant "$broadcast")")" "$version" late + pid="$HARNESS_PID" + exec 8<>"$heads" + harness_spawn "$name-sub" "$LOGS/$name-sub.log" run_tail_subscriber "$heads" "$sub" subscribe "$broadcast" "$(token_url --subscribe "$(subscribe_grant "$broadcast")")" "$version" late + subscriber_pid="$HARNESS_PID" + if read -r -t "$TIMEOUT" head <&8 && [[ "$head" == "late head" ]]; then + printf 'late tail\n' >&9 + fi + harness_wait "$subscriber_pid" || true + if [[ "$head" == "late head" ]] && grep -qx 'late join clean groups=0,1 frames=6' "$LOGS/$name-sub.log"; then + printf 'clean end\n' >&9 + harness_wait "$pid" || true + if [[ -n "$version" ]] && ! check_versions "late join $pub -> $sub" "$from" "$version"; then + record fail "${cell[@]}" seconds=$((SECONDS - started)) detail="a relay connection negotiated another version" + overall=1 + elif grep -qx 'tail acknowledged' "$LOGS/$name-pub.log"; then + echo " PASS late join $pub -> $sub (group 0 from its head; clean end 2)" + record pass "${cell[@]}" seconds=$((SECONDS - started)) + else + echo " FAIL late join $pub -> $sub (publisher did not acknowledge)" + record fail "${cell[@]}" seconds=$((SECONDS - started)) detail="publisher did not acknowledge" + overall=1 + cat "$LOGS/$name-pub.log" + fi + else + local why="missing group 0's head" + [[ "$head" != "late head" ]] || why="missing objects or clean end" + echo " FAIL late join $pub -> $sub ($why)" + record fail "${cell[@]}" seconds=$((SECONDS - started)) detail="$why" + overall=1 + cat "$LOGS/$name-pub.log" "$LOGS/$name-sub.log" + harness_reap "$pid" + harness_reap "$subscriber_pid" + fi + exec 8>&- 9>&- + rm "$fifo" "$heads" +} + +# This checkout's CLI FETCHes a past group of a finished track, under the same relay close check as +# live readers. Every object has its own bytes, so a FETCH that drops, repeats, or reorders one fails. run_fetch_round() { - local name="fetch-rust" fifo="$LOGS/fetch-ack" broadcast="fetch-$$-$RANDOM" pid from version + local pub="$1" name="fetch-$1" fifo="$LOGS/fetch-ack" broadcast="fetch-$1-$$-$RANDOM" pid from version local started=$SECONDS why="" + local cell=(case="CLI FETCH" publisher="$pub" subscriber=rust log="$LOGS/$name-pub.log") + if is_broken "$pub"; then + echo " FAIL CLI FETCH $pub (client unavailable)" + record fail "${cell[@]}" detail="client unavailable" + overall=1 + return + fi version=$(pinned_version) from=$(relay_next_line) mkfifo "$fifo" exec 9<>"$fifo" - harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_tail_publisher "$fifo" rust publish "$broadcast" "$(token_url --publish "$(publish_grant "$broadcast")")" "$version" cached + harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_tail_publisher "$fifo" "$pub" publish "$broadcast" "$(token_url --publish "$(publish_grant "$broadcast")")" "$version" cached pid="$HARNESS_PID" if timeout -k 3 "$TIMEOUT" "$MOQ" --connect "$(token_url --subscribe "$(subscribe_grant "$broadcast")")" ${version:+--connect-version "$version"} \ - --broadcast "$broadcast" fetch tail --group 0 >"$LOGS/$name.raw" && - python3 - "$LOGS/$name.raw" <<'PYCODE' -import pathlib, sys -assert pathlib.Path(sys.argv[1]).read_bytes() == bytes(256 * 1024), "incorrect FETCH payload" + --broadcast "$broadcast" fetch tail --group 1 --json >"$LOGS/$name.json" && + python3 - "$LOGS/$name.json" <<'PYCODE' +import base64, json, sys +frames = [json.loads(line) for line in open(sys.argv[1])] +assert [(frame["group"], frame["frame"], frame["size"]) for frame in frames] == [(1, index, 64 * 1024) for index in range(3)], frames +assert [base64.b64decode(frame["payload"], validate=True) for frame in frames] == [bytes([16 + index]) * (64 * 1024) for index in range(3)], "incorrect FETCH payload" PYCODE then printf 'clean end\n' >&9 harness_wait "$pid" || true if grep -qx 'tail acknowledged' "$LOGS/$name-pub.log"; then - echo " PASS CLI FETCH (group 0; 262144 bytes)" + echo " PASS CLI FETCH $pub (group 1; 3 objects)" else - echo " FAIL CLI FETCH (publisher did not acknowledge)" + echo " FAIL CLI FETCH $pub (publisher did not acknowledge)" why="publisher did not acknowledge" overall=1 cat "$LOGS/$name-pub.log" fi else - echo " FAIL CLI FETCH" + echo " FAIL CLI FETCH $pub" why="incorrect or missing FETCH payload" overall=1 + cat "$LOGS/$name-pub.log" harness_reap "$pid" fi exec 9>&- @@ -1950,7 +2020,7 @@ PYCODE why="${why:-a relay connection negotiated another version}" overall=1 fi - local cell=(case="CLI FETCH" publisher=rust subscriber=rust seconds=$((SECONDS - started)) log="$LOGS/$name-pub.log") + cell+=(seconds=$((SECONDS - started))) if [[ -z "$why" ]]; then record pass "${cell[@]}"; else record fail "${cell[@]}" detail="$why"; fi } @@ -2126,7 +2196,18 @@ run_control_case() { run_tails() { local runtime version echo "=== CLI FETCH close ===" - run_fetch_round + run_fetch_round rust + for runtime in js-native-node js-native-bun; do + ! needs "$runtime" || run_fetch_round "$runtime" + done + echo "=== late join ===" + run_late_pair rust rust + for runtime in js-native-node js-native-bun; do + if needs "$runtime"; then + run_late_pair rust "$runtime" + run_late_pair "$runtime" rust + fi + done echo "=== finite track tails ===" run_tail_pair rust rust for runtime in js-native-node js-native-bun; do diff --git a/test/receive-credit/package.json b/test/receive-credit/package.json index c9b094ac6b..57ecb72fa2 100644 --- a/test/receive-credit/package.json +++ b/test/receive-credit/package.json @@ -7,6 +7,6 @@ }, "dependencies": { "@moq/net": "workspace:*", - "@moq/web-transport": "^0.1.5" + "@moq/web-transport": "^0.1.6" } }