@torrent-tv/proxy 2.89.17 → 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.
Files changed (299) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/server.js +0 -11
  4. package/.claude/commands/opsx/apply.md +0 -155
  5. package/.claude/commands/opsx/archive.md +0 -160
  6. package/.claude/commands/opsx/explore.md +0 -174
  7. package/.claude/commands/opsx/propose.md +0 -109
  8. package/.claude/commands/opsx/sync.md +0 -143
  9. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  10. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  11. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  12. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  13. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  14. package/.dockerignore +0 -5
  15. package/AGENTS.md +0 -363
  16. package/CHANGELOG.md +0 -2377
  17. package/Dockerfile +0 -30
  18. package/biome.json +0 -412
  19. package/corpus.tmp.json +0 -1
  20. package/docs/browser-proxy-contract.md +0 -155
  21. package/docs/container-architecture.md +0 -273
  22. package/docs/download-architecture.md +0 -261
  23. package/docs/encode-architecture.md +0 -765
  24. package/docs/encode-run-state.md +0 -96
  25. package/docs/logs.md +0 -151
  26. package/docs/playback-start-forecast.md +0 -113
  27. package/docs/socks5-egress-research.md +0 -114
  28. package/docs/storage-architecture.md +0 -273
  29. package/knip.json +0 -14
  30. package/main2.cpuprofile +0 -1
  31. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  32. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  33. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  34. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  35. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  36. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  37. package/openspec/changes/binary-distribution/proposal.md +0 -53
  38. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  39. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  40. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  41. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  42. package/openspec/changes/cold-start/design.md +0 -98
  43. package/openspec/changes/cold-start/proposal.md +0 -62
  44. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  45. package/openspec/changes/cold-start/tasks.md +0 -48
  46. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  47. package/openspec/changes/disk-cap/proposal.md +0 -37
  48. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  49. package/openspec/changes/disk-cap/tasks.md +0 -19
  50. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  51. package/openspec/changes/proxy-observability/design.md +0 -38
  52. package/openspec/changes/proxy-observability/proposal.md +0 -49
  53. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  54. package/openspec/changes/proxy-observability/tasks.md +0 -21
  55. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  56. package/openspec/changes/seek-debounce/design.md +0 -118
  57. package/openspec/changes/seek-debounce/proposal.md +0 -59
  58. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  59. package/openspec/changes/seek-debounce/tasks.md +0 -33
  60. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  61. package/openspec/changes/subtitle-language/proposal.md +0 -50
  62. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  63. package/openspec/changes/subtitle-language/tasks.md +0 -26
  64. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  65. package/openspec/changes/track-selection/design.md +0 -47
  66. package/openspec/changes/track-selection/proposal.md +0 -45
  67. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  68. package/openspec/changes/track-selection/tasks.md +0 -20
  69. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  70. package/openspec/changes/transcode-quality/proposal.md +0 -51
  71. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  72. package/openspec/changes/transcode-quality/tasks.md +0 -63
  73. package/openspec/config.yaml +0 -38
  74. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  75. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  76. package/research/double-spawn-2026-09-10.md +0 -171
  77. package/research/handover-2026-09-13.md +0 -209
  78. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  79. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  80. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  81. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  82. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  83. package/scripts/build-audio-samples.mjs +0 -31
  84. package/scripts/render-run-graph.js +0 -173
  85. package/test/asset-paths.test.js +0 -28
  86. package/test/audio-buffer-continuity.test.js +0 -77
  87. package/test/audio-calibration.test.js +0 -23
  88. package/test/audio-inventory.test.js +0 -212
  89. package/test/audio-track-bitrate.test.js +0 -40
  90. package/test/audio-warm-recorded.test.js +0 -63
  91. package/test/auto-quality-step.test.js +0 -762
  92. package/test/available-share.test.js +0 -76
  93. package/test/background-fill.test.js +0 -190
  94. package/test/client-log-file.test.js +0 -126
  95. package/test/client-logs-route.test.js +0 -34
  96. package/test/coalesce.test.js +0 -39
  97. package/test/completed-files.test.js +0 -115
  98. package/test/concurrent-cost.test.js +0 -148
  99. package/test/container-media-info.test.js +0 -228
  100. package/test/contention.test.js +0 -76
  101. package/test/core-dumps.test.js +0 -57
  102. package/test/coverage-follows-the-disk.test.js +0 -233
  103. package/test/coverage-map.test.js +0 -195
  104. package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
  105. package/test/cut-times-timeline.test.js +0 -65
  106. package/test/cuts-follow-published-grid.test.js +0 -109
  107. package/test/data-channel-frame.test.js +0 -63
  108. package/test/data-channel-viewer-lifecycle.test.js +0 -193
  109. package/test/dead-torrent-handle.test.js +0 -52
  110. package/test/declared-rates.test.js +0 -116
  111. package/test/declared-tracks.test.js +0 -43
  112. package/test/decode-cost-fit.test.js +0 -202
  113. package/test/decode-cost.test.js +0 -475
  114. package/test/delivery-probe-field.test.js +0 -173
  115. package/test/delivery-probe.test.js +0 -382
  116. package/test/demand-register.test.js +0 -206
  117. package/test/dht-bootstrap.test.js +0 -72
  118. package/test/drain-threat.test.js +0 -65
  119. package/test/duplicate-add.test.js +0 -48
  120. package/test/encode-admission.test.js +0 -170
  121. package/test/encode-cost.test.js +0 -275
  122. package/test/encode-exit.test.js +0 -111
  123. package/test/encode-orchestrator.test.js +0 -426
  124. package/test/encode-plan-viewers.test.js +0 -725
  125. package/test/encode-plan.test.js +0 -545
  126. package/test/encode-run-state.test.js +0 -314
  127. package/test/encode-run.test.js +0 -248
  128. package/test/encode-slope.test.js +0 -46
  129. package/test/encoded-output.test.js +0 -39
  130. package/test/encoder-kinds.test.js +0 -122
  131. package/test/encoder-readings.test.js +0 -68
  132. package/test/episode-naming.test.js +0 -131
  133. package/test/every-claimant-is-told-its-share.test.js +0 -152
  134. package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
  135. package/test/failed-start-breaker.test.js +0 -202
  136. package/test/fastest-wires.test.js +0 -143
  137. package/test/ffmpeg-stream-counts.test.js +0 -101
  138. package/test/file-edges.test.js +0 -191
  139. package/test/files-in-use.test.js +0 -34
  140. package/test/fixtures/audio-frame-boundary.json +0 -1
  141. package/test/fixtures/refused-audio-20261002.json +0 -10
  142. package/test/fmp4-presentation-clock.test.js +0 -148
  143. package/test/fmp4-self-contained.test.js +0 -80
  144. package/test/fmp4-timestamps.test.js +0 -140
  145. package/test/fmp4-track-completeness.test.js +0 -41
  146. package/test/format-keyed-outputs.test.js +0 -78
  147. package/test/health-metrics.test.js +0 -36
  148. package/test/held-read-ownership.test.js +0 -77
  149. package/test/held-request-width.test.js +0 -157
  150. package/test/helpers/encode-run.js +0 -248
  151. package/test/helpers/held-file.js +0 -77
  152. package/test/helpers/manager.js +0 -62
  153. package/test/helpers/matroska-file.js +0 -296
  154. package/test/helpers/output-spec.js +0 -63
  155. package/test/host-load.test.js +0 -68
  156. package/test/index-accuracy-is-about-the-file.test.js +0 -128
  157. package/test/init-compat.test.js +0 -219
  158. package/test/input-lost-quiets-the-plan.test.js +0 -261
  159. package/test/input-unavailable.test.js +0 -48
  160. package/test/installation-id.test.js +0 -39
  161. package/test/keeping-period.test.js +0 -83
  162. package/test/keyframe-index-accuracy.test.js +0 -188
  163. package/test/keyframe-table-budget.test.js +0 -123
  164. package/test/keyframes-belong-to-the-file.test.js +0 -249
  165. package/test/learned-median.test.js +0 -37
  166. package/test/letting-go-asks-who-is-watching.test.js +0 -191
  167. package/test/limit-row-by-area.test.js +0 -60
  168. package/test/link-budget.test.js +0 -111
  169. package/test/link-probe.test.js +0 -56
  170. package/test/local-encoding-data.test.js +0 -273
  171. package/test/logger-repeats.test.js +0 -134
  172. package/test/look-ahead-coverage.test.js +0 -56
  173. package/test/manager-surface.test.js +0 -291
  174. package/test/matroska-blocks.test.js +0 -0
  175. package/test/matroska-cluster-discovery.test.js +0 -323
  176. package/test/matroska-cues-track.test.js +0 -192
  177. package/test/media-time.test.js +0 -62
  178. package/test/memory-budget.test.js +0 -390
  179. package/test/move-cost.test.js +0 -216
  180. package/test/mp4-composition-times.test.js +0 -0
  181. package/test/mp4-subtitles.test.js +0 -173
  182. package/test/one-authority.test.js +0 -285
  183. package/test/one-budget.test.js +0 -149
  184. package/test/one-output-one-session.test.js +0 -273
  185. package/test/one-resource-divided.test.js +0 -185
  186. package/test/one-serving-output-per-height.test.js +0 -458
  187. package/test/orchestrator-wired.test.js +0 -207
  188. package/test/output-catalog.test.js +0 -39
  189. package/test/output-shape.test.js +0 -21
  190. package/test/output-spec.test.js +0 -251
  191. package/test/output-speed.test.js +0 -92
  192. package/test/outputs-being-prepared.test.js +0 -40
  193. package/test/packet-witness-ring.test.js +0 -236
  194. package/test/packet-witness.test.js +0 -148
  195. package/test/piece-completeness.test.js +0 -78
  196. package/test/piece-disk-store.test.js +0 -401
  197. package/test/piece-from-whole-file.test.js +0 -129
  198. package/test/piece-lru.test.js +0 -319
  199. package/test/piece-reader.test.js +0 -162
  200. package/test/piece-selection-offset.test.js +0 -85
  201. package/test/piece-store-eviction.test.js +0 -595
  202. package/test/piece-store-never-refuses.test.js +0 -153
  203. package/test/piece-store-reservations.test.js +0 -403
  204. package/test/piece-store-slow-disk.test.js +0 -159
  205. package/test/piece-tail.test.js +0 -97
  206. package/test/plan-host-timings.test.js +0 -68
  207. package/test/plan-is-steady.test.js +0 -225
  208. package/test/playback-readiness.test.js +0 -518
  209. package/test/playback-start-regressions.test.js +0 -101
  210. package/test/priority-map-download.test.js +0 -174
  211. package/test/priority-map-emptied.test.js +0 -204
  212. package/test/priority-map-per-output.test.js +0 -215
  213. package/test/priority-map.test.js +0 -163
  214. package/test/probe-wedge-certainty.test.js +0 -60
  215. package/test/produced-copy-choice.test.js +0 -213
  216. package/test/published-timeline.test.js +0 -83
  217. package/test/quality-offer.test.js +0 -160
  218. package/test/quality-variants.test.js +0 -1274
  219. package/test/rate-control-in-the-output.test.js +0 -181
  220. package/test/read-survives-withdrawal.test.js +0 -164
  221. package/test/read-window.test.js +0 -365
  222. package/test/reads-not-yet-arrived.test.js +0 -218
  223. package/test/resume-warm.test.js +0 -39
  224. package/test/run-graph-drift.test.js +0 -37
  225. package/test/run-inputs.test.js +0 -80
  226. package/test/run-intervals.test.js +0 -100
  227. package/test/run-position-follows-published-grid.test.js +0 -89
  228. package/test/run-progress.test.js +0 -64
  229. package/test/same-height-switch.test.js +0 -663
  230. package/test/seek-frees-the-viewers-requests.test.js +0 -217
  231. package/test/seek-landing.test.js +0 -109
  232. package/test/seek-target-not-superseded.test.js +0 -195
  233. package/test/segment-closed-on-both-branches.test.js +0 -114
  234. package/test/segment-cut-times.test.js +0 -63
  235. package/test/segment-demand.test.js +0 -80
  236. package/test/segment-hold-supersede.test.js +0 -91
  237. package/test/segment-judged-by-its-own-header.test.js +0 -222
  238. package/test/segment-serve-wiring.test.js +0 -481
  239. package/test/segment-store-eviction.test.js +0 -247
  240. package/test/segment-store.test.js +0 -352
  241. package/test/segment-true-start.test.js +0 -86
  242. package/test/segments-are-shared.test.js +0 -176
  243. package/test/send-chunk-bytes.test.js +0 -86
  244. package/test/serving-existing-output.test.js +0 -111
  245. package/test/serving-output.test.js +0 -102
  246. package/test/shared-piece-store.test.js +0 -310
  247. package/test/sidecar-naming.test.js +0 -142
  248. package/test/soundtrack-rate-bound.test.js +0 -289
  249. package/test/source-file.test.js +0 -133
  250. package/test/source-files-route.test.js +0 -113
  251. package/test/source-registry.test.js +0 -18
  252. package/test/split-a-stretch.test.js +0 -139
  253. package/test/stale-request-after-seek.test.js +0 -158
  254. package/test/startup-readings.test.js +0 -124
  255. package/test/stream-route.test.js +0 -237
  256. package/test/subtitle-cue-framing.test.js +0 -200
  257. package/test/subtitle-cue-source.test.js +0 -102
  258. package/test/subtitle-cue-walk.test.js +0 -385
  259. package/test/subtitle-cursor.test.js +0 -63
  260. package/test/subtitle-defaults.test.js +0 -118
  261. package/test/subtitle-language.test.js +0 -252
  262. package/test/subtitle-metadata.test.js +0 -15
  263. package/test/subtitle-plan-waits.test.js +0 -125
  264. package/test/subtitle-track-numbering.test.js +0 -391
  265. package/test/supply-margin.test.js +0 -190
  266. package/test/swarm-follows-readers.test.js +0 -174
  267. package/test/swarm-reach.test.js +0 -130
  268. package/test/swarm-selection.test.js +0 -220
  269. package/test/tail-duplication.test.js +0 -167
  270. package/test/the-channel-has-both-ends.test.js +0 -91
  271. package/test/the-torrent-thread-serves-bytes.test.js +0 -107
  272. package/test/thread-pool.test.js +0 -53
  273. package/test/timeline.test.js +0 -84
  274. package/test/torrent-contents.test.js +0 -235
  275. package/test/torrent-cost.test.js +0 -71
  276. package/test/torrent-files.test.js +0 -221
  277. package/test/torrent-naming.test.js +0 -255
  278. package/test/tracks-begin-together.test.js +0 -209
  279. package/test/tunnel-renewal.test.js +0 -167
  280. package/test/two-viewers-one-picture.test.js +0 -508
  281. package/test/upload-hurry.test.js +0 -186
  282. package/test/usrsctp-state.test.js +0 -131
  283. package/test/video-facts.test.js +0 -102
  284. package/test/viewer-assignments.test.js +0 -143
  285. package/test/viewer-outputs.test.js +0 -285
  286. package/test/viewer-presence.test.js +0 -116
  287. package/test/viewer-requests-admission.test.js +0 -92
  288. package/test/viewer-starts-on-map.test.js +0 -27
  289. package/test/viewer-states.test.js +0 -192
  290. package/test/viewer-subtitle-subscription.test.js +0 -96
  291. package/test/viewer.test.js +0 -139
  292. package/test/viewing-generations.test.js +0 -390
  293. package/test/visible-rung.test.js +0 -37
  294. package/test/wait-ledger.test.js +0 -100
  295. package/test/webrtc-shim.test.js +0 -149
  296. package/test/wedge-certainty.test.js +0 -131
  297. package/test/whole-file-held-read.test.js +0 -30
  298. package/test/withdraw-piece-claim.test.js +0 -212
  299. package/test/worker-channel.test.js +0 -158
