@torrent-tv/proxy 2.86.0 → 2.87.1

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 (385) hide show
  1. package/CHANGELOG.md +2142 -1915
  2. package/CLAUDE.md +322 -197
  3. package/assets/calibration/NOTICE.md +2 -2
  4. package/bin/cli.js +684 -616
  5. package/biome.json +409 -233
  6. package/docs/browser-proxy-contract.md +94 -0
  7. package/docs/container-architecture.md +218 -213
  8. package/docs/download-architecture.md +7 -7
  9. package/docs/encode-architecture.md +287 -11
  10. package/docs/encode-run-state.md +2 -2
  11. package/docs/logs.md +97 -97
  12. package/docs/{disk-architecture.md → storage-architecture.md} +107 -1
  13. package/openspec/changes/adaptive-bitrate/design.md +2 -2
  14. package/openspec/changes/adaptive-bitrate/proposal.md +1 -1
  15. package/openspec/changes/adaptive-bitrate/tasks.md +1 -1
  16. package/openspec/changes/chunked-request-bodies/design.md +1 -1
  17. package/openspec/changes/chunked-request-bodies/proposal.md +1 -1
  18. package/openspec/changes/chunked-request-bodies/tasks.md +1 -1
  19. package/openspec/changes/cold-start/design.md +1 -1
  20. package/openspec/changes/disk-cap/proposal.md +1 -1
  21. package/openspec/changes/proxy-observability/proposal.md +2 -2
  22. package/openspec/changes/track-selection/proposal.md +1 -1
  23. package/openspec/changes/transcode-quality/proposal.md +1 -1
  24. package/package.json +2 -2
  25. package/research/delivery-wedge-stand-ladder-2026-09-13.md +329 -329
  26. package/research/double-spawn-2026-09-10.md +171 -171
  27. package/routes/api/playback-plan/post.js +2 -2
  28. package/routes/api/sources/files/get.js +1 -1
  29. package/routes/api/sources/stats/get.js +1 -1
  30. package/routes/api/sources/warm/post.js +10 -3
  31. package/routes/api/subtitles/get.js +230 -230
  32. package/routes/api/transcode-sessions/fragment-far/post.js +3 -3
  33. package/routes/api/transcode-sessions/net-report/post.js +129 -94
  34. package/routes/api/transcode-sessions/post.js +160 -139
  35. package/routes/api/transcode-sessions/progress/get.js +3 -3
  36. package/routes/api/transcode-sessions/release/post.js +3 -3
  37. package/routes/api/transcode-sessions/seek/post.js +12 -3
  38. package/routes/stream/get.js +2 -2
  39. package/routes/transcode/audio-file/get.js +15 -6
  40. package/routes/transcode/audio-warm/get.js +9 -6
  41. package/routes/transcode/session-file/get.js +52 -268
  42. package/routes/transcode/variant-file/get.js +46 -7
  43. package/routes/transcode/variant-warm/get.js +19 -6
  44. package/scripts/render-run-graph.js +1 -1
  45. package/server.js +720 -465
  46. package/services/encode/CoverageMap.js +428 -428
  47. package/services/encode/CushionReport.js +345 -0
  48. package/services/encode/EncodeAdmission.js +332 -0
  49. package/services/{orchestrators → encode}/EncodeOrchestrator.js +307 -29
  50. package/services/encode/EncodeRun.js +16 -9
  51. package/services/encode/EncodeRuns.js +1229 -0
  52. package/services/encode/Encoder.js +18 -2
  53. package/services/encode/EncoderSelection.js +38 -0
  54. package/services/encode/LocalObservations.js +359 -0
  55. package/services/encode/NvencEncoder.js +5 -0
  56. package/services/encode/OutputOpening.js +755 -0
  57. package/services/encode/OutputTimes.js +579 -0
  58. package/services/encode/Renditions.js +2162 -0
  59. package/services/encode/RunProgress.js +84 -0
  60. package/services/encode/SoftwareEncoder.js +12 -7
  61. package/services/encode/args.js +402 -186
  62. package/services/encode/calibration.js +361 -0
  63. package/services/encode/contention.js +128 -128
  64. package/services/encode/encode-run-state.js +16 -20
  65. package/services/encode/fingerprint.js +322 -0
  66. package/services/{hwaccel.js → encode/hwaccel.js} +82 -42
  67. package/services/{learned-median.js → encode/learned-median.js} +11 -0
  68. package/services/encode/output/EncodedOutput.js +57 -0
  69. package/services/encode/output/Output.js +131 -0
  70. package/services/{output/LiveOutputs.js → encode/output/OutputCatalog.js} +141 -40
  71. package/services/encode/output/OutputSpec.js +390 -0
  72. package/services/{output → encode/output}/Timeline.js +12 -37
  73. package/services/encode/output/index.js +20 -0
  74. package/services/encode/output/ladder.js +32 -0
  75. package/services/{output → encode/output}/playlists.js +3 -0
  76. package/services/encode/output-key-format.js +21 -0
  77. package/services/encode/quality/EncodeCost.js +1083 -0
  78. package/services/encode/quality/HostLoad.js +525 -0
  79. package/services/encode/quality/HostTimings.js +249 -0
  80. package/services/encode/quality/OutputQualityState.js +28 -0
  81. package/services/encode/quality/QualityController.js +935 -0
  82. package/services/encode/quality/QualityOffer.js +416 -0
  83. package/services/encode/quality/drain-threat.js +47 -0
  84. package/services/encode/quality/link-budget.js +254 -0
  85. package/services/encode/quality/output-format.js +266 -0
  86. package/services/encode/quality/serving-output.js +216 -0
  87. package/services/encode/quality/visible-rung.js +57 -0
  88. package/services/encode/run-command.js +23 -20
  89. package/services/encode/run-inputs.js +42 -0
  90. package/services/{segment-formats → encode/segment-formats}/fmp4.js +63 -0
  91. package/services/{segment-formats → encode/segment-formats}/index.js +3 -3
  92. package/services/encode/segment-formats/init-compat.js +324 -0
  93. package/services/{segment-formats → encode/segment-formats}/mp4-boxes.js +8 -3
  94. package/services/encode/throughput.js +97 -0
  95. package/services/{orchestrators → media}/ContainerOrchestrator.js +45 -7
  96. package/services/media/KeyframeTables.js +316 -0
  97. package/services/{source → media}/SourceFile.js +7 -55
  98. package/services/{torrent-worker/subtitle-cues.js → media/SubtitleCues.js} +103 -132
  99. package/services/media/SubtitleOrchestrator.js +167 -0
  100. package/services/{audio-inventory.js → media/audio-inventory.js} +7 -1
  101. package/services/{container → media/container}/AviContainer.js +266 -266
  102. package/services/{container → media/container}/Container.js +596 -601
  103. package/services/media/container/ContainerFactory.js +56 -0
  104. package/services/media/container/KeyframeTable.js +272 -0
  105. package/services/{container → media/container}/MatroskaContainer.js +1485 -1485
  106. package/services/{container → media/container}/Mp4Container.js +1244 -1244
  107. package/services/{container → media/container}/SubtitleFileContainer.js +322 -322
  108. package/services/media/keyframe-probe.js +157 -0
  109. package/services/media/media-info-probe.js +93 -0
  110. package/services/{playback-planner.js → media/playback-planner.js} +82 -39
  111. package/services/{tracks → media/tracks}/AudioTrack.js +131 -131
  112. package/services/{tracks → media/tracks}/language-detect.js +174 -174
  113. package/services/server/OutputLifecycle.js +418 -0
  114. package/services/server/SegmentServing.js +1146 -0
  115. package/services/server/ViewerRequests.js +522 -0
  116. package/services/server/controllers/PlaybackController.js +36 -0
  117. package/services/{controllers → server/controllers}/SubtitleController.js +17 -33
  118. package/services/server/http-responses.js +60 -0
  119. package/services/server/transcode-session-files.js +325 -0
  120. package/services/server/wire-outputs.js +983 -0
  121. package/services/storage/Diagnostics.js +202 -0
  122. package/services/storage/MachineBudget.js +235 -0
  123. package/services/{piece-store → storage}/allowance.js +107 -107
  124. package/services/{core-dumps.js → storage/core-dumps.js} +1 -1
  125. package/services/{files → storage/files}/CompletedFiles.js +116 -1
  126. package/services/{disk → storage}/free.js +33 -0
  127. package/services/storage/machine-memory.js +56 -0
  128. package/services/{memory-report.js → storage/memory-report.js} +575 -596
  129. package/services/{piece-store → storage/piece-store}/piece-disk-store.js +0 -7
  130. package/services/{piece-store → storage/piece-store}/shared-piece-store.js +28 -21
  131. package/services/{encode → storage/segment-store}/SegmentStore.js +395 -8
  132. package/services/storage/wire.js +175 -0
  133. package/services/{download → torrent/download}/SwarmSelection.js +2 -2
  134. package/services/{download → torrent/download}/registry.js +2 -2
  135. package/services/torrent/files.js +1 -1
  136. package/services/torrent/piece-store-of.js +29 -0
  137. package/services/{torrent-pool.js → torrent/torrent-pool.js} +26 -119
  138. package/services/{torrent-worker → torrent/worker}/background-fill.js +2 -2
  139. package/services/{torrent-worker → torrent/worker}/channel.js +271 -250
  140. package/services/{torrent-worker → torrent/worker}/client.js +77 -58
  141. package/services/torrent/worker/held-bytes.js +155 -0
  142. package/services/{torrent-worker → torrent/worker}/install-webrtc-shim.js +1 -1
  143. package/services/{torrent-worker → torrent/worker}/piece-reader.js +21 -30
  144. package/services/{torrent-worker → torrent/worker}/pool-adapter.js +101 -137
  145. package/services/{torrent-worker → torrent/worker}/protocol.js +26 -30
  146. package/services/torrent/worker/resume-warm.js +107 -0
  147. package/services/{torrent-worker → torrent/worker}/webrtc-shim.js +2 -2
  148. package/services/{torrent-worker → torrent/worker}/worker.js +68 -159
  149. package/services/{data-channel-handler.js → transport/data-channel-handler.js} +1356 -1356
  150. package/services/{delivery-probe.js → transport/delivery-probe.js} +842 -842
  151. package/services/{health-collector.js → transport/health-collector.js} +6 -35
  152. package/services/{packet-witness.js → transport/packet-witness.js} +808 -784
  153. package/services/{port-mapper.js → transport/port-mapper.js} +1 -1
  154. package/services/{usrsctp-state.js → transport/usrsctp-state.js} +1 -1
  155. package/services/{webrtc-manager.js → transport/webrtc-manager.js} +1 -1
  156. package/services/viewer/Assignments.js +340 -0
  157. package/services/{priority → viewer}/PriorityMap.js +390 -390
  158. package/services/{priority → viewer}/PriorityOrchestrator.js +325 -320
  159. package/services/viewer/Viewer.js +657 -483
  160. package/services/viewer/Viewers.js +368 -257
  161. package/services/viewer/active-output.js +37 -54
  162. package/services/viewer/audio-start.js +4 -3
  163. package/services/viewer/buffer-trend.js +81 -0
  164. package/services/viewer/choices.js +647 -0
  165. package/services/viewer/positions.js +126 -120
  166. package/services/viewer/report-intake.js +46 -45
  167. package/test/asset-paths.test.js +28 -0
  168. package/test/audio-inventory.test.js +3 -3
  169. package/test/audio-track-bitrate.test.js +40 -0
  170. package/test/auto-quality-step.test.js +707 -515
  171. package/test/available-share.test.js +1 -1
  172. package/test/background-fill.test.js +1 -1
  173. package/test/client-log-file.test.js +110 -110
  174. package/test/completed-files.test.js +1 -1
  175. package/test/concurrent-cost.test.js +13 -3
  176. package/test/container-media-info.test.js +3 -3
  177. package/test/core-dumps.test.js +1 -1
  178. package/test/coverage-follows-the-disk.test.js +46 -9
  179. package/test/cue-push-carries-what-the-walk-found.test.js +58 -0
  180. package/test/cut-times-timeline.test.js +2 -2
  181. package/test/cuts-follow-published-grid.test.js +9 -8
  182. package/test/data-channel-frame.test.js +1 -1
  183. package/test/dead-torrent-handle.test.js +1 -1
  184. package/test/declared-rates.test.js +2 -2
  185. package/test/declared-tracks.test.js +2 -2
  186. package/test/decode-cost-fit.test.js +1 -1
  187. package/test/decode-cost.test.js +34 -25
  188. package/test/delivery-probe.test.js +1 -1
  189. package/test/demand-register.test.js +4 -4
  190. package/test/dht-bootstrap.test.js +1 -1
  191. package/test/drain-threat.test.js +65 -0
  192. package/test/duplicate-add.test.js +1 -1
  193. package/test/encode-admission.test.js +146 -0
  194. package/test/encode-cost.test.js +199 -10
  195. package/test/encode-orchestrator.test.js +39 -1
  196. package/test/encode-plan-viewers.test.js +2 -2
  197. package/test/encode-run.test.js +2 -2
  198. package/test/encode-slope.test.js +1 -1
  199. package/test/encoded-output.test.js +39 -0
  200. package/test/encoder-readings.test.js +1 -1
  201. package/test/every-claimant-is-told-its-share.test.js +152 -0
  202. package/test/failed-encoder-still-serves-what-exists.test.js +354 -0
  203. package/test/failed-start-breaker.test.js +81 -30
  204. package/test/fastest-wires.test.js +1 -1
  205. package/test/ffmpeg-stream-counts.test.js +1 -1
  206. package/test/file-edges.test.js +3 -3
  207. package/test/fmp4-self-contained.test.js +1 -1
  208. package/test/fmp4-timestamps.test.js +1 -1
  209. package/test/fmp4-track-completeness.test.js +1 -1
  210. package/test/format-keyed-outputs.test.js +78 -0
  211. package/test/health-metrics.test.js +3 -2
  212. package/test/held-request-width.test.js +22 -23
  213. package/test/helpers/encode-run.js +136 -136
  214. package/test/helpers/held-file.js +29 -0
  215. package/test/helpers/manager.js +57 -0
  216. package/test/helpers/output-spec.js +63 -0
  217. package/test/host-load.test.js +1 -1
  218. package/test/index-accuracy-is-about-the-file.test.js +128 -0
  219. package/test/init-compat.test.js +219 -0
  220. package/test/input-lost-quiets-the-plan.test.js +1 -1
  221. package/test/input-unavailable.test.js +1 -1
  222. package/test/keeping-period.test.js +4 -4
  223. package/test/keyframe-index-accuracy.test.js +97 -45
  224. package/test/keyframe-table-budget.test.js +28 -33
  225. package/test/keyframes-belong-to-the-file.test.js +174 -57
  226. package/test/learned-median.test.js +1 -1
  227. package/test/letting-go-asks-who-is-watching.test.js +191 -0
  228. package/test/limit-row-by-area.test.js +60 -0
  229. package/test/link-budget.test.js +111 -0
  230. package/test/link-probe.test.js +56 -56
  231. package/test/local-encoding-data.test.js +273 -0
  232. package/test/look-ahead-coverage.test.js +1 -1
  233. package/test/manager-surface.test.js +294 -0
  234. package/test/matroska-blocks.test.js +0 -0
  235. package/test/matroska-cues-track.test.js +1 -1
  236. package/test/memory-budget.test.js +2 -2
  237. package/test/mp4-composition-times.test.js +0 -0
  238. package/test/mp4-subtitles.test.js +1 -1
  239. package/test/one-authority.test.js +45 -41
  240. package/test/one-budget.test.js +149 -0
  241. package/test/one-output-one-session.test.js +204 -0
  242. package/test/{disk-space.test.js → one-resource-divided.test.js} +30 -10
  243. package/test/one-serving-output-per-height.test.js +458 -0
  244. package/test/orchestrator-wired.test.js +46 -45
  245. package/test/output-catalog.test.js +39 -0
  246. package/test/output-shape.test.js +4 -51
  247. package/test/output-spec.test.js +251 -157
  248. package/test/output-speed.test.js +17 -15
  249. package/test/outputs-being-prepared.test.js +40 -0
  250. package/test/packet-witness-ring.test.js +2 -2
  251. package/test/packet-witness.test.js +1 -1
  252. package/test/piece-disk-store.test.js +2 -2
  253. package/test/piece-from-whole-file.test.js +1 -1
  254. package/test/piece-lru.test.js +1 -1
  255. package/test/piece-reader.test.js +2 -2
  256. package/test/piece-store-eviction.test.js +1 -1
  257. package/test/piece-store-never-refuses.test.js +1 -1
  258. package/test/piece-store-reservations.test.js +1 -1
  259. package/test/piece-store-slow-disk.test.js +1 -1
  260. package/test/piece-tail.test.js +1 -1
  261. package/test/plan-host-timings.test.js +1 -1
  262. package/test/plan-is-steady.test.js +225 -225
  263. package/test/priority-map-download.test.js +4 -4
  264. package/test/priority-map-emptied.test.js +204 -205
  265. package/test/priority-map-per-output.test.js +215 -209
  266. package/test/priority-map.test.js +1 -1
  267. package/test/probe-wedge-certainty.test.js +1 -1
  268. package/test/produced-copy-choice.test.js +15 -60
  269. package/test/quality-offer.test.js +162 -0
  270. package/test/quality-variants.test.js +1229 -1167
  271. package/test/rate-control-in-the-output.test.js +180 -0
  272. package/test/read-survives-withdrawal.test.js +2 -2
  273. package/test/read-window.test.js +10 -3
  274. package/test/resume-warm.test.js +1 -1
  275. package/test/run-inputs.test.js +80 -0
  276. package/test/run-position-follows-published-grid.test.js +13 -11
  277. package/test/run-progress.test.js +65 -0
  278. package/test/same-height-switch.test.js +664 -0
  279. package/test/seek-frees-the-viewers-requests.test.js +217 -0
  280. package/test/seek-landing.test.js +13 -13
  281. package/test/seek-target-not-superseded.test.js +28 -29
  282. package/test/segment-closed-on-both-branches.test.js +96 -0
  283. package/test/segment-cut-times.test.js +1 -1
  284. package/test/segment-hold-supersede.test.js +28 -35
  285. package/test/segment-judged-by-its-own-header.test.js +221 -0
  286. package/test/segment-serve-wiring.test.js +130 -39
  287. package/test/segment-store-eviction.test.js +22 -7
  288. package/test/segment-store.test.js +98 -14
  289. package/test/segment-true-start.test.js +1 -1
  290. package/test/segments-are-shared.test.js +17 -16
  291. package/test/send-chunk-bytes.test.js +1 -1
  292. package/test/serving-existing-output.test.js +102 -0
  293. package/test/serving-output.test.js +102 -0
  294. package/test/shared-piece-store.test.js +1 -1
  295. package/test/source-file.test.js +1 -1
  296. package/test/stale-request-after-seek.test.js +17 -21
  297. package/test/startup-readings.test.js +10 -5
  298. package/test/subtitle-cue-framing.test.js +5 -5
  299. package/test/subtitle-cue-source.test.js +36 -38
  300. package/test/subtitle-cue-walk.test.js +11 -10
  301. package/test/subtitle-defaults.test.js +1 -1
  302. package/test/subtitle-language.test.js +4 -4
  303. package/test/subtitle-track-numbering.test.js +5 -4
  304. package/test/supply-margin.test.js +1 -1
  305. package/test/swarm-follows-readers.test.js +3 -3
  306. package/test/swarm-reach.test.js +1 -1
  307. package/test/swarm-selection.test.js +3 -3
  308. package/test/tail-duplication.test.js +1 -1
  309. package/test/the-channel-has-both-ends.test.js +91 -0
  310. package/test/the-torrent-thread-serves-bytes.test.js +107 -0
  311. package/test/thread-pool.test.js +3 -3
  312. package/test/timeline.test.js +1 -12
  313. package/test/torrent-cost.test.js +1 -1
  314. package/test/tracks-begin-together.test.js +38 -24
  315. package/test/tunnel-renewal.test.js +1 -1
  316. package/test/two-viewers-one-picture.test.js +120 -87
  317. package/test/upload-hurry.test.js +3 -3
  318. package/test/usrsctp-state.test.js +1 -1
  319. package/test/video-facts.test.js +1 -1
  320. package/test/viewer-assignments.test.js +143 -0
  321. package/test/viewer-outputs.test.js +60 -52
  322. package/test/viewer-presence.test.js +22 -25
  323. package/test/viewer-requests-admission.test.js +89 -0
  324. package/test/viewer-states.test.js +189 -202
  325. package/test/viewer-subtitle-subscription.test.js +1 -1
  326. package/test/viewer.test.js +139 -136
  327. package/test/viewing-generations.test.js +390 -0
  328. package/test/visible-rung.test.js +37 -0
  329. package/test/wait-ledger.test.js +1 -1
  330. package/test/webrtc-shim.test.js +3 -3
  331. package/test/wedge-certainty.test.js +2 -2
  332. package/test/withdraw-piece-claim.test.js +2 -2
  333. package/test/worker-channel.test.js +1 -31
  334. package/utils/client-log-file.js +151 -151
  335. package/scripts/read-container-index.mjs +0 -108
  336. package/services/container/ContainerFactory.js +0 -122
  337. package/services/controllers/PlaybackController.js +0 -33
  338. package/services/disk/DiskSpace.js +0 -150
  339. package/services/disk/wire.js +0 -61
  340. package/services/hls-session-manager.js +0 -9608
  341. package/services/orchestrators/SubtitleOrchestrator.js +0 -160
  342. package/services/output/Output.js +0 -94
  343. package/services/output/OutputSpec.js +0 -202
  344. package/services/output/index.js +0 -1
  345. package/services/output/ladder.js +0 -26
  346. package/services/produced-index.js +0 -222
  347. package/services/quality/EncodeCost.js +0 -555
  348. package/services/torrent-worker/container-tracks.js +0 -414
  349. package/services/viewer/link-readings.js +0 -56
  350. package/test/produced-index.test.js +0 -142
  351. /package/{services → bin}/thread-pool.js +0 -0
  352. /package/services/{available-share.js → encode/available-share.js} +0 -0
  353. /package/services/{decode-cost-fit.js → encode/decode-cost-fit.js} +0 -0
  354. /package/services/{encoder-readings.js → encode/encoder-readings.js} +0 -0
  355. /package/services/{host-load.js → encode/host-load.js} +0 -0
  356. /package/services/{output → encode/output}/cut-grid.js +0 -0
  357. /package/services/{output → encode/output}/rates.js +0 -0
  358. /package/services/{segment-formats → encode/segment-formats}/mpegts.js +0 -0
  359. /package/services/{torrent-cost.js → encode/torrent-cost.js} +0 -0
  360. /package/services/{container → media/container}/ebml-reader.js +0 -0
  361. /package/services/{ffmpeg-banner.js → media/ffmpeg-banner.js} +0 -0
  362. /package/services/{tracks → media/tracks}/ContainerTrack.js +0 -0
  363. /package/services/{tracks → media/tracks}/ImageSubtitleTrack.js +0 -0
  364. /package/services/{tracks → media/tracks}/SubtitleTrack.js +0 -0
  365. /package/services/{tracks → media/tracks}/TextSubtitleTrack.js +0 -0
  366. /package/services/{tracks → media/tracks}/VideoTrack.js +0 -0
  367. /package/services/{tracks → media/tracks}/index.js +0 -0
  368. /package/services/{files → storage/files}/piece-from-whole-file.js +0 -0
  369. /package/services/{disk → storage}/keep.js +0 -0
  370. /package/services/{piece-store → storage/piece-store}/piece-lru.js +0 -0
  371. /package/services/{disk → storage}/returns.js +0 -0
  372. /package/services/{demand → torrent/demand}/DemandRegister.js +0 -0
  373. /package/services/{demand → torrent/demand}/Urgency.js +0 -0
  374. /package/services/{demand → torrent/demand}/Window.js +0 -0
  375. /package/services/{demand → torrent/demand}/index.js +0 -0
  376. /package/services/{demand → torrent/demand}/pieces.js +0 -0
  377. /package/services/{download → torrent/download}/withdraw-claim.js +0 -0
  378. /package/services/{supply-margin.js → torrent/supply-margin.js} +0 -0
  379. /package/services/{torrent-source-key.js → torrent/torrent-source-key.js} +0 -0
  380. /package/services/{torrent-worker → torrent/worker}/fastest-wires.js +0 -0
  381. /package/services/{torrent-worker → torrent/worker}/handle-state.js +0 -0
  382. /package/services/{nat-classifier.js → transport/nat-classifier.js} +0 -0
  383. /package/services/{registry-api.js → transport/registry-api.js} +0 -0
  384. /package/services/{tunnel-client.js → transport/tunnel-client.js} +0 -0
  385. /package/services/{priority → viewer}/WaitLedger.js +0 -0
