diff --git a/bun.lock b/bun.lock index 1e1a013bda9..a37860ad8fe 100644 --- a/bun.lock +++ b/bun.lock @@ -259,7 +259,6 @@ "@moq/qmux": "workspace:^", "@moq/signals": "workspace:*", "pako": "^3.0.3", - "sorted-btree": "^2.1.0", }, "devDependencies": { "@types/bun": "^1.4.4", @@ -1864,8 +1863,6 @@ "solid-refresh": ["solid-refresh@0.6.3", "", { "dependencies": { "@babel/generator": "^7.23.6", "@babel/helper-module-imports": "^7.22.15", "@babel/types": "^7.23.6" }, "peerDependencies": { "solid-js": "^1.3" } }, "sha512-F3aPsX6hVw9ttm5LYlth8Q15x6MlI/J3Dn+o3EQyRTtTxidepSTwAYdozt01/YA+7ObcciagGEyXIopGZzQtbA=="], - "sorted-btree": ["sorted-btree@2.1.0", "", {}, "sha512-AtYXy3lL+5jrATpbymC2bM8anN/3maLkmVCd94MzypnKjokfCid/zeS3rvXedv7W6ffSfqKIGdz3UaJPWRBZ0g=="], - "source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="], "source-map-js": ["source-map-js@1.2.2", "", {}, "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw=="], diff --git a/doc/lib/js/clock.md b/doc/lib/js/clock.md index 6b76531ddb3..a50c1ee6eec 100644 --- a/doc/lib/js/clock.md +++ b/doc/lib/js/clock.md @@ -10,14 +10,15 @@ description: Logical time and timers with a manual clock for deterministic tests Use `@moq/clock` when a deadline and the elapsed time beside it must come from one clock. Its default backend reads the host's monotonic and wall clocks; -a test installs a `Manual` clock without patching the host's timers. +a test installs a `Manual` clock from `@moq/clock/test` without patching the host's timers. ```sh bun add @moq/clock ``` ```ts -import { Duration, Manual, now, sleep } from "@moq/clock"; +import { Duration, now, sleep } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; const clock = new Manual(); const installed = clock.install(); diff --git a/js/auth/src/key.test.ts b/js/auth/src/key.test.ts index e197a919d2c..8ee176ec0a0 100644 --- a/js/auth/src/key.test.ts +++ b/js/auth/src/key.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Manual, Wall, wall } from "@moq/clock"; +import { Wall, wall } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { base64url, exportJWK, generateKeyPair, SignJWT } from "jose"; import type { Algorithm } from "./algorithm.ts"; import { authorize, type Claims } from "./claims.ts"; diff --git a/js/clock/README.md b/js/clock/README.md index b1a0fe6edbc..3fdeea8d2fa 100644 --- a/js/clock/README.md +++ b/js/clock/README.md @@ -1,10 +1,11 @@ # @moq/clock Logical monotonic time, wall time, and timers from one clock per JavaScript realm. -Use `Manual` to test time without replacing the host's timers. +Use `Manual` from `@moq/clock/test` to test time without replacing the host's timers. ```ts -import { Duration, Instant, Manual, now, sleep } from "@moq/clock"; +import { Duration, Instant, now, sleep } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; const clock = new Manual(); const installed = clock.install(); diff --git a/js/clock/api/index.api.md b/js/clock/api/index.api.md index 85b3cbc07e6..83014dc190b 100644 --- a/js/clock/api/index.api.md +++ b/js/clock/api/index.api.md @@ -73,19 +73,6 @@ export class Interval { tick(): Promise; } -export class Manual { - constructor(); - static readonly WALL_START: Wall; - advance(duration: Duration): Promise; - drive(work: PromiseLike): Promise; - fire(): Promise; - install(): Installed; - jump(duration: Duration): void; - now(): Instant; - stepWall(wall: Wall): void; - wall(): Wall; -} - export const MissedTickBehavior: { readonly Burst: "burst"; readonly Delay: "delay"; diff --git a/js/clock/api/test.api.md b/js/clock/api/test.api.md index a45a1084063..136bb5b748f 100644 --- a/js/clock/api/test.api.md +++ b/js/clock/api/test.api.md @@ -1,5 +1,23 @@ # `@moq/clock/test` ```ts +import { Duration } from "@moq/clock"; +import { Installed } from "@moq/clock"; +import { Instant } from "@moq/clock"; +import { Wall } from "@moq/clock"; + +export class Manual { + constructor(); + static readonly WALL_START: Wall; + advance(duration: Duration): Promise; + drive(work: PromiseLike): Promise; + fire(): Promise; + install(): Installed; + jump(duration: Duration): void; + now(): Instant; + stepWall(wall: Wall): void; + wall(): Wall; +} + export function hostTime(): void; ``` diff --git a/js/clock/bench/timers.ts b/js/clock/bench/timers.ts index d8803805130..6f14da95c42 100644 --- a/js/clock/bench/timers.ts +++ b/js/clock/bench/timers.ts @@ -1,5 +1,6 @@ // Sweep armed timers x timers made ready, with independent and shared abort scopes. -import { Duration, Manual, sleep } from "../src/index.ts"; +import { Duration, sleep } from "../src/index.ts"; +import { Manual } from "../src/test.ts"; console.log("mode,scope,armed,ready,arm_us,advance_us,cancel_us"); for (const mode of ["jump", "advance"]) { diff --git a/js/clock/src/index.test.ts b/js/clock/src/index.test.ts index 164395eef19..3c11c1bc4bc 100644 --- a/js/clock/src/index.test.ts +++ b/js/clock/src/index.test.ts @@ -7,7 +7,6 @@ import { type Installed, Instant, interval, - Manual, MissedTickBehavior, now, origin, @@ -19,7 +18,7 @@ import { wall, yieldNow, } from "./index.ts"; -import { hostTime } from "./test.ts"; +import { hostTime, Manual } from "./test.ts"; const installs: Installed[] = []; afterEach(() => { diff --git a/js/clock/src/index.ts b/js/clock/src/index.ts index 7c6927d55f7..ddc8c6810ed 100644 --- a/js/clock/src/index.ts +++ b/js/clock/src/index.ts @@ -1,6 +1,6 @@ /** * Logical monotonic time, wall time, and timers from one clock per JS realm. - * Install a Manual clock for deterministic tests without replacing host timers. + * Tests install a `Manual` clock from `@moq/clock/test` without replacing host timers. * * @module */ @@ -9,7 +9,6 @@ import { backend } from "./ambient.ts"; import { type Wall, wallOf } from "./types.ts"; export type { Installed } from "./ambient.ts"; -export { Manual } from "./manual.ts"; export { Elapsed, Interval, diff --git a/js/clock/src/test.ts b/js/clock/src/test.ts index 5b5e9bc08b5..605518a7908 100644 --- a/js/clock/src/test.ts +++ b/js/clock/src/test.ts @@ -6,6 +6,8 @@ import { guard } from "./host.ts"; +export { Manual } from "./manual.ts"; + /** * Let the current test's timers fire on the host clock, for real sockets, devices, or processes. * Call it in the test or a `beforeEach`; it does nothing without the `@moq/clock` test preload. diff --git a/js/hang/src/container/consumer.backpressure.test.ts b/js/hang/src/container/consumer.backpressure.test.ts index 7a39e2c4dc5..58e421d08d7 100644 --- a/js/hang/src/container/consumer.backpressure.test.ts +++ b/js/hang/src/container/consumer.backpressure.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Elapsed, Instant, Manual, timeout } from "@moq/clock"; +import { Duration, Elapsed, Instant, timeout } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Time, Track } from "@moq/net"; import { Consumer, type Read } from "./consumer.ts"; import { encodeFrame, Format } from "./legacy.ts"; diff --git a/js/hang/src/container/consumer.holes.test.ts b/js/hang/src/container/consumer.holes.test.ts index 7f5dc747082..a159c0c9f9d 100644 --- a/js/hang/src/container/consumer.holes.test.ts +++ b/js/hang/src/container/consumer.holes.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Time, Track } from "@moq/net"; import { Consumer, type Read } from "./consumer.ts"; import { encodeFrame, Format } from "./legacy.ts"; diff --git a/js/hang/src/container/consumer.nonsequential.test.ts b/js/hang/src/container/consumer.nonsequential.test.ts index 7fed8b3bcbd..e54b7e5d21a 100644 --- a/js/hang/src/container/consumer.nonsequential.test.ts +++ b/js/hang/src/container/consumer.nonsequential.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, test } from "bun:test"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Group, Time, Track, Varint } from "@moq/net"; import { Consumer } from "./consumer.ts"; import { Format as LegacyFormat } from "./legacy.ts"; diff --git a/js/hang/src/container/consumer.outoforder.test.ts b/js/hang/src/container/consumer.outoforder.test.ts index 74330cec692..4bc403aaa23 100644 --- a/js/hang/src/container/consumer.outoforder.test.ts +++ b/js/hang/src/container/consumer.outoforder.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, test } from "bun:test"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Group, Time, Track, Varint } from "@moq/net"; import { Consumer } from "./consumer.ts"; import { Format as LegacyFormat } from "./legacy.ts"; diff --git a/js/hang/src/container/consumer.rewind.test.ts b/js/hang/src/container/consumer.rewind.test.ts index 403c911ad13..6cbe7554a70 100644 --- a/js/hang/src/container/consumer.rewind.test.ts +++ b/js/hang/src/container/consumer.rewind.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, test } from "bun:test"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Time, Track } from "@moq/net"; import { Consumer } from "./consumer"; import { encodeFrame, Format, Producer } from "./legacy"; diff --git a/js/hang/src/container/consumer.startup.test.ts b/js/hang/src/container/consumer.startup.test.ts index 1a7b486249c..67e32c7be63 100644 --- a/js/hang/src/container/consumer.startup.test.ts +++ b/js/hang/src/container/consumer.startup.test.ts @@ -1,5 +1,6 @@ import { expect, onTestFinished, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Group, Error as NetError, StreamCode, Time, Track } from "@moq/net"; import { Consumer, type Read } from "./consumer.ts"; import { encodeFrame, Format } from "./legacy.ts"; diff --git a/js/hang/src/container/consumer.test.ts b/js/hang/src/container/consumer.test.ts index 53731c956c3..fd7018ae712 100644 --- a/js/hang/src/container/consumer.test.ts +++ b/js/hang/src/container/consumer.test.ts @@ -1,6 +1,7 @@ import { afterEach, beforeEach, expect, spyOn, test } from "bun:test"; import { readFileSync } from "node:fs"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Format as LocFormat } from "@moq/loc"; import { type Group, Error as NetError, SessionCode, StreamCode, Time, Track, Varint } from "@moq/net"; import { decodeInitSegment, type InitSegment } from "../cmaf/decode.ts"; diff --git a/js/hang/src/container/consumer.warmup.test.ts b/js/hang/src/container/consumer.warmup.test.ts index d35d7668473..05ad34c35ad 100644 --- a/js/hang/src/container/consumer.warmup.test.ts +++ b/js/hang/src/container/consumer.warmup.test.ts @@ -1,5 +1,6 @@ import { expect, onTestFinished, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Group, Time, Track } from "@moq/net"; import { Consumer, type Read } from "./consumer.ts"; import { encodeFrame, Format } from "./legacy.ts"; diff --git a/js/json/src/snapshot/snapshot.test.ts b/js/json/src/snapshot/snapshot.test.ts index 39702a4c44b..695870b5dd8 100644 --- a/js/json/src/snapshot/snapshot.test.ts +++ b/js/json/src/snapshot/snapshot.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Error as NetError, StreamCode, Time, Track } from "@moq/net"; import { hooks } from "../../../net/src/internal.ts"; import { Consumer } from "./consumer.ts"; diff --git a/js/net/bench/drift.ts b/js/net/bench/drift.ts index 33bde3424d2..b8cd1ea003b 100644 --- a/js/net/bench/drift.ts +++ b/js/net/bench/drift.ts @@ -1,5 +1,6 @@ /** Sweep publishers, readers, and retained history for a parked frame read's drift check. */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Group, Time, Track } from "@moq/net"; import { hooks } from "../src/internal.ts"; diff --git a/js/net/bench/forward.ts b/js/net/bench/forward.ts index f6b647841aa..8abcc0c67e5 100644 --- a/js/net/bench/forward.ts +++ b/js/net/bench/forward.ts @@ -3,7 +3,7 @@ * a watch coming and going over held watches and attached sessions. */ -import { Manual } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { announcedView } from "../src/announced.test-util"; import * as Announce from "../src/announced.ts"; import { AuthSession } from "../src/auth_session.ts"; diff --git a/js/net/bench/refresh.ts b/js/net/bench/refresh.ts index 0dca76f3ce0..219b56f2394 100644 --- a/js/net/bench/refresh.ts +++ b/js/net/bench/refresh.ts @@ -1,5 +1,6 @@ /** Sweep retained groups, unrelated tracks, and joined readers for a refresh crossing one lite hop. */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { accept } from "../src/connection/accept.ts"; import { connect } from "../src/connection/connect.ts"; import { ALPN_07_WIP } from "../src/lite/version.ts"; diff --git a/js/net/bench/replay.ts b/js/net/bench/replay.ts index 7d445d1d692..7f78650ad02 100644 --- a/js/net/bench/replay.ts +++ b/js/net/bench/replay.ts @@ -1,5 +1,6 @@ /** Sweep cached-group replay to joining subscribers, and arrivals into unread backlogs. */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Track } from "@moq/net"; type Order = "monotonic" | "reverse" | "mixed"; diff --git a/js/net/bench/resume-history.ts b/js/net/bench/resume-history.ts index 2045992cbea..db707957199 100644 --- a/js/net/bench/resume-history.ts +++ b/js/net/bench/resume-history.ts @@ -16,7 +16,8 @@ * exposes `gc` and fails once a retired route stays reachable. Bun scans its stack conservatively, * so a dead reference there can survive a collection. */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import type { Producer as BroadcastProducer } from "../src/broadcast.ts"; import { accept } from "../src/connection/accept.ts"; import { connect } from "../src/connection/connect.ts"; diff --git a/js/net/package.json b/js/net/package.json index 19ccc9ccb1d..b996b74a770 100644 --- a/js/net/package.json +++ b/js/net/package.json @@ -25,8 +25,7 @@ "@moq/pattern": "workspace:^", "@moq/qmux": "workspace:^", "@moq/signals": "workspace:*", - "pako": "^3.0.3", - "sorted-btree": "^2.1.0" + "pako": "^3.0.3" }, "peerDependencies": { "zod": "^4.5.0" diff --git a/js/net/src/auth.test.ts b/js/net/src/auth.test.ts index 54117af06ad..97fa80c8bb6 100644 --- a/js/net/src/auth.test.ts +++ b/js/net/src/auth.test.ts @@ -1,5 +1,6 @@ import { describe, expect, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Credential, Duplicate, diff --git a/js/net/src/broadcast.test.ts b/js/net/src/broadcast.test.ts index 0921b47fa9f..9b7f472bffa 100644 --- a/js/net/src/broadcast.test.ts +++ b/js/net/src/broadcast.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; import * as cache from "./cache.ts"; import { NotFound, StreamCode, toStreamCode } from "./error.ts"; diff --git a/js/net/src/cache.test.ts b/js/net/src/cache.test.ts index 675ed6b8530..607c4133f33 100644 --- a/js/net/src/cache.test.ts +++ b/js/net/src/cache.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as cache from "./cache.ts"; import { StreamCode, StreamError, TooFarBehind } from "./error.ts"; import { hooks, staleHole } from "./internal.ts"; diff --git a/js/net/src/connection/bandwidth.test.ts b/js/net/src/connection/bandwidth.test.ts index 91948b57ab6..ebddddda04d 100644 --- a/js/net/src/connection/bandwidth.test.ts +++ b/js/net/src/connection/bandwidth.test.ts @@ -1,5 +1,6 @@ import { afterEach, expect, spyOn, test } from "bun:test"; -import { Duration, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Lite from "../lite/index.ts"; import { createMockTransportPair, type MockTransport } from "../mock.ts"; import { Producer as TrackProducer } from "../track.ts"; diff --git a/js/net/src/connection/close.test.ts b/js/net/src/connection/close.test.ts index e131f521aba..2f998961ab0 100644 --- a/js/net/src/connection/close.test.ts +++ b/js/net/src/connection/close.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Ietf from "../ietf/index.ts"; import * as Lite from "../lite/index.ts"; import { createMockTransportPair, type MockTransport } from "../mock.ts"; diff --git a/js/net/src/connection/connect.test.ts b/js/net/src/connection/connect.test.ts index 3c485665b2a..e8d932bad2d 100644 --- a/js/net/src/connection/connect.test.ts +++ b/js/net/src/connection/connect.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Instant, Manual, sleep, yieldNow } from "@moq/clock"; -import { hostTime } from "@moq/clock/test"; +import { Duration, Instant, sleep, yieldNow } from "@moq/clock"; +import { hostTime, Manual } from "@moq/clock/test"; import { Session as Qmux, selectSubprotocol, type WebSocketLike } from "@moq/qmux"; import { ConnectTimeout, SessionCode, SessionError } from "../error.ts"; import * as Ietf from "../ietf/index.ts"; diff --git a/js/net/src/connection/forward.test.ts b/js/net/src/connection/forward.test.ts index ae4629173fc..fded70ba6f0 100644 --- a/js/net/src/connection/forward.test.ts +++ b/js/net/src/connection/forward.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, jest, spyOn, test } from "bun:test"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Announce from "../announced.ts"; import { AuthSession } from "../auth_session.ts"; import { type Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "../broadcast.ts"; diff --git a/js/net/src/connection/migrate.test.ts b/js/net/src/connection/migrate.test.ts index 1fa6c19ad2d..fe5d16f5552 100644 --- a/js/net/src/connection/migrate.test.ts +++ b/js/net/src/connection/migrate.test.ts @@ -1,5 +1,6 @@ import { afterEach, expect, spyOn, test } from "bun:test"; -import { Duration, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { RefusedRedirect } from "../error.ts"; import * as Lite from "../lite/index.ts"; import { createMockTransportPair } from "../mock.ts"; diff --git a/js/net/src/connection/pool.test.ts b/js/net/src/connection/pool.test.ts index 643845b9e00..f04a407bbd1 100644 --- a/js/net/src/connection/pool.test.ts +++ b/js/net/src/connection/pool.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, test } from "bun:test"; -import { Duration, type Installed, Manual } from "@moq/clock"; +import { Duration, type Installed } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Signal } from "@moq/signals"; import { SessionCode, SessionError } from "../error.ts"; import * as Lite from "../lite/index.ts"; diff --git a/js/net/src/connection/reload.test.ts b/js/net/src/connection/reload.test.ts index 4b5b75ec90e..0439262c224 100644 --- a/js/net/src/connection/reload.test.ts +++ b/js/net/src/connection/reload.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, type Instant, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, type Instant, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Session as Qmux, type WebSocketStreamLike } from "@moq/qmux"; import { Effect, type Getter, Signal } from "@moq/signals"; import * as Announce from "../announced.ts"; diff --git a/js/net/src/connection/stats.test.ts b/js/net/src/connection/stats.test.ts index 917f898720c..570274af09c 100644 --- a/js/net/src/connection/stats.test.ts +++ b/js/net/src/connection/stats.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Session as QmuxSession } from "@moq/qmux"; import { Effect } from "@moq/signals"; import * as Ietf from "../ietf/index.ts"; diff --git a/js/net/src/connection/ticker.test.ts b/js/net/src/connection/ticker.test.ts index 9e9e4f74025..a4cd5a28e10 100644 --- a/js/net/src/connection/ticker.test.ts +++ b/js/net/src/connection/ticker.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { tick } from "./ticker.ts"; test("subscribers share one tick and the loop stops with the last", async () => { diff --git a/js/net/src/fill.test.ts b/js/net/src/fill.test.ts index bde1ffc93a3..96fdb714fb8 100644 --- a/js/net/src/fill.test.ts +++ b/js/net/src/fill.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Producer as BroadcastProducer } from "./broadcast.ts"; import { accept as acceptSession, connect as connectSession } from "./connection/index.ts"; import { NotFound, StreamCode, StreamError, toStreamCode } from "./error.ts"; diff --git a/js/net/src/goaway-requests.test.ts b/js/net/src/goaway-requests.test.ts index d27f5a184c3..e68f74f3cd1 100644 --- a/js/net/src/goaway-requests.test.ts +++ b/js/net/src/goaway-requests.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Once } from "@moq/signals"; import { accept } from "./connection/accept.ts"; import { connect } from "./connection/connect.ts"; diff --git a/js/net/src/group.test.ts b/js/net/src/group.test.ts index 18a4c5e615c..c603e8ad3b4 100644 --- a/js/net/src/group.test.ts +++ b/js/net/src/group.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Signal } from "@moq/signals"; import { FrameTooLarge, StreamCode, StreamError } from "./error.ts"; import { encodable } from "./flate/group.ts"; diff --git a/js/net/src/ietf/aliases.test.ts b/js/net/src/ietf/aliases.test.ts index de0b942fe17..344af83f827 100644 --- a/js/net/src/ietf/aliases.test.ts +++ b/js/net/src/ietf/aliases.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { DuplicateTrackAlias, RetiredTrackAlias, SharedTrackAlias, TrackAliases } from "./aliases.ts"; test("waits for the control message that establishes an alias", async () => { diff --git a/js/net/src/ietf/join.test.ts b/js/net/src/ietf/join.test.ts index 0ae451fba79..7d6bf381bb0 100644 --- a/js/net/src/ietf/join.test.ts +++ b/js/net/src/ietf/join.test.ts @@ -1,5 +1,6 @@ import { expect, jest, onTestFinished, test } from "bun:test"; -import { Duration, Manual, now } from "@moq/clock"; +import { Duration, now } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Connection from "../connection/index.ts"; import { StreamCode } from "../error.ts"; import { hooks } from "../internal.ts"; diff --git a/js/net/src/ietf/malformed.test.ts b/js/net/src/ietf/malformed.test.ts index 338052db693..398d447804b 100644 --- a/js/net/src/ietf/malformed.test.ts +++ b/js/net/src/ietf/malformed.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, type Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import type { Manual } from "@moq/clock/test"; import { offered } from "../connection/extensions.ts"; import { exchangeSetup } from "../connection/handshake.ts"; import { ProtocolViolation, SessionCode, StreamCode, StreamError } from "../error.ts"; diff --git a/js/net/src/ietf/publisher.test.ts b/js/net/src/ietf/publisher.test.ts index 50a4ecd7c16..6ad40173ee6 100644 --- a/js/net/src/ietf/publisher.test.ts +++ b/js/net/src/ietf/publisher.test.ts @@ -1,5 +1,6 @@ import { expect, onTestFinished, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Signal } from "@moq/signals"; import type { Credential, Grant } from "../auth.ts"; import { Producer as BroadcastProducer } from "../broadcast.ts"; diff --git a/js/net/src/ietf/request_stream.test.ts b/js/net/src/ietf/request_stream.test.ts index 7875f20a354..85746837863 100644 --- a/js/net/src/ietf/request_stream.test.ts +++ b/js/net/src/ietf/request_stream.test.ts @@ -1,5 +1,6 @@ import { expect, mock, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { ProtocolViolation, SessionCode, StreamCode, StreamError } from "../error.ts"; import { manual, settlesWithin } from "../mock.ts"; import { Reader, Stream } from "../stream.ts"; diff --git a/js/net/src/ietf/subscriber.test.ts b/js/net/src/ietf/subscriber.test.ts index 4c3ac4ffe05..4dcd964d106 100644 --- a/js/net/src/ietf/subscriber.test.ts +++ b/js/net/src/ietf/subscriber.test.ts @@ -1,5 +1,6 @@ import { expect, jest, onTestFinished, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Once } from "@moq/signals"; import type * as announce from "../announced.ts"; import { ProtocolViolation, StreamCode, Stream as StreamError } from "../error.ts"; diff --git a/js/net/src/ietf/tail.test.ts b/js/net/src/ietf/tail.test.ts index 8f1a868e32e..c2b880d8693 100644 --- a/js/net/src/ietf/tail.test.ts +++ b/js/net/src/ietf/tail.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { ProtocolViolation, StreamCode, StreamError } from "../error.ts"; import type { Consumer as GroupConsumer } from "../group.ts"; import { hooks } from "../internal.ts"; diff --git a/js/net/src/integration.test.ts b/js/net/src/integration.test.ts index 7e48c1c73f3..cc5f138123e 100644 --- a/js/net/src/integration.test.ts +++ b/js/net/src/integration.test.ts @@ -1,5 +1,6 @@ import { afterEach, expect, mock, onTestFinished, spyOn, test } from "bun:test"; -import { Duration, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Session as Qmux } from "@moq/qmux"; import type * as Announce from "./announced.ts"; import { type Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; diff --git a/js/net/src/ledger.ts b/js/net/src/ledger.ts index 4a99d35339c..100f87491bf 100644 --- a/js/net/src/ledger.ts +++ b/js/net/src/ledger.ts @@ -1,10 +1,6 @@ import { Duration, type Instant } from "@moq/clock"; -import * as btree from "sorted-btree"; import { max, min } from "./util/sequence.ts"; - -// sorted-btree ships only CommonJS: Node binds its default import to `module.exports`, -// while Bun and bundlers bind it to the class. -const BTree = (btree.default as unknown as { default?: typeof btree.default }).default ?? btree.default; +import { Sorted } from "./util/sorted.ts"; const compare = (a: bigint, b: bigint): number => (a < b ? -1 : a > b ? 1 : 0); @@ -45,23 +41,30 @@ export class Ledger { // can no longer be waited for, so it folds into the runs around it, which bounds this by // the gaps opened within the grace rather than every gap ever seen. A fold is final: a // later, longer grace or a lowered floor cannot reopen it. - #runs = new BTree(undefined, compare); + #runs = new Sorted((run) => run.start, compare); // Demand can restart a gap below an older one. Index ages separately so expiring // one gap never scans all the younger ones. Both indexes own exactly the same runs. - #ages = new BTree(undefined, (a, b) => a.since.cmp(b.since) || compare(a.start, b.start)); + #ages = new Sorted( + (run) => run, + (a, b) => a.since.cmp(b.since) || compare(a.start, b.start), + ); #last?: Run; // Exclude the leading gap, which has no lower run to fold into. #next?: Run; + #insert(run: Run): void { + this.#runs.insert(run); + this.#ages.insert(run); + } + #remove(run: Run): void { this.#runs.delete(run.start); this.#ages.delete(run); } #nextExpiry(): void { - const first = this.#runs.minKey(); - const oldest = this.#ages.minKey(); - this.#next = oldest?.start === first ? this.#ages.nextHigherKey(oldest) : oldest; + const oldest = this.#ages.first(); + this.#next = oldest && oldest === this.#runs.first() ? this.#ages.higher(oldest) : oldest; } /** Record sequences `[start, end)` as accounted for. Gaps fold only on {@link expire}. */ @@ -75,24 +78,21 @@ export class Ledger { return; } - const lower = this.#runs.getPairOrNextLower(start)?.[1]; + const lower = this.#runs.floor(start); const below = lower && lower.end >= start ? lower : undefined; if (below && end <= below.end) return; // Splitting a gap inherits its age; only an arrival past all runs opens a new one. - const run = below ?? { start, end, since: this.#runs.getPairOrNextHigher(start)?.[1].since ?? at }; + const run = below ?? { start, end, since: this.#runs.ceil(start)?.since ?? at }; run.end = max(run.end, end); - let next = this.#runs.getPairOrNextHigher(start); - if (next?.[1] === below) next = this.#runs.nextHigherPair(start); - while (next && next[0] <= run.end) { - run.end = max(run.end, next[1].end); - this.#remove(next[1]); - next = this.#runs.nextHigherPair(next[0]); - } - if (!below) { - this.#runs.set(run.start, run); - this.#ages.set(run, undefined); + let next = this.#runs.ceil(start); + if (next === below) next = this.#runs.higher(start); + while (next && next.start <= run.end) { + run.end = max(run.end, next.end); + this.#remove(next); + next = this.#runs.higher(next.start); } + if (!below) this.#insert(run); if (!next) this.#last = run; this.#nextExpiry(); } @@ -101,7 +101,7 @@ export class Ledger { expire(at: Instant, grace: Duration): void { while (this.#next && at.since(this.#next.since).ge(grace)) { const run = this.#next; - const below = this.#runs.nextLowerPair(run.start)?.[1]; + const below = this.#runs.lower(run.start); if (!below) throw new Error("an expiring gap must have a lower run"); below.end = run.end; this.#remove(run); @@ -117,7 +117,7 @@ export class Ledger { foldOldest(): { start: bigint; end: bigint } | undefined { const run = this.#next; if (!run) return undefined; - const below = this.#runs.nextLowerPair(run.start)?.[1]; + const below = this.#runs.lower(run.start); if (!below) throw new Error("a folding gap must have a lower run"); const gap = { start: below.end, end: run.start }; below.end = run.end; @@ -139,25 +139,25 @@ export class Ledger { /** The lowest sequence accounted for. */ first(): bigint | undefined { - return this.#runs.minKey(); + return this.#runs.first()?.start; } /** The exclusive end of the run accounting for `sequence`, undefined when none does. */ runEnd(sequence: bigint): bigint | undefined { - const run = this.#runs.getPairOrNextLower(sequence)?.[1]; + const run = this.#runs.floor(sequence); return run !== undefined && sequence < run.end ? run.end : undefined; } /** The exclusive end of the highest run starting at or below `sequence`. */ endBelow(sequence: bigint): bigint | undefined { - return this.#runs.getPairOrNextLower(sequence)?.[1].end; + return this.#runs.floor(sequence)?.end; } /** Whether every sequence in `[start, end)` is accounted for. */ covers(start: bigint, end: bigint): boolean { if (start >= end) return true; // Runs merge on insert, so one run covers the span or none does. - const run = this.#runs.getPairOrNextLower(start)?.[1]; + const run = this.#runs.floor(start); return run !== undefined && end <= run.end; } @@ -168,8 +168,8 @@ export class Ledger { gaps(start: bigint, end: bigint): { start: bigint; end: bigint; since?: Instant }[] { const gaps: { start: bigint; end: bigint; since?: Instant }[] = []; let below = start; - const lower = this.#runs.getPairOrNextLower(start)?.[1]; - for (const [, run] of this.#runs.entries(lower?.start ?? start)) { + const lower = this.#runs.floor(start); + for (const run of this.#runs.from(lower?.start ?? start)) { if (below >= end) return gaps; if (run.end <= below) continue; if (below < run.start) gaps.push({ start: below, end: min(run.start, end), since: run.since }); @@ -186,9 +186,9 @@ export class Ledger { */ unaccount(start: bigint, end: bigint, at: Instant): void { if (start >= end) return; - const lower = this.#runs.getPairOrNextLower(start)?.[1]; + const lower = this.#runs.floor(start); const overlapping: Run[] = []; - for (const [, run] of this.#runs.entries(lower?.start ?? start)) { + for (const run of this.#runs.from(lower?.start ?? start)) { if (run.start >= end) break; if (run.end > start) overlapping.push(run); } @@ -197,32 +197,27 @@ export class Ledger { this.#remove(run); if (this.#last === run) this.#last = undefined; if (run.start < start) { - const below = { start: run.start, end: start, since: run.since }; - this.#runs.set(below.start, below); - this.#ages.set(below, undefined); + this.#insert({ start: run.start, end: start, since: run.since }); } if (end < run.end) { - const above = { start: end, end: run.end, since: at }; - this.#runs.set(above.start, above); - this.#ages.set(above, undefined); + this.#insert({ start: end, end: run.end, since: at }); } } - const last = this.#runs.maxKey(); - this.#last = last === undefined ? undefined : this.#runs.get(last); + this.#last = this.#runs.last(); this.demand(start, end, at); } /** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */ demand(start: bigint, end: bigint, at: Instant): void { if (start >= end) return; - const lower = this.#runs.getPairOrNextLower(start)?.[1]; + const lower = this.#runs.floor(start); let below = lower?.end ?? 0n; - for (const [, run] of this.#runs.entries(start)) { + for (const run of this.#runs.from(start)) { if (below >= end) break; if (start < run.start) { this.#ages.delete(run); run.since = at; - this.#ages.set(run, undefined); + this.#ages.insert(run); } below = run.end; } diff --git a/js/net/src/lite/compression.test.ts b/js/net/src/lite/compression.test.ts index 59860840d29..276a0b1ba87 100644 --- a/js/net/src/lite/compression.test.ts +++ b/js/net/src/lite/compression.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { accept } from "../connection/accept.ts"; import { connect } from "../connection/connect.ts"; import { createMockTransportPair } from "../mock.ts"; diff --git a/js/net/src/lite/connection.test.ts b/js/net/src/lite/connection.test.ts index b30ae3cc49e..88e89d64336 100644 --- a/js/net/src/lite/connection.test.ts +++ b/js/net/src/lite/connection.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Session as Qmux } from "@moq/qmux"; import { accept } from "../connection/accept.ts"; import { connect } from "../connection/connect.ts"; diff --git a/js/net/src/lite/copy_fill.test.ts b/js/net/src/lite/copy_fill.test.ts index d6a8ce7a9d2..deeefd64568 100644 --- a/js/net/src/lite/copy_fill.test.ts +++ b/js/net/src/lite/copy_fill.test.ts @@ -3,7 +3,8 @@ // SUBSCRIBE of its own, as its `Recovery` does: below where the copy's feed started, by the copy's // start rule, and inside the copy, once it evicted what it received. import { expect, test } from "bun:test"; -import { Duration, Elapsed, Manual, sleep, timeout } from "@moq/clock"; +import { Duration, Elapsed, sleep, timeout } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { DEFAULT_EXPIRY } from "../cache.ts"; import { accept as acceptSession, connect as connectSession } from "../connection/index.ts"; import { StreamCode, StreamError } from "../error.ts"; diff --git a/js/net/src/lite/drop_record.test.ts b/js/net/src/lite/drop_record.test.ts index cdd307ef151..3341c1f3c7a 100644 --- a/js/net/src/lite/drop_record.test.ts +++ b/js/net/src/lite/drop_record.test.ts @@ -3,7 +3,8 @@ // all on mock transports and a manual clock. Mirrors rs/moq-net/tests/integration/drop_record.rs. import { afterEach, expect, mock, spyOn, test } from "bun:test"; -import { Duration, Elapsed, type Manual, timeout } from "@moq/clock"; +import { Duration, Elapsed, timeout } from "@moq/clock"; +import type { Manual } from "@moq/clock/test"; import * as cache from "../cache.ts"; import { accept, connect } from "../connection/index.ts"; import { StreamCode, StreamError, TooFarBehind, toStreamCode } from "../error.ts"; diff --git a/js/net/src/lite/publisher.test.ts b/js/net/src/lite/publisher.test.ts index 3dcf268056c..5eecdf35e0b 100644 --- a/js/net/src/lite/publisher.test.ts +++ b/js/net/src/lite/publisher.test.ts @@ -1,5 +1,6 @@ import { expect, mock, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Signal } from "@moq/signals"; import type { Grant } from "../auth.ts"; import { Producer as BroadcastProducer } from "../broadcast.ts"; diff --git a/js/net/src/lite/refresh.test.ts b/js/net/src/lite/refresh.test.ts index ed68142e56f..12e2866d035 100644 --- a/js/net/src/lite/refresh.test.ts +++ b/js/net/src/lite/refresh.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { accept } from "../connection/accept.ts"; import { connect } from "../connection/connect.ts"; import { createMockTransportPair } from "../mock.ts"; diff --git a/js/net/src/lite/subscriber.test.ts b/js/net/src/lite/subscriber.test.ts index 32929730997..212fd5e044a 100644 --- a/js/net/src/lite/subscriber.test.ts +++ b/js/net/src/lite/subscriber.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Elapsed, Manual, timeout, yieldNow } from "@moq/clock"; +import { Duration, Elapsed, timeout, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Getter, Signal } from "@moq/signals"; import type { RouteOptions } from "../announced.ts"; import type { Grant } from "../auth.ts"; diff --git a/js/net/src/lite/tail.test.ts b/js/net/src/lite/tail.test.ts index b13528c12dc..5384bfc5895 100644 --- a/js/net/src/lite/tail.test.ts +++ b/js/net/src/lite/tail.test.ts @@ -1,5 +1,6 @@ import { describe, expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { ProtocolViolation, StreamCode, StreamError } from "../error.ts"; import type { Consumer as GroupConsumer } from "../group.ts"; import { randomHop } from "../hop.ts"; diff --git a/js/net/src/mock.ts b/js/net/src/mock.ts index c9bd5936cb7..f92a7fe3c61 100644 --- a/js/net/src/mock.ts +++ b/js/net/src/mock.ts @@ -4,7 +4,8 @@ * Creates paired client/server transports connected by in-memory streams. */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import type { Getter } from "@moq/signals"; import { Consumer as BroadcastConsumer } from "./broadcast.ts"; import type { TransportStats } from "./connection/stats.ts"; diff --git a/js/net/src/net-cleanups.test.ts b/js/net/src/net-cleanups.test.ts index 6a1c7f02eda..43ba5a1053e 100644 --- a/js/net/src/net-cleanups.test.ts +++ b/js/net/src/net-cleanups.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { accept } from "./connection/accept.ts"; import { connect } from "./connection/connect.ts"; import { ConnectTimeout } from "./error.ts"; diff --git a/js/net/src/open.test.ts b/js/net/src/open.test.ts index 20f233b8e1d..c4513f1f187 100644 --- a/js/net/src/open.test.ts +++ b/js/net/src/open.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Session as Qmux } from "@moq/qmux"; import { Version } from "./lite/version.ts"; import { createMockTransportPair } from "./mock.ts"; diff --git a/js/net/src/parked-expiry.test.ts b/js/net/src/parked-expiry.test.ts index ca6c393ef20..7421e66aa0f 100644 --- a/js/net/src/parked-expiry.test.ts +++ b/js/net/src/parked-expiry.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { StreamCode } from "./error.ts"; import { randomHop } from "./hop.ts"; import { Publisher as IetfPublisher } from "./ietf/publisher.ts"; diff --git a/js/net/src/request-deadline.test.ts b/js/net/src/request-deadline.test.ts index 46e8e3b9e98..f37e2905d33 100644 --- a/js/net/src/request-deadline.test.ts +++ b/js/net/src/request-deadline.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { SessionCode, SessionError } from "./error.ts"; import { HopSchema } from "./hop.ts"; import { NativeSession } from "./ietf/session.ts"; diff --git a/js/net/src/resume.model.test.ts b/js/net/src/resume.model.test.ts index cc210425f44..3c59f6ebed2 100644 --- a/js/net/src/resume.model.test.ts +++ b/js/net/src/resume.model.test.ts @@ -12,7 +12,8 @@ */ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import fc from "fast-check"; import { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; import { NotFound, StreamCode, StreamError, TooFarBehind } from "./error.ts"; diff --git a/js/net/src/resume.test.ts b/js/net/src/resume.test.ts index be37d471d92..b479a39c6dd 100644 --- a/js/net/src/resume.test.ts +++ b/js/net/src/resume.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; import * as cache from "./cache.ts"; import { NotFound, SessionCode, SessionError, StreamCode, StreamError } from "./error.ts"; diff --git a/js/net/src/socket.test.ts b/js/net/src/socket.test.ts index cd76e168adb..5f3322c3eed 100644 --- a/js/net/src/socket.test.ts +++ b/js/net/src/socket.test.ts @@ -1,5 +1,6 @@ import { afterEach, expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { type Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; import { accept as acceptConnection } from "./connection/accept.ts"; import { connect } from "./connection/connect.ts"; diff --git a/js/net/src/subscribe_priority.test.ts b/js/net/src/subscribe_priority.test.ts index 06dfa5569e3..7038fff86ee 100644 --- a/js/net/src/subscribe_priority.test.ts +++ b/js/net/src/subscribe_priority.test.ts @@ -3,7 +3,8 @@ // relay case lives with the Rust relay (rs/moq-net/tests/integration/subscribe_priority.rs). import { expect, spyOn, test } from "bun:test"; -import { Manual, yieldNow } from "@moq/clock"; +import { yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { accept, connect, type Session } from "./connection/index.ts"; import * as Ietf from "./ietf/index.ts"; import { SubscribeUpdate } from "./ietf/subscribe.ts"; diff --git a/js/net/src/tail.test.ts b/js/net/src/tail.test.ts index d9b8871f0fc..5a6b7b9a016 100644 --- a/js/net/src/tail.test.ts +++ b/js/net/src/tail.test.ts @@ -1,5 +1,6 @@ import { afterEach, describe, expect, test } from "bun:test"; -import { Duration, type Installed, Instant, Manual } from "@moq/clock"; +import { Duration, type Installed, Instant } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Once } from "@moq/signals"; import { accept, connect } from "./connection/index.ts"; import * as Ietf from "./ietf/index.ts"; diff --git a/js/net/src/track.test.ts b/js/net/src/track.test.ts index 51d1cb4c65d..b68c1183e0b 100644 --- a/js/net/src/track.test.ts +++ b/js/net/src/track.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Instant, Manual, Wall, yieldNow } from "@moq/clock"; +import { Duration, Instant, Wall, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { race } from "@moq/signals"; import { DEFAULT_EXPIRY } from "./cache.ts"; import { ProtocolViolation, Skipped, StreamCode, StreamError, TimestampMismatch, TooFarBehind } from "./error.ts"; diff --git a/js/net/src/util/sorted.test.ts b/js/net/src/util/sorted.test.ts new file mode 100644 index 00000000000..c871812faf3 --- /dev/null +++ b/js/net/src/util/sorted.test.ts @@ -0,0 +1,57 @@ +import { expect, test } from "bun:test"; +import fc from "fast-check"; +import { Sorted } from "./sorted.ts"; + +type Op = { insert: boolean; key: number }; + +// Enough distinct keys and operations to split, merge, and empty chunks of 256. +const ops = fc.array(fc.record({ insert: fc.boolean(), key: fc.integer({ min: 0, max: 3000 }) }), { + maxLength: 4000, + size: "max", +}); + +test("agrees with a sorted array on every lookup after any inserts and deletes", () => { + fc.assert( + fc.property(ops, fc.integer({ min: -1, max: 3001 }), (ops: Op[], probe) => { + const sorted = new Sorted( + (value) => value.key, + (a, b) => a - b, + ); + const model = new Set(); + for (const { insert, key } of ops) { + if (insert && !model.has(key)) { + sorted.insert({ key }); + model.add(key); + } else if (!insert) { + sorted.delete(key); + model.delete(key); + } + } + const keys = [...model].sort((a, b) => a - b); + expect(sorted.size).toBe(keys.length); + expect([...sorted.from(-1)].map((value) => value.key)).toEqual(keys); + expect(sorted.first()?.key).toBe(keys[0]); + expect(sorted.last()?.key).toBe(keys.at(-1)); + for (const key of [probe, ...keys.slice(0, 50)]) { + expect(sorted.ceil(key)?.key).toBe(keys.find((k) => k >= key)); + expect(sorted.higher(key)?.key).toBe(keys.find((k) => k > key)); + expect(sorted.floor(key)?.key).toBe(keys.findLast((k) => k <= key)); + expect(sorted.lower(key)?.key).toBe(keys.findLast((k) => k < key)); + expect([...sorted.from(key)].map((value) => value.key)).toEqual(keys.filter((k) => k >= key)); + } + }), + { numRuns: 100 }, + ); +}); + +test("draining in any order empties every chunk", () => { + const sorted = new Sorted( + (value) => value, + (a, b) => a - b, + ); + for (let i = 0; i < 5000; i++) sorted.insert((i * 7919) % 5000); + for (let i = 0; i < 5000; i++) sorted.delete((i * 104729) % 5000); + expect(sorted.size).toBe(0); + expect(sorted.first()).toBeUndefined(); + expect([...sorted.from(0)]).toEqual([]); +}); diff --git a/js/net/src/util/sorted.ts b/js/net/src/util/sorted.ts new file mode 100644 index 00000000000..78c0d021d2b --- /dev/null +++ b/js/net/src/util/sorted.ts @@ -0,0 +1,153 @@ +// Chunks stay between LOAD / 2 and 2 * LOAD entries, so an insert or delete shifts one chunk +// and the chunk index rather than the whole collection. +const LOAD = 256; + +/** + * Distinct values ordered by a key, with neighbor lookups by key. + * + * Kept in sorted chunks, the layout of Python's `sortedcontainers`: a lookup is two binary + * searches, and an insert or delete costs O(log n + LOAD + n / LOAD) moves. Callers must not + * change a stored value's key, and must not mutate the list while iterating {@link from}. + * + * @internal + */ +export class Sorted { + #chunks: V[][] = []; + #size = 0; + // The position the last #seek found. + #c = 0; + #i = 0; + readonly #key: (value: V) => K; + readonly #compare: (a: K, b: K) => number; + + constructor(key: (value: V) => K, compare: (a: K, b: K) => number) { + this.#key = key; + this.#compare = compare; + } + + /** How many values it holds. */ + get size(): number { + return this.#size; + } + + /** The value with the lowest key. */ + first(): V | undefined { + return this.#chunks[0]?.[0]; + } + + /** The value with the highest key. */ + last(): V | undefined { + return this.#chunks.at(-1)?.at(-1); + } + + /** The value with the lowest key at or above `key`. */ + ceil(key: K): V | undefined { + this.#seek(key, true); + return this.#at(); + } + + /** The value with the lowest key above `key`. */ + higher(key: K): V | undefined { + this.#seek(key, false); + return this.#at(); + } + + /** The value with the highest key at or below `key`. */ + floor(key: K): V | undefined { + this.#seek(key, false); + return this.#before(); + } + + /** The value with the highest key below `key`. */ + lower(key: K): V | undefined { + this.#seek(key, true); + return this.#before(); + } + + /** Every value with a key at or above `key`, in order. */ + *from(key: K): Generator { + this.#seek(key, true); + let i = this.#i; + for (let c = this.#c; c < this.#chunks.length; c++, i = 0) { + const chunk = this.#chunks[c]; + for (; i < chunk.length; i++) yield chunk[i]; + } + } + + /** Add `value`, whose key no stored value has. */ + insert(value: V): void { + this.#size++; + const last = this.#chunks.length - 1; + if (last < 0) { + this.#chunks.push([value]); + return; + } + this.#seek(this.#key(value), false); + let c = this.#c; + let i = this.#i; + if (c > last) { + c = last; + i = this.#chunks[last].length; + } + const chunk = this.#chunks[c]; + chunk.splice(i, 0, value); + if (chunk.length > 2 * LOAD) this.#chunks.splice(c + 1, 0, chunk.splice(LOAD)); + } + + /** Remove the value stored under `key`, if any. */ + delete(key: K): void { + this.#seek(key, true); + const c = this.#c; + const i = this.#i; + const chunk = this.#chunks[c]; + if (!chunk || this.#compare(this.#key(chunk[i]), key) !== 0) return; + this.#size--; + chunk.splice(i, 1); + if (this.#chunks.length === 1) { + if (chunk.length === 0) this.#chunks.pop(); + } else if (chunk.length < LOAD / 2) { + // Merge into a neighbor so chunks stay large enough to keep the chunk index short. + const a = c > 0 ? c - 1 : c; + const merged = this.#chunks[a].concat(this.#chunks[a + 1]); + const half = merged.length >>> 1; + if (merged.length > 2 * LOAD) this.#chunks.splice(a, 2, merged.slice(0, half), merged.slice(half)); + else this.#chunks.splice(a, 2, merged); + } + } + + // Point `#c` and `#i` at the first value whose key is above `key`, or at or above it when + // `inclusive`. Fields rather than a returned pair, so a lookup allocates nothing. + #seek(key: K, inclusive: boolean): void { + let lo = 0; + let hi = this.#chunks.length; + while (lo < hi) { + const mid = (lo + hi) >>> 1; + const chunk = this.#chunks[mid]; + if (this.#above(chunk[chunk.length - 1], key, inclusive)) hi = mid; + else lo = mid + 1; + } + this.#c = lo; + const chunk = this.#chunks[lo]; + lo = 0; + hi = chunk?.length ?? 0; + while (lo < hi) { + const mid = (lo + hi) >>> 1; + if (this.#above(chunk[mid], key, inclusive)) hi = mid; + else lo = mid + 1; + } + this.#i = lo; + } + + #above(value: V, key: K, inclusive: boolean): boolean { + const order = this.#compare(this.#key(value), key); + return inclusive ? order >= 0 : order > 0; + } + + #at(): V | undefined { + return this.#chunks[this.#c]?.[this.#i]; + } + + #before(): V | undefined { + return this.#i > 0 ? this.#chunks[this.#c][this.#i - 1] : this.#chunks[this.#c - 1]?.at(-1); + } +} diff --git a/js/net/src/util/timeout.test.ts b/js/net/src/util/timeout.test.ts index b83af8a2e8d..38ab4d923bf 100644 --- a/js/net/src/util/timeout.test.ts +++ b/js/net/src/util/timeout.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { TimeoutError, withTimeout } from "./timeout.ts"; test("withTimeout: resolves before deadline", async () => { diff --git a/js/p2p/src/transport.test.ts b/js/p2p/src/transport.test.ts index 1024733a003..66e2bfc0676 100644 --- a/js/p2p/src/transport.test.ts +++ b/js/p2p/src/transport.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Channel } from "./channel.ts"; import { peers } from "./mock.ts"; import { Transport } from "./transport.ts"; diff --git a/js/publish/bench/audio-page.ts b/js/publish/bench/audio-page.ts index 08bbc0d44ef..cf7e9a64d6d 100644 --- a/js/publish/bench/audio-page.ts +++ b/js/publish/bench/audio-page.ts @@ -1,4 +1,5 @@ -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Moq from "@moq/net"; import { Signal } from "@moq/signals"; import type { AudioFrame, Capture, Format } from "../src/audio/capture"; diff --git a/js/publish/bench/catalog.ts b/js/publish/bench/catalog.ts index 2423fdec500..31a8877c4bd 100644 --- a/js/publish/bench/catalog.ts +++ b/js/publish/bench/catalog.ts @@ -1,6 +1,7 @@ /** Sweep tracks x viewers for 1000 estimate rises inside one second. */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import * as Json from "@moq/json"; import { Track } from "@moq/net"; diff --git a/js/publish/src/audio/encoder.test.ts b/js/publish/src/audio/encoder.test.ts index a91c4b1bda9..15ed9fc91dc 100644 --- a/js/publish/src/audio/encoder.test.ts +++ b/js/publish/src/audio/encoder.test.ts @@ -1,5 +1,6 @@ import { describe, expect, mock, spyOn, test } from "bun:test"; -import { Duration, Instant, Manual, now } from "@moq/clock"; +import { Duration, Instant, now } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; import * as Json from "@moq/json"; diff --git a/js/publish/src/broadcast.test.ts b/js/publish/src/broadcast.test.ts index bc36085b9a5..495c3d648b5 100644 --- a/js/publish/src/broadcast.test.ts +++ b/js/publish/src/broadcast.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Stats } from "@moq/hang"; import * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; diff --git a/js/publish/src/catalog.test.ts b/js/publish/src/catalog.test.ts index 19b6b195d7c..e50c26e196a 100644 --- a/js/publish/src/catalog.test.ts +++ b/js/publish/src/catalog.test.ts @@ -1,5 +1,6 @@ import { afterEach, describe, expect, test } from "bun:test"; -import { Duration, type Installed, Manual, Wall } from "@moq/clock"; +import { Duration, type Installed, Wall } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import * as Json from "@moq/json"; import { Track } from "@moq/net"; diff --git a/js/publish/src/source/file.test.ts b/js/publish/src/source/file.test.ts index 1ed494e048f..69c8cd8846a 100644 --- a/js/publish/src/source/file.test.ts +++ b/js/publish/src/source/file.test.ts @@ -1,5 +1,6 @@ import { expect, mock, spyOn, test } from "bun:test"; -import { Duration, Instant, Manual } from "@moq/clock"; +import { Duration, Instant } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { File as FileSource } from "./file"; const flush = () => new Promise((resolve) => queueMicrotask(resolve)); diff --git a/js/publish/src/source/pace.test.ts b/js/publish/src/source/pace.test.ts index 4ee01188471..d9a88685182 100644 --- a/js/publish/src/source/pace.test.ts +++ b/js/publish/src/source/pace.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Instant, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, Instant, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { pace, type Sample, SEEK_BEHIND, type Sink } from "./pace"; import { Timeline } from "./timeline"; diff --git a/js/publish/src/source/retry.test.ts b/js/publish/src/source/retry.test.ts index 7cb6756917b..4509dc0fa6a 100644 --- a/js/publish/src/source/retry.test.ts +++ b/js/publish/src/source/retry.test.ts @@ -1,5 +1,6 @@ import { expect, spyOn, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Signal } from "@moq/signals"; import { Camera } from "./camera"; import { Microphone } from "./microphone"; diff --git a/js/publish/src/video/capture.test.ts b/js/publish/src/video/capture.test.ts index c6d6baeb147..4931e7bfdcf 100644 --- a/js/publish/src/video/capture.test.ts +++ b/js/publish/src/video/capture.test.ts @@ -1,5 +1,6 @@ import { expect, mock, test } from "bun:test"; -import { Duration, Instant, Manual } from "@moq/clock"; +import { Duration, Instant } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Moq from "@moq/net"; import { Effect, Signal } from "@moq/signals"; import { Order } from "../order"; diff --git a/js/publish/src/video/encoder-stall.test.ts b/js/publish/src/video/encoder-stall.test.ts index 6658bfcc10f..bb7e0e44f6b 100644 --- a/js/publish/src/video/encoder-stall.test.ts +++ b/js/publish/src/video/encoder-stall.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Instant, Manual } from "@moq/clock"; +import { Duration, Instant } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { u53 } from "@moq/hang/catalog"; import * as Moq from "@moq/net"; import { Signal } from "@moq/signals"; diff --git a/js/publish/src/video/encoder.test.ts b/js/publish/src/video/encoder.test.ts index c10de13348e..306f6e66318 100644 --- a/js/publish/src/video/encoder.test.ts +++ b/js/publish/src/video/encoder.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, spyOn, test } from "bun:test"; -import { Duration, type Installed, Manual, sleep } from "@moq/clock"; +import { Duration, type Installed, sleep } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; import * as Json from "@moq/json"; diff --git a/js/qmux/src/session.test.ts b/js/qmux/src/session.test.ts index 03f013eb936..be2a8be6a7f 100644 --- a/js/qmux/src/session.test.ts +++ b/js/qmux/src/session.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test"; -import { Duration, type Installed, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, type Installed, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { SessionError, StreamError } from "./error.ts"; import * as Frame from "./frame.ts"; import { DEFAULT_MAX_RECORD_SIZE, type TransportParams } from "./frame.ts"; diff --git a/js/qmux/src/web-socket-stream.test.ts b/js/qmux/src/web-socket-stream.test.ts index bdb3050707f..84a7fdbd33e 100644 --- a/js/qmux/src/web-socket-stream.test.ts +++ b/js/qmux/src/web-socket-stream.test.ts @@ -1,5 +1,6 @@ import { describe, expect, onTestFinished, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { openWebSocketStream, type WebSocketConstructor, diff --git a/js/room/src/chat.test.ts b/js/room/src/chat.test.ts index f0c5246c909..cae3306d740 100644 --- a/js/room/src/chat.test.ts +++ b/js/room/src/chat.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Broadcast, Time } from "@moq/net"; import { HISTORY, info, Publisher, Subscriber, TRACK } from "./chat.ts"; diff --git a/js/signals/src/index.test.ts b/js/signals/src/index.test.ts index 40b22d853fe..6841779273b 100644 --- a/js/signals/src/index.test.ts +++ b/js/signals/src/index.test.ts @@ -1,5 +1,6 @@ import { describe, expect, spyOn, test } from "bun:test"; -import { Duration, type Installed, Instant, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, type Installed, Instant, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Computed, type Dispose, Effect, type GetPromise, Once, race, Signal } from "./index.ts"; const NO_SUBSCRIPTION_WARNING = "Effect did not subscribe to any signals; it will never rerun."; diff --git a/js/watch/src/audio/decoder.test.ts b/js/watch/src/audio/decoder.test.ts index d2028a5eebe..c5857cd8942 100644 --- a/js/watch/src/audio/decoder.test.ts +++ b/js/watch/src/audio/decoder.test.ts @@ -1,6 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"; import { readFileSync } from "node:fs"; -import { Duration, Manual, now } from "@moq/clock"; +import { Duration, now } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; import * as Moq from "@moq/net"; diff --git a/js/watch/src/audio/playout.test.ts b/js/watch/src/audio/playout.test.ts index 8477904a5b3..27d0e2ed1bc 100644 --- a/js/watch/src/audio/playout.test.ts +++ b/js/watch/src/audio/playout.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "bun:test"; -import { Duration, Instant, Manual } from "@moq/clock"; +import { Duration, Instant } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Container from "@moq/hang/container"; import { Time, Track, Varint } from "@moq/net"; import { Signal } from "@moq/signals"; diff --git a/js/watch/src/audio/replay.ts b/js/watch/src/audio/replay.ts index 575d731981a..5adcfcdf156 100644 --- a/js/watch/src/audio/replay.ts +++ b/js/watch/src/audio/replay.ts @@ -16,7 +16,8 @@ * @internal Test support, not part of the player. */ -import { Duration, Instant, Manual } from "@moq/clock"; +import { Duration, Instant } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import type * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; import { type Group, Time, Track } from "@moq/net"; diff --git a/js/watch/src/echo.test.ts b/js/watch/src/echo.test.ts index 33167a6d988..dea7d1288d4 100644 --- a/js/watch/src/echo.test.ts +++ b/js/watch/src/echo.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Echo as Schema } from "@moq/hang"; import type * as Catalog from "@moq/hang/catalog"; import * as Json from "@moq/json"; diff --git a/js/watch/src/feedback.test.ts b/js/watch/src/feedback.test.ts index e8bf6d49d37..09ba14ff16d 100644 --- a/js/watch/src/feedback.test.ts +++ b/js/watch/src/feedback.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, now, Wall, wall } from "@moq/clock"; +import { Duration, now, Wall, wall } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import { Path } from "@moq/net"; import { arrivedAt, Tally } from "./feedback"; diff --git a/js/watch/src/retention.test.ts b/js/watch/src/retention.test.ts index 22ea7b4c612..5a0c75d5dfd 100644 --- a/js/watch/src/retention.test.ts +++ b/js/watch/src/retention.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, expect, spyOn, test } from "bun:test"; -import { Duration, type Installed, Instant, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, type Installed, Instant, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Container } from "@moq/hang"; import * as Moq from "@moq/net"; import { Time } from "@moq/net"; diff --git a/js/watch/src/sync.test.ts b/js/watch/src/sync.test.ts index 4a6056993cc..9e5cf9f09ef 100644 --- a/js/watch/src/sync.test.ts +++ b/js/watch/src/sync.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test"; -import { Duration, type Installed, Instant, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, type Installed, Instant, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; // A monotonic instant `ms` after the clock origin. const at = (ms: number) => Instant.ZERO.saturatingAdd(Duration.millis(ms)); diff --git a/js/watch/src/video/decoder.test.ts b/js/watch/src/video/decoder.test.ts index dc50964bdcf..b6fcd82b0bf 100644 --- a/js/watch/src/video/decoder.test.ts +++ b/js/watch/src/video/decoder.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it, spyOn } from "bun:test"; import { readFileSync } from "node:fs"; -import { Duration, Instant, Manual, now, yieldNow } from "@moq/clock"; +import { Duration, Instant, now, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; import * as Moq from "@moq/net"; diff --git a/quest/m0/nightly/bundle-size.md b/quest/m0/nightly/bundle-size.md deleted file mode 100644 index 74dabd4f831..00000000000 --- a/quest/m0/nightly/bundle-size.md +++ /dev/null @@ -1,29 +0,0 @@ -# [M] The JS bundles shed what isn't worth its weight - -## Goal - -Every shipped JS bundle drops what does not earn its bytes, and the rest of -the growth since 2026-10-22 is justified in the PR as feature growth, so the -30-day size check passes once its window moves past the growth. - -## Plan - -Found by the triage of Nightly run -[43447849289](https://github.com/moq-dev/moq/actions/runs/43447849289) -(2026-11-13) and [moq-dev/moq#8654](https://github.com/moq-dev/moq/pull/8654): -every JS bundle grew 11 to 15% over about 96 js/net, qmux, and clock -commits, with no single culprit (`js/net` brotli 136,880 to 157,282 bytes). -The 30-day check (10% limit) compares against the 10-22 report from 11-21 and -fails every night until about 12-13 unless the bundles shrink. - -Decided 2026-11-13 (maintainer, /quest-plan): ✅ audit and shrink, then accept -the rest as feature growth (rejected: cut until every bundle is within 10%, -which may cost features; accept without an audit). Do not loosen the check. - -Known item: `@moq/clock`'s test-only `Manual` clock ships in every bundle -(about 2.3 KB) because the package index re-exports it. Attribute the rest -with `sh/size/bundles.ts`. - -## Related - -- [Audit cost](/quest/m3/audit-cost.md) - the recurring audit that also covers bundle size diff --git a/quest/m3/audit-cost.md b/quest/m3/audit-cost.md index 66b47e5d504..b0782ff9252 100644 --- a/quest/m3/audit-cost.md +++ b/quest/m3/audit-cost.md @@ -96,9 +96,7 @@ tests [moq-dev/moq#7600](https://github.com/moq-dev/moq/pull/7600), build time closure and normalize hashed filenames. - `nm -S -C --defined-only` on the shipped static libraries attributes native growth by namespace. -- Kept: `sorted-btree` (the `@js-sdsl/ordered-map` candidate was slower on - ascending and rolling arrivals), and the whole Rust workspace in the Python - sdist, minus `test_data` +- Kept: the whole Rust workspace in the Python sdist, minus `test_data` ([moq-dev/moq#6867](https://github.com/moq-dev/moq/pull/6867)). `opt-level = "s"` for the bindings needs codec, crypto, and FFI throughput measurements first. @@ -135,7 +133,8 @@ tests [moq-dev/moq#7600](https://github.com/moq-dev/moq/pull/7600), build time `assert_matches`, `cpu-time`, `stats_alloc`, `unsafe-libopus`, the QUIC/UDP, RTMP, V4L2, NVIDIA, VA-API, UniFFI, and LibAV forks ([vendor-sync](/quest/m3/vendor-sync/README.md) ports upstream), and JS's - Zod, pako, sorted-btree, and UUIDv7. `moq-gst` keeps its Rust 1.92 floor + Zod, pako, and UUIDv7. Replaced: `sorted-btree`, by the ledger's in-tree + chunked `Sorted` list (about 5 KB Brotli per bundle). `moq-gst` keeps its Rust 1.92 floor for GStreamer. ## Required diff --git a/test/audio-quality/clients/js/src/capture.test.ts b/test/audio-quality/clients/js/src/capture.test.ts index 5d53de50f41..ece60c5fe62 100644 --- a/test/audio-quality/clients/js/src/capture.test.ts +++ b/test/audio-quality/clients/js/src/capture.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { Duration, Manual, yieldNow } from "@moq/clock"; +import { Duration, yieldNow } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Catalog from "@moq/hang/catalog"; import { Legacy } from "@moq/hang/container"; import { Group, Error as NetError, Origin, Path, Time } from "@moq/net"; diff --git a/test/audio-quality/clients/js/src/probe.test.ts b/test/audio-quality/clients/js/src/probe.test.ts index bc7e700b588..8aa8ed52ce5 100644 --- a/test/audio-quality/clients/js/src/probe.test.ts +++ b/test/audio-quality/clients/js/src/probe.test.ts @@ -1,5 +1,6 @@ import { expect, mock, test } from "bun:test"; -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Effect, Signal } from "@moq/signals"; import type MoqWatch from "@moq/watch/element"; import { Observed } from "../../../../../js/net/src/util/observed.ts"; diff --git a/test/interop/clients/js/net-cleanups/main.ts b/test/interop/clients/js/net-cleanups/main.ts index 947635ebc01..ebca1c954e9 100644 --- a/test/interop/clients/js/net-cleanups/main.ts +++ b/test/interop/clients/js/net-cleanups/main.ts @@ -1,6 +1,7 @@ /** Public net consumers and native browser streams, plus the shared fan-out sweep. @module */ -import { Duration, Manual } from "@moq/clock"; +import { Duration } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import * as Net from "@moq/net"; import { fanout } from "../../../../../js/net/bench/compression-fanout"; import { createMockTransportPair } from "../../../../../js/net/src/mock"; diff --git a/test/relay-fill/relay.ts b/test/relay-fill/relay.ts index 477ae30da34..7fe08316297 100644 --- a/test/relay-fill/relay.ts +++ b/test/relay-fill/relay.ts @@ -7,7 +7,7 @@ // `fetches` reports how many downstream FETCHes the relay forwarded upstream. import assert from "node:assert/strict"; import { createInterface } from "node:readline"; -import { Manual } from "@moq/clock"; +import { Manual } from "@moq/clock/test"; import { Session } from "@moq/qmux"; import { DEFAULT_EXPIRY } from "../../js/net/src/cache.ts"; import { connect } from "../../js/net/src/connection/connect.ts";