@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.
Files changed (299) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/routes/api/client-logs/post.js +9 -2
  4. package/server.js +0 -11
  5. package/.claude/commands/opsx/apply.md +0 -155
  6. package/.claude/commands/opsx/archive.md +0 -160
  7. package/.claude/commands/opsx/explore.md +0 -174
  8. package/.claude/commands/opsx/propose.md +0 -109
  9. package/.claude/commands/opsx/sync.md +0 -143
  10. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  11. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  12. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  13. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  14. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  15. package/.dockerignore +0 -5
  16. package/AGENTS.md +0 -363
  17. package/CHANGELOG.md +0 -2373
  18. package/Dockerfile +0 -30
  19. package/biome.json +0 -412
  20. package/corpus.tmp.json +0 -1
  21. package/docs/browser-proxy-contract.md +0 -155
  22. package/docs/container-architecture.md +0 -273
  23. package/docs/download-architecture.md +0 -261
  24. package/docs/encode-architecture.md +0 -765
  25. package/docs/encode-run-state.md +0 -96
  26. package/docs/logs.md +0 -138
  27. package/docs/playback-start-forecast.md +0 -113
  28. package/docs/socks5-egress-research.md +0 -114
  29. package/docs/storage-architecture.md +0 -273
  30. package/knip.json +0 -14
  31. package/main2.cpuprofile +0 -1
  32. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  33. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  34. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  35. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  36. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  37. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  38. package/openspec/changes/binary-distribution/proposal.md +0 -53
  39. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  40. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  41. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  42. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  43. package/openspec/changes/cold-start/design.md +0 -98
  44. package/openspec/changes/cold-start/proposal.md +0 -62
  45. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  46. package/openspec/changes/cold-start/tasks.md +0 -48
  47. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  48. package/openspec/changes/disk-cap/proposal.md +0 -37
  49. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  50. package/openspec/changes/disk-cap/tasks.md +0 -19
  51. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  52. package/openspec/changes/proxy-observability/design.md +0 -38
  53. package/openspec/changes/proxy-observability/proposal.md +0 -49
  54. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  55. package/openspec/changes/proxy-observability/tasks.md +0 -21
  56. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  57. package/openspec/changes/seek-debounce/design.md +0 -118
  58. package/openspec/changes/seek-debounce/proposal.md +0 -59
  59. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  60. package/openspec/changes/seek-debounce/tasks.md +0 -33
  61. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  62. package/openspec/changes/subtitle-language/proposal.md +0 -50
  63. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  64. package/openspec/changes/subtitle-language/tasks.md +0 -26
  65. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  66. package/openspec/changes/track-selection/design.md +0 -47
  67. package/openspec/changes/track-selection/proposal.md +0 -45
  68. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  69. package/openspec/changes/track-selection/tasks.md +0 -20
  70. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  71. package/openspec/changes/transcode-quality/proposal.md +0 -51
  72. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  73. package/openspec/changes/transcode-quality/tasks.md +0 -63
  74. package/openspec/config.yaml +0 -38
  75. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  76. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  77. package/research/double-spawn-2026-09-10.md +0 -171
  78. package/research/handover-2026-09-13.md +0 -209
  79. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  80. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  81. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  82. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  83. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  84. package/scripts/build-audio-samples.mjs +0 -31
  85. package/scripts/render-run-graph.js +0 -173
  86. package/test/asset-paths.test.js +0 -28
  87. package/test/audio-buffer-continuity.test.js +0 -77
  88. package/test/audio-calibration.test.js +0 -23
  89. package/test/audio-inventory.test.js +0 -212
  90. package/test/audio-track-bitrate.test.js +0 -40
  91. package/test/audio-warm-recorded.test.js +0 -63
  92. package/test/auto-quality-step.test.js +0 -762
  93. package/test/available-share.test.js +0 -76
  94. package/test/background-fill.test.js +0 -190
  95. package/test/client-log-file.test.js +0 -126
  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,219 +0,0 @@
