@torrent-tv/proxy 2.89.17 → 2.89.19

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 (300) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/server.js +0 -11
  4. package/utils/client-log-file.js +147 -42
  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 -2377
  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 -151
  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/client-logs-route.test.js +0 -34
  97. package/test/coalesce.test.js +0 -39
  98. package/test/completed-files.test.js +0 -115
  99. package/test/concurrent-cost.test.js +0 -148
  100. package/test/container-media-info.test.js +0 -228
  101. package/test/contention.test.js +0 -76
  102. package/test/core-dumps.test.js +0 -57
  103. package/test/coverage-follows-the-disk.test.js +0 -233
  104. package/test/coverage-map.test.js +0 -195
  105. package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
  106. package/test/cut-times-timeline.test.js +0 -65
  107. package/test/cuts-follow-published-grid.test.js +0 -109
  108. package/test/data-channel-frame.test.js +0 -63
  109. package/test/data-channel-viewer-lifecycle.test.js +0 -193
  110. package/test/dead-torrent-handle.test.js +0 -52
  111. package/test/declared-rates.test.js +0 -116
  112. package/test/declared-tracks.test.js +0 -43
  113. package/test/decode-cost-fit.test.js +0 -202
  114. package/test/decode-cost.test.js +0 -475
  115. package/test/delivery-probe-field.test.js +0 -173
  116. package/test/delivery-probe.test.js +0 -382
  117. package/test/demand-register.test.js +0 -206
  118. package/test/dht-bootstrap.test.js +0 -72
  119. package/test/drain-threat.test.js +0 -65
  120. package/test/duplicate-add.test.js +0 -48
  121. package/test/encode-admission.test.js +0 -170
  122. package/test/encode-cost.test.js +0 -275
  123. package/test/encode-exit.test.js +0 -111
  124. package/test/encode-orchestrator.test.js +0 -426
  125. package/test/encode-plan-viewers.test.js +0 -725
  126. package/test/encode-plan.test.js +0 -545
  127. package/test/encode-run-state.test.js +0 -314
  128. package/test/encode-run.test.js +0 -248
  129. package/test/encode-slope.test.js +0 -46
  130. package/test/encoded-output.test.js +0 -39
  131. package/test/encoder-kinds.test.js +0 -122
  132. package/test/encoder-readings.test.js +0 -68
  133. package/test/episode-naming.test.js +0 -131
  134. package/test/every-claimant-is-told-its-share.test.js +0 -152
  135. package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
  136. package/test/failed-start-breaker.test.js +0 -202
  137. package/test/fastest-wires.test.js +0 -143
  138. package/test/ffmpeg-stream-counts.test.js +0 -101
  139. package/test/file-edges.test.js +0 -191
  140. package/test/files-in-use.test.js +0 -34
  141. package/test/fixtures/audio-frame-boundary.json +0 -1
  142. package/test/fixtures/refused-audio-20261002.json +0 -10
  143. package/test/fmp4-presentation-clock.test.js +0 -148
  144. package/test/fmp4-self-contained.test.js +0 -80
  145. package/test/fmp4-timestamps.test.js +0 -140
  146. package/test/fmp4-track-completeness.test.js +0 -41
  147. package/test/format-keyed-outputs.test.js +0 -78
  148. package/test/health-metrics.test.js +0 -36
  149. package/test/held-read-ownership.test.js +0 -77
  150. package/test/held-request-width.test.js +0 -157
  151. package/test/helpers/encode-run.js +0 -248
  152. package/test/helpers/held-file.js +0 -77
  153. package/test/helpers/manager.js +0 -62
  154. package/test/helpers/matroska-file.js +0 -296
  155. package/test/helpers/output-spec.js +0 -63
  156. package/test/host-load.test.js +0 -68
  157. package/test/index-accuracy-is-about-the-file.test.js +0 -128
  158. package/test/init-compat.test.js +0 -219
  159. package/test/input-lost-quiets-the-plan.test.js +0 -261
  160. package/test/input-unavailable.test.js +0 -48
  161. package/test/installation-id.test.js +0 -39
  162. package/test/keeping-period.test.js +0 -83
  163. package/test/keyframe-index-accuracy.test.js +0 -188
  164. package/test/keyframe-table-budget.test.js +0 -123
  165. package/test/keyframes-belong-to-the-file.test.js +0 -249
  166. package/test/learned-median.test.js +0 -37
  167. package/test/letting-go-asks-who-is-watching.test.js +0 -191
  168. package/test/limit-row-by-area.test.js +0 -60
  169. package/test/link-budget.test.js +0 -111
  170. package/test/link-probe.test.js +0 -56
  171. package/test/local-encoding-data.test.js +0 -273
  172. package/test/logger-repeats.test.js +0 -134
  173. package/test/look-ahead-coverage.test.js +0 -56
  174. package/test/manager-surface.test.js +0 -291
  175. package/test/matroska-blocks.test.js +0 -0
  176. package/test/matroska-cluster-discovery.test.js +0 -323
  177. package/test/matroska-cues-track.test.js +0 -192
  178. package/test/media-time.test.js +0 -62
  179. package/test/memory-budget.test.js +0 -390
  180. package/test/move-cost.test.js +0 -216
  181. package/test/mp4-composition-times.test.js +0 -0
  182. package/test/mp4-subtitles.test.js +0 -173
  183. package/test/one-authority.test.js +0 -285
  184. package/test/one-budget.test.js +0 -149
  185. package/test/one-output-one-session.test.js +0 -273
  186. package/test/one-resource-divided.test.js +0 -185
  187. package/test/one-serving-output-per-height.test.js +0 -458
  188. package/test/orchestrator-wired.test.js +0 -207
  189. package/test/output-catalog.test.js +0 -39
  190. package/test/output-shape.test.js +0 -21
  191. package/test/output-spec.test.js +0 -251
  192. package/test/output-speed.test.js +0 -92
  193. package/test/outputs-being-prepared.test.js +0 -40
  194. package/test/packet-witness-ring.test.js +0 -236
  195. package/test/packet-witness.test.js +0 -148
  196. package/test/piece-completeness.test.js +0 -78
  197. package/test/piece-disk-store.test.js +0 -401
  198. package/test/piece-from-whole-file.test.js +0 -129
  199. package/test/piece-lru.test.js +0 -319
  200. package/test/piece-reader.test.js +0 -162
  201. package/test/piece-selection-offset.test.js +0 -85
  202. package/test/piece-store-eviction.test.js +0 -595
  203. package/test/piece-store-never-refuses.test.js +0 -153
  204. package/test/piece-store-reservations.test.js +0 -403
  205. package/test/piece-store-slow-disk.test.js +0 -159
  206. package/test/piece-tail.test.js +0 -97
  207. package/test/plan-host-timings.test.js +0 -68
  208. package/test/plan-is-steady.test.js +0 -225
  209. package/test/playback-readiness.test.js +0 -518
  210. package/test/playback-start-regressions.test.js +0 -101
  211. package/test/priority-map-download.test.js +0 -174
  212. package/test/priority-map-emptied.test.js +0 -204
  213. package/test/priority-map-per-output.test.js +0 -215
  214. package/test/priority-map.test.js +0 -163
  215. package/test/probe-wedge-certainty.test.js +0 -60
  216. package/test/produced-copy-choice.test.js +0 -213
  217. package/test/published-timeline.test.js +0 -83
  218. package/test/quality-offer.test.js +0 -160
  219. package/test/quality-variants.test.js +0 -1274
  220. package/test/rate-control-in-the-output.test.js +0 -181
  221. package/test/read-survives-withdrawal.test.js +0 -164
  222. package/test/read-window.test.js +0 -365
  223. package/test/reads-not-yet-arrived.test.js +0 -218
  224. package/test/resume-warm.test.js +0 -39
  225. package/test/run-graph-drift.test.js +0 -37
  226. package/test/run-inputs.test.js +0 -80
  227. package/test/run-intervals.test.js +0 -100
  228. package/test/run-position-follows-published-grid.test.js +0 -89
  229. package/test/run-progress.test.js +0 -64
  230. package/test/same-height-switch.test.js +0 -663
  231. package/test/seek-frees-the-viewers-requests.test.js +0 -217
  232. package/test/seek-landing.test.js +0 -109
  233. package/test/seek-target-not-superseded.test.js +0 -195
  234. package/test/segment-closed-on-both-branches.test.js +0 -114
  235. package/test/segment-cut-times.test.js +0 -63
  236. package/test/segment-demand.test.js +0 -80
  237. package/test/segment-hold-supersede.test.js +0 -91
  238. package/test/segment-judged-by-its-own-header.test.js +0 -222
  239. package/test/segment-serve-wiring.test.js +0 -481
  240. package/test/segment-store-eviction.test.js +0 -247
  241. package/test/segment-store.test.js +0 -352
  242. package/test/segment-true-start.test.js +0 -86
  243. package/test/segments-are-shared.test.js +0 -176
  244. package/test/send-chunk-bytes.test.js +0 -86
  245. package/test/serving-existing-output.test.js +0 -111
  246. package/test/serving-output.test.js +0 -102
  247. package/test/shared-piece-store.test.js +0 -310
  248. package/test/sidecar-naming.test.js +0 -142
  249. package/test/soundtrack-rate-bound.test.js +0 -289
  250. package/test/source-file.test.js +0 -133
  251. package/test/source-files-route.test.js +0 -113
  252. package/test/source-registry.test.js +0 -18
  253. package/test/split-a-stretch.test.js +0 -139
  254. package/test/stale-request-after-seek.test.js +0 -158
  255. package/test/startup-readings.test.js +0 -124
  256. package/test/stream-route.test.js +0 -237
  257. package/test/subtitle-cue-framing.test.js +0 -200
  258. package/test/subtitle-cue-source.test.js +0 -102
  259. package/test/subtitle-cue-walk.test.js +0 -385
  260. package/test/subtitle-cursor.test.js +0 -63
  261. package/test/subtitle-defaults.test.js +0 -118
  262. package/test/subtitle-language.test.js +0 -252
  263. package/test/subtitle-metadata.test.js +0 -15
  264. package/test/subtitle-plan-waits.test.js +0 -125
  265. package/test/subtitle-track-numbering.test.js +0 -391
  266. package/test/supply-margin.test.js +0 -190
  267. package/test/swarm-follows-readers.test.js +0 -174
  268. package/test/swarm-reach.test.js +0 -130
  269. package/test/swarm-selection.test.js +0 -220
  270. package/test/tail-duplication.test.js +0 -167
  271. package/test/the-channel-has-both-ends.test.js +0 -91
  272. package/test/the-torrent-thread-serves-bytes.test.js +0 -107
  273. package/test/thread-pool.test.js +0 -53
  274. package/test/timeline.test.js +0 -84
  275. package/test/torrent-contents.test.js +0 -235
  276. package/test/torrent-cost.test.js +0 -71
  277. package/test/torrent-files.test.js +0 -221
  278. package/test/torrent-naming.test.js +0 -255
  279. package/test/tracks-begin-together.test.js +0 -209
  280. package/test/tunnel-renewal.test.js +0 -167
  281. package/test/two-viewers-one-picture.test.js +0 -508
  282. package/test/upload-hurry.test.js +0 -186
  283. package/test/usrsctp-state.test.js +0 -131
  284. package/test/video-facts.test.js +0 -102
  285. package/test/viewer-assignments.test.js +0 -143
  286. package/test/viewer-outputs.test.js +0 -285
  287. package/test/viewer-presence.test.js +0 -116
  288. package/test/viewer-requests-admission.test.js +0 -92
  289. package/test/viewer-starts-on-map.test.js +0 -27
  290. package/test/viewer-states.test.js +0 -192
  291. package/test/viewer-subtitle-subscription.test.js +0 -96
  292. package/test/viewer.test.js +0 -139
  293. package/test/viewing-generations.test.js +0 -390
  294. package/test/visible-rung.test.js +0 -37
  295. package/test/wait-ledger.test.js +0 -100
  296. package/test/webrtc-shim.test.js +0 -149
  297. package/test/wedge-certainty.test.js +0 -131
  298. package/test/whole-file-held-read.test.js +0 -30
  299. package/test/withdraw-piece-claim.test.js +0 -212
  300. package/test/worker-channel.test.js +0 -158
