@norskvideo/ctl-test-harness 0.1.113 → 0.1.115
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/daemon.d.ts +4 -1
- package/daemon.js +5 -2
- package/package.json +5 -1
- package/quiet-box.d.ts +35 -0
- package/quiet-box.js +76 -0
package/daemon.d.ts
CHANGED
|
@@ -21,6 +21,9 @@ export declare function runCli(storeDir: string, ...args: string[]): Promise<{
|
|
|
21
21
|
exitCode: number;
|
|
22
22
|
}>;
|
|
23
23
|
export declare function isPortFree(port: number): Promise<boolean>;
|
|
24
|
+
/** `-sTCP:LISTEN` is load-bearing: without it lsof also reports every process
|
|
25
|
+
* holding a client socket to the port, including this test runner's own
|
|
26
|
+
* keep-alive connection to a previous daemon there. */
|
|
24
27
|
export declare function killProcessOnPort(port: number): void;
|
|
25
28
|
/** The daemon handle callers hold: enough to kill it and await its exit,
|
|
26
29
|
* without tying the interface to one runtime's spawn return type. */
|
|
@@ -83,7 +86,7 @@ export declare function ctlSupportsEphemeralPorts(): Promise<boolean>;
|
|
|
83
86
|
/** Root the instance working directory under the store dir (itself under
|
|
84
87
|
* TEST_TMP_BASE) rather than the daemon default ~/norsk-runtime. The launcher
|
|
85
88
|
* bind-mounts the workdir as /data and then mounts the stored template's
|
|
86
|
-
*
|
|
89
|
+
* assets/ and dashboards/ (which live under the store dir) *inside* it — Docker Desktop
|
|
87
90
|
* rejects a nested bind mount whose inner source resolves to a different host
|
|
88
91
|
* share-root than the outer, so both mounts must share the TEST_TMP_BASE root.
|
|
89
92
|
* With NORSK_CTL_STORE_DIR set, config.yaml is read from <storeDir>/config.yaml.
|
package/daemon.js
CHANGED
|
@@ -112,9 +112,12 @@ export function isPortFree(port) {
|
|
|
112
112
|
srv.listen(port, () => srv.close(() => resolve(true)));
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
+
/** `-sTCP:LISTEN` is load-bearing: without it lsof also reports every process
|
|
116
|
+
* holding a client socket to the port, including this test runner's own
|
|
117
|
+
* keep-alive connection to a previous daemon there. */
|
|
115
118
|
export function killProcessOnPort(port) {
|
|
116
119
|
try {
|
|
117
|
-
const result = spawnSync("lsof", ["-ti", `:${port}
|
|
120
|
+
const result = spawnSync("lsof", ["-ti", `:${port}`, "-sTCP:LISTEN"], { encoding: "utf-8" });
|
|
118
121
|
const pids = splitLines(result.stdout ?? "");
|
|
119
122
|
for (const pid of pids) {
|
|
120
123
|
try {
|
|
@@ -200,7 +203,7 @@ export function ctlSupportsEphemeralPorts() {
|
|
|
200
203
|
/** Root the instance working directory under the store dir (itself under
|
|
201
204
|
* TEST_TMP_BASE) rather than the daemon default ~/norsk-runtime. The launcher
|
|
202
205
|
* bind-mounts the workdir as /data and then mounts the stored template's
|
|
203
|
-
*
|
|
206
|
+
* assets/ and dashboards/ (which live under the store dir) *inside* it — Docker Desktop
|
|
204
207
|
* rejects a nested bind mount whose inner source resolves to a different host
|
|
205
208
|
* share-root than the outer, so both mounts must share the TEST_TMP_BASE root.
|
|
206
209
|
* With NORSK_CTL_STORE_DIR set, config.yaml is read from <storeDir>/config.yaml.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@norskvideo/ctl-test-harness",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.115",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"types": "./reap.d.ts",
|
|
41
41
|
"default": "./reap.js"
|
|
42
42
|
},
|
|
43
|
+
"./quiet-box": {
|
|
44
|
+
"types": "./quiet-box.d.ts",
|
|
45
|
+
"default": "./quiet-box.js"
|
|
46
|
+
},
|
|
43
47
|
"./source-pump": {
|
|
44
48
|
"types": "./source-pump.d.ts",
|
|
45
49
|
"default": "./source-pump.js"
|
package/quiet-box.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { runCli } from "./daemon.js";
|
|
2
|
+
/** Set to `1` to run the engine tier even when foreign instances are live — for a
|
|
3
|
+
* single-tenant box/CI where those instances are your own and you accept the
|
|
4
|
+
* shared-network churn. */
|
|
5
|
+
export declare const BUSY_BOX_OVERRIDE_ENV = "NORSK_ALLOW_BUSY_BOX";
|
|
6
|
+
/** The box's primary daemon — the one an unscoped `norsk-ctl` command reaches. */
|
|
7
|
+
export declare const PRIMARY_DAEMON_PORT: number;
|
|
8
|
+
export type QuietBoxVerdict = {
|
|
9
|
+
clear: true;
|
|
10
|
+
} | {
|
|
11
|
+
clear: false;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
/** Decide whether the engine tier may run given the foreign instances live on the
|
|
15
|
+
* box. Pure: the caller supplies the discovered list and the override flag. */
|
|
16
|
+
export declare function quietBoxVerdict(foreignInstances: readonly string[], opts: {
|
|
17
|
+
override: boolean;
|
|
18
|
+
}): QuietBoxVerdict;
|
|
19
|
+
export interface DiscoverDeps {
|
|
20
|
+
/** Does a daemon answer /api/ready on this port? */
|
|
21
|
+
answers(port: number): Promise<boolean>;
|
|
22
|
+
list(storeDir: string, port: number): ReturnType<typeof runCli>;
|
|
23
|
+
}
|
|
24
|
+
/** Running instances on the box's primary daemon that are not ours. Best-effort:
|
|
25
|
+
* if the primary daemon is unreachable or is our own daemon, the box is quiet
|
|
26
|
+
* from our perspective and this returns []. `probeStoreDir` is only used to root
|
|
27
|
+
* the CLI invocation; the query itself reads the daemon's HTTP API by port.
|
|
28
|
+
* The port is asked directly first: the CLI auto-starts a daemon on a silent
|
|
29
|
+
* port and polls it for 30 seconds, which is not a question but a side effect. */
|
|
30
|
+
export declare function discoverForeignInstances(opts: {
|
|
31
|
+
probeStoreDir: string;
|
|
32
|
+
primaryPort: number;
|
|
33
|
+
ownPort: number;
|
|
34
|
+
deps?: DiscoverDeps;
|
|
35
|
+
}): Promise<string[]>;
|
package/quiet-box.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Engine-tier preflight guard (ET-3). The daemon's `norsk-net` bridge and
|
|
2
|
+
// `norsk-proxy` container are box-global singletons keyed by a FIXED name —
|
|
3
|
+
// `norsk-ctl config set` exposes only working-directory / public-host / proxy-port
|
|
4
|
+
// / upgrade-check, so there is no way to namespace them per daemon. A second daemon
|
|
5
|
+
// standing instances up on the same box therefore shares them, and tearing our
|
|
6
|
+
// instances down churns that shared network: observed 2026-08-04 to stop a
|
|
7
|
+
// co-running `auth-verify` env's instances during doc-guide runs.
|
|
8
|
+
//
|
|
9
|
+
// Until norsk-ctl can namespace the network per daemon (the real isolation fix,
|
|
10
|
+
// tracked as ET-3), the engine harness REFUSES to run when the box already carries
|
|
11
|
+
// foreign launched instances rather than silently clobber them. The decision itself
|
|
12
|
+
// is pure and unit-tested; `discoverForeignInstances` is the impure probe that feeds
|
|
13
|
+
// it the live list.
|
|
14
|
+
import { runCli } from "./daemon.js";
|
|
15
|
+
/** Set to `1` to run the engine tier even when foreign instances are live — for a
|
|
16
|
+
* single-tenant box/CI where those instances are your own and you accept the
|
|
17
|
+
* shared-network churn. */
|
|
18
|
+
export const BUSY_BOX_OVERRIDE_ENV = "NORSK_ALLOW_BUSY_BOX";
|
|
19
|
+
/** The box's primary daemon — the one an unscoped `norsk-ctl` command reaches. */
|
|
20
|
+
export const PRIMARY_DAEMON_PORT = Number(process.env.NORSK_CTL_PORT ?? 8333);
|
|
21
|
+
/** Decide whether the engine tier may run given the foreign instances live on the
|
|
22
|
+
* box. Pure: the caller supplies the discovered list and the override flag. */
|
|
23
|
+
export function quietBoxVerdict(foreignInstances, opts) {
|
|
24
|
+
if (foreignInstances.length === 0 || opts.override)
|
|
25
|
+
return { clear: true };
|
|
26
|
+
const list = foreignInstances.join(", ");
|
|
27
|
+
return {
|
|
28
|
+
clear: false,
|
|
29
|
+
message: `Refusing to run the engine tier: ${foreignInstances.length} foreign norsk-ctl ` +
|
|
30
|
+
`instance(s) are live on this box (${list}). Standing our own instances up shares the ` +
|
|
31
|
+
`box-global norsk-net / norsk-proxy singletons, and tearing them down would clobber ` +
|
|
32
|
+
`that environment (ET-3). Stop those instances first, or set ${BUSY_BOX_OVERRIDE_ENV}=1 ` +
|
|
33
|
+
`if they are your own and you accept the shared-network churn.`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const defaultDiscoverDeps = {
|
|
37
|
+
answers: async (port) => {
|
|
38
|
+
try {
|
|
39
|
+
const r = await fetch(`http://localhost:${port}/api/ready`, { signal: AbortSignal.timeout(1000) });
|
|
40
|
+
return r.ok;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
list: (storeDir, port) => runCli(storeDir, "--port", String(port), "instance", "list", "-o", "json"),
|
|
47
|
+
};
|
|
48
|
+
/** Running instances on the box's primary daemon that are not ours. Best-effort:
|
|
49
|
+
* if the primary daemon is unreachable or is our own daemon, the box is quiet
|
|
50
|
+
* from our perspective and this returns []. `probeStoreDir` is only used to root
|
|
51
|
+
* the CLI invocation; the query itself reads the daemon's HTTP API by port.
|
|
52
|
+
* The port is asked directly first: the CLI auto-starts a daemon on a silent
|
|
53
|
+
* port and polls it for 30 seconds, which is not a question but a side effect. */
|
|
54
|
+
export async function discoverForeignInstances(opts) {
|
|
55
|
+
if (opts.primaryPort === opts.ownPort)
|
|
56
|
+
return [];
|
|
57
|
+
const deps = opts.deps ?? defaultDiscoverDeps;
|
|
58
|
+
if (!(await deps.answers(opts.primaryPort)))
|
|
59
|
+
return [];
|
|
60
|
+
let r;
|
|
61
|
+
try {
|
|
62
|
+
r = await deps.list(opts.probeStoreDir, opts.primaryPort);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
if (r.exitCode !== 0)
|
|
68
|
+
return [];
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(r.stdout);
|
|
71
|
+
return (parsed.instances ?? []).filter((i) => i.status === "running" || i.status === "healthy").map((i) => i.id);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|