diff --git a/js/pattern/src/index.test.ts b/js/pattern/src/index.test.ts index 0378be70ba2..d05b94ccada 100644 --- a/js/pattern/src/index.test.ts +++ b/js/pattern/src/index.test.ts @@ -6,7 +6,7 @@ import { compareSpecificity, IntersectionError, InvalidPattern, Pattern, Pattern interface Vectors { parse: { text: string; canonical?: string; segments?: Segment[] | null; error?: InvalidPattern.Code }[]; literal: ({ path: string; pattern: string } | { path: string; error: InvalidPattern.Code })[]; - subtree: { path: string; pattern: string }[]; + subtree: ({ path: string; pattern: string } | { path: string; error: InvalidPattern.Code })[]; head: { pattern: string; head: string; literal: boolean; globstar: boolean }[]; matches: { pattern: string; path: string; expect: boolean }[]; contains: { outer: string; inner: string; expect: boolean }[]; @@ -68,7 +68,14 @@ describe("vectors", () => { ).toBe(c.error); else expect(Pattern.literal(c.path).text, c.path).toBe(c.pattern); } - for (const c of vectors.subtree) expect(Pattern.subtree(c.path).text, c.path).toBe(c.pattern); + for (const c of vectors.subtree) { + if ("error" in c) + expect( + errorCode(() => Pattern.subtree(c.path)), + c.path, + ).toBe(c.error); + else expect(Pattern.subtree(c.path).text, c.path).toBe(c.pattern); + } }); test("head", () => { diff --git a/js/pattern/src/index.ts b/js/pattern/src/index.ts index c95676ea422..f5e367902c9 100644 --- a/js/pattern/src/index.ts +++ b/js/pattern/src/index.ts @@ -421,9 +421,16 @@ export class Pattern { return new Pattern(splitPath(path).map((value) => ({ kind: "literal", value }))); } - /** The pattern matching `path` and everything beneath it: `path/**`. The empty path yields `**`. */ + /** + * The pattern matching `path` and everything beneath it: `path/**`. + * + * The empty path yields `**`, and a path of {@link Pattern.MAX_SEGMENTS} yields the + * literal, since nothing can sit beneath it. + */ static subtree(path: string): Pattern { - return new Pattern([...splitPath(path).map((value): Segment => ({ kind: "literal", value })), GLOBSTAR]); + const segments = splitPath(path).map((value): Segment => ({ kind: "literal", value })); + if (segments.length < MAX_PATTERN_SEGMENTS) segments.push(GLOBSTAR); + return new Pattern(segments); } /** The pattern matching every path: `**`. */ diff --git a/quest/m1/README.md b/quest/m1/README.md index 50e3d328e92..02917b9ac35 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -46,7 +46,6 @@ transport, benchmark tooling); worktrees isolate commits, not semantics. - [Track tail hardening](/quest/m1/track-tail-hardening.md) - Rust and JS wait out a track's tail by the same rules, with the known hang, count, truncation, grace, and memory holes closed - [Session death parity](/quest/m1/session-death.md) - a local close ends tracks cleanly in both languages, and JS group readers see the session's error on session death - [JS scoped routes](/quest/m1/js-scoped-routes.md) - a scoped JS origin reader announces the preferred route among those in its scope, like Rust, with the fan-out benchmarked -- [JS subtree at max depth](/quest/m1/js-pattern-depth.md) - `Pattern.subtree` returns the literal path at 32 segments like Rust, pinned by a shared pattern.json vector - [moq play decode schedule](/quest/m1/play-decode-schedule.md) - `moq play` video keeps valid pictures across rewinds, reordering deeper than 100 ms, and decoder batches larger than three - [moqsrc stop](/quest/m1/moqsrc-stop.md) - moqsrc's stop blocks until its session ends, without deadlocking on a blocked pad push - [More tests under load](/quest/m1/test-flakes-2.md) - the second round of load-only failures, fixed at the cause diff --git a/quest/m1/js-pattern-depth.md b/quest/m1/js-pattern-depth.md deleted file mode 100644 index 3921c8eec15..00000000000 --- a/quest/m1/js-pattern-depth.md +++ /dev/null @@ -1,21 +0,0 @@ -# [XS] JS subtree at max depth - -## Goal - -`Pattern.subtree` in `@moq/pattern` accepts a 32-segment path (the wire path -limit) and returns the literal path, as Rust's `Pattern::subtree` does since -https://github.com/moq-dev/moq/pull/4284. A 33-segment path still throws -`TooManySegments`. - -## Plan - -`js/pattern/src/index.ts` always appends `**`, so a max-depth path becomes 33 -segments and throws, which empties an announce subscription under that prefix -just as it did in Rust. Nothing can sit beneath a max-depth path, so the path -itself is the whole subtree. - -The Rust regression is a unit test in `rs/moq-pattern/src/pattern.rs`, which -JS never runs. Move the max-depth case (and the 33-segment refusal, if the -vector shape grows an error field the way `literal` has one) into the shared -`rs/moq-pattern/tests/pattern.json`, so both languages run the same vector -and the next divergence fails in whichever side lags. diff --git a/rs/moq-pattern/src/pattern.rs b/rs/moq-pattern/src/pattern.rs index fb9004a7a83..49dca7f8c2f 100644 --- a/rs/moq-pattern/src/pattern.rs +++ b/rs/moq-pattern/src/pattern.rs @@ -998,10 +998,6 @@ mod tests { assert_eq!(Pattern::literal("").unwrap(), Pattern::default()); assert_eq!(Pattern::subtree("foo").unwrap(), pattern("foo/**")); assert_eq!(Pattern::subtree("/").unwrap(), Pattern::all()); - let max = ["a"; Pattern::MAX_SEGMENTS].join("/"); - assert_eq!(Pattern::subtree(&max).unwrap(), pattern(&max)); - let deep = ["a"; Pattern::MAX_SEGMENTS + 1].join("/"); - assert_eq!(Pattern::subtree(&deep), Err(InvalidPattern::TooManySegments)); assert_eq!(Pattern::literal("a/*"), Err(InvalidPattern::InvalidSegment("*".into()))); assert_eq!(Pattern::literal("**"), Err(InvalidPattern::InvalidSegment("**".into()))); } diff --git a/rs/moq-pattern/tests/pattern.json b/rs/moq-pattern/tests/pattern.json index bf479d8c36f..ae8b85bdab9 100644 --- a/rs/moq-pattern/tests/pattern.json +++ b/rs/moq-pattern/tests/pattern.json @@ -1,5 +1,5 @@ { - "$comment": "Golden vectors shared by rs/moq-net (tests/pattern.rs) and js/net (src/pattern.test.ts). Both test suites read this file, so the two implementations cannot drift apart silently.", + "$comment": "Golden vectors shared by rs/moq-pattern (tests/pattern.rs) and js/pattern (src/index.test.ts). Both test suites read this file, so the two implementations cannot drift apart silently.", "parse": [ { "text": "", @@ -197,6 +197,14 @@ { "path": "a/b/", "pattern": "a/b/**" + }, + { + "path": "a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/a/b/c/d/e/f", + "pattern": "a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/a/b/c/d/e/f" + }, + { + "path": "a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/a/b/c/d/e/f/g", + "error": "too-many-segments" } ], "head": [ diff --git a/rs/moq-pattern/tests/pattern.rs b/rs/moq-pattern/tests/pattern.rs index 1c252428113..2d64bb39119 100644 --- a/rs/moq-pattern/tests/pattern.rs +++ b/rs/moq-pattern/tests/pattern.rs @@ -77,11 +77,14 @@ fn literal_and_subtree() { } for case in vectors["subtree"].as_array().unwrap() { let path = case["path"].as_str().unwrap(); - assert_eq!( - Pattern::subtree(path).unwrap(), - pattern(case["pattern"].as_str().unwrap()), - "subtree {path:?}" - ); + match Pattern::subtree(path) { + Ok(got) => assert_eq!(got, pattern(case["pattern"].as_str().unwrap()), "subtree {path:?}"), + Err(err) => assert_eq!( + error_code(&err), + case["error"].as_str().unwrap_or("ok"), + "subtree {path:?}" + ), + } } }