@torrent-tv/proxy 2.55.14 → 2.57.0
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/CHANGELOG.md +1169 -1150
- package/bin/cli.js +494 -478
- package/package.json +1 -1
- package/routes/api/subtitles/get.js +13 -4
- package/services/container-index/matroska-subtitles.js +6 -0
- package/services/container-index/mp4-subtitles.js +25 -1
- package/services/data-channel-handler.js +1133 -949
- package/services/delivery-probe.js +338 -255
- package/services/packet-witness.js +784 -406
- package/services/torrent-worker/client.js +2 -1
- package/services/torrent-worker/subtitle-cues.js +182 -21
- package/services/torrent-worker/worker.js +28 -2
- package/test/delivery-probe.test.js +124 -78
- package/test/packet-witness-ring.test.js +236 -0
- package/test/packet-witness.test.js +148 -120
- package/test/subtitle-track-numbering.test.js +262 -0
- package/test/wedge-certainty.test.js +131 -0
|
@@ -0,0 +1,236 @@
|
|
|
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/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: "68296f7d-0000-0000-0000-000000000000",
|
|
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
|
+
});
|
|
@@ -1,120 +1,148 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The packet witness's gating rules and command construction.
|
|
3
|
-
*
|
|
4
|
-
* Roadmap item 10: a send queue wedged longer than ~30 s must start a bounded
|
|
5
|
-
* tcpdump on its own, because the 2026-08-24 episode proved no counter above
|
|
6
|
-
* the wire can name the cause. Everything here is the part that decides WHEN
|
|
7
|
-
* and WITH WHAT ARGUMENTS — the spawning itself is thin glue around these.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import assert from "node:assert/strict";
|
|
11
|
-
import test from "node:test";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
buildTcpdumpArgs,
|
|
15
|
-
createPacketWitness,
|
|
16
|
-
isWitnessCapture,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
assert.equal(normalizeRemoteAddress("
|
|
43
|
-
assert.equal(normalizeRemoteAddress(""), null);
|
|
44
|
-
assert.equal(normalizeRemoteAddress(
|
|
45
|
-
assert.equal(normalizeRemoteAddress(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"-
|
|
58
|
-
"
|
|
59
|
-
"-
|
|
60
|
-
"
|
|
61
|
-
"-
|
|
62
|
-
"
|
|
63
|
-
"-
|
|
64
|
-
|
|
65
|
-
"-
|
|
66
|
-
String(
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
assert.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
assert.
|
|
120
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file The packet witness's gating rules and command construction.
|
|
3
|
+
*
|
|
4
|
+
* Roadmap item 10: a send queue wedged longer than ~30 s must start a bounded
|
|
5
|
+
* tcpdump on its own, because the 2026-08-24 episode proved no counter above
|
|
6
|
+
* the wire can name the cause. Everything here is the part that decides WHEN
|
|
7
|
+
* and WITH WHAT ARGUMENTS — the spawning itself is thin glue around these.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import test from "node:test";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
buildTcpdumpArgs,
|
|
15
|
+
createPacketWitness,
|
|
16
|
+
isWitnessCapture,
|
|
17
|
+
isWitnessRingFile,
|
|
18
|
+
normalizeRemoteAddress,
|
|
19
|
+
shouldStartCapture,
|
|
20
|
+
WITNESS_RING_FILE_MB,
|
|
21
|
+
WITNESS_RING_FILES,
|
|
22
|
+
WITNESS_RTO_CEILING_SECONDS,
|
|
23
|
+
WITNESS_TAIL_SECONDS
|
|
24
|
+
} from "../services/packet-witness.js";
|
|
25
|
+
|
|
26
|
+
test("an IPv4 literal survives unchanged", () => {
|
|
27
|
+
assert.equal(normalizeRemoteAddress("192.168.178.57"), "192.168.178.57");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("an IPv6 literal survives unchanged", () => {
|
|
31
|
+
assert.equal(
|
|
32
|
+
normalizeRemoteAddress("2001:1c00:a603:2100:a129:a1a1:7f07:3f0b"),
|
|
33
|
+
"2001:1c00:a603:2100:a129:a1a1:7f07:3f0b"
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("a zone suffix is stripped", () => {
|
|
38
|
+
assert.equal(normalizeRemoteAddress("fe80::2aca:8001:3ba6:f16f%18"), "fe80::2aca:8001:3ba6:f16f");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("hostnames, garbage and shell text are rejected", () => {
|
|
42
|
+
assert.equal(normalizeRemoteAddress("homeassistant.local"), null);
|
|
43
|
+
assert.equal(normalizeRemoteAddress("8.8.8.8; rm -rf /"), null);
|
|
44
|
+
assert.equal(normalizeRemoteAddress("999.1.1.1"), null);
|
|
45
|
+
assert.equal(normalizeRemoteAddress(""), null);
|
|
46
|
+
assert.equal(normalizeRemoteAddress(undefined), null);
|
|
47
|
+
assert.equal(normalizeRemoteAddress(42), null);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("the tcpdump command line is bounded and filtered to one peer", () => {
|
|
51
|
+
const args = buildTcpdumpArgs({
|
|
52
|
+
host: "2001:db8::1",
|
|
53
|
+
port: 9090,
|
|
54
|
+
filePrefix: "/data/packet-witness.e2b5ef39.1787600000.pcap"
|
|
55
|
+
});
|
|
56
|
+
assert.deepEqual(args, [
|
|
57
|
+
"-n",
|
|
58
|
+
"-S",
|
|
59
|
+
"-s",
|
|
60
|
+
"128",
|
|
61
|
+
"-i",
|
|
62
|
+
"any",
|
|
63
|
+
"-w",
|
|
64
|
+
"/data/packet-witness.e2b5ef39.1787600000.pcap",
|
|
65
|
+
"-C",
|
|
66
|
+
String(WITNESS_RING_FILE_MB),
|
|
67
|
+
"-W",
|
|
68
|
+
String(WITNESS_RING_FILES),
|
|
69
|
+
"udp",
|
|
70
|
+
"and",
|
|
71
|
+
"port",
|
|
72
|
+
"9090",
|
|
73
|
+
"and",
|
|
74
|
+
"host",
|
|
75
|
+
"2001:db8::1"
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("rotation is by size, so the ring files cannot collapse onto one name", () => {
|
|
80
|
+
// `-G` with a name carrying no strftime field overwrote a single file, which
|
|
81
|
+
// is why both field captures held 28 s instead of the intended 120.
|
|
82
|
+
const args = buildTcpdumpArgs({ port: 9090, filePrefix: "/data/ring.pcap" });
|
|
83
|
+
assert.equal(args.includes("-G"), false);
|
|
84
|
+
assert.equal(args[args.indexOf("-C") + 1], String(WITNESS_RING_FILE_MB));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("with no peer named the ring records every peer on the port", () => {
|
|
88
|
+
const args = buildTcpdumpArgs({ port: 9090, filePrefix: "/data/ring.pcap" });
|
|
89
|
+
assert.equal(args.includes("host"), false);
|
|
90
|
+
assert.deepEqual(args.slice(-4), ["udp", "and", "port", "9090"]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("the tail outlasts three retransmission timeouts", () => {
|
|
94
|
+
assert.equal(WITNESS_TAIL_SECONDS, WITNESS_RTO_CEILING_SECONDS * 3);
|
|
95
|
+
// A zero-window probe is due once per timeout, so a window shorter than the
|
|
96
|
+
// ceiling could not tell silence from a probe that had not come round yet.
|
|
97
|
+
assert.ok(WITNESS_TAIL_SECONDS > WITNESS_RTO_CEILING_SECONDS);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("ring files are told apart from the copies kept as evidence", () => {
|
|
101
|
+
assert.equal(isWitnessRingFile("packet-witness-ring.pcap"), true);
|
|
102
|
+
assert.equal(isWitnessRingFile("packet-witness-ring.pcap3"), true);
|
|
103
|
+
assert.equal(isWitnessRingFile("packet-witness.e2b5ef39.1787600000.before1.pcap"), false);
|
|
104
|
+
assert.equal(isWitnessCapture("packet-witness-ring.pcap3"), false);
|
|
105
|
+
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.before1.pcap"), true);
|
|
106
|
+
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.tail.pcap1"), true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("one capture runs at a time", () => {
|
|
110
|
+
assert.equal(shouldStartCapture({ running: true, lastStartedAt: Date.now() }), false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("the first capture of a process is always allowed", () => {
|
|
114
|
+
assert.equal(shouldStartCapture({ running: false, lastStartedAt: 0, now: 1000 }), true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("a capture within the cooldown is refused, one after it is allowed", () => {
|
|
118
|
+
const state = { running: false, lastStartedAt: 10_000 };
|
|
119
|
+
assert.equal(shouldStartCapture({ ...state, now: 10_000 + 599_999 }), false);
|
|
120
|
+
assert.equal(shouldStartCapture({ ...state, now: 10_000 + 600_000 }), true);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("capture files are recognised by name, rotations included", () => {
|
|
124
|
+
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.pcap"), true);
|
|
125
|
+
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.pcap20260825T120000"), true);
|
|
126
|
+
assert.equal(isWitnessCapture("core.WorkerThread.81.1787600000"), false);
|
|
127
|
+
assert.equal(isWitnessCapture("proxy.log"), false);
|
|
128
|
+
assert.equal(isWitnessCapture("../packet-witness.x.pcap"), false);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("a trigger without a usable remote endpoint is refused without touching anything", () => {
|
|
132
|
+
const lines = [];
|
|
133
|
+
const witness = createPacketWitness({
|
|
134
|
+
log: (message) => lines.push(message),
|
|
135
|
+
dir: "",
|
|
136
|
+
port: 9090
|
|
137
|
+
});
|
|
138
|
+
const started = witness.maybeCapture({
|
|
139
|
+
sessionId: "e2b5ef39-0000",
|
|
140
|
+
tag: "e2b5ef39",
|
|
141
|
+
label: "proxy",
|
|
142
|
+
remote: null,
|
|
143
|
+
queuedBytes: 160_000_000,
|
|
144
|
+
stuckForMs: 31_000
|
|
145
|
+
});
|
|
146
|
+
assert.equal(started, false);
|
|
147
|
+
assert.deepEqual(lines, []);
|
|
148
|
+
});
|