1
- /**
2
- * @file The rule that decides whether one output's pieces may be played under
3
- * another's header — and it is written BEFORE the experiment that will use it.
4
- *
5
- * The order matters and was a review finding: a criterion derived from the
6
- * differences an experiment happened to produce proves only that those
7
- * differences were handled. This one compares the whole header, names every
8
- * difference by where it sits, and refuses anything no listed exception covers.
9
- */
10
-
11
- import test from "node:test";
12
- import assert from "node:assert/strict";
13
- import { INIT_DIFFERENCE_EXCEPTIONS, compareInits, initLeaves } from "../services/encode/segment-formats/init-compat.js";
14
-
15
- /**
16
- * One ISO base media box.
17
- *
18
- * @param {string} type
19
- * @param {...(Buffer | number[])} parts
20
- * @returns {Buffer}
21
- */
22
- function box(type, ...parts) {
23
- const body = Buffer.concat(parts.map((part) => (Buffer.isBuffer(part) ? part : Buffer.from(part))));
24
- const header = Buffer.alloc(8);
25
- header.writeUInt32BE(body.length + 8, 0);
26
- header.write(type, 4, "latin1");
27
- return Buffer.concat([header, body]);
28
- }
29
-
30
- /**
31
- * A version-0 `mdhd`: version+flags, creation, modification, timescale,
32
- * duration, language, quality.
33
- *
34
- * @param {number} timescale
35
- * @returns {Buffer}
36
- */
37
- function mdhd(timescale) {
38
- const body = Buffer.alloc(24);
39
- body.writeUInt32BE(timescale, 12);
40
- return box("mdhd", body);
41
- }
42
-
43
- /**
44
- * A `btrt`: decoding buffer size, maximum rate, average rate.
45
- *
46
- * @param {number} maxBitrate
47
- * @returns {Buffer}
48
- */
49
- function btrt(maxBitrate) {
50
- const body = Buffer.alloc(12);
51
- body.writeUInt32BE(1875072, 0);
52
- body.writeUInt32BE(maxBitrate, 4);
53
- body.writeUInt32BE(maxBitrate, 8);
54
- return box("btrt", body);
55
- }
56
-
57
- /**
58
- * A `stsd` carrying one visual sample entry: its 78-byte preamble, then the
59
- * codec configuration, then optionally a bit rate declaration.
60
- *
61
- * @param {{ entryType?: string, config?: number[], maxBitrate?: number | null, preamble?: number }} [how]
62
- * @returns {Buffer}
63
- */
64
- function stsd({ entryType = "avc1", config = [1, 100, 0, 31], maxBitrate = null, preamble = 78 } = {}) {
65
- const versionAndCount = Buffer.alloc(8);
66
- versionAndCount.writeUInt32BE(1, 4);
67
- const children = [box("avcC", config)];
68
- if (maxBitrate !== null) {
69
- children.push(btrt(maxBitrate));
70
- }
71
- const entry = box(entryType, Buffer.alloc(preamble), ...children);
72
- return box("stsd", versionAndCount, entry);
73
- }
74
-
75
- /**
76
- * A whole init segment, shaped as ffmpeg writes one.
77
- *
78
- * @param {{ timescale?: number, tracks?: number } & Parameters<typeof stsd>[0]} [how]
79
- * @returns {Buffer}
80
- */
81
- function init({ timescale = 90000, tracks = 1, ...entry } = {}) {
82
- const trak = (index) =>
83
- box(
84
- "trak",
85
- box("tkhd", Buffer.alloc(84, index)),
86
- box("mdia", mdhd(timescale), box("hdlr", Buffer.alloc(32)), box("minf", box("stbl", stsd(entry))))
87
- );
88
- const traks = [];
89
- for (let index = 0; index < tracks; index += 1) {
90
- traks.push(trak(index));
91
- }
92
- return Buffer.concat([
93
- box("ftyp", Buffer.from("isom")),
94
- box("moov", box("mvhd", Buffer.alloc(100)), ...traks, box("mvex", box("trex", Buffer.alloc(24))))
95
- ]);
96
- }
97
-
98
- const ENTRY = "moov[0]/trak[0]/mdia[0]/minf[0]/stbl[0]/stsd[0]/avc1[0]";
99
-
100
- test("every exception carries the reason it is one", () => {
101
- for (const exception of INIT_DIFFERENCE_EXCEPTIONS) {
102
- assert.ok(exception.why && exception.why.length > 40, `no reason given for ${JSON.stringify(exception)}`);
103
- assert.ok(
104
- exception.path !== undefined || exception.sampleEntryBox !== undefined,
105
- "an exception says WHAT it covers"
106
- );
107
- }
108
- });
109
-
110
- test("every leaf of the header is named by whose child it is, inside a sample entry too", () => {
111
- const paths = [...initLeaves(init({ tracks: 2, maxBitrate: 3_000_000 })).keys()];
112
-
113
- assert.ok(paths.includes("moov[0]/trak[0]/mdia[0]/mdhd[0]"), paths.join(" "));
114
- assert.ok(paths.includes("moov[0]/trak[1]/mdia[0]/mdhd[0]"), "the second track is its own path");
115
- assert.ok(paths.includes("moov[0]/mvex[0]/trex[0]"));
116
- assert.ok(
117
- paths.includes(`${ENTRY}/avcC[0]`),
118
- "the codec configuration is a leaf of its own, so it can refuse on its own"
119
- );
120
- assert.ok(paths.includes(`${ENTRY}/btrt[0]`), "and so is the bit rate declaration");
121
- });
122
-
123
- test("one header serves its own pieces", () => {
124
- const answer = compareInits(init(), init());
125
-
126
- assert.equal(answer.compatible, true);
127
- assert.deepEqual(answer.differences, []);
128
- });
129
-
130
- test("a bit rate declaration is the one difference that does not refuse", () => {
131
- const answer = compareInits(init({ maxBitrate: 3_000_000 }), init({ maxBitrate: 1_200_000 }));
132
-
133
- assert.equal(answer.compatible, true, answer.differences.join(" | "));
134
- assert.deepEqual(answer.refusedPaths, []);
135
- assert.ok(
136
- answer.differences.some((line) => line.includes("max 3000000") && line.includes("max 1200000")),
137
- `the difference is still reported, with its numbers: ${answer.differences.join(" | ")}`
138
- );
139
- });
140
-
141
- test("allowing the bit rate does not allow the parameter sets beside it", () => {
142
- const answer = compareInits(
143
- init({ maxBitrate: 3_000_000, config: [1, 100, 0, 31] }),
144
- init({ maxBitrate: 1_200_000, config: [1, 100, 0, 30] })
145
- );
146
-
147
- assert.equal(answer.compatible, false);
148
- assert.deepEqual(answer.refusedPaths, [`${ENTRY}/avcC[0]`]);
149
- });
150
-
151
- test("the bit rate exception is scoped to a sample entry", () => {
152
- const strayLeft = box("moov", box("trak", box("mdia", box("minf", box("stbl", btrt(3_000_000))))));
153
- const strayRight = box("moov", box("trak", box("mdia", box("minf", box("stbl", btrt(1_200_000))))));
154
-
155
- const answer = compareInits(strayLeft, strayRight);
156
-
157
- assert.equal(answer.compatible, false, "a btrt that is nobody's sample entry is not the box the reason is about");
158
- assert.deepEqual(answer.refusedPaths, ["moov[0]/trak[0]/mdia[0]/minf[0]/stbl[0]/btrt[0]"]);
159
- });
160
-
161
- test("a sample entry whose children do not tile is compared whole", () => {
162
- const answer = compareInits(init({ preamble: 8, config: [1, 100, 0, 31] }), init({ preamble: 8, config: [1, 100, 0, 30] }));
163
-
164
- assert.equal(answer.compatible, false);
165
- assert.deepEqual(
166
- answer.refusedPaths,
167
- [ENTRY],
168
- "the descent is checked, and where it does not hold the whole entry refuses"
169
- );
170
- });
171
-
172
- test("a different media timescale is refused, and said in those words", () => {
173
- const answer = compareInits(init({ timescale: 90000 }), init({ timescale: 48000 }));
174
-
175
- assert.equal(answer.compatible, false);
176
- assert.ok(
177
- answer.differences.some((line) => line.includes("timescale 90000 against 48000")),
178
- answer.differences.join(" | ")
179
- );
180
- assert.deepEqual(answer.refusedPaths, ["moov[0]/trak[0]/mdia[0]/mdhd[0]"]);
181
- });
182
-
183
- test("a track present in one header and not the other is refused", () => {
184
- const answer = compareInits(init({ tracks: 1 }), init({ tracks: 2 }));
185
-
186
- assert.equal(answer.compatible, false);
187
- assert.ok(
188
- answer.differences.some((line) => line.includes("trak[1]") && line.includes("absent from the first")),
189
- answer.differences.join(" | ")
190
- );
191
- });
192
-
193
- test("an exact-path exception decides by path", () => {
194
- const served = init({ timescale: 90000 });
195
- const made = init({ timescale: 48000 });
196
-
197
- const refused = compareInits(served, made);
198
- const permitted = compareInits(served, made, {
199
- exceptions: [{ path: "moov[0]/trak[0]/mdia[0]/mdhd[0]", why: "for this check only" }]
200
- });
201
-
202
- assert.equal(refused.compatible, false);
203
- assert.equal(permitted.compatible, true, "the exception list is what decides, and it is asked by path");
204
- assert.equal(permitted.differences.length, 1, "a permitted difference is still reported");
205
- });
206
-
207
- test("allowing one path does not allow the same box of another track", () => {
208
- const answer = compareInits(init({ tracks: 2, timescale: 90000 }), init({ tracks: 2, timescale: 48000 }), {
209
- exceptions: [{ path: "moov[0]/trak[0]/mdia[0]/mdhd[0]", why: "for this check only" }]
210
- });
211
-
212
- assert.equal(answer.compatible, false);
213
- assert.deepEqual(answer.refusedPaths, ["moov[0]/trak[1]/mdia[0]/mdhd[0]"]);
214
- });
215
-
216
- test("a missing header is never compatible", () => {
217
- assert.equal(compareInits(init(), Buffer.alloc(0)).compatible, false);
218
- assert.equal(compareInits(Buffer.alloc(0), init()).compatible, false);
219
- });
@@ -1,261 +0,0 @@
1
- /**
2
- * @file An output whose input is away gets no encoders until it may.
3
- *
4
- * A run whose input has gone is not alive, so the plan reads the stretch it held
5
- * as free and places another run there at once — which dies the same way,
6
- * because nothing about the state has changed. A delay existed for exactly this,
7
- * doubling from 2 s to 15 s, and it was timed against the DEAD RUN, which the
8
- * plan never consults. Field 2026-09-12: 2432 ffmpeg starts in 23 minutes, one
9
- * every 0.57 s, for 61 minutes, against a delay that had reached its ceiling
10
- * long before; the flood also turned the log over twice and destroyed the
11
- * record of how the failure began.
12
- *
13
- * The delay lives beside the decision it governs now, and these check that it
14
- * binds.
15
- */
16
-
17
- import test from "node:test";
18
- import assert from "node:assert/strict";
19
- import { EventEmitter } from "node:events";
20
- import { EncodeRun } from "../services/encode/EncodeRun.js";
21
- import { ENCODE_EXIT } from "../services/encode/encode-exit.js";
22
- import { SoftwareEncoder } from "../services/encode/SoftwareEncoder.js";
23
- import { EncodeOrchestrator } from "../services/encode/EncodeOrchestrator.js";
24
-
25
- const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
26
-
27
- class FakeProcess extends EventEmitter {
28
- constructor() {
29
- super();
30
- this.pid = 1;
31
- }
32
-
33
- kill(signal) {
34
- this.emit("exit", null, signal);
35
- }
36
- }
37
-
38
- /** An orchestrator whose clock the test moves, and a count of what it started. */
39
- function orchestrator() {
40
- const lines = [];
41
- let clock = 1_000;
42
- let started = 0;
43
- let asked = 0;
44
- /** @type {EncodeOrchestrator} */
45
- let made;
46
- /** @type {{ run: EncodeRun, process: FakeProcess }[]} */
47
- const runs = [];
48
- made = new EncodeOrchestrator({
49
- maxRunsFor: () => 1,
50
- segmentSeconds: 4,
51
- startingSpeedFor: () => 2,
52
- refetchSecPerFilmSecond: () => 0.25,
53
- now: () => clock,
54
- planSoon: () => { asked += 1; },
55
- logger: { info: (line) => lines.push(line), warn: (line) => lines.push(line) },
56
- makeRun: ({ address, from, to }) => {
57
- started += 1;
58
- const process_ = new FakeProcess();
59
- const run = new EncodeRun({
60
- address,
61
- encoder: new SoftwareEncoder(),
62
- from,
63
- to,
64
- buildArgs: () => ["-i", "in", "out"],
65
- spawn: () => process_,
66
- logger: { info: (line) => lines.push(line), warn: (line) => lines.push(line) },
67
- now: () => clock,
68
- onEnded: (ended) => made.noteEnded(ended)
69
- });
70
- runs.push({ run, process: process_ });
71
- return run;
72
- }
73
- });
74
- made.setSegmentCount(PICTURE, 1000);
75
- made.noteStartupCosts({ killCostSec: 0, firstByteWaitSec: 0.12 });
76
-
77
- const wants = () => made.notePriorityMap(PICTURE, [
78
- { from: 0, to: 20, priority: 1, withinSeconds: 0 }
79
- ]);
80
-
81
- return {
82
- made,
83
- lines,
84
- wants,
85
- runs,
86
- startedCount: () => started,
87
- askedToPlanAgain: () => asked,
88
- advance: (ms) => { clock += ms; },
89
- /** End the newest run the way a torrent going away ends one. */
90
- loseTheInput: () => {
91
- const newest = runs[runs.length - 1];
92
- made.noteEnded({
93
- address: PICTURE,
94
- run: newest.run,
95
- from: newest.run.from,
96
- to: newest.run.to,
97
- ending: ENCODE_EXIT.INPUT_LOST,
98
- because: "the torrent went away"
99
- });
100
- }
101
- };
102
- }
103
-
104
- test("nothing is placed on an output whose input has just gone", () => {
105
- const stand = orchestrator();
106
- stand.wants();
107
- stand.made.reconcile();
108
- assert.equal(stand.startedCount(), 1, "one encoder for the one thing wanted");
109
-
110
- stand.loseTheInput();
111
- // The plan is asked again by every event there is — a request, a report, a
112
- // piece — and in the field that was about twice a second.
113
- for (let attempt = 0; attempt < 20; attempt += 1) {
114
- stand.made.reconcile();
115
- }
116
- assert.equal(
117
- stand.startedCount(),
118
- 1,
119
- "twenty decisions while the input is away must not be twenty processes"
120
- );
121
- });
122
-
123
- test("once the wait is over the plan places again", () => {
124
- const stand = orchestrator();
125
- stand.wants();
126
- stand.made.reconcile();
127
- stand.loseTheInput();
128
- stand.made.reconcile();
129
- assert.equal(stand.startedCount(), 1);
130
-
131
- // The first wait is the base delay; anything past it lets the plan act.
132
- stand.advance(2_001);
133
- stand.made.reconcile();
134
- assert.equal(stand.startedCount(), 2, "the data may be back, and that is worth one attempt");
135
- });
136
-
137
- test("the wait doubles while the input stays away, and is capped", () => {
138
- const stand = orchestrator();
139
- stand.wants();
140
- stand.made.reconcile();
141
-
142
- const waits = [];
143
- for (let attempt = 0; attempt < 8; attempt += 1) {
144
- stand.loseTheInput();
145
- // Find the shortest advance that lets the plan act again, by stepping to
146
- // just before and just after the boundary rather than reading a private.
147
- let waited = 0;
148
- const step = 250;
149
- for (;;) {
150
- const before = stand.startedCount();
151
- stand.made.reconcile();
152
- if (stand.startedCount() > before) {
153
- break;
154
- }
155
- stand.advance(step);
156
- waited += step;
157
- assert.ok(waited < 60_000, "a wait must not be unbounded");
158
- }
159
- waits.push(waited);
160
- }
161
-
162
- for (let at = 1; at < waits.length; at += 1) {
163
- assert.ok(
164
- waits[at] >= waits[at - 1],
165
- `the wait must not shrink while the input stays away: ${JSON.stringify(waits)}`
166
- );
167
- }
168
- assert.ok(
169
- waits[waits.length - 1] <= 15_000,
170
- `and it must stop growing: ${JSON.stringify(waits)}`
171
- );
172
- assert.ok(
173
- waits[waits.length - 1] > waits[0],
174
- `and it must actually have grown: ${JSON.stringify(waits)}`
175
- );
176
- });
177
-
178
- test("a wake-up is asked for, because no event arrives while the data is away", async () => {
179
- const stand = orchestrator();
180
- stand.wants();
181
- stand.made.reconcile();
182
- stand.loseTheInput();
183
- // The wake-up runs on the real clock — the orchestrator's injected `now` is
184
- // what the DECISION reads, and a timer is not a decision. So this waits for
185
- // the condition, with a deadline only as a backstop; a fixed pause here would
186
- // measure the machine.
187
- const deadline = Date.now() + 10_000;
188
- while (stand.askedToPlanAgain() === 0) {
189
- if (Date.now() > deadline) {
190
- assert.fail("nothing about the state changes while the input is missing, so the plan must be recalled");
191
- }
192
- await new Promise((resolve) => setTimeout(resolve, 25));
193
- }
194
- assert.ok(stand.askedToPlanAgain() >= 1);
195
- });
196
-
197
- test("an ending that is not about the input clears the wait", () => {
198
- const stand = orchestrator();
199
- stand.wants();
200
- stand.made.reconcile();
201
- stand.loseTheInput();
202
- stand.made.reconcile();
203
- assert.equal(stand.startedCount(), 1, "held back, as it should be");
204
-
205
- stand.advance(2_001);
206
- stand.made.reconcile();
207
- assert.equal(stand.startedCount(), 2);
208
-
209
- // This one PRODUCED and was then stopped: a segment came out of the input, so
210
- // the input was plainly there and the next attempt starts from no delay.
211
- const newest = stand.runs[stand.runs.length - 1];
212
- stand.made.noteEnded({
213
- address: PICTURE,
214
- run: newest.run,
215
- from: newest.run.from,
216
- to: newest.run.to,
217
- reached: newest.run.from,
218
- firstOutputMs: 120,
219
- ending: ENCODE_EXIT.STOPPED,
220
- because: "we asked it to"
221
- });
222
- stand.made.reconcile();
223
- assert.equal(stand.startedCount(), 3, "a file that has just produced is not suspect");
224
- });
225
-
226
- test("an ending that produced NOTHING does not lift the wait", () => {
227
- const stand = orchestrator();
228
- stand.wants();
229
- stand.made.reconcile();
230
- stand.loseTheInput();
231
-
232
- // At the moment of failure several runs end at once. One of them ending
233
- // without having made anything proves nothing about the input, and lifting
234
- // the wait on it is the storm again with an extra step.
235
- const newest = stand.runs[stand.runs.length - 1];
236
- stand.made.noteEnded({
237
- address: PICTURE,
238
- run: newest.run,
239
- from: newest.run.from,
240
- to: newest.run.to,
241
- reached: newest.run.from - 1,
242
- firstOutputMs: null,
243
- ending: ENCODE_EXIT.GONE,
244
- because: "it is no longer running, and it did not say so"
245
- });
246
- for (let attempt = 0; attempt < 10; attempt += 1) {
247
- stand.made.reconcile();
248
- }
249
- assert.equal(stand.startedCount(), 1, "an ending with nothing produced is no evidence");
250
- });
251
-
252
- test("the wait is said out loud, with the attempt and how long", () => {
253
- const stand = orchestrator();
254
- stand.wants();
255
- stand.made.reconcile();
256
- stand.loseTheInput();
257
- assert.ok(
258
- stand.lines.some((line) => /its input was not there \(attempt 1\)/.test(line)),
259
- `the reason nothing is being placed must be readable: ${JSON.stringify(stand.lines.slice(-4))}`
260
- );
261
- });
@@ -1,48 +0,0 @@
1
- /**
2
- * @file Telling "the data is not here yet" from "this cannot be encoded".
3
- *
4
- * A run that dies because its input went away used to condemn the whole
5
- * session: state `failed`, and every request for the playlist answered 500
6
- * from then on. But the torrent can be added again and the pieces downloaded
7
- * again, so the data being gone is a wait, not a verdict — measured 2026-08-06,
8
- * a torrent evicted mid-seek killed a session whose swarm was right there and
9
- * whose data would have come back in seconds.
10
- *
11
- * The classification is what decides which of the two happened, so it is tested
12
- * on the exact messages the field produced.
13
- */
14
-
15
- import test from "node:test";
16
- import assert from "node:assert/strict";
17
- import { isInputUnavailable } from "../services/encode/EncodeRuns.js";
18
-
19
- test("the messages the field produced when data went away are all temporary", () => {
20
- for (const message of [
21
- "[http @ 0x7f99b19f00] Error reading HTTP response: End of file",
22
- "File 0 not found in torrent:17c46f5c36b94865858bfeaa412693c097328a50.",
23
- "File 5 not found in magnet:8d3b6c2e74df473e3649521f927ae33b20cd9e67.",
24
- "Unknown source 9711bbde2debdcd0d1fbd8cf88d68fd9612e5d31.",
25
- "[in#0/matroska,webm @ 0x7f9005f340] Read error at pos. 138556 (0x21d3c)",
26
- "Server returned 503 Service Unavailable",
27
- "Input/output error"
28
- ]) {
29
- assert.equal(isInputUnavailable(message), true, `should be retried: ${message}`);
30
- }
31
- });
32
-
33
- test("a real encoding failure is not mistaken for one", () => {
34
- for (const message of [
35
- "Cannot write moov atom before AC3 packets. Set the delay_moov flag to fix this.",
36
- "Could not write header (incorrect codec parameters ?): Invalid argument",
37
- "Unknown encoder 'h264_v4l2m2m'",
38
- "ffmpeg exited with code 1"
39
- ]) {
40
- assert.equal(isInputUnavailable(message), false, `should stay terminal: ${message}`);
41
- }
42
- });
43
-
44
- test("nothing at all is not a reason to retry for ever", () => {
45
- assert.equal(isInputUnavailable(""), false);
46
- assert.equal(isInputUnavailable(undefined), false);
47
- assert.equal(isInputUnavailable(null), false);
48
- });
@@ -1,39 +0,0 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { installationId } from "../services/identity/installation-id.js";
7
-
8
- test("an installation id is reused from its state directory", (t) => {
9
- const stateDir = mkdtempSync(path.join(os.tmpdir(), "proxy-identity-"));
10
- t.after(() => rmSync(stateDir, { recursive: true, force: true }));
11
-
12
- assert.equal(installationId({ stateDir, makeId: () => "first-id" }), "first-id");
13
- assert.equal(installationId({ stateDir, makeId: () => "unexpected-id" }), "first-id");
14
- assert.deepEqual(JSON.parse(readFileSync(path.join(stateDir, "proxy-identity.json"), "utf8")), { id: "first-id" });
15
- });
16
-
17
- test("an explicit id takes precedence and becomes the saved installation id", (t) => {
18
- const stateDir = mkdtempSync(path.join(os.tmpdir(), "proxy-identity-"));
19
- t.after(() => rmSync(stateDir, { recursive: true, force: true }));
20
-
21
- assert.equal(installationId({ stateDir, explicitId: " configured-id " }), "configured-id");
22
- assert.equal(installationId({ stateDir, makeId: () => "unexpected-id" }), "configured-id");
23
- });
24
-
25
- test("without a state directory the default id stays ephemeral", () => {
26
- let calls = 0;
27
- const makeId = () => `id-${++calls}`;
28
-
29
- assert.equal(installationId({ makeId }), "id-1");
30
- assert.equal(installationId({ makeId }), "id-2");
31
- });
32
-
33
- test("a damaged saved identity is reported instead of silently replaced", (t) => {
34
- const stateDir = mkdtempSync(path.join(os.tmpdir(), "proxy-identity-"));
35
- t.after(() => rmSync(stateDir, { recursive: true, force: true }));
36
- writeFileSync(path.join(stateDir, "proxy-identity.json"), "{}\n");
37
-
38
- assert.throws(() => installationId({ stateDir, makeId: () => "replacement" }), /Invalid proxy identity file/);
39
- });
@@ -1,83 +0,0 @@
1
- /**
2
- * @file How long material nobody is using is kept, and where that number comes
3
- * from.
4
- *
5
- * It was three numbers and they contradicted each other: a torrent went at
6
- * fifteen minutes while the session it feeds lived to thirty, so between them
7
- * there was a session with no source. All three stand for one unmeasured thing
8
- * — whether the viewer comes back — so they are one number now, and the thing
9
- * they stand for is being measured.
10
- */
11
-
12
- import test from "node:test";
13
- import assert from "node:assert/strict";
14
- import { IDLE_KEEP_MS } from "../services/storage/keep.js";
15
- import { Returns } from "../services/storage/returns.js";
16
-
17
- const MINUTE = 60 * 1000;
18
-
19
- test("material outlives the session that reads it", () => {
20
- // The contradiction this replaced, stated as the rule it must never break
21
- // again: whatever holds a source must not go while something that reads it
22
- // is still alive. The session's own period is thirty minutes.
23
- const SESSION_TTL_MS = 30 * MINUTE;
24
- assert.ok(
25
- IDLE_KEEP_MS > SESSION_TTL_MS,
26
- "a session would outlive its own source again: material is kept " +
27
- `${IDLE_KEEP_MS / MINUTE}min against a session's ${SESSION_TTL_MS / MINUTE}min`
28
- );
29
- });
30
-
31
- test("one number, and both kinds of material read it", async () => {
32
- // Two guesses about one unknown is what produced the contradiction. Asserted
33
- // on the source: a second literal period appearing anywhere is the fault
34
- // coming back.
35
- const { readFileSync } = await import("node:fs");
36
- const path = await import("node:path");
37
- const { fileURLToPath } = await import("node:url");
38
- const here = path.dirname(fileURLToPath(import.meta.url));
39
- const read = (relative) => readFileSync(path.join(here, "..", relative), "utf8");
40
-
41
- assert.match(read("services/torrent/torrent-pool.js"), /TORRENT_IDLE_TTL_MS = IDLE_KEEP_MS/);
42
- assert.match(read("services/server/OutputLifecycle.js"), /SEGMENT_STORE_IDLE_MS = IDLE_KEEP_MS/);
43
- });
44
-
45
- test("a session opened on material still held is a return, and its age is kept", () => {
46
- const returns = new Returns();
47
- const now = 10 * 60 * MINUTE;
48
-
49
- returns.note({ lastReadAt: now - 5 * MINUTE, now });
50
- returns.note({ lastReadAt: now - 45 * MINUTE, now });
51
- returns.note({ lastReadAt: now - 20 * MINUTE, now });
52
-
53
- const shape = returns.shape();
54
- assert.equal(shape.warm, 3);
55
- assert.equal(shape.cold, 0);
56
- assert.equal(shape.medianMs, 20 * MINUTE, "the middle return is not the median");
57
- assert.equal(shape.longestMs, 45 * MINUTE);
58
- });
59
-
60
- test("a session opened on material this proxy never had is not a return", () => {
61
- const returns = new Returns();
62
- const now = 10 * 60 * MINUTE;
63
-
64
- returns.note({ lastReadAt: null, now });
65
- returns.note({ lastReadAt: 0, now });
66
-
67
- assert.equal(returns.shape(), null, "an opening with nothing behind it was counted as a return");
68
- });
69
-
70
- test("the reading says what viewers do beside what is being kept", () => {
71
- const returns = new Returns();
72
- const now = 10 * 60 * MINUTE;
73
- assert.equal(returns.describe(IDLE_KEEP_MS), null, "it spoke before it had anything to say");
74
-
75
- returns.note({ lastReadAt: now - 12 * MINUTE, now });
76
- returns.note({ lastReadAt: null, now });
77
-
78
- const line = returns.describe(IDLE_KEEP_MS);
79
- assert.match(line, /1 session\(s\) opened on material still held/);
80
- assert.match(line, /1 on material gone/);
81
- assert.match(line, /median 12min after the last read/);
82
- assert.match(line, /kept for 60min/);
83
- });