@norskvideo/ctl-test-harness 0.1.66 → 0.1.68

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 CHANGED
@@ -56,6 +56,21 @@ export interface StartDaemonOptions {
56
56
  * A suite that writes its own config.yaml (to pick a networkMode, a proxy
57
57
  * port) still gets the working directory added, unless it states one. */
58
58
  export declare function seedDaemonConfig(storeDir: string): void;
59
+ /** The environment a test daemon is spawned with.
60
+ *
61
+ * The daemon's singleton containers default to box-global names, and on a
62
+ * docker-outside-of-docker runner the "box" is a host daemon shared by every
63
+ * runner on it: concurrent jobs replaced and removed each other's `norsk-proxy`
64
+ * (and each daemon start `rm -f`s the cpu-monitor sidecar by name). The port
65
+ * alone is not unique there -- two repos' slugs can hash into the same band --
66
+ * so the names carry the store dir too, which is per run and per job. A ctl
67
+ * that predates an override ignores it. */
68
+ export declare function daemonSpawnEnv(o: {
69
+ storeDir: string;
70
+ port: number;
71
+ inherited: Record<string, string | undefined>;
72
+ overrides?: Record<string, string>;
73
+ }): Record<string, string | undefined>;
59
74
  export declare function startDaemon(storeDir: string, options?: StartDaemonOptions): {
60
75
  daemon: DaemonProcess;
61
76
  ready: Promise<void>;
package/daemon.js CHANGED
@@ -8,6 +8,7 @@
8
8
  // works under bun AND under Playwright's Node workers — so the doc-guide tier
9
9
  // consumes these same bodies instead of keeping a third fork.
10
10
  import { spawn, spawnSync } from "node:child_process";
11
+ import { createHash } from "node:crypto";
11
12
  import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
12
13
  import { createServer } from "node:net";
13
14
  import { join } from "node:path";
@@ -145,6 +146,31 @@ export function seedDaemonConfig(storeDir) {
145
146
  const separator = existing === "" || existing.endsWith("\n") ? "" : "\n";
146
147
  writeFileSync(configPath, `${existing}${separator}${workdirLine}`);
147
148
  }
149
+ /** The environment a test daemon is spawned with.
150
+ *
151
+ * The daemon's singleton containers default to box-global names, and on a
152
+ * docker-outside-of-docker runner the "box" is a host daemon shared by every
153
+ * runner on it: concurrent jobs replaced and removed each other's `norsk-proxy`
154
+ * (and each daemon start `rm -f`s the cpu-monitor sidecar by name). The port
155
+ * alone is not unique there -- two repos' slugs can hash into the same band --
156
+ * so the names carry the store dir too, which is per run and per job. A ctl
157
+ * that predates an override ignores it. */
158
+ export function daemonSpawnEnv(o) {
159
+ // A spawned daemon must boot GUARDED: exercising the real ingress secret is
160
+ // the point of the tiers that spawn one. The unit tier's marker would
161
+ // otherwise be inherited straight through this env spread and quietly open
162
+ // it (RFC 0003 D10b).
163
+ const { NORSK_CTL_UNGUARDED_TEST_DAEMON: _unguarded, ...inherited } = o.inherited;
164
+ const id = `${o.port}-${createHash("sha256").update(o.storeDir).digest("hex").slice(0, 8)}`;
165
+ return {
166
+ NORSK_CTL_PROXY_CONTAINER: `norsk-proxy-${id}`,
167
+ NORSK_CTL_CPU_MONITOR_CONTAINER: `norsk-ctl-cpu-monitor-${id}`,
168
+ ...inherited,
169
+ NORSK_CTL_STORE_DIR: o.storeDir,
170
+ NORSK_CTL_PORT: String(o.port),
171
+ ...o.overrides,
172
+ };
173
+ }
148
174
  export function startDaemon(storeDir, options) {
149
175
  const port = options?.port ?? 8333;
150
176
  // Before the spawn, so anything reaching for this daemon's ingress secret can
@@ -154,15 +180,15 @@ export function startDaemon(storeDir, options) {
154
180
  if (options?.seedConfig !== false)
155
181
  seedDaemonConfig(storeDir);
156
182
  const [cmd, ...cmdArgs] = cliCommand;
157
- // A spawned daemon must boot GUARDED: exercising the real ingress secret is
158
- // the point of the tiers that spawn one. The unit tier's marker would
159
- // otherwise be inherited straight through this env spread and quietly open
160
- // it (RFC 0003 D10b).
161
- const { NORSK_CTL_UNGUARDED_TEST_DAEMON: _unguarded, ...inheritedEnv } = process.env;
162
183
  const proc = spawn(cmd, [...cmdArgs, "serve"], {
163
184
  stdio: "inherit",
164
185
  detached: options?.detached === true,
165
- env: { ...inheritedEnv, NORSK_CTL_STORE_DIR: storeDir, NORSK_CTL_PORT: String(port), ...options?.env },
186
+ env: daemonSpawnEnv({
187
+ storeDir,
188
+ port,
189
+ inherited: process.env,
190
+ ...(options?.env ? { overrides: options.env } : {}),
191
+ }),
166
192
  });
167
193
  const spawnFailed = new Promise((_, reject) => {
168
194
  proc.once("error", (e) => reject(new Error(cliUnavailableMessage(cliCommand, e.message))));
package/demo/run.d.ts CHANGED
@@ -246,8 +246,8 @@ export declare function demoUrlHost(opts: {
246
246
  *
247
247
  * The daemon is a process in this very process' container, so `localhost`
248
248
  * reaches it. Its proxy is NOT: every `nginx proxy starting on port N` is
249
- * followed by `docker: Container norsk-proxy Created/Started`, for a private
250
- * daemon exactly as for a reused one. On a docker-outside-of-docker runner
249
+ * followed by `docker: Container norsk-proxy[-<id>] Created/Started`, for a
250
+ * private daemon exactly as for a reused one. On a docker-outside-of-docker runner
251
251
  * that container is created by the HOST's daemon and publishes there
252
252
  * (`0.0.0.0:22263->22263/tcp`, HostIp "" — measured on test2, 2026-10-01), so
253
253
  * from inside this container `localhost:<proxyPort>` reaches nothing at all.
package/demo/run.js CHANGED
@@ -348,8 +348,8 @@ export function demoUrlHost(opts) {
348
348
  *
349
349
  * The daemon is a process in this very process' container, so `localhost`
350
350
  * reaches it. Its proxy is NOT: every `nginx proxy starting on port N` is
351
- * followed by `docker: Container norsk-proxy Created/Started`, for a private
352
- * daemon exactly as for a reused one. On a docker-outside-of-docker runner
351
+ * followed by `docker: Container norsk-proxy[-<id>] Created/Started`, for a
352
+ * private daemon exactly as for a reused one. On a docker-outside-of-docker runner
353
353
  * that container is created by the HOST's daemon and publishes there
354
354
  * (`0.0.0.0:22263->22263/tcp`, HostIp "" — measured on test2, 2026-10-01), so
355
355
  * from inside this container `localhost:<proxyPort>` reaches nothing at all.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-test-harness",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {