@torrent-tv/proxy 2.89.16 → 2.89.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -3
- package/package.json +10 -2
- package/routes/api/client-logs/post.js +9 -2
- package/server.js +0 -11
- package/.claude/commands/opsx/apply.md +0 -155
- package/.claude/commands/opsx/archive.md +0 -160
- package/.claude/commands/opsx/explore.md +0 -174
- package/.claude/commands/opsx/propose.md +0 -109
- package/.claude/commands/opsx/sync.md +0 -143
- package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
- package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
- package/.claude/skills/openspec-explore/SKILL.md +0 -289
- package/.claude/skills/openspec-propose/SKILL.md +0 -113
- package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
- package/.dockerignore +0 -5
- package/AGENTS.md +0 -363
- package/CHANGELOG.md +0 -2373
- package/Dockerfile +0 -30
- package/biome.json +0 -412
- package/corpus.tmp.json +0 -1
- package/docs/browser-proxy-contract.md +0 -155
- package/docs/container-architecture.md +0 -273
- package/docs/download-architecture.md +0 -261
- package/docs/encode-architecture.md +0 -765
- package/docs/encode-run-state.md +0 -96
- package/docs/logs.md +0 -138
- package/docs/playback-start-forecast.md +0 -113
- package/docs/socks5-egress-research.md +0 -114
- package/docs/storage-architecture.md +0 -273
- package/knip.json +0 -14
- package/main2.cpuprofile +0 -1
- package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
- package/openspec/changes/adaptive-bitrate/design.md +0 -92
- package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
- package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
- package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
- package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
- package/openspec/changes/binary-distribution/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/design.md +0 -81
- package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
- package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
- package/openspec/changes/cold-start/design.md +0 -98
- package/openspec/changes/cold-start/proposal.md +0 -62
- package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
- package/openspec/changes/cold-start/tasks.md +0 -48
- package/openspec/changes/disk-cap/.openspec.yaml +0 -2
- package/openspec/changes/disk-cap/proposal.md +0 -37
- package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
- package/openspec/changes/disk-cap/tasks.md +0 -19
- package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
- package/openspec/changes/proxy-observability/design.md +0 -38
- package/openspec/changes/proxy-observability/proposal.md +0 -49
- package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
- package/openspec/changes/proxy-observability/tasks.md +0 -21
- package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
- package/openspec/changes/seek-debounce/design.md +0 -118
- package/openspec/changes/seek-debounce/proposal.md +0 -59
- package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
- package/openspec/changes/seek-debounce/tasks.md +0 -33
- package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
- package/openspec/changes/subtitle-language/proposal.md +0 -50
- package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
- package/openspec/changes/subtitle-language/tasks.md +0 -26
- package/openspec/changes/track-selection/.openspec.yaml +0 -2
- package/openspec/changes/track-selection/design.md +0 -47
- package/openspec/changes/track-selection/proposal.md +0 -45
- package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
- package/openspec/changes/track-selection/tasks.md +0 -20
- package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
- package/openspec/changes/transcode-quality/proposal.md +0 -51
- package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
- package/openspec/changes/transcode-quality/tasks.md +0 -63
- package/openspec/config.yaml +0 -38
- package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
- package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
- package/research/double-spawn-2026-09-10.md +0 -171
- package/research/handover-2026-09-13.md +0 -209
- package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
- package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
- package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
- package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
- package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
- package/scripts/build-audio-samples.mjs +0 -31
- package/scripts/render-run-graph.js +0 -173
- package/test/asset-paths.test.js +0 -28
- package/test/audio-buffer-continuity.test.js +0 -77
- package/test/audio-calibration.test.js +0 -23
- package/test/audio-inventory.test.js +0 -212
- package/test/audio-track-bitrate.test.js +0 -40
- package/test/audio-warm-recorded.test.js +0 -63
- package/test/auto-quality-step.test.js +0 -762
- package/test/available-share.test.js +0 -76
- package/test/background-fill.test.js +0 -190
- package/test/client-log-file.test.js +0 -126
- package/test/coalesce.test.js +0 -39
- package/test/completed-files.test.js +0 -115
- package/test/concurrent-cost.test.js +0 -148
- package/test/container-media-info.test.js +0 -228
- package/test/contention.test.js +0 -76
- package/test/core-dumps.test.js +0 -57
- package/test/coverage-follows-the-disk.test.js +0 -233
- package/test/coverage-map.test.js +0 -195
- package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
- package/test/cut-times-timeline.test.js +0 -65
- package/test/cuts-follow-published-grid.test.js +0 -109
- package/test/data-channel-frame.test.js +0 -63
- package/test/data-channel-viewer-lifecycle.test.js +0 -193
- package/test/dead-torrent-handle.test.js +0 -52
- package/test/declared-rates.test.js +0 -116
- package/test/declared-tracks.test.js +0 -43
- package/test/decode-cost-fit.test.js +0 -202
- package/test/decode-cost.test.js +0 -475
- package/test/delivery-probe-field.test.js +0 -173
- package/test/delivery-probe.test.js +0 -382
- package/test/demand-register.test.js +0 -206
- package/test/dht-bootstrap.test.js +0 -72
- package/test/drain-threat.test.js +0 -65
- package/test/duplicate-add.test.js +0 -48
- package/test/encode-admission.test.js +0 -170
- package/test/encode-cost.test.js +0 -275
- package/test/encode-exit.test.js +0 -111
- package/test/encode-orchestrator.test.js +0 -426
- package/test/encode-plan-viewers.test.js +0 -725
- package/test/encode-plan.test.js +0 -545
- package/test/encode-run-state.test.js +0 -314
- package/test/encode-run.test.js +0 -248
- package/test/encode-slope.test.js +0 -46
- package/test/encoded-output.test.js +0 -39
- package/test/encoder-kinds.test.js +0 -122
- package/test/encoder-readings.test.js +0 -68
- package/test/episode-naming.test.js +0 -131
- package/test/every-claimant-is-told-its-share.test.js +0 -152
- package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
- package/test/failed-start-breaker.test.js +0 -202
- package/test/fastest-wires.test.js +0 -143
- package/test/ffmpeg-stream-counts.test.js +0 -101
- package/test/file-edges.test.js +0 -191
- package/test/files-in-use.test.js +0 -34
- package/test/fixtures/audio-frame-boundary.json +0 -1
- package/test/fixtures/refused-audio-20261002.json +0 -10
- package/test/fmp4-presentation-clock.test.js +0 -148
- package/test/fmp4-self-contained.test.js +0 -80
- package/test/fmp4-timestamps.test.js +0 -140
- package/test/fmp4-track-completeness.test.js +0 -41
- package/test/format-keyed-outputs.test.js +0 -78
- package/test/health-metrics.test.js +0 -36
- package/test/held-read-ownership.test.js +0 -77
- package/test/held-request-width.test.js +0 -157
- package/test/helpers/encode-run.js +0 -248
- package/test/helpers/held-file.js +0 -77
- package/test/helpers/manager.js +0 -62
- package/test/helpers/matroska-file.js +0 -296
- package/test/helpers/output-spec.js +0 -63
- package/test/host-load.test.js +0 -68
- package/test/index-accuracy-is-about-the-file.test.js +0 -128
- package/test/init-compat.test.js +0 -219
- package/test/input-lost-quiets-the-plan.test.js +0 -261
- package/test/input-unavailable.test.js +0 -48
- package/test/installation-id.test.js +0 -39
- package/test/keeping-period.test.js +0 -83
- package/test/keyframe-index-accuracy.test.js +0 -188
- package/test/keyframe-table-budget.test.js +0 -123
- package/test/keyframes-belong-to-the-file.test.js +0 -249
- package/test/learned-median.test.js +0 -37
- package/test/letting-go-asks-who-is-watching.test.js +0 -191
- package/test/limit-row-by-area.test.js +0 -60
- package/test/link-budget.test.js +0 -111
- package/test/link-probe.test.js +0 -56
- package/test/local-encoding-data.test.js +0 -273
- package/test/logger-repeats.test.js +0 -134
- package/test/look-ahead-coverage.test.js +0 -56
- package/test/manager-surface.test.js +0 -291
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cluster-discovery.test.js +0 -323
- package/test/matroska-cues-track.test.js +0 -192
- package/test/media-time.test.js +0 -62
- package/test/memory-budget.test.js +0 -390
- package/test/move-cost.test.js +0 -216
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +0 -173
- package/test/one-authority.test.js +0 -285
- package/test/one-budget.test.js +0 -149
- package/test/one-output-one-session.test.js +0 -273
- package/test/one-resource-divided.test.js +0 -185
- package/test/one-serving-output-per-height.test.js +0 -458
- package/test/orchestrator-wired.test.js +0 -207
- package/test/output-catalog.test.js +0 -39
- package/test/output-shape.test.js +0 -21
- package/test/output-spec.test.js +0 -251
- package/test/output-speed.test.js +0 -92
- package/test/outputs-being-prepared.test.js +0 -40
- package/test/packet-witness-ring.test.js +0 -236
- package/test/packet-witness.test.js +0 -148
- package/test/piece-completeness.test.js +0 -78
- package/test/piece-disk-store.test.js +0 -401
- package/test/piece-from-whole-file.test.js +0 -129
- package/test/piece-lru.test.js +0 -319
- package/test/piece-reader.test.js +0 -162
- package/test/piece-selection-offset.test.js +0 -85
- package/test/piece-store-eviction.test.js +0 -595
- package/test/piece-store-never-refuses.test.js +0 -153
- package/test/piece-store-reservations.test.js +0 -403
- package/test/piece-store-slow-disk.test.js +0 -159
- package/test/piece-tail.test.js +0 -97
- package/test/plan-host-timings.test.js +0 -68
- package/test/plan-is-steady.test.js +0 -225
- package/test/playback-readiness.test.js +0 -518
- package/test/playback-start-regressions.test.js +0 -101
- package/test/priority-map-download.test.js +0 -174
- package/test/priority-map-emptied.test.js +0 -204
- package/test/priority-map-per-output.test.js +0 -215
- package/test/priority-map.test.js +0 -163
- package/test/probe-wedge-certainty.test.js +0 -60
- package/test/produced-copy-choice.test.js +0 -213
- package/test/published-timeline.test.js +0 -83
- package/test/quality-offer.test.js +0 -160
- package/test/quality-variants.test.js +0 -1274
- package/test/rate-control-in-the-output.test.js +0 -181
- package/test/read-survives-withdrawal.test.js +0 -164
- package/test/read-window.test.js +0 -365
- package/test/reads-not-yet-arrived.test.js +0 -218
- package/test/resume-warm.test.js +0 -39
- package/test/run-graph-drift.test.js +0 -37
- package/test/run-inputs.test.js +0 -80
- package/test/run-intervals.test.js +0 -100
- package/test/run-position-follows-published-grid.test.js +0 -89
- package/test/run-progress.test.js +0 -64
- package/test/same-height-switch.test.js +0 -663
- package/test/seek-frees-the-viewers-requests.test.js +0 -217
- package/test/seek-landing.test.js +0 -109
- package/test/seek-target-not-superseded.test.js +0 -195
- package/test/segment-closed-on-both-branches.test.js +0 -114
- package/test/segment-cut-times.test.js +0 -63
- package/test/segment-demand.test.js +0 -80
- package/test/segment-hold-supersede.test.js +0 -91
- package/test/segment-judged-by-its-own-header.test.js +0 -222
- package/test/segment-serve-wiring.test.js +0 -481
- package/test/segment-store-eviction.test.js +0 -247
- package/test/segment-store.test.js +0 -352
- package/test/segment-true-start.test.js +0 -86
- package/test/segments-are-shared.test.js +0 -176
- package/test/send-chunk-bytes.test.js +0 -86
- package/test/serving-existing-output.test.js +0 -111
- package/test/serving-output.test.js +0 -102
- package/test/shared-piece-store.test.js +0 -310
- package/test/sidecar-naming.test.js +0 -142
- package/test/soundtrack-rate-bound.test.js +0 -289
- package/test/source-file.test.js +0 -133
- package/test/source-files-route.test.js +0 -113
- package/test/source-registry.test.js +0 -18
- package/test/split-a-stretch.test.js +0 -139
- package/test/stale-request-after-seek.test.js +0 -158
- package/test/startup-readings.test.js +0 -124
- package/test/stream-route.test.js +0 -237
- package/test/subtitle-cue-framing.test.js +0 -200
- package/test/subtitle-cue-source.test.js +0 -102
- package/test/subtitle-cue-walk.test.js +0 -385
- package/test/subtitle-cursor.test.js +0 -63
- package/test/subtitle-defaults.test.js +0 -118
- package/test/subtitle-language.test.js +0 -252
- package/test/subtitle-metadata.test.js +0 -15
- package/test/subtitle-plan-waits.test.js +0 -125
- package/test/subtitle-track-numbering.test.js +0 -391
- package/test/supply-margin.test.js +0 -190
- package/test/swarm-follows-readers.test.js +0 -174
- package/test/swarm-reach.test.js +0 -130
- package/test/swarm-selection.test.js +0 -220
- package/test/tail-duplication.test.js +0 -167
- package/test/the-channel-has-both-ends.test.js +0 -91
- package/test/the-torrent-thread-serves-bytes.test.js +0 -107
- package/test/thread-pool.test.js +0 -53
- package/test/timeline.test.js +0 -84
- package/test/torrent-contents.test.js +0 -235
- package/test/torrent-cost.test.js +0 -71
- package/test/torrent-files.test.js +0 -221
- package/test/torrent-naming.test.js +0 -255
- package/test/tracks-begin-together.test.js +0 -209
- package/test/tunnel-renewal.test.js +0 -167
- package/test/two-viewers-one-picture.test.js +0 -508
- package/test/upload-hurry.test.js +0 -186
- package/test/usrsctp-state.test.js +0 -131
- package/test/video-facts.test.js +0 -102
- package/test/viewer-assignments.test.js +0 -143
- package/test/viewer-outputs.test.js +0 -285
- package/test/viewer-presence.test.js +0 -116
- package/test/viewer-requests-admission.test.js +0 -92
- package/test/viewer-starts-on-map.test.js +0 -27
- package/test/viewer-states.test.js +0 -192
- package/test/viewer-subtitle-subscription.test.js +0 -96
- package/test/viewer.test.js +0 -139
- package/test/viewing-generations.test.js +0 -390
- package/test/visible-rung.test.js +0 -37
- package/test/wait-ledger.test.js +0 -100
- package/test/webrtc-shim.test.js +0 -149
- package/test/wedge-certainty.test.js +0 -131
- package/test/whole-file-held-read.test.js +0 -30
- package/test/withdraw-piece-claim.test.js +0 -212
- package/test/worker-channel.test.js +0 -158
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file What the HTTP layer asks of the components, checked from the HTTP layer.
|
|
3
|
-
*
|
|
4
|
-
* Written as the net under the dismantling of `hls-session-manager.js`, which
|
|
5
|
-
* was 9608 lines and 142 methods and is now gone: its members are methods of
|
|
6
|
-
* the components that own them, wired by `services/server/wire-outputs.js`.
|
|
7
|
-
* Most tests that build those components name something INSIDE them — a field,
|
|
8
|
-
* a fake output shaped the way one happens to be shaped — so they move when the
|
|
9
|
-
* code moves, and a test that moves with the code cannot say the code still
|
|
10
|
-
* works.
|
|
11
|
-
*
|
|
12
|
-
* This one is derived from the other side: from what the HTTP layer asks of
|
|
13
|
-
* the components. That contract does not move. A route calling a member that no longer exists
|
|
14
|
-
* is the exact failure a nine-step move risks, and it is silent — Fastify
|
|
15
|
-
* answers 500 at runtime, months later, on a path no unit test walks.
|
|
16
|
-
*
|
|
17
|
-
* So the first check READS `routes/` and `server.js` rather than listing what
|
|
18
|
-
* the manager has. It cannot go stale: adding a call to a route adds it to the
|
|
19
|
-
* requirement, and removing the member it names breaks this test the same
|
|
20
|
-
* minute.
|
|
21
|
-
*
|
|
22
|
-
* The second is a characteristic record rather than a judgement: what the
|
|
23
|
-
* progress report carries today. Eighteen figures reach the page from it and
|
|
24
|
-
* nothing on this side of the wire knows which of them the page needs, so the
|
|
25
|
-
* honest statement is "these are the ones there were" — the point being that a
|
|
26
|
-
* move must not change them, not that they are the right ones.
|
|
27
|
-
*
|
|
28
|
-
* Every manager here has a store root of its own, for the reason
|
|
29
|
-
* `helpers/manager.js` records.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import test from "node:test";
|
|
33
|
-
import assert from "node:assert/strict";
|
|
34
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
35
|
-
import path from "node:path";
|
|
36
|
-
import { fileURLToPath } from "node:url";
|
|
37
|
-
import { SourceFile } from "../services/media/SourceFile.js";
|
|
38
|
-
import { Timeline } from "../services/encode/output/Timeline.js";
|
|
39
|
-
import { managerWithOwnStore } from "./helpers/manager.js";
|
|
40
|
-
import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
|
|
41
|
-
import { Output } from "../services/encode/output/Output.js";
|
|
42
|
-
import { outputSpec } from "./helpers/output-spec.js";
|
|
43
|
-
|
|
44
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
45
|
-
const PROXY = path.join(HERE, "..");
|
|
46
|
-
const SESSION_ID = "aaaaaaaabbbbcccc";
|
|
47
|
-
/** The components the HTTP layer is handed. */
|
|
48
|
-
const COMPONENTS = ["serving", "viewerRequests", "renditions", "lifecycle", "quality", "outputs", "hostTimings", "viewers", "encodeRuns"];
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Every `.js` file under a directory, at any depth.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} dir
|
|
54
|
-
* @returns {string[]}
|
|
55
|
-
*/
|
|
56
|
-
function jsFilesUnder(dir) {
|
|
57
|
-
/** @type {string[]} */
|
|
58
|
-
const found = [];
|
|
59
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
60
|
-
const full = path.join(dir, entry.name);
|
|
61
|
-
if (entry.isDirectory()) {
|
|
62
|
-
found.push(...jsFilesUnder(full));
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (entry.name.endsWith(".js")) {
|
|
66
|
-
found.push(full);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return found;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* What the HTTP layer asks of each component, read from the HTTP layer.
|
|
74
|
-
*
|
|
75
|
-
* Deliberately not a list kept here: a list is a second statement of the same
|
|
76
|
-
* fact, and the two drift. The callers are the statement. A route names the
|
|
77
|
-
* component it was handed (`serving.getFileStream`); `server.js` names it
|
|
78
|
-
* through what the wiring returned (`outputParts.serving.getFileStream`).
|
|
79
|
-
*
|
|
80
|
-
* @returns {Map<string, string[]>} `component.member` to the files that ask for it.
|
|
81
|
-
*/
|
|
82
|
-
function membersTheHttpLayerCalls() {
|
|
83
|
-
/** @type {Map<string, string[]>} */
|
|
84
|
-
const asked = new Map();
|
|
85
|
-
const sources = [path.join(PROXY, "server.js"), ...jsFilesUnder(path.join(PROXY, "routes"))];
|
|
86
|
-
const pattern = new RegExp(String.raw`\b(${COMPONENTS.join("|")})\.([A-Za-z][A-Za-z0-9]*)\(`, "g");
|
|
87
|
-
for (const file of sources) {
|
|
88
|
-
const text = readFileSync(file, "utf8");
|
|
89
|
-
for (const match of text.matchAll(pattern)) {
|
|
90
|
-
const asking = `${match[1]}.${match[2]}`;
|
|
91
|
-
const where = asked.get(asking) ?? [];
|
|
92
|
-
where.push(path.relative(PROXY, file));
|
|
93
|
-
asked.set(asking, where);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return asked;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* A manager with nothing running behind it, over a store of its own.
|
|
101
|
-
*
|
|
102
|
-
* Its two timers are unref'd, so nothing here keeps the process alive.
|
|
103
|
-
*
|
|
104
|
-
* @returns {object}
|
|
105
|
-
*/
|
|
106
|
-
function bareManager() {
|
|
107
|
-
return managerWithOwnStore().manager;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* A session shaped like a live one, with no encoder behind it.
|
|
112
|
-
*
|
|
113
|
-
* @param {{ id?: string }} [params]
|
|
114
|
-
* @returns {object}
|
|
115
|
-
*/
|
|
116
|
-
function fakeSession({ id = SESSION_ID } = {}) {
|
|
117
|
-
return {
|
|
118
|
-
id,
|
|
119
|
-
spec: outputSpec({ cutGrid: "keyframe", audioSeparate: true }),
|
|
120
|
-
outputKey: "surface:fmt=fmp4:grid=kf@0:video-only:v=0/copy",
|
|
121
|
-
dirPath: path.join(PROXY, "test", "does-not-exist"),
|
|
122
|
-
file: new SourceFile({ sourceKey: "torrent:abc", fileIndex: 0, name: "video.mkv" })
|
|
123
|
-
.learn({ width: 1920, height: 1080 }),
|
|
124
|
-
get inputFile() { return this.file; },
|
|
125
|
-
get audioFile() { return this.file; },
|
|
126
|
-
timeline: new Timeline({
|
|
127
|
-
boundaries: Array.from({ length: 11 }, (_, index) => index * 4),
|
|
128
|
-
cutGrid: "keyframe"
|
|
129
|
-
}),
|
|
130
|
-
segmentFormat: fmp4Format,
|
|
131
|
-
output: new Output({
|
|
132
|
-
encodeWidth: 0,
|
|
133
|
-
encodeHeight: 0,
|
|
134
|
-
outputFps: 24,
|
|
135
|
-
softwarePreset: null,
|
|
136
|
-
applyTonemap: false
|
|
137
|
-
}),
|
|
138
|
-
transcodeVideo: false,
|
|
139
|
-
transcodeAudio: true,
|
|
140
|
-
audioTrackIndex: 0,
|
|
141
|
-
audioSourceTrackIndex: 0,
|
|
142
|
-
useSyntheticPlaylist: true,
|
|
143
|
-
playlistText: "#EXTM3U\n",
|
|
144
|
-
segmentCount: 10,
|
|
145
|
-
progress: { state: "running", processedSeconds: 0, startPositionSeconds: 0 }
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
test("every call the HTTP layer makes is answered", () => {
|
|
150
|
-
const parts = bareManager();
|
|
151
|
-
const asked = membersTheHttpLayerCalls();
|
|
152
|
-
// If this ever reads zero the extraction has broken, and the test would then
|
|
153
|
-
// pass by asking nothing at all.
|
|
154
|
-
assert.ok(asked.size >= 15, `expected the HTTP layer to ask for members, found ${asked.size}`);
|
|
155
|
-
|
|
156
|
-
const missing = [];
|
|
157
|
-
for (const [asking, callers] of asked) {
|
|
158
|
-
const [component, member] = asking.split(".");
|
|
159
|
-
if (!(parts[component] && member in parts[component])) {
|
|
160
|
-
missing.push(`${asking} (asked by ${[...new Set(callers)].join(", ")})`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
assert.deepEqual(missing, [], `the HTTP layer calls members no component has:\n${missing.join("\n")}`);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("the progress report keeps every figure it carries today", async () => {
|
|
167
|
-
const manager = bareManager();
|
|
168
|
-
manager.outputs.set(SESSION_ID, fakeSession());
|
|
169
|
-
const progress = await manager.viewerRequests.getSessionProgress(SESSION_ID, "viewer-one");
|
|
170
|
-
assert.ok(progress, "a live session has a progress report");
|
|
171
|
-
|
|
172
|
-
// A characteristic record: what the page is given now. The claim is "a move
|
|
173
|
-
// did not change this", never "this is the right set".
|
|
174
|
-
const carried = [
|
|
175
|
-
"sessionId",
|
|
176
|
-
"state",
|
|
177
|
-
"minimumBufferSeconds",
|
|
178
|
-
"processedSeconds",
|
|
179
|
-
"inputBytes",
|
|
180
|
-
"startPositionSeconds",
|
|
181
|
-
"totalSeconds",
|
|
182
|
-
"percent",
|
|
183
|
-
"remainingSeconds",
|
|
184
|
-
"segmentDurationSec",
|
|
185
|
-
"currentHeight",
|
|
186
|
-
"offeredHeights",
|
|
187
|
-
"requestedHeight",
|
|
188
|
-
"expectedSessionCreateMs",
|
|
189
|
-
"expectedFirstSegmentMs",
|
|
190
|
-
"updatedAt",
|
|
191
|
-
"error"
|
|
192
|
-
];
|
|
193
|
-
const absent = carried.filter((key) => !(key in progress));
|
|
194
|
-
assert.deepEqual(absent, [], `the progress report lost ${absent.join(", ")}`);
|
|
195
|
-
assert.equal(progress.sessionId, SESSION_ID);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("a session that is not there is answered, not invented", async () => {
|
|
199
|
-
const manager = bareManager();
|
|
200
|
-
const absent = "ffffffffffffffff";
|
|
201
|
-
|
|
202
|
-
assert.equal(await manager.viewerRequests.getSessionProgress(absent), null);
|
|
203
|
-
assert.equal((await manager.serving.getFileStream(absent, "segment-00000.mp4")).kind, "not-found");
|
|
204
|
-
// A name no session could have must be refused before anything touches the
|
|
205
|
-
// disk with it.
|
|
206
|
-
assert.equal((await manager.serving.getFileStream("../../etc", "segment-00000.mp4")).kind, "not-found");
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test("what a viewer states about themselves is kept and answered", () => {
|
|
210
|
-
const manager = bareManager();
|
|
211
|
-
manager.outputs.set(SESSION_ID, fakeSession());
|
|
212
|
-
|
|
213
|
-
// Nine public members had no test of any kind before the dismantling began,
|
|
214
|
-
// and six of them are the viewer's own facts — the ones that move into
|
|
215
|
-
// `viewer/`. They are cheap to state and were simply never stated.
|
|
216
|
-
|
|
217
|
-
// A SEEK DOES ONE THING: it puts the viewer where they now are. Recorded
|
|
218
|
-
// here because it used to do eleven, and because the one remaining effect is
|
|
219
|
-
// what every reading of a viewer's position now rests on.
|
|
220
|
-
assert.equal(manager.viewerRequests.requestSeek(SESSION_ID, 120, "viewer-one"), true);
|
|
221
|
-
assert.equal(manager.viewerRequests.viewerPositionOf(SESSION_ID, "viewer-one"), 120);
|
|
222
|
-
assert.equal(manager.viewerRequests.requestSeek("no-such-session", 120, "viewer-one"), false);
|
|
223
|
-
|
|
224
|
-
// A seek wakes requests held on each output this viewer watches so each one
|
|
225
|
-
// can check whether it is still the segment this viewer needs.
|
|
226
|
-
assert.equal(manager.serving.seekEpoch(SESSION_ID), 1, "a seek invalidates waits on the watched output");
|
|
227
|
-
assert.equal(manager.serving.seekEpoch("no-such-session"), 0);
|
|
228
|
-
|
|
229
|
-
manager.encodeRuns.noteInputBytes(SESSION_ID, 4096);
|
|
230
|
-
manager.encodeRuns.noteInputBytes(SESSION_ID, 1024);
|
|
231
|
-
assert.equal(
|
|
232
|
-
manager.encodeRuns.inputBytesOf(manager.outputs.get(SESSION_ID)),
|
|
233
|
-
5120,
|
|
234
|
-
"input bytes accumulate at their owner"
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
// A far fragment is a reading and must never throw, whatever the player says.
|
|
238
|
-
manager.serving.recordFragmentFar(SESSION_ID, {
|
|
239
|
-
sn: 40, track: "video", fragStartSec: 200, bufferEndSec: 130, currentTimeSec: 128
|
|
240
|
-
});
|
|
241
|
-
manager.serving.recordFragmentFar("no-such-session", { sn: 1, track: "video" });
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test("a session nobody has touched is disposed, one that is being watched is not", async () => {
|
|
245
|
-
const manager = bareManager();
|
|
246
|
-
const stale = fakeSession({ id: "1111111111111111" });
|
|
247
|
-
const fresh = fakeSession({ id: "2222222222222222" });
|
|
248
|
-
// Older than any TTL this manager could carry, without naming one here: the
|
|
249
|
-
// period is the manager's business and this test is about the rule.
|
|
250
|
-
manager.outputs.set(stale.id, stale);
|
|
251
|
-
manager.outputs.set(fresh.id, fresh);
|
|
252
|
-
manager.outputs.touch(stale, Date.now() - (2 * 60 * 60 * 1000));
|
|
253
|
-
|
|
254
|
-
await manager.lifecycle.cleanupExpired();
|
|
255
|
-
|
|
256
|
-
assert.equal(manager.outputs.has(stale.id), false, "an untouched session goes");
|
|
257
|
-
assert.equal("state" in stale, false, "removal from the registry is the only lifetime fact");
|
|
258
|
-
assert.equal(manager.outputs.has(fresh.id), true, "a session just read stays");
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("what a file declares and what this host could offer are answered without a session", () => {
|
|
262
|
-
const manager = bareManager();
|
|
263
|
-
const session = fakeSession();
|
|
264
|
-
manager.outputs.set(SESSION_ID, session);
|
|
265
|
-
|
|
266
|
-
// `declaredTracks` reads the session's own record and must answer even when
|
|
267
|
-
// nothing has probed the file yet.
|
|
268
|
-
assert.doesNotThrow(() => manager.renditions.declaredTracks(session));
|
|
269
|
-
|
|
270
|
-
// The offer is predicted before any session exists — that is its whole point,
|
|
271
|
-
// the menu being complete from the moment a file is opened.
|
|
272
|
-
assert.equal(manager.quality.predictOfferedHeights({ height: 0, width: 0 }), null, "an unknown picture offers nothing");
|
|
273
|
-
const offered = manager.quality.predictOfferedHeights({
|
|
274
|
-
height: 1080, width: 1920, fps: 24, sourceKey: "torrent:abc", fileIndex: 0
|
|
275
|
-
});
|
|
276
|
-
// TWO ANSWERS, not one: what this host can hold when the picture is copied,
|
|
277
|
-
// and what it can hold when it is re-encoded. The browser decides which of
|
|
278
|
-
// the two applies, because whether it can play the source is its own fact.
|
|
279
|
-
assert.ok(Array.isArray(offered?.copy), "the copied branch gets a list");
|
|
280
|
-
assert.ok(Array.isArray(offered?.transcode), "the re-encoded branch gets a list");
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
test("a segment name that is not one is refused", async () => {
|
|
284
|
-
const manager = bareManager();
|
|
285
|
-
manager.outputs.set(SESSION_ID, fakeSession());
|
|
286
|
-
|
|
287
|
-
for (const name of ["../key.txt", "segment-00000.mp4/../../x", "making-0-00000.mp4"]) {
|
|
288
|
-
const answer = await manager.serving.getFileStream(SESSION_ID, name);
|
|
289
|
-
assert.equal(answer.kind, "not-found", `${name} must not be servable`);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
Binary file
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Where a Matroska file's clusters are, found from what is downloaded —
|
|
3
|
-
* and what is read out of them, in what order, within what memory.
|
|
4
|
-
*
|
|
5
|
-
* RFC 9559 §22.1 says each subtitle frame SHOULD be named by the Cues table, and
|
|
6
|
-
* a file may have no Cues at all. Until 2026-10-01 such a file showed no
|
|
7
|
-
* subtitles ever. Every check builds a file element by element, says which
|
|
8
|
-
* byte ranges are "downloaded", and runs passes of the walk the way arriving
|
|
9
|
-
* pieces would. Fakes only.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import test from "node:test";
|
|
13
|
-
import assert from "node:assert/strict";
|
|
14
|
-
|
|
15
|
-
import { MatroskaContainer } from "../services/media/container/MatroskaContainer.js";
|
|
16
|
-
import {
|
|
17
|
-
ID,
|
|
18
|
-
buildMatroska,
|
|
19
|
-
clusterData,
|
|
20
|
-
cueBlock,
|
|
21
|
-
element,
|
|
22
|
-
heldOver,
|
|
23
|
-
idBytes,
|
|
24
|
-
pictureBlock,
|
|
25
|
-
readerOver,
|
|
26
|
-
trackEntry
|
|
27
|
-
} from "./helpers/matroska-file.js";
|
|
28
|
-
|
|
29
|
-
const TRACKS = [
|
|
30
|
-
trackEntry({ number: 1, type: 1, codecId: "V_MPEG4/ISO/AVC", language: "jpn" }),
|
|
31
|
-
trackEntry({ number: 2, type: 17, codecId: "S_TEXT/UTF8" })
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
/** One cluster a second-and-a-bit long with one line on track 2 and a picture. */
|
|
35
|
-
function plainCluster(ticks, text, picture = Buffer.alloc(16, 7)) {
|
|
36
|
-
return {
|
|
37
|
-
ticks,
|
|
38
|
-
data: clusterData({
|
|
39
|
-
ticks,
|
|
40
|
-
blocks: [pictureBlock({ track: 1, payload: picture }), cueBlock({ track: 2, relativeTicks: 0, durationTicks: 900, text })]
|
|
41
|
-
})
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function planOf(file) {
|
|
46
|
-
const { read } = readerOver(file);
|
|
47
|
-
const container = new MatroskaContainer({ readRange: read, fileSize: file.length });
|
|
48
|
-
return { container, plan: await container.readSubtitlePlan() };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function pass(container, plan, progress, held) {
|
|
52
|
-
const result = await container.readHeldCues(plan, plan.tracks[0], progress, held);
|
|
53
|
-
return { ...result, texts: (result.found.get(2) ?? []).map((cue) => cue.text) };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
test("a Cues table that names only the picture still leads to every subtitle line", async () => {
|
|
57
|
-
const { file } = buildMatroska({
|
|
58
|
-
tracks: TRACKS,
|
|
59
|
-
cues: [1],
|
|
60
|
-
clusters: [plainCluster(0, "a"), plainCluster(10_000, "b"), plainCluster(20_000, "c")]
|
|
61
|
-
});
|
|
62
|
-
const { container, plan } = await planOf(file);
|
|
63
|
-
assert.equal(plan.cuesState, "complete");
|
|
64
|
-
assert.deepEqual(plan.tracks[0].clusterPositions, [], "the table names no cluster for the subtitle track");
|
|
65
|
-
const result = await pass(container, plan, {}, heldOver(file, [[0, file.length - 1]]));
|
|
66
|
-
assert.deepEqual(result.texts.sort(), ["a", "b", "c"]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("with no Cues, the chain reads what is joined up and the search finds what lies past a gap", async () => {
|
|
70
|
-
const { file, clusterAt } = buildMatroska({
|
|
71
|
-
tracks: TRACKS,
|
|
72
|
-
cues: null,
|
|
73
|
-
clusters: [plainCluster(0, "a"), plainCluster(10_000, "b"), plainCluster(20_000, "c"), plainCluster(30_000, "d")]
|
|
74
|
-
});
|
|
75
|
-
const { container, plan } = await planOf(file);
|
|
76
|
-
assert.equal(plan.cuesState, "absent");
|
|
77
|
-
const progress = {};
|
|
78
|
-
const gap = [clusterAt[2], clusterAt[3] - 1];
|
|
79
|
-
const first = await pass(container, plan, progress, heldOver(file, [[0, gap[0] - 1], [gap[1] + 1, file.length - 1]]));
|
|
80
|
-
assert.deepEqual(first.texts.sort(), ["a", "b", "d"], "the third cluster is not downloaded; the fourth is found by searching");
|
|
81
|
-
assert.equal(first.stats.fromSearch, 1);
|
|
82
|
-
|
|
83
|
-
const second = await pass(container, plan, progress, heldOver(file, [[0, file.length - 1]]));
|
|
84
|
-
assert.deepEqual(second.texts, ["c"], "the gap filled: the chain reaches the third, and nothing is read twice");
|
|
85
|
-
assert.deepEqual(second.withdrawn, [], "the search was right, so nothing is taken back");
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("the walk reads the structure of a cluster, not the frames of its picture", async () => {
|
|
89
|
-
// Pictures of 64 KB: a walk that read them would move them all.
|
|
90
|
-
const picture = Buffer.alloc(64 * 1024, 7);
|
|
91
|
-
const { file } = buildMatroska({
|
|
92
|
-
tracks: TRACKS,
|
|
93
|
-
cues: [1],
|
|
94
|
-
clusters: [plainCluster(0, "a", picture), plainCluster(10_000, "b", picture), plainCluster(20_000, "c", picture)]
|
|
95
|
-
});
|
|
96
|
-
const { container, plan } = await planOf(file);
|
|
97
|
-
const reads = [];
|
|
98
|
-
const held = heldOver(file, [[0, file.length - 1]], { portionBytes: 4 * 1024 * 1024, reads });
|
|
99
|
-
const result = await pass(container, plan, {}, held);
|
|
100
|
-
assert.deepEqual(result.texts.sort(), ["a", "b", "c"]);
|
|
101
|
-
const moved = reads.reduce((sum, { start, end }) => sum + (end - start + 1), 0);
|
|
102
|
-
assert.ok(moved < picture.length, `${moved} bytes read for three clusters of ${picture.length}-byte pictures`);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("with no Cues, the search stops at the first cluster it accepts and the chain knows the rest", async () => {
|
|
106
|
-
const picture = Buffer.alloc(64 * 1024, 7);
|
|
107
|
-
const { file, clusterAt } = buildMatroska({
|
|
108
|
-
tracks: TRACKS,
|
|
109
|
-
cues: null,
|
|
110
|
-
clusters: [0, 10_000, 20_000, 30_000, 40_000].map((ticks, index) => plainCluster(ticks, String(index), picture))
|
|
111
|
-
});
|
|
112
|
-
const { container, plan } = await planOf(file);
|
|
113
|
-
const reads = [];
|
|
114
|
-
// The first cluster's header is not here, so nothing establishes the chain:
|
|
115
|
-
// only the search can start it.
|
|
116
|
-
const held = heldOver(file, [[0, clusterAt[0] - 1], [clusterAt[0] + 12, file.length - 1]], { portionBytes: 32 * 1024, reads });
|
|
117
|
-
const result = await pass(container, plan, {}, held);
|
|
118
|
-
assert.deepEqual(result.texts.sort(), ["1", "2", "3", "4"]);
|
|
119
|
-
assert.equal(result.stats.fromSearch, 4, "found by the search, then by its chain");
|
|
120
|
-
const searchedPast = reads.filter(({ start }) => start > clusterAt[2]).reduce((sum, { start, end }) => sum + (end - start + 1), 0);
|
|
121
|
-
assert.ok(searchedPast < picture.length, `${searchedPast} bytes read past the third cluster`);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test("a Cluster id inside a picture's bytes is checked and refused, and gives no line", async () => {
|
|
125
|
-
// An id, a plausible size and some bytes — inside a SimpleBlock's payload.
|
|
126
|
-
const fake = Buffer.concat([idBytes(ID.CLUSTER), Buffer.from([0x88]), Buffer.alloc(8, 0x41)]);
|
|
127
|
-
const { file, clusterAt } = buildMatroska({
|
|
128
|
-
tracks: TRACKS,
|
|
129
|
-
cues: null,
|
|
130
|
-
clusters: [plainCluster(0, "a"), plainCluster(10_000, "b", Buffer.concat([Buffer.alloc(8), fake, Buffer.alloc(8)]))]
|
|
131
|
-
});
|
|
132
|
-
const { container, plan } = await planOf(file);
|
|
133
|
-
// The second cluster's own header is not downloaded, so nothing establishes it.
|
|
134
|
-
const result = await pass(
|
|
135
|
-
container,
|
|
136
|
-
plan,
|
|
137
|
-
{},
|
|
138
|
-
heldOver(file, [[0, clusterAt[1] - 1], [clusterAt[1] + 12, file.length - 1]])
|
|
139
|
-
);
|
|
140
|
-
assert.deepEqual(result.texts, ["a"]);
|
|
141
|
-
assert.ok(result.stats.rejectedCandidates >= 1, "the false start was looked at and refused");
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test("a candidate that a cluster the file establishes later turns out to contain is taken back, with its lines", async () => {
|
|
145
|
-
// A whole, well-formed cluster hidden inside a picture block of a real one.
|
|
146
|
-
const hidden = element(
|
|
147
|
-
ID.CLUSTER,
|
|
148
|
-
clusterData({ ticks: 12_000, blocks: [cueBlock({ track: 2, relativeTicks: 0, durationTicks: 500, text: "hidden" })] })
|
|
149
|
-
);
|
|
150
|
-
const { file, clusterAt } = buildMatroska({
|
|
151
|
-
tracks: TRACKS,
|
|
152
|
-
cues: null,
|
|
153
|
-
clusters: [
|
|
154
|
-
plainCluster(0, "a"),
|
|
155
|
-
plainCluster(10_000, "b", Buffer.concat([Buffer.alloc(4), hidden, Buffer.alloc(4)])),
|
|
156
|
-
plainCluster(20_000, "c")
|
|
157
|
-
]
|
|
158
|
-
});
|
|
159
|
-
const { container, plan } = await planOf(file);
|
|
160
|
-
const progress = {};
|
|
161
|
-
const hiddenAt = file.indexOf(hidden);
|
|
162
|
-
const first = await pass(
|
|
163
|
-
container,
|
|
164
|
-
plan,
|
|
165
|
-
progress,
|
|
166
|
-
heldOver(file, [[0, clusterAt[1] - 1], [clusterAt[1] + 12, file.length - 1]])
|
|
167
|
-
);
|
|
168
|
-
assert.ok(first.texts.includes("hidden"), "the search found it and its structure held");
|
|
169
|
-
|
|
170
|
-
const second = await pass(container, plan, progress, heldOver(file, [[0, file.length - 1]]));
|
|
171
|
-
assert.deepEqual(second.withdrawn, [hiddenAt], "the real cluster around it takes it back");
|
|
172
|
-
assert.deepEqual(second.texts, ["b"], "and gives its own line");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("a cluster whose bytes are only partly here is read once, when they all are", async () => {
|
|
176
|
-
const { file, clusterAt } = buildMatroska({
|
|
177
|
-
tracks: TRACKS,
|
|
178
|
-
cues: [1],
|
|
179
|
-
clusters: [plainCluster(0, "a"), plainCluster(10_000, "b")]
|
|
180
|
-
});
|
|
181
|
-
const { container, plan } = await planOf(file);
|
|
182
|
-
const progress = {};
|
|
183
|
-
const partly = await pass(container, plan, progress, heldOver(file, [[0, clusterAt[1] + 20]]));
|
|
184
|
-
assert.deepEqual(partly.texts, ["a"]);
|
|
185
|
-
const whole = await pass(container, plan, progress, heldOver(file, [[0, file.length - 1]]));
|
|
186
|
-
assert.deepEqual(whole.texts, ["b"]);
|
|
187
|
-
const again = await pass(container, plan, progress, heldOver(file, [[0, file.length - 1]]));
|
|
188
|
-
assert.deepEqual(again.texts, [], "nothing is read twice");
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test("a cluster of unknown size ends where the next top-level element begins", async () => {
|
|
192
|
-
const { file } = buildMatroska({
|
|
193
|
-
tracks: TRACKS,
|
|
194
|
-
cues: null,
|
|
195
|
-
clusters: [plainCluster(0, "a"), { ...plainCluster(10_000, "b"), unknownSize: true }, plainCluster(20_000, "c")]
|
|
196
|
-
});
|
|
197
|
-
const { container, plan } = await planOf(file);
|
|
198
|
-
const progress = {};
|
|
199
|
-
const held = heldOver(file, [[0, file.length - 1]]);
|
|
200
|
-
const first = await pass(container, plan, progress, held);
|
|
201
|
-
const second = await pass(container, plan, progress, held);
|
|
202
|
-
assert.deepEqual([...first.texts, ...second.texts].sort(), ["a", "b", "c"]);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test("a CRC-32 before the Timestamp is a cluster like any other; a candidate whose CRC is wrong is refused", async () => {
|
|
206
|
-
const withCrc = (ticks, text, crc) => ({
|
|
207
|
-
ticks,
|
|
208
|
-
data: clusterData({ ticks, crc, blocks: [cueBlock({ track: 2, relativeTicks: 0, durationTicks: 500, text })] })
|
|
209
|
-
});
|
|
210
|
-
for (const [crc, expected] of [[true, ["b", "c"]], ["wrong", ["c"]]]) {
|
|
211
|
-
const { file, clusterAt } = buildMatroska({
|
|
212
|
-
tracks: TRACKS,
|
|
213
|
-
cues: null,
|
|
214
|
-
clusters: [withCrc(0, "a", false), withCrc(10_000, "b", crc), withCrc(20_000, "c", false)]
|
|
215
|
-
});
|
|
216
|
-
const { container, plan } = await planOf(file);
|
|
217
|
-
// The first cluster's header is not here, so the second is reached only by
|
|
218
|
-
// the search, which checks the CRC.
|
|
219
|
-
const result = await pass(container, plan, {}, heldOver(file, [[0, clusterAt[0] - 1], [clusterAt[0] + 12, file.length - 1]]));
|
|
220
|
-
assert.deepEqual(result.texts.sort(), expected, `crc ${crc}`);
|
|
221
|
-
if (crc === "wrong") {
|
|
222
|
-
assert.ok(result.stats.rejectedCandidates >= 1);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
test("a candidate whose end has not arrived waits, and is read when it has", async () => {
|
|
228
|
-
const { file, clusterAt } = buildMatroska({
|
|
229
|
-
tracks: TRACKS,
|
|
230
|
-
cues: null,
|
|
231
|
-
clusters: [plainCluster(0, "a"), plainCluster(10_000, "b"), plainCluster(20_000, "c")]
|
|
232
|
-
});
|
|
233
|
-
const { container, plan } = await planOf(file);
|
|
234
|
-
const progress = {};
|
|
235
|
-
const first = await pass(
|
|
236
|
-
container,
|
|
237
|
-
plan,
|
|
238
|
-
progress,
|
|
239
|
-
heldOver(file, [[0, clusterAt[1] - 1], [clusterAt[2], clusterAt[2] + 20]])
|
|
240
|
-
);
|
|
241
|
-
assert.deepEqual(first.texts, ["a"]);
|
|
242
|
-
assert.equal(first.stats.pendingCandidates, 1, "found, and waiting for its bytes");
|
|
243
|
-
const second = await pass(container, plan, progress, heldOver(file, [[0, clusterAt[1] - 1], [clusterAt[2], file.length - 1]]));
|
|
244
|
-
assert.deepEqual(second.texts, ["c"]);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
test("an id cut by the end of what is downloaded is found once the run grows", async () => {
|
|
248
|
-
const { file, clusterAt } = buildMatroska({
|
|
249
|
-
tracks: TRACKS,
|
|
250
|
-
cues: null,
|
|
251
|
-
clusters: [plainCluster(0, "a"), plainCluster(10_000, "b"), plainCluster(20_000, "c")]
|
|
252
|
-
});
|
|
253
|
-
const { container, plan } = await planOf(file);
|
|
254
|
-
const progress = {};
|
|
255
|
-
// The run ends two bytes into the third cluster's id.
|
|
256
|
-
await pass(container, plan, progress, heldOver(file, [[0, clusterAt[1] - 1], [clusterAt[1] + 12, clusterAt[2] + 1]]));
|
|
257
|
-
const grown = await pass(container, plan, progress, heldOver(file, [[0, clusterAt[1] - 1], [clusterAt[1] + 12, file.length - 1]]));
|
|
258
|
-
assert.ok(grown.texts.includes("c"), "the cut id was searched again and found");
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("the cluster a viewer stands in is read first, then the one before it, then onward", async () => {
|
|
262
|
-
const clusters = [0, 10_000, 20_000, 30_000, 40_000].map((ticks) => plainCluster(ticks, `at ${ticks / 1000}`));
|
|
263
|
-
// A line that starts in the 10 s cluster and is still on screen at 25 s.
|
|
264
|
-
clusters[1] = {
|
|
265
|
-
ticks: 10_000,
|
|
266
|
-
data: clusterData({ ticks: 10_000, blocks: [cueBlock({ track: 2, relativeTicks: 0, durationTicks: 16_000, text: "at 10" })] })
|
|
267
|
-
};
|
|
268
|
-
const { file } = buildMatroska({ tracks: TRACKS, cues: [1], clusters });
|
|
269
|
-
const { container, plan } = await planOf(file);
|
|
270
|
-
const progress = {};
|
|
271
|
-
const held = heldOver(file, [[0, file.length - 1]], { wantedSeconds: [25] });
|
|
272
|
-
const first = await pass(container, plan, progress, held);
|
|
273
|
-
assert.deepEqual(first.texts, ["at 20", "at 10"], "the pass ends with what is on screen, to be pushed at once");
|
|
274
|
-
assert.equal(first.more, true, "and says there is more to read now");
|
|
275
|
-
const second = await pass(container, plan, progress, held);
|
|
276
|
-
assert.deepEqual(second.texts, ["at 30", "at 40", "at 0"], "then onward from the viewer, then the rest");
|
|
277
|
-
assert.equal(second.more, false);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test("a pass reading the rest stops when a viewer moves, and the next one starts from there", async () => {
|
|
281
|
-
const clusters = [0, 10_000, 20_000, 30_000, 40_000, 50_000].map((ticks) => plainCluster(ticks, `at ${ticks / 1000}`));
|
|
282
|
-
const { file } = buildMatroska({ tracks: TRACKS, cues: [1], clusters });
|
|
283
|
-
const { container, plan } = await planOf(file);
|
|
284
|
-
const progress = {};
|
|
285
|
-
let viewer = [];
|
|
286
|
-
let readsBeforeSeek = 2;
|
|
287
|
-
const held = heldOver(file, [[0, file.length - 1]]);
|
|
288
|
-
held.wantedSeconds = () => {
|
|
289
|
-
// The viewer seeks to 45 s after the pass has read two clusters.
|
|
290
|
-
readsBeforeSeek -= 1;
|
|
291
|
-
if (readsBeforeSeek < 0) {
|
|
292
|
-
viewer = [45];
|
|
293
|
-
}
|
|
294
|
-
return viewer;
|
|
295
|
-
};
|
|
296
|
-
const first = await pass(container, plan, progress, held);
|
|
297
|
-
assert.equal(first.more, true, "stopped for the viewer who moved");
|
|
298
|
-
const second = await pass(container, plan, progress, held);
|
|
299
|
-
assert.deepEqual(second.texts.slice(0, 1), ["at 40"], "the next pass reads where the viewer now is first");
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
test("no read is larger than one portion, and a block larger than one is refused while the rest is read", async () => {
|
|
303
|
-
const portion = 96;
|
|
304
|
-
const { file } = buildMatroska({
|
|
305
|
-
tracks: TRACKS,
|
|
306
|
-
cues: [1],
|
|
307
|
-
clusters: [
|
|
308
|
-
plainCluster(0, "short"),
|
|
309
|
-
{
|
|
310
|
-
ticks: 10_000,
|
|
311
|
-
data: clusterData({ ticks: 10_000, blocks: [cueBlock({ track: 2, relativeTicks: 0, durationTicks: 500, text: "x".repeat(200) })] })
|
|
312
|
-
},
|
|
313
|
-
plainCluster(20_000, "also short")
|
|
314
|
-
]
|
|
315
|
-
});
|
|
316
|
-
const { container, plan } = await planOf(file);
|
|
317
|
-
const reads = [];
|
|
318
|
-
const result = await pass(container, plan, {}, heldOver(file, [[0, file.length - 1]], { portionBytes: portion, reads }));
|
|
319
|
-
assert.deepEqual(result.texts.sort(), ["also short", "short"]);
|
|
320
|
-
assert.equal(result.stats.refusedElements, 1);
|
|
321
|
-
assert.ok(reads.every(({ start, end }) => end - start + 1 <= portion), "every read stayed within one portion");
|
|
322
|
-
});
|
|
323
|
-
|