@@ -1,63 +0,0 @@
1
- /**
2
- * The playlist and the real segments must describe the same thing.
3
- *
4
- * They did not. The playlist was built from the container index while ffmpeg
5
- * chose its own cut points from a target duration, and the two only ever agreed
6
- * by luck — on a field file the index listed 1902 keyframes, ffmpeg found about
7
- * twice as many, and segment #876 meant 1:26:50 to the player and roughly
8
- * minute 58 to ffmpeg. Seeks landed nowhere near where they were aimed.
9
- *
10
- * These tests pin the arithmetic that ties the two together.
11
- */
12
-
13
- import test from "node:test";
14
- import assert from "node:assert/strict";
15
- import { segmentCutTimesFrom } from "../services/encode/run-command.js";
16
-
17
- test("cut times are the interior boundaries, rebased on the run start", () => {
18
- // Segments 0-10, 10-20, 20-30, 30-40 (file ends at 40).
19
- const boundaries = [0, 10, 20, 30, 40];
20
-
21
- assert.deepEqual(
22
- segmentCutTimesFrom(boundaries, 0),
23
- [10, 20, 30],
24
- "from the start, the cuts are every boundary except 0 and the file end"
25
- );
26
-
27
- // Restarting at segment 2 means the run begins at 20 s; a cut at 30 s is 10 s
28
- // into the run. Sending 30 would put it at 50 — `-segment_times` counts from
29
- // the run, which is what made a seek land in the wrong place.
30
- assert.deepEqual(
31
- segmentCutTimesFrom(boundaries, 2),
32
- [10],
33
- "after a restart the times must be relative to where the run starts"
34
- );
35
- });
36
-
37
- test("uneven, real-world boundaries survive the rebasing exactly", () => {
38
- // Keyframes never land on round numbers; rounding here is what would push a
39
- // cut past its keyframe and silently double a segment.
40
- // Starting at segment 1 leaves segments 1, 2 and 3 — three segments, so two
41
- // cuts between them, each measured from the run start at 10.427.
42
- const boundaries = [0, 10.427, 20.854, 31.281, 41.708];
43
- assert.deepEqual(segmentCutTimesFrom(boundaries, 1), [10.427, 20.854]);
44
- });
45
-
46
- test("boundaries that cannot serve are refused rather than half-used", () => {
47
- assert.equal(segmentCutTimesFrom(null, 0), null);
48
- assert.equal(segmentCutTimesFrom([], 0), null);
49
- assert.equal(segmentCutTimesFrom([0], 0), null, "a single boundary describes no segment");
50
- assert.equal(
51
- segmentCutTimesFrom([0, 10, 20], 2),
52
- null,
53
- "a start index at or past the last boundary has no run to describe"
54
- );
55
- });
56
-
57
- test("the final run has no interior cuts and asks for none", () => {
58
- assert.deepEqual(
59
- segmentCutTimesFrom([0, 10, 20], 1),
60
- [],
61
- "starting at the last segment leaves nothing to cut, which is not an error"
62
- );
63
- });
@@ -1,80 +0,0 @@
1
- /**
2
- * @file What is wanted of one output, in its own segment numbers.
3
- *
4
- * The class held a window per viewer per band and merged them itself. That was
5
- * the priority layer's work done a second time in the wrong place, and it
6
- * carried the viewer's name as the key of a claim — against the rule that the
7
- * encoding and the viewer are not connected at all. The behaviours those checks
8
- * pinned (a viewer's own bands, two viewers as a union) are the priority map's
9
- * and are checked there.
10
- *
11
- * What is left is a holder: one map per output, replaced whole, and an empty one
12
- * meaning nobody is coming.
13
- */
14
-
15
- import test from "node:test";
16
- import assert from "node:assert/strict";
17
- import { SegmentDemand } from "../services/encode/SegmentDemand.js";
18
-
19
- const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
20
- const SOUND = "torrent:abc:fmt=fmp4:grid=kf@0:audio-only:a=0/0/aac";
21
-
22
- test("an output nothing has been said about wants nothing", () => {
23
- const demand = new SegmentDemand();
24
- assert.deepEqual(demand.mapOn(PICTURE), []);
25
- assert.deepEqual(demand.addresses(), []);
26
- });
27
-
28
- test("a map replaces whatever was wanted before, rather than adding to it", () => {
29
- // The map is a statement of what is wanted NOW, built fresh each time from
30
- // where the viewers are. Accumulating them would keep serving people who have
31
- // moved or gone.
32
- const demand = new SegmentDemand();
33
- demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
34
- demand.state(PICTURE, [{ from: 500, to: 530, priority: 32, withinSeconds: 0 }]);
35
- assert.deepEqual(demand.mapOn(PICTURE), [{ from: 500, to: 530, priority: 32, withinSeconds: 0 }]);
36
- });
37
-
38
- test("an empty map is a statement, and it is kept as one", () => {
39
- // It says nobody is coming anywhere in this output, which is what stops the
40
- // encoders on it. Dropped instead of stored, the output would look like one
41
- // nothing had ever been said about, and the last map with people in it would
42
- // stand as current.
43
- const demand = new SegmentDemand();
44
- demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
45
- demand.state(PICTURE, []);
46
- assert.deepEqual(demand.mapOn(PICTURE), []);
47
- assert.deepEqual(demand.addresses(), [PICTURE], "the output is still one that has been spoken about");
48
- });
49
-
50
- test("each output holds its own map", () => {
51
- // Two outputs of one film are cut independently — 454 pieces against 401 on
52
- // the field file — so the same second is a different number in each, and one
53
- // map cannot serve both.
54
- const demand = new SegmentDemand();
55
- demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
56
- demand.state(SOUND, [{ from: 88, to: 115, priority: 32, withinSeconds: 0 }]);
57
- assert.equal(demand.mapOn(PICTURE)[0].from, 100);
58
- assert.equal(demand.mapOn(SOUND)[0].from, 88);
59
- assert.deepEqual(demand.addresses().sort(), [SOUND, PICTURE].sort());
60
- });
61
-
62
- test("an output can be forgotten entirely", () => {
63
- const demand = new SegmentDemand();
64
- demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
65
- demand.forget(PICTURE);
66
- assert.deepEqual(demand.addresses(), []);
67
- });
68
-
69
- test("nothing about a viewer can be stated, because nothing about one is held", () => {
70
- // The check that the rule holds by construction: there is no name to pass and
71
- // no way to ask about one.
72
- const demand = new SegmentDemand();
73
- assert.equal(typeof (/** @type {any} */ (demand).want), "undefined");
74
- assert.equal(typeof (/** @type {any} */ (demand).windowsOn), "undefined");
75
- assert.equal(
76
- demand.state.length,
77
- 2,
78
- "an address and a map, and nothing else"
79
- );
80
- });
@@ -1,91 +0,0 @@
1
- /**
2
- * @file A held segment request must not outlive the position it was made for.
3
- *
4
- * hls.js keeps ONE fragment load outstanding. So a request being held for a
5
- * segment blocks the request for wherever the viewer has just moved to, and our
6
- * route held each one for 60 s. Measured 2026-08-04: a backward seek into fully
7
- * downloaded data waited 57 s for a held request for `#609` to run out its
8
- * timer, and the segment the viewer actually wanted was then served in 15 ms.
9
- *
10
- * `research/hls-seek-prior-art-2026-08-02.md` prescribed this guard from
11
- * `hls-media-server` — one outstanding wait per session — and it was never
12
- * built.
13
- *
14
- * WHAT IS LEFT HERE IS THE ROUTE'S OWN BEHAVIOUR: a segment that arrives while
15
- * a request is held must still be served. The release itself moved to
16
- * `test/seek-frees-the-viewers-requests.test.js`, and the check that stood here
17
- * is why: it replaced `waitForSegment` with a function returning true and moved
18
- * the epoch by hand, so it described the route against a stand-in and passed
19
- * for months while no seek moved that epoch at all.
20
- */
21
-
22
- import test from "node:test";
23
- import assert from "node:assert/strict";
24
- import { handleTranscodeSessionFileGet } from "../routes/transcode/session-file/get.js";
25
-
26
- /**
27
- * A reply that records what the route answered.
28
- *
29
- * @returns {{ reply: object, sent: { code: number, headers: Record<string, string>, body: unknown } }}
30
- */
31
- function recordingReply() {
32
- const sent = { code: 200, headers: {}, body: undefined };
33
- const reply = {
34
- code(value) {
35
- sent.code = value;
36
- return reply;
37
- },
38
- header(name, value) {
39
- sent.headers[name.toLowerCase()] = String(value);
40
- return reply;
41
- },
42
- send(body) {
43
- sent.body = body;
44
- return reply;
45
- }
46
- };
47
- return { reply, sent };
48
- }
49
-
50
- /**
51
- * What the file route asks of the viewer operations besides the hold itself:
52
- * whether the request's generation is still taken, the record of what answered
53
- * it, and the hold a response keeps. Everything is taken and recorded nowhere,
54
- * because these checks are about the hold.
55
- *
56
- * @param {object} serving
57
- * @returns {object}
58
- */
59
- const routeViewerRequests = (serving) => ({
60
- ...serving,
61
- acceptsRequest: () => true,
62
- noteAnsweredDirectly: () => {},
63
- holdResponse: () => () => {}
64
- });
65
-
66
- const request = (fileName) => ({
67
- params: { sessionId: "1111111122223333", fileName },
68
- raw: { on() {}, off() {} }
69
- });
70
-
71
- test("without a seek the request is still held until the segment appears", async () => {
72
- let polls = 0;
73
- const serving = {
74
- seekEpoch: () => 7,
75
- // The segment is published between polls.
76
- waitForSegment: async () => true,
77
- async getFileStream() {
78
- polls += 1;
79
- if (polls < 3) {
80
- return { kind: "warming-up" };
81
- }
82
- return { kind: "ok", contentType: "video/mp4", stream: "bytes", isPlaylist: false };
83
- }
84
- };
85
-
86
- const { reply, sent } = recordingReply();
87
- await handleTranscodeSessionFileGet(request("segment-00610.mp4"), reply, { serving: serving, viewerRequests: routeViewerRequests(serving) });
88
-
89
- assert.equal(sent.body, "bytes", "a segment that arrives late must still be served");
90
- assert.equal(sent.headers["content-type"], "video/mp4");
91
- });
@@ -1,222 +0,0 @@
1
- /**
2
- * @file A piece short of a track is judged against ITS OWN header.
3
- *
4
- * The question "does this piece carry every track" has two possible answers and
5
- * they call for opposite actions, which is why asking it against the session's
6
- * cached header alone was not enough: a piece that disagrees with that header
7
- * may be short, or the header may be the odd one out. A self-contained piece
8
- * carries a `moov` of its own, so it can be compared with itself, and that
9
- * comparison tells the two apart without asking anything about encoders.
10
- *
11
- * WHAT THIS REPLACED. The action used to be chosen by "is any run of this
12
- * session alive?" — a question about the SESSION, asked about a fact of the
13
- * BYTES. A run anywhere in the film meant "still being written; waiting for
14
- * it", and nothing re-judged or re-made the piece afterwards, so one
15
- * misjudgement became permanent.
16
- *
17
- * Field 2026-09-14: `segment-00033.mp4` of a copied picture, already served
18
- * whole to one viewer at 5 099 421 bytes, was refused to a second viewer for
19
- * five minutes — four holds of sixty seconds each, then 503 — while the run in
20
- * force was at #192 and beyond. That viewer's picture stood still 196.2 s and
21
- * then a further 56.2 s.
22
- *
23
- * The run question is also unanswerable and does not need asking: a piece being
24
- * written is called `making-<tag>-NNNNN.mp4` and takes its served name by a
25
- * rename, which is atomic. A file under its served name is never being written.
26
- */
27
-
28
- import test from "node:test";
29
- import assert from "node:assert/strict";
30
- import { access, writeFile } from "node:fs/promises";
31
- import path from "node:path";
32
- import { SourceFile } from "../services/media/SourceFile.js";
33
- import { Timeline } from "../services/encode/output/Timeline.js";
34
- import { managerWithOwnStore } from "./helpers/manager.js";
35
- import { startRunOn } from "./helpers/encode-run.js";
36
- import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
37
- import { outputSpec } from "./helpers/output-spec.js";
38
-
39
- const SESSION_ID = "3333333344445555";
40
- const OUTPUT_KEY = "own-header:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
41
- const MOVIE_TIMESCALE = 1000;
42
-
43
- /**
44
- * @param {string} type
45
- * @param {Buffer} body
46
- * @returns {Buffer}
47
- */
48
- function box(type, body) {
49
- const head = Buffer.alloc(8);
50
- head.writeUInt32BE(8 + body.length, 0);
51
- head.write(type, 4, "latin1");
52
- return Buffer.concat([head, body]);
53
- }
54
-
55
- /**
56
- * @param {number} trackId
57
- * @returns {Buffer}
58
- */
59
- function trak(trackId) {
60
- const tkhdBody = Buffer.alloc(84);
61
- tkhdBody.writeUInt32BE(trackId, 12);
62
- const mdhdBody = Buffer.alloc(20);
63
- mdhdBody.writeUInt32BE(90_000, 12);
64
- return box("trak", Buffer.concat([
65
- box("tkhd", tkhdBody),
66
- box("mdia", box("mdhd", mdhdBody))
67
- ]));
68
- }
69
-
70
- /**
71
- * A header declaring `tracks` tracks.
72
- *
73
- * @param {number} tracks
74
- * @returns {Buffer}
75
- */
76
- function moovOf(tracks) {
77
- const mvhdBody = Buffer.alloc(100);
78
- mvhdBody.writeUInt32BE(MOVIE_TIMESCALE, 12);
79
- const traks = [];
80
- for (let id = 1; id <= tracks; id += 1) {
81
- traks.push(trak(id));
82
- }
83
- return box("moov", Buffer.concat([box("mvhd", mvhdBody), ...traks]));
84
- }
85
-
86
- /**
87
- * @param {number} trackId
88
- * @returns {Buffer}
89
- */
90
- function traf(trackId) {
91
- const tfhdBody = Buffer.alloc(8);
92
- tfhdBody.writeUInt32BE(trackId, 4);
93
- const tfdtBody = Buffer.alloc(12);
94
- tfdtBody.writeUInt8(1, 0);
95
- tfdtBody.writeBigUInt64BE(0n, 4);
96
- return box("traf", Buffer.concat([box("tfhd", tfhdBody), box("tfdt", tfdtBody)]));
97
- }
98
-
99
- /**
100
- * A piece shaped like the `segment` muxer's output.
101
- *
102
- * @param {{ declares: number, carries: number }} shape - How many tracks its own
103
- * header declares, and how many its fragments actually carry. The two differ
104
- * only in a piece a run closed short.
105
- * @returns {Buffer}
106
- */
107
- function selfContainedPiece({ declares, carries }) {
108
- const trafs = [];
109
- for (let id = 1; id <= carries; id += 1) {
110
- trafs.push(traf(id));
111
- }
112
- return Buffer.concat([
113
- box("ftyp", Buffer.alloc(16, 0)),
114
- moovOf(declares),
115
- box("moof", Buffer.concat(trafs)),
116
- box("mdat", Buffer.alloc(64, 0x5a)),
117
- box("mfra", Buffer.alloc(24, 0))
118
- ]);
119
- }
120
-
121
- /**
122
- * A manager with one session whose first two pieces are already on disk.
123
- *
124
- * @param {{ piece: Buffer, sessionHeader: Buffer }} params - The piece written
125
- * for every number, and what the session has cached as its header.
126
- * @returns {Promise<{ manager: object, dirPath: string }>}
127
- */
128
- async function managerHolding({ piece, sessionHeader }) {
129
- const { manager } = managerWithOwnStore();
130
- manager.segmentStore.useFormat(OUTPUT_KEY, fmp4Format);
131
- const dirPath = manager.segmentStore.directoryFor(OUTPUT_KEY);
132
- await writeFile(path.join(dirPath, "segment-00000.mp4"), piece);
133
- await writeFile(path.join(dirPath, "segment-00001.mp4"), piece);
134
-
135
- const session = {
136
- id: SESSION_ID,
137
- spec: outputSpec({ transcodeVideo: false }),
138
- outputKey: OUTPUT_KEY,
139
- dirPath,
140
- timeline: new Timeline({ boundaries: [0, 12.5, 25, 37.5, 50, 62.5], cutGrid: "uniform" }),
141
- state: "ready",
142
- file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" })
143
- .learn({ durationSeconds: 62.5 }),
144
- get inputFile() { return this.file; },
145
- get audioFile() { return this.file; },
146
- lastAloneSpeed: 2,
147
- startedAt: Date.now(),
148
- lastAccessedAt: Date.now(),
149
- runs: new Set(),
150
- lastError: "",
151
- segmentCount: 5,
152
- segmentFormat: fmp4Format,
153
- useSyntheticPlaylist: true,
154
- playlistText: "#EXTM3U\n",
155
- waitEpoch: 0
156
- };
157
- manager.outputs.set(SESSION_ID, session);
158
- // The header this output serves is the store's, one owner for it.
159
- manager.segmentStore.keepInit(OUTPUT_KEY, sessionHeader);
160
- // No plan runs here: this file is about the path that answers a request.
161
- manager.encodeRuns.planEncodersNow = () => {};
162
- manager.encodeRuns.planEncodersSoon = () => {};
163
- // A LIVE RUN, deliberately. Under the rule this replaced, a live run anywhere
164
- // was what turned a refusal into a permanent one — so both cases below are
165
- // asked with one running, which is the state the field failure happened in.
166
- startRunOn(session, { from: 0, usesExplicitCuts: true, speedX: 2 });
167
- return { manager, dirPath };
168
- }
169
-
170
- test("a piece that agrees with its own header is served, whatever the session's header says", async () => {
171
- // Two tracks declared, two carried: whole by its own account. The session's
172
- // cached header declares three — the state that cannot be told from a short
173
- // piece without asking the piece itself.
174
- const piece = selfContainedPiece({ declares: 2, carries: 2 });
175
- const { manager, dirPath } = await managerHolding({
176
- piece,
177
- sessionHeader: moovOf(3)
178
- });
179
-
180
- const answer = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
181
-
182
- assert.equal(answer.kind, "file", "the piece is whole and must reach the viewer");
183
- await access(path.join(dirPath, "segment-00000.mp4"));
184
- });
185
-
186
- test("a piece that disagrees with its own header is removed, so it can be made again", async () => {
187
- // Two tracks declared, one carried: closed short by a run that was killed
188
- // mid-piece, which is what this check exists to catch.
189
- const piece = selfContainedPiece({ declares: 2, carries: 1 });
190
- const { manager, dirPath } = await managerHolding({
191
- piece,
192
- sessionHeader: moovOf(2)
193
- });
194
-
195
- const answer = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
196
-
197
- assert.equal(answer.kind, "warming-up", "a short piece is not servable");
198
- await assert.rejects(
199
- () => access(path.join(dirPath, "segment-00000.mp4")),
200
- /ENOENT/,
201
- "and it is removed, or nothing will ever make it again"
202
- );
203
- });
204
-
205
- test("a live run elsewhere in the film does not make a short piece permanent", async () => {
206
- const piece = selfContainedPiece({ declares: 2, carries: 1 });
207
- const { manager, dirPath } = await managerHolding({
208
- piece,
209
- sessionHeader: moovOf(2)
210
- });
211
- // The field state exactly: the run in force is hundreds of segments ahead of
212
- // the piece being asked for.
213
- startRunOn(manager.outputs.get(SESSION_ID), { from: 192, usesExplicitCuts: true, speedX: 2 });
214
-
215
- await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
216
-
217
- await assert.rejects(
218
- () => access(path.join(dirPath, "segment-00000.mp4")),
219
- /ENOENT/,
220
- "a run a thousand segments away says nothing about these bytes"
221
- );
222
- });