@@ -0,0 +1,39 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { OutputCatalog } from "../services/encode/output/OutputCatalog.js";
4
+
5
+ test("the catalog owns creation and access times", () => {
6
+ let now = 100;
7
+ const registry = new OutputCatalog({ now: () => now });
8
+ const output = { id: "picture" };
9
+ registry.set(output.id, output);
10
+
11
+ now = 250;
12
+ registry.touch(output);
13
+
14
+ assert.equal(registry.startedAt(output), 100);
15
+ assert.equal(registry.lastAccessedAt(output), 250);
16
+ assert.equal("startedAt" in output, false);
17
+ assert.equal("lastAccessedAt" in output, false);
18
+ });
19
+
20
+ test("expiry is decided from the catalog's access time", () => {
21
+ let now = 100;
22
+ const registry = new OutputCatalog({ now: () => now });
23
+ registry.set("old", { id: "old" });
24
+ now = 200;
25
+ registry.set("fresh", { id: "fresh" });
26
+
27
+ assert.deepEqual(registry.expiredBefore(150), ["old"]);
28
+ });
29
+
30
+ test("removal deletes both the output and its lifetime", () => {
31
+ const registry = new OutputCatalog({ now: () => 100 });
32
+ const output = { id: "picture" };
33
+ registry.set(output.id, output);
34
+ registry.delete(output.id);
35
+
36
+ assert.equal(registry.get(output.id), undefined);
37
+ assert.equal(registry.startedAt(output), null);
38
+ assert.equal(registry.touch(output, 200), false);
39
+ });
@@ -1,51 +1,13 @@
1
1
  /**
2
- * @file What an output is encoded AS is decided once, for the output.
2
+ * @file The shape an encoder is given for an output.
3
3
  *
4
- * The realtime budget decides the box, the frame rate and the speed setting
5
- * from what the machine could hold at that moment. Decided per SESSION, two
6
- * sessions of one output made minutes apart could be given different pictures
7
- * while claiming the same identity — and everything downstream assumes they
8
- * cannot be, from a segment of one standing in for a segment of the other to
9
- * the single RESOLUTION the master names for both.
4
+ * The format itself is the output's identity (`OutputSpec`), decided before
5
+ * the output is named; this is that format in the terms the encoder takes.
10
6
  */
