@torrent-tv/proxy 2.89.6 → 2.89.8

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 (92) hide show
  1. package/AGENTS.md +32 -12
  2. package/CHANGELOG.md +2340 -2330
  3. package/assets/calibration/audio/NOTICE.md +19 -19
  4. package/assets/calibration/audio/manifest.json +98 -98
  5. package/biome.json +412 -412
  6. package/docs/browser-proxy-contract.md +155 -155
  7. package/docs/container-architecture.md +273 -273
  8. package/docs/encode-run-state.md +1 -1
  9. package/docs/playback-start-forecast.md +113 -98
  10. package/package.json +51 -50
  11. package/routes/api/sources/files/get.js +106 -106
  12. package/scripts/build-audio-samples.mjs +31 -31
  13. package/services/encode/EncodeRun.js +67 -15
  14. package/services/encode/EncodeRuns.js +19 -7
  15. package/services/encode/OutputOpening.js +784 -784
  16. package/services/encode/audio-calibration.js +67 -67
  17. package/services/encode/audio-work-rate.js +15 -15
  18. package/services/encode/encode-exit.js +2 -0
  19. package/services/encode/hwaccel.js +1894 -1894
  20. package/services/encode/output/index.js +24 -24
  21. package/services/encode/piece-completeness.js +60 -2
  22. package/services/encode/run-command.js +757 -755
  23. package/services/encode/segment-formats/index.js +1 -0
  24. package/services/encode/segment-formats/mp4-boxes.js +8 -1
  25. package/services/media/ContainerOrchestrator.js +202 -202
  26. package/services/media/KeyframeTables.js +356 -356
  27. package/services/media/SubtitleCues.js +592 -592
  28. package/services/media/audio-inventory.js +299 -299
  29. package/services/media/container/AviContainer.js +268 -268
  30. package/services/media/container/Container.js +632 -632
  31. package/services/media/container/ContainerFactory.js +38 -38
  32. package/services/media/container/MatroskaContainer.js +1031 -1031
  33. package/services/media/container/Mp4Container.js +1354 -1354
  34. package/services/media/container/SubtitleFileContainer.js +339 -339
  35. package/services/media/container/ebml-stream.js +174 -174
  36. package/services/media/container/matroska-clusters.js +1165 -1165
  37. package/services/media/container/unavailable.js +77 -77
  38. package/services/media/tracks/ContainerTrack.js +84 -84
  39. package/services/media/tracks/TextSubtitleTrack.js +295 -295
  40. package/services/storage/piece-store/shared-piece-store.js +1937 -1937
  41. package/services/storage/segment-store/SegmentStore.js +1294 -1294
  42. package/services/torrent/Contents.js +382 -382
  43. package/services/torrent/episode-naming.js +182 -182
  44. package/services/torrent/torrent-pool.js +2688 -2688
  45. package/services/torrent/worker/client.js +836 -836
  46. package/services/torrent/worker/held-bytes.js +231 -231
  47. package/services/torrent/worker/worker.js +1137 -1137
  48. package/services/transport/data-channel-handler.js +1373 -1373
  49. package/services/viewer/PriorityMap.js +421 -421
  50. package/test/audio-calibration.test.js +23 -23
  51. package/test/auto-quality-step.test.js +762 -762
  52. package/test/coalesce.test.js +39 -39
  53. package/test/coverage-follows-the-disk.test.js +5 -0
  54. package/test/decode-cost.test.js +475 -475
  55. package/test/encode-run.test.js +58 -0
  56. package/test/episode-naming.test.js +131 -131
  57. package/test/failed-encoder-still-serves-what-exists.test.js +1 -1
  58. package/test/fixtures/audio-frame-boundary.json +1 -1
  59. package/test/fixtures/refused-audio-20261002.json +10 -0
  60. package/test/fmp4-presentation-clock.test.js +4 -2
  61. package/test/format-keyed-outputs.test.js +78 -78
  62. package/test/health-metrics.test.js +11 -13
  63. package/test/held-read-ownership.test.js +77 -77
  64. package/test/helpers/encode-run.js +14 -6
  65. package/test/helpers/held-file.js +77 -77
  66. package/test/helpers/manager.js +62 -62
  67. package/test/helpers/matroska-file.js +296 -296
  68. package/test/keyframe-table-budget.test.js +123 -123
  69. package/test/matroska-cluster-discovery.test.js +323 -323
  70. package/test/one-output-one-session.test.js +273 -273
  71. package/test/output-speed.test.js +6 -1
  72. package/test/piece-completeness.test.js +37 -1
  73. package/test/quality-variants.test.js +1274 -1270
  74. package/test/rate-control-in-the-output.test.js +4 -3
  75. package/test/reads-not-yet-arrived.test.js +218 -218
  76. package/test/seek-frees-the-viewers-requests.test.js +1 -1
  77. package/test/segment-closed-on-both-branches.test.js +114 -114
  78. package/test/segment-judged-by-its-own-header.test.js +222 -222
  79. package/test/segment-serve-wiring.test.js +481 -481
  80. package/test/serving-existing-output.test.js +111 -111
  81. package/test/source-files-route.test.js +113 -113
  82. package/test/subtitle-cue-walk.test.js +385 -385
  83. package/test/subtitle-metadata.test.js +15 -15
  84. package/test/subtitle-plan-waits.test.js +125 -125
  85. package/test/subtitle-track-numbering.test.js +391 -391
  86. package/test/two-viewers-one-picture.test.js +508 -508
  87. package/test/viewer-requests-admission.test.js +92 -92
  88. package/test/viewer-starts-on-map.test.js +27 -27
  89. package/test/viewer-states.test.js +5 -2
  90. package/test/viewing-generations.test.js +390 -390
  91. package/test/whole-file-held-read.test.js +30 -30
  92. package/utils/coalesce.js +41 -41