@@ -1,91 +0,0 @@
1
- /**
2
- * @file Every call across the thread boundary has something to land on.
3
- *
4
- * The boundary is three files that have to agree, and nothing made them:
5
- * `protocol.js` names the commands, `worker.js` answers them, `client.js` asks,
6
- * and `pool-adapter.js` is what the main thread calls. A mismatch anywhere in
7
- * that chain is invisible to every other check in this repository, because a
8
- * unit test of either end alone passes and the failure needs a real worker.
9
- *
10
- * It was not hypothetical. Removing three commands on 2026-09-15 took an
11
- * unrelated neighbour with them — `client.fillFile`, which the adapter went on
12
- * calling — and left two adapter methods calling commands that no longer
13
- * existed. One of those two is the browser's own subtitle request, and it did
14
- * not even throw where anybody would see it: the orchestrator caught the error
15
- * and answered an EMPTY document, which is indistinguishable from a file that
16
- * genuinely holds no cues. That is the exact failure the whole subtitle path is
17
- * written to avoid, and it would have reached the field.
18
- *
19
- * These are structural because the property is: there is no input that makes a
20
- * call land on a method that is not there.
21
- */
22
-
23
- import test from "node:test";
24
- import assert from "node:assert/strict";
25
- import { readFileSync } from "node:fs";
26
- import path from "node:path";
27
- import { fileURLToPath } from "node:url";
28
-
29
- const WORKER = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../services/torrent/worker");
30
-
31
- /**
32
- * @param {string} name
33
- * @returns {string}
34
- */
35
- function source(name) {
36
- return readFileSync(path.join(WORKER, name), "utf8");
37
- }
38
-
39
- /**
40
- * Names a file defines at the top level of a class: methods, and fields it
41
- * assigns to itself. Both are callable or readable from outside.
42
- *
43
- * @param {string} text
44
- * @returns {Set<string>}
45
- */
46
- function membersOf(text) {
47
- const names = new Set();
48
- for (const match of text.matchAll(/^\s{2}(?:static\s+)?(?:async\s+)?(?:get\s+|set\s+)?([a-zA-Z#][a-zA-Z0-9]*)\s*[(=]/gm)) {
49
- names.add(match[1]);
50
- }
51
- // Fields a constructor or a method assigns rather than declares.
52
- for (const match of text.matchAll(/this\.([a-zA-Z][a-zA-Z0-9]*)\s*=/g)) {
53
- names.add(match[1]);
54
- }
55
- return names;
56
- }
57
-
58
- test("every client method the adapter calls exists", () => {
59
- const have = membersOf(source("client.js"));
60
- const used = [...source("pool-adapter.js").matchAll(/#client\.([a-zA-Z][a-zA-Z0-9]*)/g)].map((m) => m[1]);
61
-
62
- assert.deepEqual([...new Set(used)].filter((name) => !have.has(name)), []);
63
- });
64
-
65
- test("every command the client sends is answered by the worker", () => {
66
- const protocol = source("protocol.js");
67
- const answered = new Set([...source("worker.js").matchAll(/case Command\.([A-Z_]+):/g)].map((m) => m[1]));
68
- const sent = [...source("client.js").matchAll(/Command\.([A-Z_]+)/g)].map((m) => m[1]);
69
-
70
- const unanswered = [...new Set(sent)].filter((name) => !answered.has(name));
71
- assert.deepEqual(unanswered, [], "a command nobody answers waits for a reply that never comes");
72
-
73
- const undeclared = [...new Set(sent)].filter((name) => !protocol.includes(` ${name}:`));
74
- assert.deepEqual(undeclared, [], "and one the protocol does not name is `undefined` on the wire");
75
- });
76
-
77
- test("every event the worker posts is received somewhere on the main thread", () => {
78
- // TWO receivers, and they answer different shapes. `channel.js` matches the
79
- // replies to a request by its id — a result, an error, a chunk of a body —
80
- // while `client.js` has a `case` for each event that belongs to nobody's
81
- // request. An event handled by neither is a fact announced into silence.
82
- const receiving = `${source("client.js")}
83
- ${source("channel.js")}`;
84
- const handled = new Set([
85
- ...[...receiving.matchAll(/case Event\.([A-Z_]+):/g)].map((m) => m[1]),
86
- ...[...receiving.matchAll(/message\.type === Event\.([A-Z_]+)/g)].map((m) => m[1])
87
- ]);
88
- const posted = [...source("worker.js").matchAll(/type:\s*Event\.([A-Z_]+)/g)].map((m) => m[1]);
89
-
90
- assert.deepEqual([...new Set(posted)].filter((name) => !handled.has(name)), []);
91
- });
@@ -1,107 +0,0 @@
1
- /**
2
- * @file The torrent thread serves bytes. It does not read what a file says.
3
- *
4
- * Both halves of that were true of the design and only one was true of the
5
- * code: pieces have lived in shared memory since the reader was rewritten, and
6
- * the torrent thread ALSO parsed containers — the track table, the media info
7
- * and the keyframe index — and carried each answer back over the channel.
8
- *
9
- * The stated reason was "the main thread cannot open a read stream on one of
10
- * its files". That is true of WebTorrent's own API and not of the bytes: a
11
- * container is built from one function, `readRange(start, end)`, and the read
12
- * that serves every segment already waits for what has not arrived and steers
13
- * the swarm toward it. What the split cost was three commands, a second
14
- * `ContainerOrchestrator` in that thread, and — because an answer then had to
15
- * be carried across — the question of where each such answer is KEPT, which is
16
- * how one fact came to be stored twice.
17
- *
18
- * These checks are structural because the property is structural: there is no
19
- * input that makes a parse happen in the wrong thread, only an import.
20
- */
21
-
22
- import test from "node:test";
23
- import assert from "node:assert/strict";
24
- import { readFileSync, readdirSync } from "node:fs";
25
- import path from "node:path";
26
- import { fileURLToPath } from "node:url";
27
-
28
- const WORKER = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../services/torrent/worker");
29
-
30
- /**
31
- * @param {string} name
32
- * @returns {string}
33
- */
34
- function source(name) {
35
- return readFileSync(path.join(WORKER, name), "utf8");
36
- }
37
-
38
- test("no command asks the torrent thread what a file declares", () => {
39
- const protocol = source("protocol.js");
40
-
41
- for (const gone of [
42
- "CONTAINER_TRACKS",
43
- "CONTAINER_MEDIA_INFO",
44
- "CONTAINER_KEYFRAMES",
45
- "SUBTITLE_TRACKS",
46
- "SUBTITLE_CUES"
47
- ]) {
48
- assert.equal(
49
- protocol.includes(gone),
50
- false,
51
- `${gone} is a question about the FILE, and it is answered where the sessions are`
52
- );
53
- }
54
- });
55
-
56
- test("nothing in that thread reaches into the media layer at all", () => {
57
- // The last one to was the subtitle cue walk, and it moved with the rest: it
58
- // is handed which ranges of a file are downloaded whole and how to read one
59
- // of those, and it has no use for a torrent beyond that. What stayed behind
60
- // is the two things only this thread can answer — the bitfield as a list of
61
- // ranges, and a store read that never fetches (`held-bytes.js`).
62
- const reaching = readdirSync(WORKER)
63
- .filter((name) => name.endsWith(".js"))
64
- .filter((name) => /from "(?:\.\.\/)+media\//.test(source(name)));
65
-
66
- assert.deepEqual(reaching, []);
67
- });
68
-
69
- test("what the walk may read is answered as a list, not asked per cluster", () => {
70
- // A pass asks about every cluster of the file — hundreds on the field files,
71
- // every three seconds. One list per pass costs one message; the same answers
72
- // one at a time would cost hundreds of round trips for a walk that is meant
73
- // to be free when there is nothing new to find.
74
- const held = source("held-bytes.js");
75
-
76
- assert.match(held, /export function heldRangesOf\(torrent, fileIndex\)/);
77
- assert.match(held, /export function readHeldBytes\(/);
78
- });
79
-
80
- test("the walk's read never fetches", () => {
81
- // The ordinary range read declares demand and steers the swarm, which is
82
- // right for a viewer waiting on a segment and wrong here: switching subtitles
83
- // on must not pull bytes the viewer is not waiting for.
84
- const held = source("held-bytes.js");
85
-
86
- assert.equal(held.includes("demandFor"), false);
87
- assert.equal(held.includes("readFragments"), false);
88
- });
89
-
90
- test("the resume warm is TOLD how long the file runs", () => {
91
- // It used to read the container itself to find out, which is what a file
92
- // states about itself. What is left here is the part that really is the
93
- // torrent's: a position in seconds becomes a byte offset, and that region is
94
- // pulled off the swarm.
95
- const warm = source("resume-warm.js");
96
-
97
- assert.match(warm, /options\.durationSeconds/);
98
- assert.equal(warm.includes("containerOrchestrator"), false);
99
- assert.equal(warm.includes("ContainerFactory"), false);
100
- });
101
-
102
- test("the main thread can read a byte range of a file", () => {
103
- // The one thing the move needed, and the whole of what a container is built
104
- // from. Without it the parse has nowhere to get its bytes and the commands
105
- // come back.
106
- assert.match(source("pool-adapter.js"), /async readRangeOf\(torrent, fileIndex, start, end\)/);
107
- });
@@ -1,53 +0,0 @@
1
- /**
2
- * @file The blocking-call pool is stated before anything can create it.
3
- *
4
- * Field 2026-08-18: a film with 517 seeders spent eleven minutes with zero
5
- * peers on the addon host. Every announce timed out — UDP and HTTP alike — and
6
- * the cause was not the network: resolving that torrent's ten tracker names as
7
- * a burst took 7.58 s on the default four-thread pool, against 27-42 ms each
8
- * when the pool was larger. A dead tracker holds a thread for the resolver's
9
- * whole timeout, and every announce queued behind it misses its own deadline.
10
- */
11
-
12
- import test from "node:test";
13
- import assert from "node:assert/strict";
14
- import { readFile } from "node:fs/promises";
15
- import path from "node:path";
16
- import { fileURLToPath } from "node:url";
17
-
18
- const here = path.dirname(fileURLToPath(import.meta.url));
19
-
20
- test("the pool is set, and left alone when the deployment states its own", async () => {
21
- const previous = process.env.UV_THREADPOOL_SIZE;
22
- try {
23
- process.env.UV_THREADPOOL_SIZE = "";
24
- await import(`../bin/thread-pool.js?first=${Date.now()}`);
25
- assert.equal(
26
- Number(process.env.UV_THREADPOOL_SIZE) >= 16,
27
- true,
28
- "enough threads for a torrent's whole announce list to resolve at once"
29
- );
30
-
31
- process.env.UV_THREADPOOL_SIZE = "8";
32
- await import(`../bin/thread-pool.js?stated=${Date.now()}`);
33
- assert.equal(process.env.UV_THREADPOOL_SIZE, "8", "a stated size is the deployment's to choose");
34
- } finally {
35
- if (previous === undefined) {
36
- delete process.env.UV_THREADPOOL_SIZE;
37
- } else {
38
- process.env.UV_THREADPOOL_SIZE = previous;
39
- }
40
- }
41
- });
42
-
43
- test("the entry point imports it before anything that could create the pool", async () => {
44
- const cli = await readFile(path.join(here, "..", "bin", "cli.js"), "utf8");
45
- const imports = [...cli.matchAll(/^import\s.*?from\s+["'](.+?)["'];|^import\s+["'](.+?)["'];/gm)]
46
- .map((match) => match[1] ?? match[2]);
47
-
48
- assert.equal(
49
- imports[0],
50
- "./thread-pool.js",
51
- "a module's imports run before its body, so this cannot be a statement in cli.js"
52
- );
53
- });
@@ -1,84 +0,0 @@
1
- /**
2
- * @file Where a file is cut is a fact about the FILE, held once.
3
- *
4
- * Every quality step of one film has to be cut at exactly the same times, and
5
- * every session serving it has to publish the same playlist. That agreement was
6
- * arranged by COPYING — a table handed to each new session at creation — and it
7
- * drifted twice in the field: 0.6-2.9 s between two sessions of one film on
8
- * 2026-08-17, and segments arriving a uniform 2.002 s before the times the
9
- * playlist named for them on 2026-08-20, four times what a player bridges.
10
- */
11
-
12
- import test from "node:test";
13
- import assert from "node:assert/strict";
14
- import { Timeline, Timelines } from "../services/encode/output/Timeline.js";
15
-
16
- /**
17
- * @returns {Timeline}
18
- */
19
- function fourSecondGrid() {
20
- // Only what is per grid. The container's own keyframe table, how exact it is,
21
- // which container answered and how long the file runs are facts of the FILE
22
- // and live on the source file — stating them here stated nothing.
23
- return new Timeline({
24
- boundaries: [0, 4, 8, 12, 16],
25
- cutGrid: "keyframe"
26
- });
27
- }
28
-
29
- test("the table the player was given does not move when the live one is corrected", () => {
30
- const timeline = fourSecondGrid();
31
-
32
- // A produced segment says where the file's cut really is. That corrects what
33
- // a run will cut at; it must never correct what the player was told, because
34
- // the player places a fragment by the playlist it holds and that text was
35
- // written once.
36
- timeline.boundaries[2] = 8.5;
37
-
38
- assert.equal(timeline.liveStartOf(2), 8.5);
39
- assert.equal(timeline.publishedStartOf(2), 8);
40
- });
41
-
42
- test("one file and grid answer with one table, whoever asks", () => {
43
- const timelines = new Timelines();
44
- const key = Timelines.keyFor("torrent:abc", 0, "keyframe");
45
-
46
- const first = timelines.get(key, fourSecondGrid);
47
- const second = timelines.get(key, () => {
48
- throw new Error("a second table would be the drift this exists to remove");
49
- });
50
-
51
- assert.equal(second, first);
52
- // A correction found by one session is seen by every other, because there is
53
- // nothing to keep in step.
54
- first.boundaries[1] = 4.5;
55
- assert.equal(second.liveStartOf(1), 4.5);
56
- });
57
-
58
- test("the same file cut two ways is two tables", () => {
59
- const timelines = new Timelines();
60
- const onKeyframes = timelines.get(Timelines.keyFor("torrent:abc", 0, "keyframe"), fourSecondGrid);
61
- const onTheEvenGrid = timelines.get(Timelines.keyFor("torrent:abc", 0, "uniform"), fourSecondGrid);
62
-
63
- assert.notEqual(onTheEvenGrid, onKeyframes);
64
- });
65
-
66
- test("which segment holds a moment", () => {
67
- const timeline = fourSecondGrid();
68
-
69
- assert.equal(timeline.indexForTime(0), 0);
70
- assert.equal(timeline.indexForTime(3.9), 0);
71
- assert.equal(timeline.indexForTime(4), 1);
72
- assert.equal(timeline.indexForTime(15.9), 3);
73
- assert.equal(timeline.indexForTime(99), 3, "past the end is the last segment, not an error");
74
- });
75
-
76
- test("a timeline nobody holds is dropped", () => {
77
- const timelines = new Timelines();
78
- const kept = timelines.get(Timelines.keyFor("torrent:abc", 0, "keyframe"), fourSecondGrid);
79
- timelines.get(Timelines.keyFor("torrent:xyz", 0, "keyframe"), fourSecondGrid);
80
-
81
- assert.equal(timelines.size, 2);
82
- assert.equal(timelines.forgetUnused(new Set([kept])), 1);
83
- assert.equal(timelines.size, 1);
84
- });
@@ -1,235 +0,0 @@
1
- /**
2
- * @file What one torrent says is in it: its pictures, what belongs to each, and
3
- * the order a person reads them in.
4
- *
5
- * The fixtures are real releases. `Drifters` ships twelve episodes in the root
6
- * with a Russian soundtrack per episode under `Rus Sound/` and a subtitle file
7
- * per episode under `Sub/[group]/`; the single-film shape ships one `.mkv` with
8
- * a dub whose name has nothing in common with it. Both are the cases the
9
- * pairing rules beside this were written against, and this file is about what
10
- * is built ON them — the grouping, the order and the leftovers.
11
- *
12
- * Measured on the survey collection, 2026-09-12, and recorded here because it
13
- * is what says the grouping is not an invention: 134 torrents, 44 of them with
14
- * more than one picture, 1357 items and 421 files paired to one. Not a single
15
- * file was paired to two pictures, and in all 1357 the grouping agreed with the
16
- * per-picture call it replaces.
17
- */
18
-
19
- import test from "node:test";
20
- import assert from "node:assert/strict";
21
- import { TorrentContents, contentsOf } from "../services/torrent/Contents.js";
22
-
23
- /**
24
- * The Drifters torrent, as WebTorrent reports it: every path prefixed with the
25
- * torrent's own name, and the episodes in the order the tool that made it chose
26
- * — which is not the order anybody reads them in.
27
- *
28
- * @param {number[]} episodes
29
- * @returns {Array<{ path: string, name: string, length: number }>}
30
- */
31
- function driftersFiles(episodes) {
32
- const files = [];
33
- const push = (relative, length) => {
34
- const name = relative.slice(relative.lastIndexOf("/") + 1);
35
- files.push({ path: `Drifters/${relative}`, name, length });
36
- };
37
- for (const episode of episodes) {
38
- const stem = `[HorribleSubs] Drifters - ${String(episode).padStart(2, "0")} [1080p]`;
39
- push(`Sub/[Stan WarHammer & Nesitach]/${stem}.ass`, 29_000);
40
- push(`Rus Sound/${stem}.mka`, 30_000_000);
41
- push(`${stem}.mkv`, 566_000_000);
42
- }
43
- return files;
44
- }
45
-
46
- test("every picture is an item, with its own sound and subtitles on it", () => {
47
- const contents = new TorrentContents({ files: driftersFiles([1, 2]), name: "Drifters" });
48
-
49
- assert.equal(contents.videoCount, 2);
50
- assert.equal(contents.items.length, 2);
51
- const [first, second] = contents.items;
52
- assert.match(first.name, / - 01 /);
53
- assert.match(second.name, / - 02 /);
54
- assert.deepEqual(
55
- first.audio.map((file) => file.name),
56
- ["[HorribleSubs] Drifters - 01 [1080p].mka"]
57
- );
58
- assert.deepEqual(
59
- first.subtitles.map((file) => file.name),
60
- ["[HorribleSubs] Drifters - 01 [1080p].ass"]
61
- );
62
- // The sound of episode 1 must never appear on the picture of episode 2: the
63
- // wrong pairing is silent everywhere downstream.
64
- assert.deepEqual(
65
- second.audio.map((file) => file.name),
66
- ["[HorribleSubs] Drifters - 02 [1080p].mka"]
67
- );
68
- });
69
-
70
- test("items come out in the order a person reads them, not the torrent's own", () => {
71
- // A real release lists its episodes 08, 06, 07, 01 — the order of whatever
72
- // tool made the torrent, routinely by size.
73
- const contents = new TorrentContents({ files: driftersFiles([8, 6, 10, 2]), name: "Drifters" });
74
-
75
- assert.deepEqual(
76
- contents.items.map((item) => item.name.match(/ - (\d+) /)[1]),
77
- ["02", "06", "08", "10"]
78
- );
79
- });
80
-
81
- test("runs of digits are compared as numbers, so 2 comes before 10", () => {
82
- const files = [
83
- { path: "Show/ep10.mkv", name: "ep10.mkv", length: 9 },
84
- { path: "Show/ep2.mkv", name: "ep2.mkv", length: 9 }
85
- ];
86
- const contents = new TorrentContents({ files, name: "Show" });
87
-
88
- assert.deepEqual(
89
- contents.items.map((item) => item.name),
90
- ["ep2.mkv", "ep10.mkv"]
91
- );
92
- });
93
-
94
- test("an item keeps the torrent's own index, whatever order it is read in", () => {
95
- const contents = new TorrentContents({ files: driftersFiles([8, 2]), name: "Drifters" });
96
-
97
- // Episode 2 is read first and is the fifth file of the torrent.
98
- assert.equal(contents.items[0].fileIndex, 5);
99
- assert.equal(contents.items[1].fileIndex, 2);
100
- });
101
-
102
- test("a file is answered for by the item it belongs to, as a picture or as a part", () => {
103
- const contents = new TorrentContents({ files: driftersFiles([1]), name: "Drifters" });
104
- const [item] = contents.items;
105
-
106
- assert.equal(contents.itemOf(item.fileIndex), item);
107
- assert.equal(contents.itemOf(item.audio[0].fileIndex), item);
108
- assert.equal(contents.itemOf(item.subtitles[0].fileIndex), item);
109
- assert.equal(contents.itemOf(404), null);
110
- });
111
-
112
- test("what belongs beside one picture is answered from what was decided once", () => {
113
- const contents = new TorrentContents({ files: driftersFiles([1, 2]), name: "Drifters" });
114
- const [first] = contents.items;
115
-
116
- const beside = contents.sidecarsOf(first.fileIndex);
117
- assert.deepEqual(beside.audio, first.audio);
118
- assert.deepEqual(beside.subtitles, first.subtitles);
119
- // Asked about a file that is not a picture, the answer is nothing rather than
120
- // the item that file happens to sit in: the question is "what goes beside
121
- // this picture", and a soundtrack is not one.
122
- assert.deepEqual(contents.sidecarsOf(first.audio[0].fileIndex), {
123
- audio: [],
124
- subtitles: [],
125
- images: []
126
- });
127
- });
128
-
129
- test("a torrent with one picture takes the dub whose name has nothing in common", () => {
130
- const files = [
131
- { path: "Film/Film.2024.1080p.mkv", name: "Film.2024.1080p.mkv", length: 4_000_000_000 },
132
- { path: "Film/Rus Sound/dub.mka", name: "dub.mka", length: 30_000_000 }
133
- ];
134
- const contents = new TorrentContents({ files, name: "Film" });
135
-
136
- assert.equal(contents.items.length, 1);
137
- assert.deepEqual(
138
- contents.items[0].audio.map((file) => file.name),
139
- ["dub.mka"]
140
- );
141
- assert.deepEqual(contents.leftovers, []);
142
- });
143
-
144
- test("what belongs to no picture is listed as such, and nothing is lost", () => {
145
- // `.nfo` is the release's own note and belongs to nothing. A `.txt` would
146
- // NOT do here: the pairing layer counts it among the subtitle formats, and a
147
- // torrent with one picture takes every sidecar there is.
148
- const files = [
149
- { path: "Film/Film.mkv", name: "Film.mkv", length: 9 },
150
- { path: "Film/release.nfo", name: "release.nfo", length: 1 },
151
- { path: "Film/Screens/unrelated.jpg", name: "unrelated.jpg", length: 1 }
152
- ];
153
- const contents = new TorrentContents({ files, name: "Film" });
154
-
155
- assert.deepEqual(
156
- contents.leftovers.map((file) => file.relativePath),
157
- ["release.nfo", "Screens/unrelated.jpg"]
158
- );
159
- const accounted =
160
- contents.items.length +
161
- contents.items.reduce(
162
- (count, item) => count + item.audio.length + item.subtitles.length + item.images.length,
163
- 0
164
- ) +
165
- contents.leftovers.length;
166
- assert.equal(accounted, files.length);
167
- });
168
-
169
- test("a torrent whose metadata has not arrived says it holds nothing", () => {
170
- const contents = new TorrentContents({ files: [], name: "" });
171
-
172
- assert.deepEqual(contents.items, []);
173
- assert.deepEqual(contents.leftovers, []);
174
- assert.equal(contents.videoCount, 0);
175
- assert.equal(contents.itemOf(0), null);
176
- });
177
-
178
- test("the answer is worked out once per torrent, and again when its files arrive", () => {
179
- const torrent = { name: "Drifters", files: [] };
180
-
181
- const empty = contentsOf(torrent);
182
- assert.equal(contentsOf(torrent), empty, "asking twice must not work it out twice");
183
-
184
- // A magnet has no files until its metadata lands, which happens exactly once.
185
- torrent.files = driftersFiles([1]);
186
- const full = contentsOf(torrent);
187
- assert.notEqual(full, empty);
188
- assert.equal(full.items.length, 1);
189
- assert.equal(contentsOf(torrent), full);
190
- });
191
-
192
- test("folders order before names, so seasons stay together", () => {
193
- const files = [
194
- { path: "Show/Season 2/ep 1.mkv", length: 9 },
195
- { path: "Show/Season 10/ep 1.mkv", length: 9 },
196
- { path: "Show/Season 1/ep 2.mkv", length: 9 },
197
- { path: "Show/Season 1/ep 1.mkv", length: 9 }
198
- ];
199
- const contents = new TorrentContents({ files, name: "Show" });
200
-
201
- assert.deepEqual(
202
- contents.items.map((item) => item.relativePath),
203
- ["Season 1/ep 1.mkv", "Season 1/ep 2.mkv", "Season 2/ep 1.mkv", "Season 10/ep 1.mkv"]
204
- );
205
- });
206
-
207
- test("every file is described by what it is, in the order a person reads them", () => {
208
- // What the browser is given. It used to answer this itself — a list of video
209
- // extensions in its parser and a second, shorter pair inside its picker —
210
- // against this one, and the three had already diverged.
211
- const files = [
212
- { path: "Film/notes.nfo", length: 1 },
213
- { path: "Film/cover.jpg", length: 2 },
214
- { path: "Film/film.mkv", length: 9 },
215
- { path: "Film/Rus Sound/dub.mka", length: 3 },
216
- { path: "Film/Sub/film.ass", length: 1 }
217
- ];
218
- const contents = new TorrentContents({ files, name: "Film" });
219
-
220
- assert.deepEqual(
221
- contents.files().map((file) => [file.relativePath, file.kind]),
222
- [
223
- ["cover.jpg", "image"],
224
- ["film.mkv", "video"],
225
- ["notes.nfo", "other"],
226
- ["Rus Sound/dub.mka", "audio"],
227
- ["Sub/film.ass", "subtitle"]
228
- ]
229
- );
230
- assert.deepEqual(
231
- contents.files().map((file) => file.fileIndex),
232
- [1, 2, 0, 3, 4],
233
- "the torrent's own numbers travel with them"
234
- );
235
- });
@@ -1,71 +0,0 @@
1
- /**
2
- * @file What the torrent costs per megabyte, once the draw that would have
3
- * happened anyway is taken off.
4
- *
5
- * The readings behind these cases are the addon host's own, 2026-08-18:
6
- * 145.4 ms/MB over 8.7 MB and 23.1 ms/MB over 54 MB in the same session, which
7
- * is what a fixed minimum-megabytes threshold failed to stop.
8
- */
9
- import assert from "node:assert/strict";
10
- import { test } from "node:test";
11
- import { baseDrawFrom, costPerMegabyteFrom } from "../services/encode/torrent-cost.js";
12
-
13
- test("the base draw is the share of a core spent with nothing to do", () => {
14
- assert.equal(baseDrawFrom({ cpuSeconds: 0.5, elapsedSeconds: 5 }), 0.1);
15
- assert.equal(baseDrawFrom({ cpuSeconds: 0, elapsedSeconds: 5 }), 0);
16
- assert.equal(baseDrawFrom({ cpuSeconds: 1, elapsedSeconds: 0 }), null);
17
- assert.equal(baseDrawFrom({ cpuSeconds: Number.NaN, elapsedSeconds: 5 }), null);
18
- });
19
-
20
- test("the draw comes off before the megabytes are divided by", () => {
21
- // 1 s of CPU over 5 s, of which 0.1 of a core is spent regardless: 0.5 s left
22
- // for 50 MB.
23
- const cost = costPerMegabyteFrom({ cpuSeconds: 1, elapsedSeconds: 5, megabytes: 50, baseDraw: 0.1 });
24
- assert.equal(cost, 0.01);
25
- });
26
-
27
- test("a small interval no longer reports a huge price", () => {
28
- // The same host and the same draw, one interval moving 54 MB and one moving
29
- // 8.7 MB. Without the subtraction the second reads six times the first.
30
- const draw = 0.1;
31
- const big = costPerMegabyteFrom({ cpuSeconds: 1.85, elapsedSeconds: 5, megabytes: 54, baseDraw: draw });
32
- const small = costPerMegabyteFrom({ cpuSeconds: 0.72, elapsedSeconds: 5, megabytes: 8.7, baseDraw: draw });
33
- assert.ok(Math.abs(big - small) / big < 0.05, `${big} vs ${small}`);
34
- });
35
-
36
- test("with no base draw measured the interval says nothing", () => {
37
- assert.equal(costPerMegabyteFrom({ cpuSeconds: 1, elapsedSeconds: 5, megabytes: 50, baseDraw: null }), null);
38
- });
39
-
40
- test("an interval that spent no more than the draw says nothing either", () => {
41
- assert.equal(costPerMegabyteFrom({ cpuSeconds: 0.5, elapsedSeconds: 5, megabytes: 50, baseDraw: 0.1 }), null);
42
- });
43
-
44
- test("nothing moved cannot be priced per megabyte", () => {
45
- assert.equal(costPerMegabyteFrom({ cpuSeconds: 1, elapsedSeconds: 5, megabytes: 0, baseDraw: 0.1 }), null);
46
- });
47
-
48
- test("a remainder inside the draw's own disagreement is not a price", () => {
49
- // The draw is 0.1 of a core and its readings disagree by 0.01 of one. Over a
50
- // five-second interval that is 0.05 s of CPU nobody can attribute, so a
51
- // remainder smaller than that says nothing however many megabytes moved.
52
- const noisy = costPerMegabyteFrom({
53
- cpuSeconds: 0.53,
54
- elapsedSeconds: 5,
55
- megabytes: 0.5,
56
- baseDraw: 0.1,
57
- drawScatter: 0.01
58
- });
59
- assert.equal(noisy, null);
60
-
61
- // The same host and the same disagreement, an interval that moved enough for
62
- // the remainder to exceed it.
63
- const solid = costPerMegabyteFrom({
64
- cpuSeconds: 1.74,
65
- elapsedSeconds: 5,
66
- megabytes: 54,
67
- baseDraw: 0.1,
68
- drawScatter: 0.01
69
- });
70
- assert.ok(Math.abs(solid - 0.023) < 0.001, `${solid}`);
71
- });