11
7
 
12
8
  import test from "node:test";
13
9
  import assert from "node:assert/strict";
14
- import { Output, Outputs } from "../services/output/Output.js";
15
-
16
- const KEY = "torrent:abc:fmt=fmp4:grid=even@0:video-only:v=0/enc:1280x720:auto";
17
-
18
- test("the second session of one output is given the shape the first was", () => {
19
- const outputs = new Outputs();
20
- const first = outputs.get(KEY, () => new Output({
21
- encodeWidth: 1280,
22
- encodeHeight: 720,
23
- outputFps: 24,
24
- softwarePreset: "veryfast",
25
- applyTonemap: false
26
- }));
27
- // A minute later the machine is busier and the budget would answer 480p. It
28
- // is not asked: the shape of this output was settled when it was first made.
29
- const second = outputs.get(KEY, () => {
30
- throw new Error("deciding twice is how two sessions of one output diverge");
31
- });
32
-
33
- assert.equal(second, first);
34
- assert.equal(second.encodeHeight, 720);
35
- });
36
-
37
- test("two outputs are two shapes", () => {
38
- const outputs = new Outputs();
39
- const tall = outputs.get(KEY, () => new Output({ encodeWidth: 1280, encodeHeight: 720, outputFps: 24 }));
40
- const short = outputs.get(`${KEY}:other`, () => new Output({
41
- encodeWidth: 854,
42
- encodeHeight: 480,
43
- outputFps: 24
44
- }));
45
-
46
- assert.notEqual(short, tall);
47
- assert.equal(short.encodeHeight, 480);
48
- });
10
+ import { Output } from "../services/encode/output/Output.js";
49
11
 