@@ -1,222 +1,222 @@
1
- /**
2
- * @file A piece short of a track is judged against ITS OWN header.
3
- *
4
- * The question "does this piece carry every track" has two possible answers and
5
- * they call for opposite actions, which is why asking it against the session's
6
- * cached header alone was not enough: a piece that disagrees with that header
7
- * may be short, or the header may be the odd one out. A self-contained piece
8
- * carries a `moov` of its own, so it can be compared with itself, and that
9
- * comparison tells the two apart without asking anything about encoders.
10
- *
11
- * WHAT THIS REPLACED. The action used to be chosen by "is any run of this
12
- * session alive?" — a question about the SESSION, asked about a fact of the
13
- * BYTES. A run anywhere in the film meant "still being written; waiting for
14
- * it", and nothing re-judged or re-made the piece afterwards, so one
15
- * misjudgement became permanent.
16
- *
17
- * Field 2026-09-14: `segment-00033.mp4` of a copied picture, already served
18
- * whole to one viewer at 5 099 421 bytes, was refused to a second viewer for
19
- * five minutes — four holds of sixty seconds each, then 503 — while the run in
20
- * force was at #192 and beyond. That viewer's picture stood still 196.2 s and
21
- * then a further 56.2 s.
22
- *
23
- * The run question is also unanswerable and does not need asking: a piece being
24
- * written is called `making-<tag>-NNNNN.mp4` and takes its served name by a
25
- * rename, which is atomic. A file under its served name is never being written.
26
- */
27
-
28
- import test from "node:test";
29
- import assert from "node:assert/strict";
30
- import { access, writeFile } from "node:fs/promises";
31
- import path from "node:path";
32
- import { SourceFile } from "../services/media/SourceFile.js";
33
- import { Timeline } from "../services/encode/output/Timeline.js";
34
- import { managerWithOwnStore } from "./helpers/manager.js";
35
- import { startRunOn } from "./helpers/encode-run.js";
36
- import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
37
- import { outputSpec } from "./helpers/output-spec.js";
38
-
39
- const SESSION_ID = "3333333344445555";
40
- const OUTPUT_KEY = "own-header:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
41
- const MOVIE_TIMESCALE = 1000;
42
-
43
- /**
44
- * @param {string} type
45
- * @param {Buffer} body
46
- * @returns {Buffer}
47
- */
48
- function box(type, body) {
49
- const head = Buffer.alloc(8);
50
- head.writeUInt32BE(8 + body.length, 0);
51
- head.write(type, 4, "latin1");
52
- return Buffer.concat([head, body]);
53
- }
54
-
55
- /**
56
- * @param {number} trackId
57
- * @returns {Buffer}
58
- */
59
- function trak(trackId) {
60
- const tkhdBody = Buffer.alloc(84);
61
- tkhdBody.writeUInt32BE(trackId, 12);
62
- const mdhdBody = Buffer.alloc(20);
63
- mdhdBody.writeUInt32BE(90_000, 12);
64
- return box("trak", Buffer.concat([
65
- box("tkhd", tkhdBody),
66
- box("mdia", box("mdhd", mdhdBody))
67
- ]));
68
- }
69
-
70
- /**
71
- * A header declaring `tracks` tracks.
72
- *
73
- * @param {number} tracks
74
- * @returns {Buffer}
75
- */
76
- function moovOf(tracks) {
77
- const mvhdBody = Buffer.alloc(100);
78
- mvhdBody.writeUInt32BE(MOVIE_TIMESCALE, 12);
79
- const traks = [];
80
- for (let id = 1; id <= tracks; id += 1) {
81
- traks.push(trak(id));
82
- }
83
- return box("moov", Buffer.concat([box("mvhd", mvhdBody), ...traks]));
84
- }
85
-
86
- /**
87
- * @param {number} trackId
88
- * @returns {Buffer}
89
- */
90
- function traf(trackId) {
91
- const tfhdBody = Buffer.alloc(8);
92
- tfhdBody.writeUInt32BE(trackId, 4);
93
- const tfdtBody = Buffer.alloc(12);
94
- tfdtBody.writeUInt8(1, 0);
95
- tfdtBody.writeBigUInt64BE(0n, 4);
96
- return box("traf", Buffer.concat([box("tfhd", tfhdBody), box("tfdt", tfdtBody)]));
97
- }
98
-
99
- /**
100
- * A piece shaped like the `segment` muxer's output.
101
- *
102
- * @param {{ declares: number, carries: number }} shape - How many tracks its own
103
- * header declares, and how many its fragments actually carry. The two differ
104
- * only in a piece a run closed short.
105
- * @returns {Buffer}
106
- */
107
- function selfContainedPiece({ declares, carries }) {
108
- const trafs = [];
109
- for (let id = 1; id <= carries; id += 1) {
110
- trafs.push(traf(id));
111
- }
112
- return Buffer.concat([
113
- box("ftyp", Buffer.alloc(16, 0)),
114
- moovOf(declares),
115
- box("moof", Buffer.concat(trafs)),
116
- box("mdat", Buffer.alloc(64, 0x5a)),
117
- box("mfra", Buffer.alloc(24, 0))
118
- ]);
119
- }
120
-
121
- /**
122
- * A manager with one session whose first two pieces are already on disk.
123
- *
124
- * @param {{ piece: Buffer, sessionHeader: Buffer }} params - The piece written
125
- * for every number, and what the session has cached as its header.
126
- * @returns {Promise<{ manager: object, dirPath: string }>}
127
- */
128
- async function managerHolding({ piece, sessionHeader }) {
129
- const { manager } = managerWithOwnStore();
130
- manager.segmentStore.useFormat(OUTPUT_KEY, fmp4Format);
131
- const dirPath = manager.segmentStore.directoryFor(OUTPUT_KEY);
132
- await writeFile(path.join(dirPath, "segment-00000.mp4"), piece);
133
- await writeFile(path.join(dirPath, "segment-00001.mp4"), piece);
134
-
135
- const session = {
136
- id: SESSION_ID,
137
- spec: outputSpec({ transcodeVideo: false }),
138
- outputKey: OUTPUT_KEY,
139
- dirPath,
140
- timeline: new Timeline({ boundaries: [0, 12.5, 25, 37.5, 50, 62.5], cutGrid: "uniform" }),
141
- state: "ready",
142
- file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" })
143
- .learn({ durationSeconds: 62.5 }),
144
- get inputFile() { return this.file; },
145
- get audioFile() { return this.file; },
146
- lastAloneSpeed: 2,
147
- startedAt: Date.now(),
148
- lastAccessedAt: Date.now(),
149
- runs: new Set(),
150
- lastError: "",
151
- segmentCount: 5,
152
- segmentFormat: fmp4Format,
153
- useSyntheticPlaylist: true,
154
- playlistText: "#EXTM3U\n",
155
- waitEpoch: 0
156
- };
157
- manager.outputs.set(SESSION_ID, session);
158
- // The header this output serves is the store's, one owner for it.
159
- manager.segmentStore.keepInit(OUTPUT_KEY, sessionHeader);
160
- // No plan runs here: this file is about the path that answers a request.
161
- manager.encodeRuns.planEncodersNow = () => {};
162
- manager.encodeRuns.planEncodersSoon = () => {};
163
- // A LIVE RUN, deliberately. Under the rule this replaced, a live run anywhere
164
- // was what turned a refusal into a permanent one — so both cases below are
165
- // asked with one running, which is the state the field failure happened in.
166
- startRunOn(session, { from: 0, usesExplicitCuts: true, speedX: 2 });
167
- return { manager, dirPath };
168
- }
169
-
170
- test("a piece that agrees with its own header is served, whatever the session's header says", async () => {
171
- // Two tracks declared, two carried: whole by its own account. The session's
172
- // cached header declares three — the state that cannot be told from a short
173
- // piece without asking the piece itself.
174
- const piece = selfContainedPiece({ declares: 2, carries: 2 });
175
- const { manager, dirPath } = await managerHolding({
176
- piece,
177
- sessionHeader: moovOf(3)
178
- });
179
-
180
- const answer = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
181
-
182
- assert.equal(answer.kind, "file", "the piece is whole and must reach the viewer");
183
- await access(path.join(dirPath, "segment-00000.mp4"));
184
- });
185
-
186
- test("a piece that disagrees with its own header is removed, so it can be made again", async () => {
187
- // Two tracks declared, one carried: closed short by a run that was killed
188
- // mid-piece, which is what this check exists to catch.
189
- const piece = selfContainedPiece({ declares: 2, carries: 1 });
190
- const { manager, dirPath } = await managerHolding({
191
- piece,
192
- sessionHeader: moovOf(2)
193
- });
194
-
195
- const answer = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
196
-
197
- assert.equal(answer.kind, "warming-up", "a short piece is not servable");
198
- await assert.rejects(
199
- () => access(path.join(dirPath, "segment-00000.mp4")),
200
- /ENOENT/,
201
- "and it is removed, or nothing will ever make it again"
202
- );
203
- });
204
-
205
- test("a live run elsewhere in the film does not make a short piece permanent", async () => {
206
- const piece = selfContainedPiece({ declares: 2, carries: 1 });
207
- const { manager, dirPath } = await managerHolding({
208
- piece,
209
- sessionHeader: moovOf(2)
210
- });
211
- // The field state exactly: the run in force is hundreds of segments ahead of
212
- // the piece being asked for.
213
- startRunOn(manager.outputs.get(SESSION_ID), { from: 192, usesExplicitCuts: true, speedX: 2 });
214
-
215
- await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
216
-
217
- await assert.rejects(
218
- () => access(path.join(dirPath, "segment-00000.mp4")),
219
- /ENOENT/,
220
- "a run a thousand segments away says nothing about these bytes"
221
- );
222
- });
1
+ /**
2
+ * @file A piece short of a track is judged against ITS OWN header.
3
+ *
4
+ * The question "does this piece carry every track" has two possible answers and
5
+ * they call for opposite actions, which is why asking it against the session's
6
+ * cached header alone was not enough: a piece that disagrees with that header
7
+ * may be short, or the header may be the odd one out. A self-contained piece
8
+ * carries a `moov` of its own, so it can be compared with itself, and that
9
+ * comparison tells the two apart without asking anything about encoders.
10
+ *
11
+ * WHAT THIS REPLACED. The action used to be chosen by "is any run of this
12
+ * session alive?" — a question about the SESSION, asked about a fact of the
13
+ * BYTES. A run anywhere in the film meant "still being written; waiting for
14
+ * it", and nothing re-judged or re-made the piece afterwards, so one
15
+ * misjudgement became permanent.
16
+ *
17
+ * Field 2026-09-14: `segment-00033.mp4` of a copied picture, already served
18
+ * whole to one viewer at 5 099 421 bytes, was refused to a second viewer for
19
+ * five minutes — four holds of sixty seconds each, then 503 — while the run in
20
+ * force was at #192 and beyond. That viewer's picture stood still 196.2 s and
21
+ * then a further 56.2 s.
22
+ *
23
+ * The run question is also unanswerable and does not need asking: a piece being
24
+ * written is called `making-<tag>-NNNNN.mp4` and takes its served name by a
25
+ * rename, which is atomic. A file under its served name is never being written.
26
+ */
27
+
28
+ import test from "node:test";
29
+ import assert from "node:assert/strict";
30
+ import { access, writeFile } from "node:fs/promises";
31
+ import path from "node:path";
32
+ import { SourceFile } from "../services/media/SourceFile.js";
33
+ import { Timeline } from "../services/encode/output/Timeline.js";
34
+ import { managerWithOwnStore } from "./helpers/manager.js";
35
+ import { startRunOn } from "./helpers/encode-run.js";
36
+ import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
37
+ import { outputSpec } from "./helpers/output-spec.js";
38
+
39
+ const SESSION_ID = "3333333344445555";
40
+ const OUTPUT_KEY = "own-header:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
41
+ const MOVIE_TIMESCALE = 1000;
42
+
43
+ /**
44
+ * @param {string} type
45
+ * @param {Buffer} body
46
+ * @returns {Buffer}
47
+ */
48
+ function box(type, body) {
49
+ const head = Buffer.alloc(8);
50
+ head.writeUInt32BE(8 + body.length, 0);
51
+ head.write(type, 4, "latin1");
52
+ return Buffer.concat([head, body]);
53
+ }
54
+
55
+ /**
56
+ * @param {number} trackId
57
+ * @returns {Buffer}
58
+ */
59
+ function trak(trackId) {
60
+ const tkhdBody = Buffer.alloc(84);
61
+ tkhdBody.writeUInt32BE(trackId, 12);
62
+ const mdhdBody = Buffer.alloc(20);
63
+ mdhdBody.writeUInt32BE(90_000, 12);
64
+ return box("trak", Buffer.concat([
65
+ box("tkhd", tkhdBody),
66
+ box("mdia", box("mdhd", mdhdBody))
67
+ ]));
68
+ }
69
+
70
+ /**
71
+ * A header declaring `tracks` tracks.
72
+ *
73
+ * @param {number} tracks
74
+ * @returns {Buffer}
75
+ */
76
+ function moovOf(tracks) {
77
+ const mvhdBody = Buffer.alloc(100);
78
+ mvhdBody.writeUInt32BE(MOVIE_TIMESCALE, 12);
79
+ const traks = [];
80
+ for (let id = 1; id <= tracks; id += 1) {
81
+ traks.push(trak(id));
82
+ }
83
+ return box("moov", Buffer.concat([box("mvhd", mvhdBody), ...traks]));
84
+ }
85
+
86
+ /**
87
+ * @param {number} trackId
88
+ * @returns {Buffer}
89
+ */
90
+ function traf(trackId) {
91
+ const tfhdBody = Buffer.alloc(8);
92
+ tfhdBody.writeUInt32BE(trackId, 4);
93
+ const tfdtBody = Buffer.alloc(12);
94
+ tfdtBody.writeUInt8(1, 0);
95
+ tfdtBody.writeBigUInt64BE(0n, 4);
96
+ return box("traf", Buffer.concat([box("tfhd", tfhdBody), box("tfdt", tfdtBody)]));
97
+ }
98
+
99
+ /**
100
+ * A piece shaped like the `segment` muxer's output.
101
+ *
102
+ * @param {{ declares: number, carries: number }} shape - How many tracks its own
103
+ * header declares, and how many its fragments actually carry. The two differ
104
+ * only in a piece a run closed short.
105
+ * @returns {Buffer}
106
+ */
107
+ function selfContainedPiece({ declares, carries }) {
108
+ const trafs = [];
109
+ for (let id = 1; id <= carries; id += 1) {
110
+ trafs.push(traf(id));
111
+ }
112
+ return Buffer.concat([
113
+ box("ftyp", Buffer.alloc(16, 0)),
114
+ moovOf(declares),
115
+ box("moof", Buffer.concat(trafs)),
116
+ box("mdat", Buffer.alloc(64, 0x5a)),
117
+ box("mfra", Buffer.alloc(24, 0))
118
+ ]);
119
+ }
120
+
121
+ /**
122
+ * A manager with one session whose first two pieces are already on disk.
123
+ *
124
+ * @param {{ piece: Buffer, sessionHeader: Buffer }} params - The piece written
125
+ * for every number, and what the session has cached as its header.
126
+ * @returns {Promise<{ manager: object, dirPath: string }>}
127
+ */
128
+ async function managerHolding({ piece, sessionHeader }) {
129
+ const { manager } = managerWithOwnStore();
130
+ manager.segmentStore.useFormat(OUTPUT_KEY, fmp4Format);
131
+ const dirPath = manager.segmentStore.directoryFor(OUTPUT_KEY);
132
+ await writeFile(path.join(dirPath, "segment-00000.mp4"), piece);
133
+ await writeFile(path.join(dirPath, "segment-00001.mp4"), piece);
134
+
135
+ const session = {
136
+ id: SESSION_ID,
137
+ spec: outputSpec({ transcodeVideo: false }),
138
+ outputKey: OUTPUT_KEY,
139
+ dirPath,
140
+ timeline: new Timeline({ boundaries: [0, 12.5, 25, 37.5, 50, 62.5], cutGrid: "uniform" }),
141
+ state: "ready",
142
+ file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" })
143
+ .learn({ durationSeconds: 62.5 }),
144
+ get inputFile() { return this.file; },
145
+ get audioFile() { return this.file; },
146
+ lastAloneSpeed: 2,
147
+ startedAt: Date.now(),
148
+ lastAccessedAt: Date.now(),
149
+ runs: new Set(),
150
+ lastError: "",
151
+ segmentCount: 5,
152
+ segmentFormat: fmp4Format,
153
+ useSyntheticPlaylist: true,
154
+ playlistText: "#EXTM3U\n",
155
+ waitEpoch: 0
156
+ };
157
+ manager.outputs.set(SESSION_ID, session);
158
+ // The header this output serves is the store's, one owner for it.
159
+ manager.segmentStore.keepInit(OUTPUT_KEY, sessionHeader);
160
+ // No plan runs here: this file is about the path that answers a request.
161
+ manager.encodeRuns.planEncodersNow = () => {};
162
+ manager.encodeRuns.planEncodersSoon = () => {};
163
+ // A LIVE RUN, deliberately. Under the rule this replaced, a live run anywhere
164
+ // was what turned a refusal into a permanent one — so both cases below are
165
+ // asked with one running, which is the state the field failure happened in.
166
+ startRunOn(session, { from: 0, usesExplicitCuts: true, speedX: 2 });
167
+ return { manager, dirPath };
168
+ }
169
+
170
+ test("a piece that agrees with its own header is served, whatever the session's header says", async () => {
171
+ // Two tracks declared, two carried: whole by its own account. The session's
172
+ // cached header declares three — the state that cannot be told from a short
173
+ // piece without asking the piece itself.
174
+ const piece = selfContainedPiece({ declares: 2, carries: 2 });
175
+ const { manager, dirPath } = await managerHolding({
176
+ piece,
177
+ sessionHeader: moovOf(3)
178
+ });
179
+
180
+ const answer = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
181
+
182
+ assert.equal(answer.kind, "file", "the piece is whole and must reach the viewer");
183
+ await access(path.join(dirPath, "segment-00000.mp4"));
184
+ });
185
+
186
+ test("a piece that disagrees with its own header is removed, so it can be made again", async () => {
187
+ // Two tracks declared, one carried: closed short by a run that was killed
188
+ // mid-piece, which is what this check exists to catch.
189
+ const piece = selfContainedPiece({ declares: 2, carries: 1 });
190
+ const { manager, dirPath } = await managerHolding({
191
+ piece,
192
+ sessionHeader: moovOf(2)
193
+ });
194
+
195
+ const answer = await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
196
+
197
+ assert.equal(answer.kind, "warming-up", "a short piece is not servable");
198
+ await assert.rejects(
199
+ () => access(path.join(dirPath, "segment-00000.mp4")),
200
+ /ENOENT/,
201
+ "and it is removed, or nothing will ever make it again"
202
+ );
203
+ });
204
+
205
+ test("a live run elsewhere in the film does not make a short piece permanent", async () => {
206
+ const piece = selfContainedPiece({ declares: 2, carries: 1 });
207
+ const { manager, dirPath } = await managerHolding({
208
+ piece,
209
+ sessionHeader: moovOf(2)
210
+ });
211
+ // The field state exactly: the run in force is hundreds of segments ahead of
212
+ // the piece being asked for.
213
+ startRunOn(manager.outputs.get(SESSION_ID), { from: 192, usesExplicitCuts: true, speedX: 2 });
214
+
215
+ await manager.serving.getFileStream(SESSION_ID, "segment-00000.mp4");
216
+
217
+ await assert.rejects(
218
+ () => access(path.join(dirPath, "segment-00000.mp4")),
219
+ /ENOENT/,
220
+ "a run a thousand segments away says nothing about these bytes"
221
+ );
222
+ });