@norskvideo/ctl-test-harness 0.1.133 → 0.1.135

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.
@@ -5,8 +5,18 @@ export type NetReachMode = "publish" | "direct";
5
5
  /** How the suite reaches instance containers. `direct` = norsk-net service DNS
6
6
  * (no host publish, no collision) — only viable on a Linux DooD runner whose
7
7
  * test container is on norsk-net. `publish` = today's host-published port,
8
- * the Docker-Desktop-safe default. Read from NORSK_TEST_NET. */
9
- export declare function netReachMode(env?: Record<string, string | undefined>): NetReachMode;
8
+ * the Docker-Desktop-safe default. Read from NORSK_TEST_NET.
9
+ *
10
+ * `direct` is a request, honoured only where it can work: service DNS answers
11
+ * inside a docker network, and only a container can join one. A runner that
12
+ * is not a container (a host runner, or one that is a VM with a docker daemon
13
+ * of its own) would launch instances with no published port and then fail to
14
+ * resolve every name it dials, so there the mode is `publish`, and the log
15
+ * says so once. */
16
+ export declare function netReachMode(env?: Record<string, string | undefined>, runnerIsContainer?: () => boolean): NetReachMode;
17
+ /** Swap how netReachMode decides the runner is a container (tests); returns a
18
+ * restore function. */
19
+ export declare function useRunnerContainerDetection(next: () => boolean): () => void;
10
20
  export interface Endpoint {
11
21
  host: string;
12
22
  port: number;
package/container-net.js CHANGED
@@ -30,7 +30,8 @@
30
30
  // routable from the host at all, so the direct path can't work there — those
31
31
  // runs MUST keep publishing. Hence the mode switch: `direct` on the Linux DooD
32
32
  // CI box, `publish` (the default) everywhere else. Nothing here changes
33
- // behaviour until a caller opts a suite into `direct`.
33
+ // behaviour until a caller opts a suite into `direct`, and a runner that is not
34
+ // a container stays on `publish` whatever it is asked (netReachMode).
34
35
  import { spawnSync } from "node:child_process";
35
36
  import { existsSync, readFileSync } from "node:fs";
36
37
  import { hostname } from "node:os";
@@ -44,9 +45,42 @@ export const MEDIA_HTTP_INTERNAL_PORT = 8080;
44
45
  /** How the suite reaches instance containers. `direct` = norsk-net service DNS
45
46
  * (no host publish, no collision) — only viable on a Linux DooD runner whose
46
47
  * test container is on norsk-net. `publish` = today's host-published port,
47
- * the Docker-Desktop-safe default. Read from NORSK_TEST_NET. */
48
- export function netReachMode(env = process.env) {
49
- return env.NORSK_TEST_NET === "direct" ? "direct" : "publish";
48
+ * the Docker-Desktop-safe default. Read from NORSK_TEST_NET.
49
+ *
50
+ * `direct` is a request, honoured only where it can work: service DNS answers
51
+ * inside a docker network, and only a container can join one. A runner that
52
+ * is not a container (a host runner, or one that is a VM with a docker daemon
53
+ * of its own) would launch instances with no published port and then fail to
54
+ * resolve every name it dials, so there the mode is `publish`, and the log
55
+ * says so once. */
56
+ export function netReachMode(env = process.env, runnerIsContainer = runnerContainerDetection) {
57
+ if (env.NORSK_TEST_NET !== "direct")
58
+ return "publish";
59
+ if (runnerIsContainer())
60
+ return "direct";
61
+ if (!saidNotAContainer) {
62
+ saidNotAContainer = true;
63
+ console.error("NORSK_TEST_NET=direct, but this runner is not a container and cannot join a docker network: reaching instances by published port instead");
64
+ }
65
+ return "publish";
66
+ }
67
+ let saidNotAContainer = false;
68
+ let runnerIsContainerMemo;
69
+ /** Whether this process is in a container the docker daemon knows. Asked once:
70
+ * the answer cannot change under a running process, and finding it can cost a
71
+ * `docker inspect`. */
72
+ let runnerContainerDetection = () => {
73
+ runnerIsContainerMemo ??= ownContainerId() !== null;
74
+ return runnerIsContainerMemo;
75
+ };
76
+ /** Swap how netReachMode decides the runner is a container (tests); returns a
77
+ * restore function. */
78
+ export function useRunnerContainerDetection(next) {
79
+ const prev = runnerContainerDetection;
80
+ runnerContainerDetection = next;
81
+ return () => {
82
+ runnerContainerDetection = prev;
83
+ };
50
84
  }
51
85
  export const authority = (e) => `${e.host}:${e.port}`;
52
86
  /** Compose's container DNS for a template-launched instance: `<id>-<service>-1`.
package/demo/run.d.ts CHANGED
@@ -58,6 +58,9 @@ export interface DemoDeps {
58
58
  /** Does the resolved ctl run its daemon and proxy on system-assigned ports?
59
59
  * Optional so an existing custom-deps consumer keeps working; absent = no. */
60
60
  supportsEphemeralPorts?(): Promise<boolean>;
61
+ /** Is this process itself in a container (see proxyUrlHost)? Optional so an
62
+ * existing custom-deps consumer keeps working; absent = runningInContainer(). */
63
+ inContainer?(): boolean;
61
64
  /** A host port free for TCP and UDP that is not in `taken` (free-port.ts).
62
65
  * Optional so an existing custom-deps consumer keeps working; absent = probe. */
63
66
  freePort?(taken: ReadonlySet<number>): Promise<number>;
package/demo/run.js CHANGED
@@ -501,7 +501,10 @@ export class DemoSession {
501
501
  const host = demoUrlHost({ publicHost: opts.publicHost, daemon: opts.daemon });
502
502
  this.host = host;
503
503
  // The proxy is a container even when the daemon is ours; see proxyUrlHost.
504
- const proxyHost = proxyUrlHost({ publicHost: opts.publicHost, inContainer: runningInContainer() });
504
+ const proxyHost = proxyUrlHost({
505
+ publicHost: opts.publicHost,
506
+ inContainer: deps.inContainer?.() ?? runningInContainer(),
507
+ });
505
508
  this.proxyHost = proxyHost;
506
509
  this.band = demoPorts(slug);
507
510
  this.ephemeralPorts = opts.ephemeralPorts === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-test-harness",
3
- "version": "0.1.133",
3
+ "version": "0.1.135",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
package/smoke.d.ts CHANGED
@@ -162,6 +162,10 @@ export interface SmokeDeps {
162
162
  * Optional so an existing custom-deps consumer keeps working; absent = no,
163
163
  * and the band decides both, as before. */
164
164
  supportsEphemeralPorts?(): Promise<boolean>;
165
+ /** The CI runner's name (GitHub's RUNNER_NAME), which keys the port band.
166
+ * Optional so an existing custom-deps consumer keeps working; absent = the
167
+ * slug's band, as before. */
168
+ runnerName?(): string | undefined;
165
169
  cli(storeDir: string, argv: string[]): Promise<CliResult>;
166
170
  startSources(opts: {
167
171
  daemonPort: number;
@@ -216,12 +220,16 @@ export interface SmokeDeps {
216
220
  }
217
221
  /** Per-slug port band, above the product integration harnesses' own bands:
218
222
  * daemon, dev backend, published Studio port and an instance base, twenty
219
- * apart per slug. */
223
+ * apart per slug. On a CI runner (`runner` given) the band is the runner's,
224
+ * not the slug's: jobs that share a docker host are always on different
225
+ * runners, so whatever the band still decides (ports ctl and freePort do not
226
+ * assign) cannot meet between them. smoke.test.ts asserts the jankings
227
+ * runners' bands are distinct per host. */
220
228
  export interface SmokePorts extends BaseHarnessPorts {
221
229
  /** The daemon's oauth2 proxy; banded so co-located runs never meet on :9443. */
222
230
  proxyPort: number;
223
231
  }
224
- export declare function smokePorts(slug: string, overrides?: Partial<SmokePorts>): SmokePorts;
232
+ export declare function smokePorts(slug: string, overrides?: Partial<SmokePorts>, runner?: string): SmokePorts;
225
233
  export declare const defaultSmokeDeps: SmokeDeps;
226
234
  /** A manifest's `ui.sidebarEntries` are what ctl's product page renders as
227
235
  * links, under /products/<name>/<route>. Nothing else checks that the product
package/smoke.js CHANGED
@@ -48,8 +48,9 @@ const MOQ_PORT_PARAM = "MOQ_PORT";
48
48
  /** ctl's allocated host port: a `*_PORT` param defaulting to `auto`, which it
49
49
  * resolves to the first free port from a PREFERRED value every run shares. */
50
50
  const isAllocatedPortParam = (name, dflt) => dflt === "auto" && /_PORT$/.test(name);
51
- export function smokePorts(slug, overrides = {}) {
52
- const daemonPort = SMOKE_PORT_BASE + hashSlot(`smoke:${slug}`, SMOKE_BANDS) * SMOKE_BAND_WIDTH;
51
+ export function smokePorts(slug, overrides = {}, runner) {
52
+ const key = runner ? `smoke:${runner}` : `smoke:${slug}`;
53
+ const daemonPort = SMOKE_PORT_BASE + hashSlot(key, SMOKE_BANDS) * SMOKE_BAND_WIDTH;
53
54
  return {
54
55
  daemonPort,
55
56
  backendPort: daemonPort + 1,
@@ -65,6 +66,7 @@ export const defaultSmokeDeps = {
65
66
  writeFile: (path, contents) => writeFileSync(path, contents),
66
67
  startDaemon,
67
68
  supportsEphemeralPorts: ctlSupportsEphemeralPorts,
69
+ runnerName: () => process.env.RUNNER_NAME || undefined,
68
70
  freePort: (taken) => freeHostPort({ taken }),
69
71
  cli: (storeDir, argv) => runCli(storeDir, ...argv),
70
72
  startSources: startSrtSources,
@@ -217,7 +219,10 @@ export function sdkClientIdentityFromEnv(env = process.env) {
217
219
  return { certB64, keyB64 };
218
220
  }
219
221
  export async function runProductSmoke(slug, spec, deps = defaultSmokeDeps) {
220
- const ports = smokePorts(slug, spec.ports);
222
+ const runner = deps.runnerName?.();
223
+ const ports = smokePorts(slug, spec.ports, runner);
224
+ if (runner)
225
+ deps.log(`${slug}: port band from runner ${runner} (daemon base :${ports.daemonPort})`);
221
226
  const storeDir = deps.storeDir(slug);
222
227
  const instanceId = `smoke-${slug}`;
223
228
  const timeouts = {