50
12
  test("a copied picture has no box of its own, and says so with zeroes", () => {
51
13
  // Zero means the source's own size, which is what a copy is by definition:
@@ -57,12 +19,3 @@ test("a copied picture has no box of its own, and says so with zeroes", () => {
57
19
  assert.equal(copied.softwarePreset, null, "and no speed setting, having no encoder");
58
20
  });
59
21
 
60
- test("a shape nobody holds is dropped", () => {
61
- const outputs = new Outputs();
62
- const kept = outputs.get(KEY, () => new Output({ encodeWidth: 1280, encodeHeight: 720, outputFps: 24 }));
63
- outputs.get(`${KEY}:other`, () => new Output({ encodeWidth: 854, encodeHeight: 480, outputFps: 24 }));
64
-
65
- assert.equal(outputs.size, 2);
66
- assert.equal(outputs.forgetUnused(new Set([kept])), 1);
67
- assert.equal(outputs.size, 1);
68
- });
@@ -1,157 +1,251 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { AudioOutput, CutGrid, OutputSpec, VideoOutput } from "../services/output/OutputSpec.js";
4
-
5
- const TORRENT = "torrent:11f0929918e2b5aa2e5b71ecdbe5c0f1a4bbf7d1";
6
-
7
- /**
8
- * The picture of a file, copied, cut at that file's own keyframes.
9
- *
10
- * @param {object} [over]
11
- * @returns {OutputSpec}
12
- */
13
- function copiedPicture(over = {}) {
14
- return new OutputSpec({
15
- sourceKey: TORRENT,
16
- segmentFormatId: "fmp4",
17
- grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
18
- video: new VideoOutput({ fileIndex: 0, encode: null }),
19
- audio: null,
20
- ...over
21
- });
22
- }
23
-
24
- test("two viewers who chose different soundtracks share one copied picture", () => {
25
- // The measurement of 2026-09-03: both sessions described the same thing word
26
- // for word and answered `segment-00000.mp4` with the same 4141899 bytes. The
27
- // soundtrack they picked is not a property of a picture that carries no
28
- // sound, so it cannot tell the two apart.
29
- assert.equal(copiedPicture().toKey(), copiedPicture().toKey());
30
- assert.equal(copiedPicture().carries, "video-only");
31
- });
32
-
33
- test("the viewer's viewport does not fork a picture that is copied", () => {
34
- // A copy is the source's own size whatever box was asked for, so there is
35
- // nowhere for a target to appear in the key.
36
- const key = copiedPicture().toKey();
37
- assert.ok(!key.includes("x"), `a copied picture states no box: ${key}`);
38
- });
39
-
40
- test("two heights of one picture are two outputs", () => {
41
- const at720 = copiedPicture({
42
- video: new VideoOutput({ fileIndex: 0, encode: { width: 1280, height: 720, exactSize: true } })
43
- });
44
- const at480 = copiedPicture({
45
- video: new VideoOutput({ fileIndex: 0, encode: { width: 854, height: 480, exactSize: true } })
46
- });
47
- assert.notEqual(at720.toKey(), at480.toKey());
48
- });
49
-
50
- test("a height produced exactly is not the same output as one the budget may move", () => {
51
- const forced = copiedPicture({
52
- video: new VideoOutput({ fileIndex: 0, encode: { width: 1280, height: 720, exactSize: true } })
53
- });
54
- const chosen = copiedPicture({
55
- video: new VideoOutput({ fileIndex: 0, encode: { width: 1280, height: 720, exactSize: false } })
56
- });
57
- assert.notEqual(forced.toKey(), chosen.toKey());
58
- });
59
-
60
- test("a soundtrack is named by the file it lives in and the track inside it", () => {
61
- // Not by the flat number the browser sends: that number spans the picture's
62
- // own tracks and the files beside it, so it means different things for
63
- // different pictures of one torrent.
64
- const dub = new OutputSpec({
65
- sourceKey: TORRENT,
66
- segmentFormatId: "fmp4",
67
- grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
68
- audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
69
- });
70
- assert.equal(dub.carries, "audio-only");
71
- assert.ok(dub.toKey().includes("a=7/0/aac"), dub.toKey());
72
- });
73
-
74
- test("one soundtrack cut for two different pictures is two outputs", () => {
75
- // The grid of a soundtrack is the picture's, so a rendition made for episode
76
- // one cannot stand in for one made for episode two even when the dub is the
77
- // same file.
78
- const forFirst = new OutputSpec({
79
- sourceKey: TORRENT,
80
- segmentFormatId: "fmp4",
81
- grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
82
- audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
83
- });
84
- const forSecond = new OutputSpec({
85
- sourceKey: TORRENT,
86
- segmentFormatId: "fmp4",
87
- grid: new CutGrid({ kind: "keyframe", fileIndex: 1 }),
88
- audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
89
- });
90
- assert.notEqual(forFirst.toKey(), forSecond.toKey());
91
- });
92
-
93
- test("a copied soundtrack and a re-encoded one are two outputs", () => {
94
- const copied = new OutputSpec({
95
- sourceKey: TORRENT,
96
- segmentFormatId: "fmp4",
97
- grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
98
- audio: new AudioOutput({ fileIndex: 0, trackIndex: 1, transcode: false })
99
- });
100
- const encoded = new OutputSpec({
101
- sourceKey: TORRENT,
102
- segmentFormatId: "fmp4",
103
- grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
104
- audio: new AudioOutput({ fileIndex: 0, trackIndex: 1, transcode: true })
105
- });
106
- assert.notEqual(copied.toKey(), encoded.toKey());
107
- });
108
-
109
- test("a browser without rendition groups gets an output carrying both tracks", () => {
110
- const muxed = new OutputSpec({
111
- sourceKey: TORRENT,
112
- segmentFormatId: "mpegts",
113
- grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
114
- video: new VideoOutput({ fileIndex: 0, encode: null }),
115
- audio: new AudioOutput({ fileIndex: 0, trackIndex: 2, transcode: true })
116
- });
117
- assert.equal(muxed.carries, "muxed");
118
- // And there the soundtrack DOES tell two of them apart, because the output
119
- // really carries it.
120
- const other = new OutputSpec({
121
- sourceKey: TORRENT,
122
- segmentFormatId: "mpegts",
123
- grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
124
- video: new VideoOutput({ fileIndex: 0, encode: null }),
125
- audio: new AudioOutput({ fileIndex: 0, trackIndex: 3, transcode: true })
126
- });
127
- assert.notEqual(muxed.toKey(), other.toKey());
128
- });
129
-
130
- test("the picture, its soundtrack and the two of them muxed are three outputs", () => {
131
- const video = copiedPicture();
132
- const audio = new OutputSpec({
133
- sourceKey: TORRENT,
134
- segmentFormatId: "fmp4",
135
- grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
136
- audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
137
- });
138
- const muxed = copiedPicture({
139
- audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
140
- });
141
- assert.equal(new Set([video.toKey(), audio.toKey(), muxed.toKey()]).size, 3);
142
- });
143
-
144
- test("two containers of the same tracks are two outputs", () => {
145
- assert.notEqual(copiedPicture().toKey(), copiedPicture({ segmentFormatId: "mpegts" }).toKey());
146
- });
147
-
148
- test("the same tracks of two different torrents are two outputs", () => {
149
- assert.notEqual(copiedPicture().toKey(), copiedPicture({ sourceKey: "torrent:0000" }).toKey());
150
- });
151
-
152
- test("a picture cut at keyframes and the same picture cut on the even grid are two outputs", () => {
153
- assert.notEqual(
154
- copiedPicture().toKey(),
155
- copiedPicture({ grid: new CutGrid({ kind: "uniform", fileIndex: 0 }) }).toKey()
156
- );
157
- });
1
+ import assert from "node:assert/strict";
2
+ import { softwareRateControlFor } from "../services/encode/args.js";
3
+ import test from "node:test";
4
+ import { createHash } from "node:crypto";
5
+ import { AudioOutput, CutGrid, isOutputName, OutputSpec, VideoOutput } from "../services/encode/output/OutputSpec.js";
6
+
7
+ const TORRENT = "torrent:11f0929918e2b5aa2e5b71ecdbe5c0f1a4bbf7d1";
8
+
9
+ /**
10
+ * The picture of a file, copied, cut at that file's own keyframes.
11
+ *
12
+ * @param {object} [over]
13
+ * @returns {OutputSpec}
14
+ */
15
+ function copiedPicture(over = {}) {
16
+ return new OutputSpec({
17
+ sourceKey: TORRENT,
18
+ segmentFormatId: "fmp4",
19
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
20
+ video: new VideoOutput({ fileIndex: 0, encode: null }),
21
+ audio: null,
22
+ ...over
23
+ });
24
+ }
25
+
26
+ test("two viewers who chose different soundtracks share one copied picture", () => {
27
+ // The measurement of 2026-09-03: both sessions described the same thing word
28
+ // for word and answered `segment-00000.mp4` with the same 4141899 bytes. The
29
+ // soundtrack they picked is not a property of a picture that carries no
30
+ // sound, so it cannot tell the two apart.
31
+ assert.equal(copiedPicture().toKey(), copiedPicture().toKey());
32
+ assert.equal(copiedPicture().carries, "video-only");
33
+ });
34
+
35
+ test("the viewer's viewport does not fork a picture that is copied", () => {
36
+ // A copy is the source's own size whatever box was asked for, so there is
37
+ // nowhere for a target to appear in the key.
38
+ const key = copiedPicture().toKey();
39
+ assert.ok(!key.includes("x"), `a copied picture states no box: ${key}`);
40
+ });
41
+
42
+ function encoded(over = {}) {
43
+ return copiedPicture({
44
+ video: new VideoOutput({
45
+ fileIndex: 0,
46
+ encode: { encoder: "libx264", width: 1280, height: 720, fps: 24, preset: "veryfast", tonemap: false, ...over }
47
+ })
48
+ });
49
+ }
50
+
51
+ test("two heights of one picture are two outputs", () => {
52
+ assert.notEqual(encoded().toKey(), encoded({ width: 854, height: 480 }).toKey());
53
+ });
54
+
55
+ test("an output is the format produced, and every part of it that reaches the header tells two apart", () => {
56
+ const base = encoded().toKey();
57
+ assert.notEqual(base, encoded({ preset: "ultrafast" }).toKey(), "the speed setting changes the PPS");
58
+ assert.notEqual(base, encoded({ encoder: "h264_nvenc" }).toKey(), "another encoder writes another SPS");
59
+ assert.notEqual(base, encoded({ fps: 30 }).toKey(), "the frame rate");
60
+ assert.notEqual(base, encoded({ tonemap: true }).toKey(), "a tone-mapped picture");
61
+ });
62
+
63
+ test("how the format was asked for is not part of it", () => {
64
+ const asked = new VideoOutput({
65
+ fileIndex: 0,
66
+ encode: { encoder: "libx264", width: 1280, height: 720, fps: 24, preset: "veryfast", tonemap: false, exactSize: true }
67
+ });
68
+ assert.equal(copiedPicture({ video: asked }).toKey(), encoded().toKey());
69
+ });
70
+
71
+ test("a key reads back into the output it names", () => {
72
+ const muxed = new OutputSpec({
73
+ sourceKey: TORRENT,
74
+ segmentFormatId: "mpegts",
75
+ grid: new CutGrid({ kind: "uniform", fileIndex: 2 }),
76
+ video: new VideoOutput({
77
+ fileIndex: 2,
78
+ encode: { encoder: "libx264", width: 854, height: 480, fps: 25, preset: null, tonemap: true }
79
+ }),
80
+ audio: new AudioOutput({ fileIndex: 5, trackIndex: 1, transcode: true })
81
+ });
82
+ for (const spec of [copiedPicture(), encoded(), muxed]) {
83
+ assert.equal(OutputSpec.fromKey(spec.toKey())?.toKey(), spec.toKey());
84
+ }
85
+ });
86
+
87
+ test("a key naming the box a viewer asked for does not read back, because it cannot say what format is inside", () => {
88
+ assert.equal(OutputSpec.fromKey(`${TORRENT}:fmt=fmp4:grid=even@0:video-only:v=0/enc:1280x720:exact`), null);
89
+ assert.equal(OutputSpec.fromKey(`${TORRENT}:fmt=fmp4:grid=even@0:video-only:v=0/enc:1280x720:budget`), null);
90
+ });
91
+
92
+ test("the bitrate limit is part of the output: two limits are two outputs, and the key reads back", () => {
93
+ // Roadmap item 97, step 10. A limit changes the bytes of every piece, so it
94
+ // names the output; the level is the nominal output's, so it is the same for
95
+ // both limits of one size and their headers agree.
96
+ const nominal = softwareRateControlFor({ width: 1280, height: 720, fps: 24 });
97
+ const lower = softwareRateControlFor({ width: 1280, height: 720, fps: 24, capKbps: 1400 });
98
+ const atNominal = encoded({ rateControl: nominal });
99
+ const atLower = encoded({ rateControl: lower });
100
+
101
+ assert.notEqual(atNominal.toKey(), atLower.toKey());
102
+ assert.notEqual(atNominal.toKey(), encoded().toKey(), "a limit and none are two outputs too");
103
+ assert.equal(nominal.level, lower.level);
104
+ for (const spec of [atNominal, atLower, encoded()]) {
105
+ assert.equal(OutputSpec.fromKey(spec.toKey())?.toKey(), spec.toKey());
106
+ }
107
+ assert.deepEqual(OutputSpec.fromKey(atLower.toKey()).video.encode.rateControl, lower);
108
+ });
109
+
110
+ test("a key written before the limit was part of it does not read back", () => {
111
+ // Its directory could hold pieces made under any limit the budget had moved
112
+ // it to, so nothing can say what is inside, and it is not served.
113
+ const current = encoded().toKey();
114
+ assert.equal(OutputSpec.fromKey(current.replace("/vbv=-", "")), null);
115
+ });
116
+
117
+ test("a soundtrack is named by the file it lives in and the track inside it", () => {
118
+ // Not by the flat number the browser sends: that number spans the picture's
119
+ // own tracks and the files beside it, so it means different things for
120
+ // different pictures of one torrent.
121
+ const dub = new OutputSpec({
122
+ sourceKey: TORRENT,
123
+ segmentFormatId: "fmp4",
124
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
125
+ audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
126
+ });
127
+ assert.equal(dub.carries, "audio-only");
128
+ assert.ok(dub.toKey().includes("a=7/0/aac"), dub.toKey());
129
+ });
130
+
131
+ test("one soundtrack cut for two different pictures is two outputs", () => {
132
+ // The grid of a soundtrack is the picture's, so a rendition made for episode
133
+ // one cannot stand in for one made for episode two even when the dub is the
134
+ // same file.
135
+ const forFirst = new OutputSpec({
136
+ sourceKey: TORRENT,
137
+ segmentFormatId: "fmp4",
138
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
139
+ audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
140
+ });
141
+ const forSecond = new OutputSpec({
142
+ sourceKey: TORRENT,
143
+ segmentFormatId: "fmp4",
144
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 1 }),
145
+ audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
146
+ });
147
+ assert.notEqual(forFirst.toKey(), forSecond.toKey());
148
+ });
149
+
150
+ test("a copied soundtrack and a re-encoded one are two outputs", () => {
151
+ const copied = new OutputSpec({
152
+ sourceKey: TORRENT,
153
+ segmentFormatId: "fmp4",
154
+ grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
155
+ audio: new AudioOutput({ fileIndex: 0, trackIndex: 1, transcode: false })
156
+ });
157
+ const encoded = new OutputSpec({
158
+ sourceKey: TORRENT,
159
+ segmentFormatId: "fmp4",
160
+ grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
161
+ audio: new AudioOutput({ fileIndex: 0, trackIndex: 1, transcode: true })
162
+ });
163
+ assert.notEqual(copied.toKey(), encoded.toKey());
164
+ });
165
+
166
+ test("a browser without rendition groups gets an output carrying both tracks", () => {
167
+ const muxed = new OutputSpec({
168
+ sourceKey: TORRENT,
169
+ segmentFormatId: "mpegts",
170
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
171
+ video: new VideoOutput({ fileIndex: 0, encode: null }),
172
+ audio: new AudioOutput({ fileIndex: 0, trackIndex: 2, transcode: true })
173
+ });
174
+ assert.equal(muxed.carries, "muxed");
175
+ // And there the soundtrack DOES tell two of them apart, because the output
176
+ // really carries it.
177
+ const other = new OutputSpec({
178
+ sourceKey: TORRENT,
179
+ segmentFormatId: "mpegts",
180
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
181
+ video: new VideoOutput({ fileIndex: 0, encode: null }),
182
+ audio: new AudioOutput({ fileIndex: 0, trackIndex: 3, transcode: true })
183
+ });
184
+ assert.notEqual(muxed.toKey(), other.toKey());
185
+ });
186
+
187
+ test("the picture, its soundtrack and the two of them muxed are three outputs", () => {
188
+ const video = copiedPicture();
189
+ const audio = new OutputSpec({
190
+ sourceKey: TORRENT,
191
+ segmentFormatId: "fmp4",
192
+ grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
193
+ audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
194
+ });
195
+ const muxed = copiedPicture({
196
+ audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
197
+ });
198
+ assert.equal(new Set([video.toKey(), audio.toKey(), muxed.toKey()]).size, 3);
199
+ });
200
+
201
+ test("two containers of the same tracks are two outputs", () => {
202
+ assert.notEqual(copiedPicture().toKey(), copiedPicture({ segmentFormatId: "mpegts" }).toKey());
203
+ });
204
+
205
+ test("the same tracks of two different torrents are two outputs", () => {
206
+ assert.notEqual(copiedPicture().toKey(), copiedPicture({ sourceKey: "torrent:0000" }).toKey());
207
+ });
208
+
209
+ test("a picture cut at keyframes and the same picture cut on the even grid are two outputs", () => {
210
+ assert.notEqual(
211
+ copiedPicture().toKey(),
212
+ copiedPicture({ grid: new CutGrid({ kind: "uniform", fileIndex: 0 }) }).toKey()
213
+ );
214
+ });
215
+
216
+ test("an output's name follows from its identity and from nothing else", () => {
217
+ // MANY VIEWERS OF ONE OUTPUT address one name because the name is the
218
+ // output's. Nobody arranges it, and nothing about the request enters it: two
219
+ // people opening the same film at different moments and at different places
220
+ // are handed the same name.
221
+ assert.equal(copiedPicture().toName(), copiedPicture().toName());
222
+ assert.notEqual(
223
+ copiedPicture().toName(),
224
+ copiedPicture({ video: new VideoOutput({ fileIndex: 1, encode: null }) }).toName(),
225
+ "and two different outputs are two different names"
226
+ );
227
+ // Stated against the key itself, which is the one thing that proves nothing
228
+ // ELSE got mixed in. Two specs built in one test run agree even if the name
229
+ // secretly carried the clock, because the clock has not moved between them —
230
+ // and "however far apart they arrive" is the whole property.
231
+ assert.equal(
232
+ copiedPicture().toName(),
233
+ createHash("sha256").update(copiedPicture().toKey()).digest("hex").slice(0, 16)
234
+ );
235
+ });
236
+
237
+ test("a name is safe to carry whole, and the guard that admits it agrees", () => {
238
+ // The name reaches the filesystem: it is what the produced pieces of this
239
+ // output are found under. So the shape is asserted here AND where a request
240
+ // is admitted, and the two must be changed together — they were not, the
241
+ // first time this name was minted, and every guarded route would have refused
242
+ // every request while no check said a word.
243
+ const name = copiedPicture().toName();
244
+
245
+ assert.ok(isOutputName(name), "the guard admits what the minting produces");
246
+ assert.equal(encodeURIComponent(name), name, "and it needs no escaping to be carried whole");
247
+ // What the guard is FOR.
248
+ assert.equal(isOutputName("../../etc/passwd"), false);
249
+ assert.equal(isOutputName("aaaaaaaa1111222"), false, "fifteen is not sixteen");
250
+ assert.equal(isOutputName("11111111-2222-3333-4444-555555555555"), false, "and the old shape is gone");
251
+ });
@@ -9,8 +9,9 @@
9
9
 
