@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,481 +0,0 @@
1
- /**
2
- * @file A finished segment on disk must reach the viewer as bytes.
3
- *
4
- * The module tests cover each piece of the fMP4 path on its own, and every one
5
- * of them passed while playback was dead: 2.9.124 called
6
- * `readSelfContainedStartSeconds` from `fmp4.js` without importing it, and the
7
- * unit test imports that function straight from `mp4-boxes.js`, so the gap
8
- * between a module and its CALLER was invisible. This test asks the session
9
- * manager for a segment that exists and insists on getting it.
10
- *
11
- * The second half pins the reason a one-word slip cost a whole release: the
12
- * failure was reported as "still being produced". Measured 2026-08-08 — segment
13
- * #0 was held for 45 281 ms with twelve finished segments in the directory, and
14
- * the log said nothing at all. Anything that goes wrong while preparing a file
15
- * that EXISTS must be named and answered, never turned into an endless wait.
16
- */
17
-
18
- import test from "node:test";
19
- import assert from "node:assert/strict";
20
- import { SourceFile } from "../services/media/SourceFile.js";
21
- import { Timeline } from "../services/encode/output/Timeline.js";
22
- import { Output } from "../services/encode/output/Output.js";
23
- import { KeyframeTable } from "../services/media/container/KeyframeTable.js";
24
- import { rm, writeFile } from "node:fs/promises";
25
- import path from "node:path";
26
- import { wireOutputs } from "../services/server/wire-outputs.js";
27
- import { ENCODE_RUN_STATE } from "../services/encode/encode-run-state.js";
28
- import { startRunOn } from "./helpers/encode-run.js";
29
- import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
30
- import { outputSpec } from "./helpers/output-spec.js";
31
-
32
- const MOVIE_TIMESCALE = 1000;
33
- const VIDEO_TIMESCALE = 90_000;
34
- const AUDIO_TIMESCALE = 48_000;
35
- const SEGMENT_START_SECONDS = 12.5;
36
- const SESSION_ID = "1111111122223333";
37
- // Its own address, so this file's directory in the shared store is nobody
38
- // else's.
39
- const OUTPUT_KEY = "serve-wiring:fmt=fmp4:grid=uniform:video-only:v=0/copy";
40
-
41
- /**
42
- * @param {string} type
43
- * @param {Buffer} body
44
- * @returns {Buffer}
45
- */
46
- function box(type, body) {
47
- const head = Buffer.alloc(8);
48
- head.writeUInt32BE(8 + body.length, 0);
49
- head.write(type, 4, "latin1");
50
- return Buffer.concat([head, body]);
51
- }
52
-
53
- /**
54
- * `elst` holding one empty edit — how the `segment` muxer records where the
55
- * piece sits on the source timeline. A version 0 entry is twelve bytes
56
- * (ISO/IEC 14496-12): duration, media time, and the media rate as an integer
57
- * and a fraction.
58
- *
59
- * @param {number} offsetSeconds
60
- * @returns {Buffer}
61
- */
62
- function emptyEdit(offsetSeconds) {
63
- const body = Buffer.alloc(20);
64
- body.writeUInt32BE(1, 4); // entry count
65
- body.writeUInt32BE(Math.round(offsetSeconds * MOVIE_TIMESCALE), 8); // duration
66
- body.writeInt32BE(-1, 12); // media_time
67
- body.writeInt16BE(1, 16); // media_rate_integer
68
- return box("elst", body);
69
- }
70
-
71
- /**
72
- * @param {number} trackId
73
- * @param {number} timescale
74
- * @param {number} offsetSeconds
75
- * @returns {Buffer}
76
- */
77
- function trak(trackId, timescale, offsetSeconds) {
78
- const tkhdBody = Buffer.alloc(84);
79
- tkhdBody.writeUInt32BE(trackId, 12);
80
- const mdhdBody = Buffer.alloc(20);
81
- mdhdBody.writeUInt32BE(timescale, 12);
82
- return box("trak", Buffer.concat([
83
- box("tkhd", tkhdBody),
84
- box("edts", emptyEdit(offsetSeconds)),
85
- box("mdia", box("mdhd", mdhdBody))
86
- ]));
87
- }
88
-
89
- /**
90
- * @param {number} trackId
91
- * @returns {Buffer}
92
- */
93
- function traf(trackId) {
94
- const tfhdBody = Buffer.alloc(8);
95
- tfhdBody.writeUInt32BE(trackId, 4);
96
- const tfdtBody = Buffer.alloc(12);
97
- tfdtBody.writeUInt8(1, 0); // version 1 — 64-bit
98
- tfdtBody.writeBigUInt64BE(0n, 4); // what ffmpeg writes: zero
99
- return box("traf", Buffer.concat([box("tfhd", tfhdBody), box("tfdt", tfdtBody)]));
100
- }
101
-
102
- /**
103
- * A piece shaped like the `segment` muxer's output: header, two fragments and a
104
- * trailing random-access index, all in one file.
105
- *
106
- * @param {number} offsetSeconds
107
- * @returns {Buffer}
108
- */
109
- function selfContainedPiece(offsetSeconds) {
110
- const mvhdBody = Buffer.alloc(100);
111
- mvhdBody.writeUInt32BE(MOVIE_TIMESCALE, 12);
112
- const moov = box("moov", Buffer.concat([
113
- box("mvhd", mvhdBody),
114
- trak(1, VIDEO_TIMESCALE, offsetSeconds),
115
- trak(2, AUDIO_TIMESCALE, offsetSeconds)
116
- ]));
117
- const moof = box("moof", Buffer.concat([traf(1), traf(2)]));
118
- const mdat = box("mdat", Buffer.alloc(64, 0x5a));
119
- const mfra = box("mfra", Buffer.alloc(24, 0));
120
- return Buffer.concat([box("ftyp", Buffer.alloc(16, 0)), moov, moof, mdat, mfra]);
121
- }
122
-
123
- /**
124
- * A manager holding one session whose segments are already on disk, cut at
125
- * explicit times — the ordinary keyframe-cut path.
126
- *
127
- * @param {{ segmentFormat?: object, audioOnly?: boolean, withRun?: boolean }} [overrides]
128
- * @returns {Promise<{ manager: object, session: object, dirPath: string }>}
129
- */
130
- async function managerWithReadySegment(overrides = {}) {
131
- const manager = wireOutputs({
132
- enabled: true,
133
- ffmpegBin: "ffmpeg",
134
- localBindHost: "127.0.0.1",
135
- localPort: 9090
136
- });
137
- // ADDRESSED THE WAY PRODUCTION ADDRESSES IT. A session's segments live in the
138
- // store's directory for its OUTPUT, and whether one is finished is asked of
139
- // the store by that same address. This fixture used to make a directory of its
140
- // own and leave the session with no output address at all, so it described a
141
- // proxy that no longer exists and asked for a segment the store had never
142
- // heard of.
143
- manager.segmentStore.useFormat(OUTPUT_KEY, overrides.segmentFormat ?? fmp4Format);
144
- const dirPath = manager.segmentStore.directoryFor(OUTPUT_KEY);
145
- const piece = selfContainedPiece(SEGMENT_START_SECONDS);
146
- // Two segments, because a piece is only finished once the next one exists.
147
- await writeFile(path.join(dirPath, "segment-00000.mp4"), piece);
148
- await writeFile(path.join(dirPath, "segment-00001.mp4"), piece);
149
-
150
- const session = {
151
- id: SESSION_ID,
152
- spec: outputSpec({
153
- transcodeVideo: overrides.transcodeVideo === true,
154
- audioOnly: overrides.audioOnly === true,
155
- cutGrid: "uniform"
156
- }),
157
- outputKey: OUTPUT_KEY,
158
- dirPath,
159
- // Where this file is cut, held by the file. A fixture that stated it
160
- // on the session was describing what production no longer does.
161
- // LONGER THAN WHAT IS ON DISK. Two segments exist; the film runs to five, so
162
- // there is film left to make and an encoder on it is warranted. With the
163
- // whole film already made, an encoder is not — the plan stops it, correctly,
164
- // and a fixture that wants a live run has to give it something to do.
165
- timeline: new Timeline({
166
- boundaries: [0, SEGMENT_START_SECONDS, 25, 37.5, 50, 62.5],
167
- cutGrid: "uniform"
168
- }),
169
- state: "ready",
170
- file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" }).learn({ durationSeconds: 62.5 }),
171
- // An ordinary session reads its own file, and its sound is inside it. The
172
- // three differ only for a soundtrack shipped as a file of its own.
173
- get inputFile() { return this.file; },
174
- get audioFile() { return this.file; },
175
- // WHAT THIS HOST ENCODES AT. Every real host measures it before a viewer
176
- // exists, and the plan compares arrivals — which cannot be computed without
177
- // it. A fixture that leaves it out describes a machine that has never
178
- // measured itself: every arrangement is then equally hopeless, they all tie,
179
- // and the plan takes the encoder away for changing nothing.
180
- lastAloneSpeed: 2,
181
- startedAt: Date.now(),
182
- lastAccessedAt: Date.now(),
183
- runs: new Set(),
184
- lastError: "",
185
- consumers: new Set(),
186
- // Who is watching this output, and how long it is. Without the first the
187
- // output has no viewers to build a priority map from, so it states no zones
188
- // at all — which reads as nobody watching and stops every encoder on it.
189
- viewers: new Map(),
190
- segmentCount: 5,
191
- segmentFormat: overrides.segmentFormat ?? fmp4Format,
192
- useSyntheticPlaylist: true,
193
- playlistText: "#EXTM3U\n",
194
- // WHAT IS BEING PRODUCED, which is also where a produced piece's landing is
195
- // recorded. Per output, so one output's reading of a piece number cannot
196
- // silence another output's reading of its own.
197
- output: new Output({ encodeWidth: 0, encodeHeight: 0, outputFps: 25, softwarePreset: null, applyTonemap: false }),
198
- // WHERE THIS FILE'S KEYFRAMES ARE, held by the file. A copied picture is cut
199
- // at these and nowhere else, which is what makes its landing evidence about
200
- // this table — and what makes a soundtrack's landing evidence about nothing
201
- // of the sort.
202
- keyframes: new KeyframeTable().learn({ times: [0, 12.5, 25, 37.5, 50], format: "matroska" }),
203
- audioOnly: overrides.audioOnly === true,
204
- waitEpoch: 0
205
- };
206
- // THE INIT IS THE STORE'S, and a player fetches it before any segment — so a
207
- // fixture that wants segments served as production serves them has to put it
208
- // there first. It used to sit on the session, which nothing reads any more:
209
- // `prepareSegmentBytes` has no timescales without it and hands the piece back
210
- // unstamped, which is silent and is exactly the fault stamping exists to
211
- // prevent.
212
- // Kept as production keeps the header lifted out of a self-contained piece:
213
- // shared by every piece, so its piece-specific empty edit is neutralized and
214
- // each piece is placed by its own.
215
- manager.segmentStore.keepInit(OUTPUT_KEY, fmp4Format.prepareSharedInit(fmp4Format.extractInit(piece)));
216
- manager.outputs.set(SESSION_ID, session);
217
- // SOMEBODY IS WATCHING IT. A segment is requested by a viewer, so a fixture
218
- // that asks for one without stating a viewer describes a state production
219
- // never reaches — and an output nobody is watching has every encoder on it
220
- // stopped, which is right and is what left the run here reading STOPPED.
221
- // NO PLAN RUNS HERE. This file is about the path that answers a request for a
222
- // segment. Deciding how many encoders there should be and where is a separate
223
- // question with its own checks, and letting it run inside these would spawn
224
- // real ffmpeg processes and replace the very run each test is watching — the
225
- // test would then be about the plan, and about it at its least stable.
226
- manager.encodeRuns.planEncodersNow = () => {};
227
- manager.encodeRuns.planEncodersSoon = () => {};
228
- // The run in force. The fixture's segments live directly in the session
229
- // directory, which is exactly what one run's directory is here.
230
- if (overrides.withRun !== false) {
231
- const run = startRunOn(session, { from: 0, usesExplicitCuts: true, speedX: 2 });
232
- manager.encodeOrchestrator.adopt(OUTPUT_KEY, run);
233
- }
234
- return { manager, session, dirPath };
235
- }
236
-
237
- test("serving a segment records what its real start says about the container's index", async (t) => {
238
- const { manager, session, dirPath } = await managerWithReadySegment();
239
- t.after(async () => {
240
- await manager.lifecycle.disposeAll();
241
- await rm(dirPath, { recursive: true, force: true });
242
- });
243
- // The tally is counted in the module tests; what this pins is that serving a
244
- // segment reaches it at all. A counter nothing increments reports a clean
245
- // grid for every output forever, which is worse than no measurement.
246
- assert.equal(session.output.landing, null, "nothing has been produced yet");
247
-
248
- await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
249
-
250
- assert.equal(session.output.landing.checked, 1, "the piece that was just produced must have been examined");
251
- });
252
-
253
- test("only a copied picture's landing is taken as evidence about the file's keyframe table", async (t) => {
254
- // The one reading, sent to the two owners the manager decides between. A
255
- // soundtrack is cut exactly where it is asked to be and has no keyframes, so
256
- // its landing is about its own output and about nothing else; sent to the
257
- // file's table it would report the file's index wrong on the strength of a
258
- // stream that never consulted it.
259
- const sound = await managerWithReadySegment({ audioOnly: true });
260
- t.after(async () => {
261
- await sound.manager.lifecycle.disposeAll();
262
- await rm(sound.dirPath, { recursive: true, force: true });
263
- });
264
-
265
- await sound.manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
266
-
267
- assert.equal(sound.session.output.landing.checked, 1, "the sound's own landing is recorded");
268
- assert.equal(
269
- sound.session.keyframes.evidence,
270
- null,
271
- "and nothing it produced is evidence about where the file's keyframes are"
272
- );
273
-
274
- const picture = await managerWithReadySegment();
275
- t.after(async () => {
276
- await picture.manager.lifecycle.disposeAll();
277
- await rm(picture.dirPath, { recursive: true, force: true });
278
- });
279
-
280
- await picture.manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
281
-
282
- assert.equal(picture.session.keyframes.evidence.checked, 1, "a copy's landing does reach the file's table");
283
- });
284
-
285
- test("a segment that exists is served, not reported as still being produced", async (t) => {
286
- const { manager, dirPath, session } = await managerWithReadySegment();
287
- t.after(async () => {
288
- await manager.lifecycle.disposeAll();
289
- await rm(dirPath, { recursive: true, force: true });
290
- });
291
-
292
- const result = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
293
-
294
- assert.equal(result.kind, "file", "a finished segment on disk must come back as bytes");
295
- assert.equal(result.contentType, fmp4Format.segmentContentType);
296
-
297
- const chunks = [];
298
- for await (const chunk of result.stream) {
299
- chunks.push(chunk);
300
- }
301
- const served = Buffer.concat(chunks);
302
- assert.equal(served.toString("latin1", 4, 8), "moof", "the init header must be stripped off a media segment");
303
-
304
- // The piece's OWN start, carried into the fragment it belongs to. Two
305
- // releases tried moving it toward the playlist instead (2.24.1 per session,
306
- // 2.25.0 by one family offset) and both desynced picture from sound in the
307
- // field the same day: the first segment of a run is not cut, it begins where
308
- // the seek landed, and the picture must land on a keyframe while the sound
309
- // need not. Reading the piece's position is also the step that threw in
310
- // 2.9.124, and it still feeds the index tally and the grid correction.
311
- assert.equal(
312
- Number(served.readBigUInt64BE(served.indexOf("tfdt") + 8)),
313
- Math.round(SEGMENT_START_SECONDS * VIDEO_TIMESCALE),
314
- "the segment must be stamped with where it really begins"
315
- );
316
- assert.equal(
317
- session.output.landing.checked,
318
- 1,
319
- "and the piece's own position must still have been read, or nothing measures the landing"
320
- );
321
- });
322
-
323
- test("a fault while preparing an existing segment is named, not turned into a wait", async (t) => {
324
- const broken = {
325
- ...fmp4Format,
326
- readSegmentStartSeconds() {
327
- throw new ReferenceError("readSelfContainedStartSeconds is not defined");
328
- }
329
- };
330
- const { manager, dirPath } = await managerWithReadySegment({ segmentFormat: broken });
331
- t.after(async () => {
332
- await manager.lifecycle.disposeAll();
333
- await rm(dirPath, { recursive: true, force: true });
334
- });
335
-
336
- const result = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
337
-
338
- assert.equal(
339
- result.kind,
340
- "failed",
341
- "answering 'warming-up' hides the fault and holds every request until the viewer gives up"
342
- );
343
- assert.match(result.message, /readSelfContainedStartSeconds is not defined/);
344
- });
345
-
346
- test("a run's FIRST segment is served once the encoder has passed it, without waiting for a next one", async (t) => {
347
- const { manager, dirPath } = await managerWithReadySegment();
348
- t.after(async () => {
349
- await manager.lifecycle.disposeAll();
350
- await rm(dirPath, { recursive: true, force: true });
351
- });
352
- // The shape a resume takes: a run begun mid-file, so its first segment has no
353
- // successor and nothing is producing one. Waiting for that successor is what
354
- // held #317 for 46 s and then answered 404 to a browser that had given up.
355
- await rm(path.join(dirPath, "segment-00001.mp4"));
356
- // WHAT PROVES IT INSTEAD: its own NAME. A piece is called something else while
357
- // it is being written and takes its served name when its writer says it is
358
- // closed, so a run's first piece is proven the moment it is finished and the
359
- // absence of a next one says nothing. This used to be inferred from the
360
- // encoder's reported position — a different question, where it has read to
361
- // rather than what it has closed.
362
-
363
- const result = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
364
-
365
- assert.equal(
366
- result.kind,
367
- "file",
368
- "the encoder is past this segment's end, so it is finished — the absence of a next one says nothing"
369
- );
370
- });
371
-
372
- test("a segment an earlier run made is served by whatever run is going now", async (t) => {
373
- const { manager, session, dirPath } = await managerWithReadySegment();
374
- t.after(async () => {
375
- await manager.lifecycle.disposeAll();
376
- await rm(dirPath, { recursive: true, force: true });
377
- });
378
- // Every run of an output writes into that output's own directory — there is
379
- // one, and runs are kept apart by their stretches instead. So a viewer who
380
- // seeks back is served what an earlier run made, with no restart and no
381
- // search: the run going now began at #40 and #0 is simply there.
382
- const run = startRunOn(session, { from: 40, usesExplicitCuts: true });
383
- manager.encodeOrchestrator.adopt(OUTPUT_KEY, run);
384
-
385
- const result = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
386
-
387
- assert.equal(result.kind, "file", "what any run of this output made is what this output holds");
388
- const chunks = [];
389
- for await (const chunk of result.stream) {
390
- chunks.push(chunk);
391
- }
392
- assert.ok(Buffer.concat(chunks).length > 0);
393
- });
394
-
395
- test("serving a run's own segment moves the run out of STARTING", async (t) => {
396
- const { manager, session, dirPath } = await managerWithReadySegment({ withRun: false });
397
- t.after(async () => {
398
- await manager.lifecycle.disposeAll();
399
- await rm(dirPath, { recursive: true, force: true });
400
- });
401
- // The table lives in `encode/encode-run-state.js` and is tested there as a graph.
402
- // What this pins is that a real serve REACHES it: a state nothing writes
403
- // describes every run as still starting, for ever, and the log built on it
404
- // would say so too.
405
- // A run that has not yet made anything: starting. The fixture's own run is
406
- // let go first, because this test is about ONE run and what serving does to
407
- // it.
408
- // ITS OWN PIECE, AND FILM STILL TO MAKE BEHIND IT. A run standing on material
409
- // that already exists is moved forward — correctly — so a fixture that wants a
410
- // live run has to put it where the work is. #1 is what it is making; #2..#4
411
- // are unmade, so it is wanted; and #1 stands under its served name, which is
412
- // what makes the piece servable at all.
413
- const run = startRunOn(session, { from: 1, producing: false, usesExplicitCuts: true, speedX: 2 });
414
- manager.encodeOrchestrator.adopt(OUTPUT_KEY, run);
415
- assert.equal(run.state, ENCODE_RUN_STATE.STARTING);
416
- assert.deepEqual(run.produced, [], "it has made nothing yet");
417
-
418
- await manager.serving.getFileStream(SESSION_ID, "segment-00001.mp4");
419
-
420
- // ASKED OF WHAT THE SERVE WROTE, not of the state that happens to follow it.
421
- // The plan owns a run's life and may end it in the same turn for reasons of
422
- // its own — the machine's budget, a viewer leaving, nothing left to make —
423
- // and a check that reads the state afterwards is really asking what the plan
424
- // decided. What the SERVE does is tell the run the piece is finished, and that
425
- // is what moves it out of starting.
426
- assert.deepEqual(run.produced, [1], "the serve told the run its piece is finished");
427
- assert.equal(run.head, 2, "so the run stands one past it");
428
- });
429
-
430
- test("a segment behind a run's own start does not claim that run has produced", async (t) => {
431
- const { manager, session, dirPath } = await managerWithReadySegment({ withRun: false });
432
- t.after(async () => {
433
- await manager.lifecycle.disposeAll();
434
- await rm(dirPath, { recursive: true, force: true });
435
- });
436
- // What moves a run out of starting is ITS OWN first segment. An earlier run's
437
- // output sits in the same directory, and after a backward seek some of it
438
- // lies ahead of the new run's beginning — so the question cannot be asked of
439
- // the number alone, and a run believed to be producing is one the look-ahead
440
- // may suspend and the seek path may wave through as "already covered".
441
- const run = startRunOn(session, { from: 5, producing: false, usesExplicitCuts: true, speedX: 2 });
442
- manager.encodeOrchestrator.adopt(OUTPUT_KEY, run);
443
-
444
- await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
445
-
446
- assert.deepEqual(run.produced, [], "#0 is somebody else's work and says nothing about this run");
447
- assert.equal(run.head, 5, "which is still where it began");
448
- });
449
-
450
- test("a request behind the run that nobody is coming for is answered absent, not held", async (t) => {
451
- // A HOLD IS ONLY RIGHT WHILE SOMETHING IS COMING. Field 2026-08-15: hls.js
452
- // asked a freshly prepared track for segment #0 while the run stood at #354,
453
- // the request was held for the whole minute, and only when it failed did the
454
- // player ask for the segment it actually needed — 63 s of spinner after a
455
- // track that had been ready in 7. Answered absent, the player moves on at
456
- // once.
457
- //
458
- // Whether anybody is coming is the encoding's answer, from the map it was
459
- // given. An EMPTY map is not that answer: a session created a moment ago has
460
- // no map yet, and read as "nobody is coming" every request behind the run
461
- // would be refused for as long as that lasted.
462
- const { manager, session, dirPath } = await managerWithReadySegment({ withRun: false });
463
- t.after(async () => {
464
- await manager.lifecycle.disposeAll();
465
- await rm(dirPath, { recursive: true, force: true });
466
- });
467
- const run = startRunOn(session, { from: 3, producing: true, usesExplicitCuts: true, speedX: 2 });
468
- manager.encodeOrchestrator.adopt(OUTPUT_KEY, run);
469
-
470
- // No map yet: the request is HELD, because nothing has said otherwise.
471
- const held = await manager.serving.getFileStream(SESSION_ID, "segment-00002.mp4");
472
- assert.notEqual(held.kind, "not-found", "a session with no map waits, it does not refuse");
473
-
474
- // Now the map says where the viewers are, and #2 is not in it.
475
- manager.encodeOrchestrator.notePriorityMap(OUTPUT_KEY, [
476
- { from: 3, to: 4, priority: 100, withinSeconds: 0 }
477
- ]);
478
- const refused = await manager.serving.getFileStream(SESSION_ID, "segment-00002.mp4");
479
-
480
- assert.equal(refused.kind, "not-found");
481
- });