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
11 changes: 9 additions & 2 deletions js/pattern/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[];
Expand Down Expand Up @@ -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", () => {
Expand Down
11 changes: 9 additions & 2 deletions js/pattern/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `**`. */
Expand Down
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions quest/m1/js-pattern-depth.md

This file was deleted.

4 changes: 0 additions & 4 deletions rs/moq-pattern/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}
Expand Down
10 changes: 9 additions & 1 deletion rs/moq-pattern/tests/pattern.json
Original file line number Diff line number Diff line change
@@ -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": "",
Expand Down Expand Up @@ -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": [
Expand Down
13 changes: 8 additions & 5 deletions rs/moq-pattern/tests/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"
),
}
}
}

Expand Down
Loading