@norskvideo/ctl-test-harness 0.1.123 → 0.1.124
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/demo/cli.d.ts +2 -0
- package/demo/cli.js +13 -1
- package/demo/dev-loop.d.ts +3 -0
- package/demo/dev-loop.js +4 -1
- package/demo/run.d.ts +12 -0
- package/demo/run.js +87 -0
- package/package.json +1 -1
package/demo/cli.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface DemoArgs {
|
|
|
19
19
|
publicHost?: string;
|
|
20
20
|
/** `up`/`check`: absent is `assigned`. */
|
|
21
21
|
ports?: DemoPortPolicy;
|
|
22
|
+
/** `dev-loop up`: extra config for the private daemon, as given (relative to the cwd). */
|
|
23
|
+
daemonConfig?: string;
|
|
22
24
|
}
|
|
23
25
|
export declare function parseDemoArgs(argv: string[]): DemoArgs;
|
|
24
26
|
export interface ResolvedSpecView {
|
package/demo/cli.js
CHANGED
|
@@ -32,6 +32,7 @@ import { demoDown, demoPorts, demoSlug, runExportCheck } from "./run.js";
|
|
|
32
32
|
const USAGE = `usage: demo <up|check|down|spec|ui> [--mode dev|image|standalone] [--daemon private|reuse] [--export-only] [--json]
|
|
33
33
|
[--ports assigned|band] [--ui zellij|tmux|none] [--public-host <host>] [--spec <path>]
|
|
34
34
|
demo dev-loop <up|refresh|down|ui> [--ui zellij|tmux|none] [--public-host <host>] [--spec <path>]
|
|
35
|
+
[--daemon-config <file>]
|
|
35
36
|
|
|
36
37
|
up launch, print the URLs, hold (Ctrl-C tears down)
|
|
37
38
|
check up, then tear down and exit 0/1 — what CI runs, always on a private daemon
|
|
@@ -61,6 +62,10 @@ const USAGE = `usage: demo <up|check|down|spec|ui> [--mode dev|image|standalone]
|
|
|
61
62
|
--ui zellij|tmux|none the multiplexer (\`none\` prints the pane commands); zellij unless said
|
|
62
63
|
--public-host <host> the name other machines reach this box by: every URL, the daemon's
|
|
63
64
|
publicHost, Studio's MoQ preview (default: PUBLIC_HOST)
|
|
65
|
+
--daemon-config <file> dev-loop up: a YAML mapping whose top-level keys are merged into the private
|
|
66
|
+
daemon's config.yaml before it serves (a storage: block, bindAddress), checked
|
|
67
|
+
by that ctl's own parser; keys the driver sets (ports, working directory,
|
|
68
|
+
proxy, public host) are refused
|
|
64
69
|
--spec <path> the demo spec (default tests/demo.spec.ts)`;
|
|
65
70
|
const DEFAULT_SPEC = "tests/demo.spec.ts";
|
|
66
71
|
const DEMO_ACTIONS = ["up", "check", "down", "spec", "ui"];
|
|
@@ -131,6 +136,9 @@ export function parseDemoArgs(argv) {
|
|
|
131
136
|
case "--public-host":
|
|
132
137
|
args.publicHost = value();
|
|
133
138
|
break;
|
|
139
|
+
case "--daemon-config":
|
|
140
|
+
args.daemonConfig = value();
|
|
141
|
+
break;
|
|
134
142
|
case "--ports": {
|
|
135
143
|
const p = value();
|
|
136
144
|
if (p !== "assigned" && p !== "band")
|
|
@@ -144,11 +152,14 @@ export function parseDemoArgs(argv) {
|
|
|
144
152
|
}
|
|
145
153
|
if (args.ui !== undefined && args.action !== "ui")
|
|
146
154
|
throw new Error("--ui belongs to ui (or dev-loop ui)");
|
|
155
|
+
if (args.daemonConfig !== undefined && !(devLoop && args.action === "up")) {
|
|
156
|
+
throw new Error("--daemon-config belongs to dev-loop up");
|
|
157
|
+
}
|
|
147
158
|
if (args.ports !== undefined && (devLoop || (args.action !== "up" && args.action !== "check"))) {
|
|
148
159
|
throw new Error("--ports belongs to up and check");
|
|
149
160
|
}
|
|
150
161
|
if (devLoop && (args.mode !== undefined || args.daemon !== "private" || args.exportOnly || args.json)) {
|
|
151
|
-
throw new Error("dev-loop takes only --ui, --public-host and --
|
|
162
|
+
throw new Error("dev-loop takes only --ui, --public-host, --spec and --daemon-config (no --mode, --daemon, --export-only or --json): it is always the source tier on a private daemon");
|
|
152
163
|
}
|
|
153
164
|
if (args.mode === "standalone" && !args.exportOnly && args.action !== "spec") {
|
|
154
165
|
throw new Error(`the full standalone tier is the dev-loop's: \`dev-loop ${args.action === "ui" ? "ui" : "up"}\` (this mode's headless gate is \`check --mode standalone --export-only\`)`);
|
|
@@ -263,6 +274,7 @@ export async function demoMain(argv, io) {
|
|
|
263
274
|
cwd: io.cwd,
|
|
264
275
|
dirs,
|
|
265
276
|
...publicHost,
|
|
277
|
+
...(args.daemonConfig !== undefined ? { daemonConfig: resolve(io.cwd, args.daemonConfig) } : {}),
|
|
266
278
|
...(io.abort ? { abort: io.abort } : {}),
|
|
267
279
|
});
|
|
268
280
|
return 0;
|
package/demo/dev-loop.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export interface DevLoopOptions {
|
|
|
11
11
|
publicHost?: string;
|
|
12
12
|
abort?: AbortSignal;
|
|
13
13
|
timeouts?: DemoTimeouts;
|
|
14
|
+
/** `up`: a YAML file whose top-level keys go into the private daemon's
|
|
15
|
+
* config.yaml before it serves (DemoSession's daemonConfig). */
|
|
16
|
+
daemonConfig?: string;
|
|
14
17
|
}
|
|
15
18
|
export interface DevLoopResult {
|
|
16
19
|
workdir: string;
|
package/demo/dev-loop.js
CHANGED
|
@@ -157,7 +157,10 @@ export async function runDevLoop(spec, opts, deps = defaultDemoDeps(opts.cwd)) {
|
|
|
157
157
|
return { workdir, studioUrl: `http://${s.host}:${studioPort}` };
|
|
158
158
|
}
|
|
159
159
|
await refuseIfUp(spec, deps);
|
|
160
|
-
const s = new DemoSession(spec, slug, opts.cwd, deps,
|
|
160
|
+
const s = new DemoSession(spec, slug, opts.cwd, deps, {
|
|
161
|
+
...common,
|
|
162
|
+
...(opts.daemonConfig !== undefined ? { daemonConfig: opts.daemonConfig } : {}),
|
|
163
|
+
});
|
|
161
164
|
let recorded = false;
|
|
162
165
|
let result;
|
|
163
166
|
let journeyError;
|
package/demo/run.d.ts
CHANGED
|
@@ -274,6 +274,11 @@ export interface SessionOptions {
|
|
|
274
274
|
ephemeralPorts?: boolean;
|
|
275
275
|
/** Private: the daemon's own node MoQ relay. */
|
|
276
276
|
moqRelay?: MoqRelayOptions;
|
|
277
|
+
/** Private: a YAML file whose top-level keys are merged into the daemon's
|
|
278
|
+
* config.yaml after `init` (see mergeDaemonConfig), so the run's one
|
|
279
|
+
* daemon can carry config the driver has no option for, a storage block
|
|
280
|
+
* say. */
|
|
281
|
+
daemonConfig?: string;
|
|
277
282
|
}
|
|
278
283
|
/** The host a demo's daemon-port URLs name.
|
|
279
284
|
*
|
|
@@ -366,6 +371,7 @@ export declare class DemoSession {
|
|
|
366
371
|
private readonly proxyAuth;
|
|
367
372
|
private readonly daemonEnv;
|
|
368
373
|
private readonly extraContainers;
|
|
374
|
+
private readonly daemonConfig;
|
|
369
375
|
constructor(spec: DemoSpec, slug: string, cwd: string, deps: DemoDeps, opts: SessionOptions);
|
|
370
376
|
/** Scheme + authority of the daemon's proxy, for `proxy` URLs. */
|
|
371
377
|
get proxyBase(): string;
|
|
@@ -386,6 +392,12 @@ export declare class DemoSession {
|
|
|
386
392
|
/** Private: init a virgin store and start a daemon on the band. Reuse: the
|
|
387
393
|
* developer's daemon must already answer. */
|
|
388
394
|
attachDaemon(): Promise<void>;
|
|
395
|
+
/** Merge the extra config into the store's config.yaml, then have the
|
|
396
|
+
* resolved ctl parse it with no daemon (`config show`): a bad block fails
|
|
397
|
+
* here with ctl's own message rather than as a daemon that never answers,
|
|
398
|
+
* and a key ctl silently drops (one it does not know, or a value it does
|
|
399
|
+
* not take) is named rather than lost. */
|
|
400
|
+
private applyDaemonConfig;
|
|
389
401
|
/** The daemon advertises the relay's fingerprint and WebSocket fallback on
|
|
390
402
|
* its proxy base, http://localhost:<proxy port>. In direct reach that port
|
|
391
403
|
* is published on the docker host, not in this container, so this
|
package/demo/run.js
CHANGED
|
@@ -30,6 +30,7 @@ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSy
|
|
|
30
30
|
import { homedir } from "node:os";
|
|
31
31
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
32
32
|
import { parseManifestSeed, repoOf } from "@norskvideo/ctl-sdk/manifest-seed";
|
|
33
|
+
import { parseDocument, parse as parseYaml } from "yaml";
|
|
33
34
|
import { preserveInstanceContainerLogsTo } from "../container-logs.js";
|
|
34
35
|
import { currentInstanceNetworks, DOCKER_NETWORK_NAME, ensureRunnerOnNetwork, instanceNetworkName, isAlreadyOnNetworkError, netReachMode, } from "../container-net.js";
|
|
35
36
|
import { cleanupDaemon, ctlSupportsEphemeralPorts, PROXY_PORT_FILE, requireLicenseFile, runCli, startDaemon, } from "../daemon.js";
|
|
@@ -344,6 +345,51 @@ const CONFIG_FILE = "config.yaml";
|
|
|
344
345
|
* The daemon port is no good: it is 0 until assigned, and on the band a
|
|
345
346
|
* previous run's daemon may still answer there. */
|
|
346
347
|
const NO_DAEMON_PORT = "1";
|
|
348
|
+
/** config.yaml keys a private daemon's run depends on: `init` writes them from
|
|
349
|
+
* the session's own ports and choices, and the proxy URLs, the store and the
|
|
350
|
+
* sign-in the driver assumes follow from them. Extra daemon config may not
|
|
351
|
+
* set them. */
|
|
352
|
+
const DRIVER_OWNED_CONFIG_KEYS = [
|
|
353
|
+
"networkMode",
|
|
354
|
+
"defaultWorkingDirectory",
|
|
355
|
+
"proxyPort",
|
|
356
|
+
"proxyAuth",
|
|
357
|
+
"httpRedirect",
|
|
358
|
+
"httpRedirectPort",
|
|
359
|
+
"externalPort",
|
|
360
|
+
"publicHost",
|
|
361
|
+
"certSource",
|
|
362
|
+
"certPath",
|
|
363
|
+
"keyPath",
|
|
364
|
+
];
|
|
365
|
+
/** Merge a YAML mapping's top-level keys into a store's config.yaml text
|
|
366
|
+
* (each key replaces any of the same name). Throws, naming `fragmentPath`,
|
|
367
|
+
* for YAML that does not parse, anything but a non-empty mapping, or a key
|
|
368
|
+
* the driver owns. Judging the values is the resolved ctl's job. */
|
|
369
|
+
function mergeDaemonConfig(configText, fragmentText, fragmentPath) {
|
|
370
|
+
let fragment;
|
|
371
|
+
try {
|
|
372
|
+
fragment = parseYaml(fragmentText);
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
throw new Error(`${fragmentPath} is not valid YAML: ${e instanceof Error ? e.message : String(e)}`);
|
|
376
|
+
}
|
|
377
|
+
if (fragment === null || typeof fragment !== "object" || Array.isArray(fragment)) {
|
|
378
|
+
throw new Error(`${fragmentPath} must be a YAML mapping of config.yaml keys (storage:, bindAddress: ...)`);
|
|
379
|
+
}
|
|
380
|
+
const keys = Object.keys(fragment);
|
|
381
|
+
if (keys.length === 0)
|
|
382
|
+
throw new Error(`${fragmentPath} sets no config.yaml keys`);
|
|
383
|
+
const owned = keys.filter((k) => DRIVER_OWNED_CONFIG_KEYS.includes(k));
|
|
384
|
+
if (owned.length > 0) {
|
|
385
|
+
throw new Error(`${fragmentPath} sets ${owned.join(", ")}, which the dev-loop sets for its private daemon (its ports, store, proxy and sign-in); remove ${owned.length === 1 ? "it" : "them"}` +
|
|
386
|
+
(owned.includes("publicHost") ? " (--public-host sets the public host)" : ""));
|
|
387
|
+
}
|
|
388
|
+
const doc = parseDocument(configText);
|
|
389
|
+
for (const key of keys)
|
|
390
|
+
doc.set(key, fragment[key]);
|
|
391
|
+
return { text: doc.toString(), keys };
|
|
392
|
+
}
|
|
347
393
|
/** The host a demo's daemon-port URLs name.
|
|
348
394
|
*
|
|
349
395
|
* NORSK_TEST_HOST is a STUDIO-port setting: on a docker-outside-of-docker
|
|
@@ -443,6 +489,7 @@ export class DemoSession {
|
|
|
443
489
|
proxyAuth;
|
|
444
490
|
daemonEnv;
|
|
445
491
|
extraContainers;
|
|
492
|
+
daemonConfig;
|
|
446
493
|
constructor(spec, slug, cwd, deps, opts) {
|
|
447
494
|
this.spec = spec;
|
|
448
495
|
this.slug = slug;
|
|
@@ -484,6 +531,10 @@ export class DemoSession {
|
|
|
484
531
|
this.proxyAuth = opts.proxy;
|
|
485
532
|
this.daemonEnv = opts.daemonEnv ?? {};
|
|
486
533
|
this.extraContainers = opts.extraContainers ?? [];
|
|
534
|
+
if (opts.daemonConfig !== undefined && opts.daemon === "reuse") {
|
|
535
|
+
throw new Error("daemonConfig needs a private daemon: the developer's daemon keeps the config it has");
|
|
536
|
+
}
|
|
537
|
+
this.daemonConfig = opts.daemonConfig;
|
|
487
538
|
this.timeouts = {
|
|
488
539
|
devReadyMs: opts.timeouts?.devReadyMs ?? 120_000,
|
|
489
540
|
healthyMs: opts.timeouts?.healthyMs ?? 180_000,
|
|
@@ -561,6 +612,8 @@ export class DemoSession {
|
|
|
561
612
|
"--no-start-server",
|
|
562
613
|
...(this.publicHost ? ["--public-host", this.publicHost] : []),
|
|
563
614
|
]);
|
|
615
|
+
if (this.daemonConfig !== undefined)
|
|
616
|
+
await this.applyDaemonConfig(this.daemonConfig);
|
|
564
617
|
const relayEnv = this.moqRelayOptions ? await this.prepareMoqRelay(this.moqRelayOptions) : {};
|
|
565
618
|
const started = this.deps.startDaemon(this.storeDir, {
|
|
566
619
|
port: this.ports.daemonPort,
|
|
@@ -583,6 +636,40 @@ export class DemoSession {
|
|
|
583
636
|
}
|
|
584
637
|
await this.attachMoqRelayPages();
|
|
585
638
|
}
|
|
639
|
+
/** Merge the extra config into the store's config.yaml, then have the
|
|
640
|
+
* resolved ctl parse it with no daemon (`config show`): a bad block fails
|
|
641
|
+
* here with ctl's own message rather than as a daemon that never answers,
|
|
642
|
+
* and a key ctl silently drops (one it does not know, or a value it does
|
|
643
|
+
* not take) is named rather than lost. */
|
|
644
|
+
async applyDaemonConfig(path) {
|
|
645
|
+
const fragment = this.deps.readFile(path);
|
|
646
|
+
if (fragment === null)
|
|
647
|
+
throw new Error(`cannot read the daemon config ${path}`);
|
|
648
|
+
const configPath = join(this.storeDir, CONFIG_FILE);
|
|
649
|
+
const config = this.deps.readFile(configPath);
|
|
650
|
+
if (config === null)
|
|
651
|
+
throw new Error(`norsk-ctl init left no ${configPath} to merge ${path} into`);
|
|
652
|
+
const merged = mergeDaemonConfig(config, fragment, path);
|
|
653
|
+
this.deps.writeFile(configPath, merged.text);
|
|
654
|
+
const argv = ["config", "show", "-o", "json"];
|
|
655
|
+
const r = await this.deps.cli(this.storeDir, ["--port", NO_DAEMON_PORT, ...argv]);
|
|
656
|
+
this.transcript.push({ argv, stdout: r.stdout, stderr: r.stderr, exitCode: r.exitCode });
|
|
657
|
+
if (r.exitCode !== 0) {
|
|
658
|
+
throw new Error(`norsk-ctl refused the config merged from ${path}:\n${(r.stderr || r.stdout).trim()}`);
|
|
659
|
+
}
|
|
660
|
+
let settings;
|
|
661
|
+
try {
|
|
662
|
+
settings = JSON.parse(r.stdout);
|
|
663
|
+
}
|
|
664
|
+
catch {
|
|
665
|
+
throw new Error(`norsk-ctl config show: not JSON: ${r.stdout.slice(0, 200)}`);
|
|
666
|
+
}
|
|
667
|
+
const dropped = merged.keys.filter((k) => settings[k] === undefined);
|
|
668
|
+
if (dropped.length > 0) {
|
|
669
|
+
throw new Error(`norsk-ctl ignored ${dropped.join(", ")} from ${path}: the resolved ctl does not know ${dropped.length === 1 ? "that key" : "those keys"}, or does not take the value given`);
|
|
670
|
+
}
|
|
671
|
+
this.deps.log(`daemon config: ${merged.keys.join(", ")} from ${path}`);
|
|
672
|
+
}
|
|
586
673
|
/** The daemon advertises the relay's fingerprint and WebSocket fallback on
|
|
587
674
|
* its proxy base, http://localhost:<proxy port>. In direct reach that port
|
|
588
675
|
* is published on the docker host, not in this container, so this
|