10
10
  import test from "node:test";
11
11
  import assert from "node:assert/strict";
12
- import { EncodeCost } from "../services/quality/EncodeCost.js";
13
- import { LiveOutputs } from "../services/output/LiveOutputs.js";
12
+ import { EncodeCost } from "../services/encode/quality/EncodeCost.js";
13
+ import { OutputCatalog } from "../services/encode/output/OutputCatalog.js";
14
+ import { outputSpec } from "./helpers/output-spec.js";
14
15
 
15
16
  const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
16
17
 
@@ -19,9 +20,13 @@ const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
19
20
  * @param {{ copySpeedX?: number | null, benchmark?: object[] | null }} host
20
21
  */
21
22
  function costOf(sessions, host = {}) {
22
- const sessionsById = new Map(sessions.map((session, index) => [String(index), session]));
23
+ const outputs = new OutputCatalog();
24
+ sessions.forEach((session, index) => outputs.set(String(index), session));
23
25
  return new EncodeCost({
24
- liveOutputs: new LiveOutputs({ sessionsById }),
26
+ runsFor: () => [],
27
+ stateFor: () => "IDLE",
28
+ progressFor: () => null,
29
+ outputs,
25
30
  host: () => ({
26
31
  benchmark: host.benchmark ?? null,
27
32
  decodeModel: null,
@@ -40,7 +45,7 @@ test("a run on this output outranks every prediction", () => {
40
45
  // It is this machine, this material and these settings. Nothing said before
41
46
  // the fact beats something seen happening.
42
47
  const cost = costOf(
43
- [{ outputKey: PICTURE, state: "ready", transcodeVideo: false, lastAloneSpeed: 9.5 }],
48
+ [{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 9.5 }],
44
49
  { copySpeedX: 600 }
45
50
  );
46
51
  assert.equal(cost.speedForOutput(PICTURE), 9.5);
@@ -52,7 +57,7 @@ test("a copied picture is priced by the startup copy measurement", () => {
52
57
  // describes it, and a copied output was planned with no speed until its own
53
58
  // run had been running long enough to report one.
54
59
  const cost = costOf(
55
- [{ outputKey: PICTURE, state: "ready", transcodeVideo: false, lastAloneSpeed: null }],
60
+ [{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: null }],
56
61
  { copySpeedX: 602 }
57
62
  );
58
63
  assert.equal(cost.speedForOutput(PICTURE), 602);
@@ -62,25 +67,22 @@ test("the fastest reading wins where several sessions produce one output", () =>
62
67
  // Two sessions whose output parameters agree ARE one output, so what either
63
68
  // of them measured about this machine is true of the other.
64
69
  const cost = costOf([
65
- { outputKey: PICTURE, state: "ready", transcodeVideo: false, lastAloneSpeed: 4 },
66
- { outputKey: PICTURE, state: "ready", transcodeVideo: false, lastAloneSpeed: 7 }
70
+ { outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 4 },
71
+ { outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 7 }
67
72
  ]);
68
73
  assert.equal(cost.speedForOutput(PICTURE), 7);
69
74
  });
70
75
 
71
- test("a disposed session says nothing about what the machine is doing", () => {
72
- const cost = costOf(
73
- [{ outputKey: PICTURE, state: "disposed", transcodeVideo: false, lastAloneSpeed: 4 }],
74
- { copySpeedX: 602 }
75
- );
76
- assert.equal(cost.speedForOutput(PICTURE), 0, "no live session, so nothing to say");
76
+ test("an output absent from the live registry says nothing about what the machine is doing", () => {
77
+ const cost = costOf([], { copySpeedX: 602 });
78
+ assert.equal(cost.speedForOutput(PICTURE), 0, "no registered output, so nothing to say");
77
79
  });
78
80
 
79
81
  test("another output's reading is not borrowed", () => {
80
82
  // Two outputs are two different pieces of work — a picture re-encoded to 480p
81
83
  // and the same picture copied are not the same speed.
82
84
  const cost = costOf([
83
- { outputKey: "other", state: "ready", transcodeVideo: false, lastAloneSpeed: 40 }
85
+ { outputKey: "other", spec: outputSpec(), lastAloneSpeed: 40 }
84
86
  ]);
85
87
  assert.equal(cost.speedForOutput(PICTURE), 0);
86
88
  });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file The places preparations hold on the machine are read off the viewers'
3
+ * own records (roadmap item 97, step 13): a step being warmed and a move to
4
+ * another limit of the height on screen are one list, and a place ends with
5
+ * the record — or the viewer — that holds it.
6
+ */
7
+
8
+ import test from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import { Viewers } from "../services/viewer/Viewers.js";
11
+ import { outputsBeingPrepared } from "../services/viewer/choices.js";
12
+
13
+ const PICTURE = { id: "1111111122223333", outputKey: "picture" };
14
+
15
+ test("a warmed step and a move between limits are one list of places", () => {
16
+ const viewers = new Viewers();
17
+ const warming = viewers.of(PICTURE, "viewer-a");
18
+ warming.warmingVariantId = "2222222233334444";
19
+ const moving = viewers.of(PICTURE, "viewer-b");
20
+ moving.sameHeightSwitch = { outputId: "3333333344445555", outputKey: "limit", askedHeights: [720] };
21
+ assert.deepEqual([...outputsBeingPrepared(viewers)].sort(), ["2222222233334444", "3333333344445555"]);
22
+ });
23
+
24
+ test("one output prepared for two viewers is one place", () => {
25
+ const viewers = new Viewers();
26
+ viewers.of(PICTURE, "viewer-a").warmingVariantId = "2222222233334444";
27
+ viewers.of(PICTURE, "viewer-b").sameHeightSwitch = { outputId: "2222222233334444", outputKey: "step" };
28
+ assert.equal(outputsBeingPrepared(viewers).size, 1);
29
+ });
30
+
31
+ test("a place ends with its record, and with the viewer", () => {
32
+ const viewers = new Viewers();
33
+ const viewer = viewers.of(PICTURE, "viewer-a");
34
+ viewer.warmingVariantId = "2222222233334444";
35
+ viewer.warmingVariantId = null;
36
+ assert.equal(outputsBeingPrepared(viewers).size, 0, "the record cleared");
37
+ viewers.of(PICTURE, "viewer-b").warmingVariantId = "2222222233334444";
38
+ viewers.hasGone("viewer-b");
39
+ assert.equal(outputsBeingPrepared(viewers).size, 0, "the viewer gone");
40
+ });