@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.
- package/README.md +14 -3
- package/package.json +10 -2
- package/routes/api/client-logs/post.js +9 -2
- package/server.js +0 -11
- package/.claude/commands/opsx/apply.md +0 -155
- package/.claude/commands/opsx/archive.md +0 -160
- package/.claude/commands/opsx/explore.md +0 -174
- package/.claude/commands/opsx/propose.md +0 -109
- package/.claude/commands/opsx/sync.md +0 -143
- package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
- package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
- package/.claude/skills/openspec-explore/SKILL.md +0 -289
- package/.claude/skills/openspec-propose/SKILL.md +0 -113
- package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
- package/.dockerignore +0 -5
- package/AGENTS.md +0 -363
- package/CHANGELOG.md +0 -2373
- package/Dockerfile +0 -30
- package/biome.json +0 -412
- package/corpus.tmp.json +0 -1
- package/docs/browser-proxy-contract.md +0 -155
- package/docs/container-architecture.md +0 -273
- package/docs/download-architecture.md +0 -261
- package/docs/encode-architecture.md +0 -765
- package/docs/encode-run-state.md +0 -96
- package/docs/logs.md +0 -138
- package/docs/playback-start-forecast.md +0 -113
- package/docs/socks5-egress-research.md +0 -114
- package/docs/storage-architecture.md +0 -273
- package/knip.json +0 -14
- package/main2.cpuprofile +0 -1
- package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
- package/openspec/changes/adaptive-bitrate/design.md +0 -92
- package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
- package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
- package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
- package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
- package/openspec/changes/binary-distribution/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/design.md +0 -81
- package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
- package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
- package/openspec/changes/cold-start/design.md +0 -98
- package/openspec/changes/cold-start/proposal.md +0 -62
- package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
- package/openspec/changes/cold-start/tasks.md +0 -48
- package/openspec/changes/disk-cap/.openspec.yaml +0 -2
- package/openspec/changes/disk-cap/proposal.md +0 -37
- package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
- package/openspec/changes/disk-cap/tasks.md +0 -19
- package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
- package/openspec/changes/proxy-observability/design.md +0 -38
- package/openspec/changes/proxy-observability/proposal.md +0 -49
- package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
- package/openspec/changes/proxy-observability/tasks.md +0 -21
- package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
- package/openspec/changes/seek-debounce/design.md +0 -118
- package/openspec/changes/seek-debounce/proposal.md +0 -59
- package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
- package/openspec/changes/seek-debounce/tasks.md +0 -33
- package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
- package/openspec/changes/subtitle-language/proposal.md +0 -50
- package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
- package/openspec/changes/subtitle-language/tasks.md +0 -26
- package/openspec/changes/track-selection/.openspec.yaml +0 -2
- package/openspec/changes/track-selection/design.md +0 -47
- package/openspec/changes/track-selection/proposal.md +0 -45
- package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
- package/openspec/changes/track-selection/tasks.md +0 -20
- package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
- package/openspec/changes/transcode-quality/proposal.md +0 -51
- package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
- package/openspec/changes/transcode-quality/tasks.md +0 -63
- package/openspec/config.yaml +0 -38
- package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
- package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
- package/research/double-spawn-2026-09-10.md +0 -171
- package/research/handover-2026-09-13.md +0 -209
- package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
- package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
- package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
- package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
- package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
- package/scripts/build-audio-samples.mjs +0 -31
- package/scripts/render-run-graph.js +0 -173
- package/test/asset-paths.test.js +0 -28
- package/test/audio-buffer-continuity.test.js +0 -77
- package/test/audio-calibration.test.js +0 -23
- package/test/audio-inventory.test.js +0 -212
- package/test/audio-track-bitrate.test.js +0 -40
- package/test/audio-warm-recorded.test.js +0 -63
- package/test/auto-quality-step.test.js +0 -762
- package/test/available-share.test.js +0 -76
- package/test/background-fill.test.js +0 -190
- package/test/client-log-file.test.js +0 -126
- package/test/coalesce.test.js +0 -39
- package/test/completed-files.test.js +0 -115
- package/test/concurrent-cost.test.js +0 -148
- package/test/container-media-info.test.js +0 -228
- package/test/contention.test.js +0 -76
- package/test/core-dumps.test.js +0 -57
- package/test/coverage-follows-the-disk.test.js +0 -233
- package/test/coverage-map.test.js +0 -195
- package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
- package/test/cut-times-timeline.test.js +0 -65
- package/test/cuts-follow-published-grid.test.js +0 -109
- package/test/data-channel-frame.test.js +0 -63
- package/test/data-channel-viewer-lifecycle.test.js +0 -193
- package/test/dead-torrent-handle.test.js +0 -52
- package/test/declared-rates.test.js +0 -116
- package/test/declared-tracks.test.js +0 -43
- package/test/decode-cost-fit.test.js +0 -202
- package/test/decode-cost.test.js +0 -475
- package/test/delivery-probe-field.test.js +0 -173
- package/test/delivery-probe.test.js +0 -382
- package/test/demand-register.test.js +0 -206
- package/test/dht-bootstrap.test.js +0 -72
- package/test/drain-threat.test.js +0 -65
- package/test/duplicate-add.test.js +0 -48
- package/test/encode-admission.test.js +0 -170
- package/test/encode-cost.test.js +0 -275
- package/test/encode-exit.test.js +0 -111
- package/test/encode-orchestrator.test.js +0 -426
- package/test/encode-plan-viewers.test.js +0 -725
- package/test/encode-plan.test.js +0 -545
- package/test/encode-run-state.test.js +0 -314
- package/test/encode-run.test.js +0 -248
- package/test/encode-slope.test.js +0 -46
- package/test/encoded-output.test.js +0 -39
- package/test/encoder-kinds.test.js +0 -122
- package/test/encoder-readings.test.js +0 -68
- package/test/episode-naming.test.js +0 -131
- package/test/every-claimant-is-told-its-share.test.js +0 -152
- package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
- package/test/failed-start-breaker.test.js +0 -202
- package/test/fastest-wires.test.js +0 -143
- package/test/ffmpeg-stream-counts.test.js +0 -101
- package/test/file-edges.test.js +0 -191
- package/test/files-in-use.test.js +0 -34
- package/test/fixtures/audio-frame-boundary.json +0 -1
- package/test/fixtures/refused-audio-20261002.json +0 -10
- package/test/fmp4-presentation-clock.test.js +0 -148
- package/test/fmp4-self-contained.test.js +0 -80
- package/test/fmp4-timestamps.test.js +0 -140
- package/test/fmp4-track-completeness.test.js +0 -41
- package/test/format-keyed-outputs.test.js +0 -78
- package/test/health-metrics.test.js +0 -36
- package/test/held-read-ownership.test.js +0 -77
- package/test/held-request-width.test.js +0 -157
- package/test/helpers/encode-run.js +0 -248
- package/test/helpers/held-file.js +0 -77
- package/test/helpers/manager.js +0 -62
- package/test/helpers/matroska-file.js +0 -296
- package/test/helpers/output-spec.js +0 -63
- package/test/host-load.test.js +0 -68
- package/test/index-accuracy-is-about-the-file.test.js +0 -128
- package/test/init-compat.test.js +0 -219
- package/test/input-lost-quiets-the-plan.test.js +0 -261
- package/test/input-unavailable.test.js +0 -48
- package/test/installation-id.test.js +0 -39
- package/test/keeping-period.test.js +0 -83
- package/test/keyframe-index-accuracy.test.js +0 -188
- package/test/keyframe-table-budget.test.js +0 -123
- package/test/keyframes-belong-to-the-file.test.js +0 -249
- package/test/learned-median.test.js +0 -37
- package/test/letting-go-asks-who-is-watching.test.js +0 -191
- package/test/limit-row-by-area.test.js +0 -60
- package/test/link-budget.test.js +0 -111
- package/test/link-probe.test.js +0 -56
- package/test/local-encoding-data.test.js +0 -273
- package/test/logger-repeats.test.js +0 -134
- package/test/look-ahead-coverage.test.js +0 -56
- package/test/manager-surface.test.js +0 -291
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cluster-discovery.test.js +0 -323
- package/test/matroska-cues-track.test.js +0 -192
- package/test/media-time.test.js +0 -62
- package/test/memory-budget.test.js +0 -390
- package/test/move-cost.test.js +0 -216
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +0 -173
- package/test/one-authority.test.js +0 -285
- package/test/one-budget.test.js +0 -149
- package/test/one-output-one-session.test.js +0 -273
- package/test/one-resource-divided.test.js +0 -185
- package/test/one-serving-output-per-height.test.js +0 -458
- package/test/orchestrator-wired.test.js +0 -207
- package/test/output-catalog.test.js +0 -39
- package/test/output-shape.test.js +0 -21
- package/test/output-spec.test.js +0 -251
- package/test/output-speed.test.js +0 -92
- package/test/outputs-being-prepared.test.js +0 -40
- package/test/packet-witness-ring.test.js +0 -236
- package/test/packet-witness.test.js +0 -148
- package/test/piece-completeness.test.js +0 -78
- package/test/piece-disk-store.test.js +0 -401
- package/test/piece-from-whole-file.test.js +0 -129
- package/test/piece-lru.test.js +0 -319
- package/test/piece-reader.test.js +0 -162
- package/test/piece-selection-offset.test.js +0 -85
- package/test/piece-store-eviction.test.js +0 -595
- package/test/piece-store-never-refuses.test.js +0 -153
- package/test/piece-store-reservations.test.js +0 -403
- package/test/piece-store-slow-disk.test.js +0 -159
- package/test/piece-tail.test.js +0 -97
- package/test/plan-host-timings.test.js +0 -68
- package/test/plan-is-steady.test.js +0 -225
- package/test/playback-readiness.test.js +0 -518
- package/test/playback-start-regressions.test.js +0 -101
- package/test/priority-map-download.test.js +0 -174
- package/test/priority-map-emptied.test.js +0 -204
- package/test/priority-map-per-output.test.js +0 -215
- package/test/priority-map.test.js +0 -163
- package/test/probe-wedge-certainty.test.js +0 -60
- package/test/produced-copy-choice.test.js +0 -213
- package/test/published-timeline.test.js +0 -83
- package/test/quality-offer.test.js +0 -160
- package/test/quality-variants.test.js +0 -1274
- package/test/rate-control-in-the-output.test.js +0 -181
- package/test/read-survives-withdrawal.test.js +0 -164
- package/test/read-window.test.js +0 -365
- package/test/reads-not-yet-arrived.test.js +0 -218
- package/test/resume-warm.test.js +0 -39
- package/test/run-graph-drift.test.js +0 -37
- package/test/run-inputs.test.js +0 -80
- package/test/run-intervals.test.js +0 -100
- package/test/run-position-follows-published-grid.test.js +0 -89
- package/test/run-progress.test.js +0 -64
- package/test/same-height-switch.test.js +0 -663
- package/test/seek-frees-the-viewers-requests.test.js +0 -217
- package/test/seek-landing.test.js +0 -109
- package/test/seek-target-not-superseded.test.js +0 -195
- package/test/segment-closed-on-both-branches.test.js +0 -114
- package/test/segment-cut-times.test.js +0 -63
- package/test/segment-demand.test.js +0 -80
- package/test/segment-hold-supersede.test.js +0 -91
- package/test/segment-judged-by-its-own-header.test.js +0 -222
- package/test/segment-serve-wiring.test.js +0 -481
- package/test/segment-store-eviction.test.js +0 -247
- package/test/segment-store.test.js +0 -352
- package/test/segment-true-start.test.js +0 -86
- package/test/segments-are-shared.test.js +0 -176
- package/test/send-chunk-bytes.test.js +0 -86
- package/test/serving-existing-output.test.js +0 -111
- package/test/serving-output.test.js +0 -102
- package/test/shared-piece-store.test.js +0 -310
- package/test/sidecar-naming.test.js +0 -142
- package/test/soundtrack-rate-bound.test.js +0 -289
- package/test/source-file.test.js +0 -133
- package/test/source-files-route.test.js +0 -113
- package/test/source-registry.test.js +0 -18
- package/test/split-a-stretch.test.js +0 -139
- package/test/stale-request-after-seek.test.js +0 -158
- package/test/startup-readings.test.js +0 -124
- package/test/stream-route.test.js +0 -237
- package/test/subtitle-cue-framing.test.js +0 -200
- package/test/subtitle-cue-source.test.js +0 -102
- package/test/subtitle-cue-walk.test.js +0 -385
- package/test/subtitle-cursor.test.js +0 -63
- package/test/subtitle-defaults.test.js +0 -118
- package/test/subtitle-language.test.js +0 -252
- package/test/subtitle-metadata.test.js +0 -15
- package/test/subtitle-plan-waits.test.js +0 -125
- package/test/subtitle-track-numbering.test.js +0 -391
- package/test/supply-margin.test.js +0 -190
- package/test/swarm-follows-readers.test.js +0 -174
- package/test/swarm-reach.test.js +0 -130
- package/test/swarm-selection.test.js +0 -220
- package/test/tail-duplication.test.js +0 -167
- package/test/the-channel-has-both-ends.test.js +0 -91
- package/test/the-torrent-thread-serves-bytes.test.js +0 -107
- package/test/thread-pool.test.js +0 -53
- package/test/timeline.test.js +0 -84
- package/test/torrent-contents.test.js +0 -235
- package/test/torrent-cost.test.js +0 -71
- package/test/torrent-files.test.js +0 -221
- package/test/torrent-naming.test.js +0 -255
- package/test/tracks-begin-together.test.js +0 -209
- package/test/tunnel-renewal.test.js +0 -167
- package/test/two-viewers-one-picture.test.js +0 -508
- package/test/upload-hurry.test.js +0 -186
- package/test/usrsctp-state.test.js +0 -131
- package/test/video-facts.test.js +0 -102
- package/test/viewer-assignments.test.js +0 -143
- package/test/viewer-outputs.test.js +0 -285
- package/test/viewer-presence.test.js +0 -116
- package/test/viewer-requests-admission.test.js +0 -92
- package/test/viewer-starts-on-map.test.js +0 -27
- package/test/viewer-states.test.js +0 -192
- package/test/viewer-subtitle-subscription.test.js +0 -96
- package/test/viewer.test.js +0 -139
- package/test/viewing-generations.test.js +0 -390
- package/test/visible-rung.test.js +0 -37
- package/test/wait-ledger.test.js +0 -100
- package/test/webrtc-shim.test.js +0 -149
- package/test/wedge-certainty.test.js +0 -131
- package/test/whole-file-held-read.test.js +0 -30
- package/test/withdraw-piece-claim.test.js +0 -212
- package/test/worker-channel.test.js +0 -158
|
@@ -1,39 +0,0 @@
|
|
|
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,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The shape an encoder is given for an output.
|
|
3
|
-
*
|
|
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.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import test from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { Output } from "../services/encode/output/Output.js";
|
|
11
|
-
|
|
12
|
-
test("a copied picture has no box of its own, and says so with zeroes", () => {
|
|
13
|
-
// Zero means the source's own size, which is what a copy is by definition:
|
|
14
|
-
// no box asked for can change one byte of it.
|
|
15
|
-
const copied = new Output({ encodeWidth: 0, encodeHeight: 0, outputFps: 24 });
|
|
16
|
-
|
|
17
|
-
assert.equal(copied.encodeWidth, 0);
|
|
18
|
-
assert.equal(copied.encodeHeight, 0);
|
|
19
|
-
assert.equal(copied.softwarePreset, null, "and no speed setting, having no encoder");
|
|
20
|
-
});
|
|
21
|
-
|
package/test/output-spec.test.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file How fast this machine produces one output.
|
|
3
|
-
*
|
|
4
|
-
* The figure every decision in the encoding layer rests on: where an encoder
|
|
5
|
-
* goes and how many run are both worked out from arrivals, and an arrival is a
|
|
6
|
-
* distance divided by this. There must therefore ALWAYS be an answer, and each
|
|
7
|
-
* of the three that can be given is a measurement rather than a guess.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import test from "node:test";
|
|
11
|
-
import assert from "node:assert/strict";
|
|
12
|
-
import { EncodeCost } from "../services/encode/quality/EncodeCost.js";
|
|
13
|
-
import { OutputCatalog } from "../services/encode/output/OutputCatalog.js";
|
|
14
|
-
import { qualityStateOf } from "../services/encode/quality/OutputQualityState.js";
|
|
15
|
-
import { outputSpec } from "./helpers/output-spec.js";
|
|
16
|
-
|
|
17
|
-
const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @param {object[]} sessions
|
|
21
|
-
* @param {{ copySpeedX?: number | null, benchmark?: object[] | null }} host
|
|
22
|
-
*/
|
|
23
|
-
function costOf(sessions, host = {}) {
|
|
24
|
-
const outputs = new OutputCatalog();
|
|
25
|
-
sessions.forEach(({ lastAloneSpeed, ...session }, index) => {
|
|
26
|
-
// What a run measured belongs to the quality component's state of the output.
|
|
27
|
-
qualityStateOf(session).lastAloneSpeed = lastAloneSpeed ?? undefined;
|
|
28
|
-
outputs.set(String(index), session);
|
|
29
|
-
});
|
|
30
|
-
return new EncodeCost({
|
|
31
|
-
runsFor: () => [],
|
|
32
|
-
stateFor: () => "IDLE",
|
|
33
|
-
outputs,
|
|
34
|
-
host: () => ({
|
|
35
|
-
benchmark: host.benchmark ?? null,
|
|
36
|
-
decodeModel: null,
|
|
37
|
-
contentionPenalties: null,
|
|
38
|
-
copySpeedX: host.copySpeedX ?? null,
|
|
39
|
-
availability: null
|
|
40
|
-
}),
|
|
41
|
-
audioCostKey: () => "",
|
|
42
|
-
runningEncoders: () => 0,
|
|
43
|
-
encodersRunningNow: () => 0,
|
|
44
|
-
torrentCostSecFor: () => 0
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
test("a run on this output outranks every prediction", () => {
|
|
49
|
-
// It is this machine, this material and these settings. Nothing said before
|
|
50
|
-
// the fact beats something seen happening.
|
|
51
|
-
const cost = costOf(
|
|
52
|
-
[{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 9.5 }],
|
|
53
|
-
{ copySpeedX: 600 }
|
|
54
|
-
);
|
|
55
|
-
assert.equal(cost.speedForOutput(PICTURE), 9.5);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("a copied picture is priced by the startup copy measurement", () => {
|
|
59
|
-
// The branch that had no figure at all until it was measured: copying neither
|
|
60
|
-
// decodes nor encodes, so neither the preset benchmark nor the decode model
|
|
61
|
-
// describes it, and a copied output was planned with no speed until its own
|
|
62
|
-
// run had been running long enough to report one.
|
|
63
|
-
const cost = costOf(
|
|
64
|
-
[{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: null }],
|
|
65
|
-
{ copySpeedX: 602 }
|
|
66
|
-
);
|
|
67
|
-
assert.equal(cost.speedForOutput(PICTURE), 602);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("the fastest reading wins where several sessions produce one output", () => {
|
|
71
|
-
// Two sessions whose output parameters agree ARE one output, so what either
|
|
72
|
-
// of them measured about this machine is true of the other.
|
|
73
|
-
const cost = costOf([
|
|
74
|
-
{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 4 },
|
|
75
|
-
{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 7 }
|
|
76
|
-
]);
|
|
77
|
-
assert.equal(cost.speedForOutput(PICTURE), 7);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("an output absent from the live registry says nothing about what the machine is doing", () => {
|
|
81
|
-
const cost = costOf([], { copySpeedX: 602 });
|
|
82
|
-
assert.equal(cost.speedForOutput(PICTURE), 0, "no registered output, so nothing to say");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("another output's reading is not borrowed", () => {
|
|
86
|
-
// Two outputs are two different pieces of work — a picture re-encoded to 480p
|
|
87
|
-
// and the same picture copied are not the same speed.
|
|
88
|
-
const cost = costOf([
|
|
89
|
-
{ outputKey: "other", spec: outputSpec(), lastAloneSpeed: 40 }
|
|
90
|
-
]);
|
|
91
|
-
assert.equal(cost.speedForOutput(PICTURE), 0);
|
|
92
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { EventEmitter } from "node:events";
|
|
4
|
-
import { mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
adoptOrphanRingFiles,
|
|
10
|
-
createPacketWitness,
|
|
11
|
-
WITNESS_RING_BASENAME
|
|
12
|
-
} from "../services/transport/packet-witness.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A stand-in for a spawned tcpdump: it records how it was called and stays
|
|
16
|
-
* "running" until something kills it.
|
|
17
|
-
*/
|
|
18
|
-
class FakeChild extends EventEmitter {
|
|
19
|
-
constructor(command, args) {
|
|
20
|
-
super();
|
|
21
|
-
this.command = command;
|
|
22
|
-
this.args = args;
|
|
23
|
-
this.killed = false;
|
|
24
|
-
this.signals = [];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
kill(signal) {
|
|
28
|
-
this.signals.push(signal);
|
|
29
|
-
if (!this.killed) {
|
|
30
|
-
this.killed = true;
|
|
31
|
-
// A real child exits asynchronously, which is what the code must wait for.
|
|
32
|
-
setImmediate(() => this.emit("close", 0, signal));
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @returns {{ spawnProcess: Function, children: FakeChild[], rings: FakeChild[] }}
|
|
40
|
-
*/
|
|
41
|
-
function makeSpawn() {
|
|
42
|
-
const children = [];
|
|
43
|
-
const spawnProcess = (command, args) => {
|
|
44
|
-
const child = new FakeChild(command, args);
|
|
45
|
-
children.push(child);
|
|
46
|
-
if (args.includes("--version")) {
|
|
47
|
-
// The availability probe: answer at once, like a present tcpdump.
|
|
48
|
-
setImmediate(() => child.emit("spawn"));
|
|
49
|
-
}
|
|
50
|
-
return child;
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
spawnProcess,
|
|
54
|
-
children,
|
|
55
|
-
get rings() {
|
|
56
|
-
return children.filter((child) => !child.args.includes("--version"));
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Wait until `check` holds, rather than for a chosen interval.
|
|
63
|
-
*
|
|
64
|
-
* A fixed sleep passes alone and fails in a full run — the defect roadmap item
|
|
65
|
-
* 51 names — and the work here is several awaits deep (probe, stop, readdir,
|
|
66
|
-
* copy, restart), so its duration is whatever the machine is busy with.
|
|
67
|
-
*
|
|
68
|
-
* @param {() => boolean | Promise<boolean>} check
|
|
69
|
-
* @param {string} what
|
|
70
|
-
* @returns {Promise<void>}
|
|
71
|
-
*/
|
|
72
|
-
async function waitFor(check, what) {
|
|
73
|
-
const deadline = Date.now() + 10_000;
|
|
74
|
-
for (;;) {
|
|
75
|
-
if (await check()) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (Date.now() > deadline) {
|
|
79
|
-
throw new Error(`timed out waiting for ${what}`);
|
|
80
|
-
}
|
|
81
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Let every already-queued microtask and immediate run. */
|
|
86
|
-
const settle = () => new Promise((resolve) => setTimeout(resolve, 20));
|
|
87
|
-
|
|
88
|
-
async function withDir(run) {
|
|
89
|
-
const dir = await mkdtemp(path.join(os.tmpdir(), "witness-ring-"));
|
|
90
|
-
try {
|
|
91
|
-
await run(dir);
|
|
92
|
-
} finally {
|
|
93
|
-
await rm(dir, { recursive: true, force: true });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
test("the ring runs while a channel is open and stops with the last one", async () => {
|
|
98
|
-
await withDir(async (dir) => {
|
|
99
|
-
const spawn = makeSpawn();
|
|
100
|
-
const witness = createPacketWitness({
|
|
101
|
-
log: () => {},
|
|
102
|
-
dir,
|
|
103
|
-
port: 9090,
|
|
104
|
-
spawnProcess: spawn.spawnProcess
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
witness.holdRing();
|
|
108
|
-
witness.holdRing();
|
|
109
|
-
await waitFor(() => spawn.rings.length === 1, "the ring to start");
|
|
110
|
-
assert.equal(spawn.rings.length, 1, "a second channel must not start a second ring");
|
|
111
|
-
assert.equal(spawn.rings[0].killed, false);
|
|
112
|
-
|
|
113
|
-
witness.releaseRing();
|
|
114
|
-
await settle();
|
|
115
|
-
assert.equal(spawn.rings[0].killed, false, "one channel left still wants the ring");
|
|
116
|
-
|
|
117
|
-
witness.releaseRing();
|
|
118
|
-
await waitFor(() => spawn.rings[0].killed, "the ring to stop");
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test("a channel that opens and closes while the ring is starting leaves nothing running", async () => {
|
|
123
|
-
await withDir(async (dir) => {
|
|
124
|
-
const spawn = makeSpawn();
|
|
125
|
-
const witness = createPacketWitness({
|
|
126
|
-
log: () => {},
|
|
127
|
-
dir,
|
|
128
|
-
port: 9090,
|
|
129
|
-
spawnProcess: spawn.spawnProcess
|
|
130
|
-
});
|
|
131
|
-
// Release before the availability probe has resolved — the start is still
|
|
132
|
-
// in flight. Without the second look after the await this leaves a tcpdump
|
|
133
|
-
// nobody holds and nobody will ever stop.
|
|
134
|
-
witness.holdRing();
|
|
135
|
-
witness.releaseRing();
|
|
136
|
-
await waitFor(
|
|
137
|
-
() => spawn.rings.every((child) => child.killed),
|
|
138
|
-
"any ring started mid-flight to be stopped"
|
|
139
|
-
);
|
|
140
|
-
const alive = spawn.rings.filter((child) => !child.killed);
|
|
141
|
-
assert.deepEqual(alive, [], "no ring may outlive the channels that wanted it");
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test("the ring's files are removed once nobody is being served", async () => {
|
|
146
|
-
await withDir(async (dir) => {
|
|
147
|
-
const spawn = makeSpawn();
|
|
148
|
-
const witness = createPacketWitness({
|
|
149
|
-
log: () => {},
|
|
150
|
-
dir,
|
|
151
|
-
port: 9090,
|
|
152
|
-
spawnProcess: spawn.spawnProcess
|
|
153
|
-
});
|
|
154
|
-
witness.holdRing();
|
|
155
|
-
await waitFor(() => spawn.rings.length === 1, "the ring to start");
|
|
156
|
-
await writeFile(path.join(dir, `${WITNESS_RING_BASENAME}0`), "pcap");
|
|
157
|
-
witness.releaseRing();
|
|
158
|
-
await waitFor(async () => (await readdir(dir)).length === 0, "the ring files to be removed");
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test("a wedge keeps the ring's history, and the ring keeps recording afterwards", async () => {
|
|
163
|
-
await withDir(async (dir) => {
|
|
164
|
-
const spawn = makeSpawn();
|
|
165
|
-
const lines = [];
|
|
166
|
-
const witness = createPacketWitness({
|
|
167
|
-
log: (message) => lines.push(message),
|
|
168
|
-
dir,
|
|
169
|
-
port: 9090,
|
|
170
|
-
spawnProcess: spawn.spawnProcess
|
|
171
|
-
});
|
|
172
|
-
witness.holdRing();
|
|
173
|
-
await waitFor(() => spawn.rings.length === 1, "the ring to start");
|
|
174
|
-
await writeFile(path.join(dir, `${WITNESS_RING_BASENAME}0`), "before-the-freeze");
|
|
175
|
-
await writeFile(path.join(dir, `${WITNESS_RING_BASENAME}1`), "also-before");
|
|
176
|
-
|
|
177
|
-
const started = witness.maybeCapture({
|
|
178
|
-
sessionId: "68296f7d00000000",
|
|
179
|
-
tag: "68296f7d",
|
|
180
|
-
label: "proxy",
|
|
181
|
-
remote: { address: "2001:db8::1", port: 61649 },
|
|
182
|
-
queuedBytes: 67_372_267,
|
|
183
|
-
stuckForMs: 4000
|
|
184
|
-
});
|
|
185
|
-
assert.equal(started, true);
|
|
186
|
-
await waitFor(
|
|
187
|
-
async () => (await readdir(dir)).filter((name) => name.includes(".before")).length === 2,
|
|
188
|
-
"both ring files to be copied aside"
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
const kept = (await readdir(dir)).filter((name) => name.includes(".before"));
|
|
192
|
-
assert.equal(kept.length, 2, "both ring files must be kept, not just the finished one");
|
|
193
|
-
assert.ok(kept.every((name) => name.startsWith("packet-witness.68296f7d.")));
|
|
194
|
-
// Stopped to flush, then started again: two ring processes over the episode.
|
|
195
|
-
await waitFor(() => spawn.rings.length >= 2, "the ring to resume after the copy");
|
|
196
|
-
assert.equal(spawn.rings.at(-1).killed, false);
|
|
197
|
-
assert.ok(lines.some((line) => line.includes("kept 2 ring file(s)")));
|
|
198
|
-
|
|
199
|
-
// End the tail capture: it would otherwise sit out its whole window, and
|
|
200
|
-
// its timer would hold this process open.
|
|
201
|
-
for (const child of spawn.children) {
|
|
202
|
-
child.kill("SIGTERM");
|
|
203
|
-
}
|
|
204
|
-
await settle();
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
test("dispose stops the ring and clears its files", async () => {
|
|
209
|
-
await withDir(async (dir) => {
|
|
210
|
-
const spawn = makeSpawn();
|
|
211
|
-
const witness = createPacketWitness({
|
|
212
|
-
log: () => {},
|
|
213
|
-
dir,
|
|
214
|
-
port: 9090,
|
|
215
|
-
spawnProcess: spawn.spawnProcess
|
|
216
|
-
});
|
|
217
|
-
witness.holdRing();
|
|
218
|
-
await waitFor(() => spawn.rings.length === 1, "the ring to start");
|
|
219
|
-
await writeFile(path.join(dir, `${WITNESS_RING_BASENAME}0`), "pcap");
|
|
220
|
-
await witness.dispose();
|
|
221
|
-
assert.equal(spawn.rings.at(-1).killed, true);
|
|
222
|
-
assert.deepEqual(await readdir(dir), []);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test("ring files left by a killed process are kept, not deleted by the next one", async () => {
|
|
227
|
-
await withDir(async (dir) => {
|
|
228
|
-
await writeFile(path.join(dir, `${WITNESS_RING_BASENAME}0`), "the seconds before the crash");
|
|
229
|
-
await writeFile(path.join(dir, `${WITNESS_RING_BASENAME}2`), "and these");
|
|
230
|
-
const adopted = await adoptOrphanRingFiles(dir);
|
|
231
|
-
assert.equal(adopted.length, 2);
|
|
232
|
-
const left = await readdir(dir);
|
|
233
|
-
assert.equal(left.filter((name) => name.startsWith(WITNESS_RING_BASENAME)).length, 0);
|
|
234
|
-
assert.ok(left.every((name) => name.startsWith("packet-witness.orphan.")));
|
|
235
|
-
});
|
|
236
|
-
});
|