@norskvideo/ctl-test-harness 0.1.9 → 0.1.11
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/container-net.js +4 -2
- package/launch.d.ts +12 -0
- package/launch.js +42 -0
- package/package.json +1 -1
package/container-net.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Reach launched product instances by their norsk-net service DNS instead of a
|
|
2
|
-
// host-published port.
|
|
3
|
-
//
|
|
2
|
+
// host-published port. Dissolves the cross-product host-port collision the
|
|
3
|
+
// release gate trips on. Consumed by the playout, funke, and commentary
|
|
4
|
+
// integration harnesses (studioApiBase / mediaHttpBase / srtEgressUrl /
|
|
5
|
+
// studioBaseFrom); commentary's WHIP path already reaches media directly.
|
|
4
6
|
//
|
|
5
7
|
// WHY host ports collide: in the docker-outside-of-docker CI runner the test
|
|
6
8
|
// process is itself a container and studio/media run as HOST-sibling containers,
|
package/launch.d.ts
CHANGED
|
@@ -12,3 +12,15 @@ export declare function withContainerUser<T>(opts: T & {
|
|
|
12
12
|
}): T & {
|
|
13
13
|
containerUser?: string;
|
|
14
14
|
};
|
|
15
|
+
/** True when the resolved norsk-ctl CLI understands `--internal-only`. Memoised. */
|
|
16
|
+
export declare function ctlSupportsNoPublish(): Promise<boolean>;
|
|
17
|
+
/** In `direct` reach mode, ask the daemon to bind no host ports (`internalOnly`)
|
|
18
|
+
* so concurrent instances on a shared runner can't collide on the product's
|
|
19
|
+
* host-port bands — but only when the resolved ctl supports the flag (see
|
|
20
|
+
* {@link ctlSupportsNoPublish}). `publish` mode and an explicit `internalOnly`
|
|
21
|
+
* pass through untouched. Async because the capability probe is. */
|
|
22
|
+
export declare function withNoPublish<T>(opts: T & {
|
|
23
|
+
internalOnly?: boolean;
|
|
24
|
+
}): Promise<T & {
|
|
25
|
+
internalOnly?: boolean;
|
|
26
|
+
}>;
|
package/launch.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// This is the prevention half; @norskvideo/ctl-test-harness/daemon's
|
|
10
10
|
// cleanupDaemon is the tolerance half (root-nuke on teardown). Pairing the two
|
|
11
11
|
// is the harness's whole "launch clean, tear down clean" story.
|
|
12
|
+
import { cliCommand } from "./cli-command.js";
|
|
13
|
+
import { netReachMode } from "./container-net.js";
|
|
12
14
|
/** The `uid:gid` the current process runs as, for docker `--container-user`, or
|
|
13
15
|
* undefined where POSIX uids don't exist (e.g. Windows, or Docker Desktop's VM
|
|
14
16
|
* which maps bind-mount ownership itself and needs no explicit spec). */
|
|
@@ -30,3 +32,43 @@ export function withContainerUser(opts) {
|
|
|
30
32
|
const user = runnerContainerUser();
|
|
31
33
|
return user === undefined ? opts : { ...opts, containerUser: user };
|
|
32
34
|
}
|
|
35
|
+
// The launch flag is `--internal-only`, NOT `--no-publish`: yargs reads a `--no-`
|
|
36
|
+
// prefix as boolean negation of a `publish` option and, under `.strict()`, aborts
|
|
37
|
+
// with "Unknown argument: publish". The CLI is also `.strict()` about unknown
|
|
38
|
+
// flags, so a ctl that predates `--internal-only` would reject it too — a newer
|
|
39
|
+
// product must still launch on an older ctl (the contract's whole additive rule).
|
|
40
|
+
// So we probe the resolved binary once and only emit the flag when it advertises
|
|
41
|
+
// it: a no-op on an old ctl (publish as today), self-upgrading when `latest`
|
|
42
|
+
// catches up — no cross-repo release ordering to get right. Cached: one `--help`
|
|
43
|
+
// spawn per process.
|
|
44
|
+
const INTERNAL_ONLY_FLAG = "--internal-only";
|
|
45
|
+
let internalOnlySupport;
|
|
46
|
+
async function probeInternalOnlySupport() {
|
|
47
|
+
try {
|
|
48
|
+
const proc = Bun.spawn([...cliCommand, "instance", "launch-template", "--help"], {
|
|
49
|
+
stdout: "pipe",
|
|
50
|
+
stderr: "pipe",
|
|
51
|
+
});
|
|
52
|
+
const [out, errText] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text()]);
|
|
53
|
+
await proc.exited;
|
|
54
|
+
return `${out}${errText}`.includes(INTERNAL_ONLY_FLAG);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** True when the resolved norsk-ctl CLI understands `--internal-only`. Memoised. */
|
|
61
|
+
export function ctlSupportsNoPublish() {
|
|
62
|
+
internalOnlySupport ??= probeInternalOnlySupport();
|
|
63
|
+
return internalOnlySupport;
|
|
64
|
+
}
|
|
65
|
+
/** In `direct` reach mode, ask the daemon to bind no host ports (`internalOnly`)
|
|
66
|
+
* so concurrent instances on a shared runner can't collide on the product's
|
|
67
|
+
* host-port bands — but only when the resolved ctl supports the flag (see
|
|
68
|
+
* {@link ctlSupportsNoPublish}). `publish` mode and an explicit `internalOnly`
|
|
69
|
+
* pass through untouched. Async because the capability probe is. */
|
|
70
|
+
export async function withNoPublish(opts) {
|
|
71
|
+
if (opts.internalOnly !== undefined || netReachMode() !== "direct")
|
|
72
|
+
return opts;
|
|
73
|
+
return (await ctlSupportsNoPublish()) ? { ...opts, internalOnly: true } : opts;
|
|
74
|
+
}
|