@norskvideo/ctl-test-harness 0.1.92 → 0.1.94
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/media-conversion/ctl.d.ts +13 -0
- package/media-conversion/ctl.js +20 -0
- package/media-conversion/evaluate.d.ts +31 -0
- package/media-conversion/evaluate.js +66 -0
- package/media-conversion/index.d.ts +8 -0
- package/media-conversion/index.js +6 -0
- package/media-conversion/local-studio.d.ts +25 -0
- package/media-conversion/local-studio.js +117 -0
- package/media-conversion/run.d.ts +46 -0
- package/media-conversion/run.js +151 -0
- package/package.json +15 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConversionLauncher } from "./run.js";
|
|
2
|
+
export type CliRunner = (...args: string[]) => Promise<{
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
exitCode: number;
|
|
6
|
+
}>;
|
|
7
|
+
export type CtlLauncherOptions = {
|
|
8
|
+
/** Runs the norsk-ctl CLI against the daemon, e.g. runCliWith bound to a store. */
|
|
9
|
+
cli: CliRunner;
|
|
10
|
+
template: string;
|
|
11
|
+
instanceId: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function ctlLauncher(opts: CtlLauncherOptions): ConversionLauncher;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function ctlLauncher(opts) {
|
|
2
|
+
const run = async (...args) => {
|
|
3
|
+
const r = await opts.cli(...args);
|
|
4
|
+
if (r.exitCode !== 0)
|
|
5
|
+
throw new Error(`norsk-ctl ${args.join(" ")} failed (${r.exitCode}): ${r.stderr || r.stdout}`);
|
|
6
|
+
return r.stdout;
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
async launch(values) {
|
|
10
|
+
const params = Object.entries(values).flatMap(([k, v]) => ["--param", `${k}=${v}`]);
|
|
11
|
+
await run("instance", "launch-template", opts.instanceId, "--template", opts.template, ...params);
|
|
12
|
+
},
|
|
13
|
+
async restart() {
|
|
14
|
+
await run("instance", "restart", opts.instanceId);
|
|
15
|
+
},
|
|
16
|
+
async stop() {
|
|
17
|
+
await run("instance", "delete", opts.instanceId, "--purge");
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MediaConversionV1 } from "@norskvideo/ctl-product-template-schema";
|
|
2
|
+
export type MediaKind = "video" | "audio" | "subtitle" | "ancillary";
|
|
3
|
+
/** One stream that came back: its kind, its format as the engine reports it,
|
|
4
|
+
* and its frames' timestamps (exact, in lowest terms, as "n/d"). */
|
|
5
|
+
export type ObservedStream = {
|
|
6
|
+
kind: MediaKind;
|
|
7
|
+
format: Record<string, string | number>;
|
|
8
|
+
stamps: string[];
|
|
9
|
+
};
|
|
10
|
+
/** Everything the source sent, and what came back in each phase of the run
|
|
11
|
+
* ("initial", "after restart"). */
|
|
12
|
+
export type Observation = {
|
|
13
|
+
sent: Set<string>;
|
|
14
|
+
phases: {
|
|
15
|
+
label: string;
|
|
16
|
+
streams: ObservedStream[];
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
export type Check = {
|
|
20
|
+
name: string;
|
|
21
|
+
ok: boolean;
|
|
22
|
+
detail: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function evaluateMediaConversion(opts: {
|
|
25
|
+
declaration: MediaConversionV1;
|
|
26
|
+
/** The launch values, so format references can be filled in. */
|
|
27
|
+
parameters: Record<string, string>;
|
|
28
|
+
observation: Observation;
|
|
29
|
+
/** Fewer frames than this on a stream counts as the output not arriving. */
|
|
30
|
+
minFrames: number;
|
|
31
|
+
}): Check[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const PARAMETER_REFERENCE = /\$\{([^}]*)\}/g;
|
|
2
|
+
function resolveFormat(value, parameters) {
|
|
3
|
+
let missing = false;
|
|
4
|
+
const resolved = value.replace(PARAMETER_REFERENCE, (_, name) => {
|
|
5
|
+
const v = parameters[name];
|
|
6
|
+
if (v === undefined)
|
|
7
|
+
missing = true;
|
|
8
|
+
return v ?? "";
|
|
9
|
+
});
|
|
10
|
+
return missing ? undefined : resolved;
|
|
11
|
+
}
|
|
12
|
+
export function evaluateMediaConversion(opts) {
|
|
13
|
+
const { declaration, parameters, observation, minFrames } = opts;
|
|
14
|
+
const checks = [];
|
|
15
|
+
for (const phase of observation.phases) {
|
|
16
|
+
const at = (name) => `${phase.label}: ${name}`;
|
|
17
|
+
const byKind = (kind) => phase.streams.filter((s) => s.kind === kind);
|
|
18
|
+
const problems = [];
|
|
19
|
+
for (const output of declaration.outputs) {
|
|
20
|
+
const expected = output.count ?? 1;
|
|
21
|
+
const streams = byKind(output.kind).filter((s) => s.stamps.length >= minFrames);
|
|
22
|
+
if (streams.length !== expected) {
|
|
23
|
+
problems.push(`${output.name}: expected ${expected} ${output.kind} stream(s) of ${minFrames}+ frames, got ${streams.length}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const declaredKinds = new Set(declaration.outputs.map((o) => o.kind));
|
|
27
|
+
for (const s of phase.streams) {
|
|
28
|
+
if (!declaredKinds.has(s.kind))
|
|
29
|
+
problems.push(`an undeclared ${s.kind} stream came back`);
|
|
30
|
+
}
|
|
31
|
+
checks.push({ name: at("outputs"), ok: problems.length === 0, detail: problems.join("; ") || "as declared" });
|
|
32
|
+
for (const output of declaration.outputs) {
|
|
33
|
+
const mismatches = [];
|
|
34
|
+
for (const [key, declared] of Object.entries(output.format ?? {})) {
|
|
35
|
+
const want = resolveFormat(declared, parameters);
|
|
36
|
+
if (want === undefined) {
|
|
37
|
+
mismatches.push(`${key}: ${declared} refers to a parameter with no value`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const s of byKind(output.kind)) {
|
|
41
|
+
const got = s.format[key];
|
|
42
|
+
if (String(got) !== want)
|
|
43
|
+
mismatches.push(`${key}: declared ${want}, got ${got}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
checks.push({
|
|
47
|
+
name: at(`format of ${output.name}`),
|
|
48
|
+
ok: mismatches.length === 0,
|
|
49
|
+
detail: mismatches.join("; ") || "as declared",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (declaration.timeline === "inherit") {
|
|
53
|
+
const stamps = phase.streams.flatMap((s) => s.stamps);
|
|
54
|
+
const foreign = stamps.filter((t) => !observation.sent.has(t));
|
|
55
|
+
// Judges only what arrived; nothing arriving is the outputs check's failure.
|
|
56
|
+
checks.push({
|
|
57
|
+
name: at("timeline"),
|
|
58
|
+
ok: foreign.length === 0,
|
|
59
|
+
detail: foreign.length === 0
|
|
60
|
+
? `${stamps.length} frames, all on the source's timestamps`
|
|
61
|
+
: `${foreign.length} of ${stamps.length} frames carry timestamps the source never sent (first: ${foreign.slice(0, 3).join(", ")})`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return checks;
|
|
66
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { CliRunner, CtlLauncherOptions } from "./ctl.js";
|
|
2
|
+
export { ctlLauncher } from "./ctl.js";
|
|
3
|
+
export type { Check, MediaKind, Observation, ObservedStream } from "./evaluate.js";
|
|
4
|
+
export { evaluateMediaConversion } from "./evaluate.js";
|
|
5
|
+
export type { LocalStudioOptions } from "./local-studio.js";
|
|
6
|
+
export { interpolate, localStudioLauncher, withLocalLinks } from "./local-studio.js";
|
|
7
|
+
export type { ConformanceLinks, ConformanceOptions, ConformanceResult, ConversionLauncher } from "./run.js";
|
|
8
|
+
export { runMediaConversionConformance } from "./run.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The norsk.io/media-conversion conformance harness (norsk-ctl C3): proves a
|
|
2
|
+
// template honours the interface it declares. See run.ts.
|
|
3
|
+
export { ctlLauncher } from "./ctl.js";
|
|
4
|
+
export { evaluateMediaConversion } from "./evaluate.js";
|
|
5
|
+
export { interpolate, localStudioLauncher, withLocalLinks } from "./local-studio.js";
|
|
6
|
+
export { runMediaConversionConformance } from "./run.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConversionLauncher } from "./run.js";
|
|
2
|
+
export type LocalStudioOptions = {
|
|
3
|
+
/** The template's workflow.yml and compose.yml, as built. */
|
|
4
|
+
workflowYaml: string;
|
|
5
|
+
composeYaml: string;
|
|
6
|
+
/** A norsk-studio checkout workspace to run studio-editor from (one whose
|
|
7
|
+
* node_modules carry the libraries the workflow needs). */
|
|
8
|
+
studioDir: string;
|
|
9
|
+
libraries: string[];
|
|
10
|
+
engine: {
|
|
11
|
+
host: string;
|
|
12
|
+
apiPort: number;
|
|
13
|
+
supportPort: number;
|
|
14
|
+
};
|
|
15
|
+
port?: number;
|
|
16
|
+
localLinks?: boolean;
|
|
17
|
+
command?: string[];
|
|
18
|
+
readyTimeoutMs?: number;
|
|
19
|
+
/** Studio's own output goes here; a temp dir by default. */
|
|
20
|
+
workDir?: string;
|
|
21
|
+
};
|
|
22
|
+
/** docker compose interpolation, for `${NAME}` and `${NAME:-default}`. */
|
|
23
|
+
export declare function interpolate(value: string, values: Record<string, string>): string;
|
|
24
|
+
export declare function withLocalLinks(workflowYaml: string): string;
|
|
25
|
+
export declare function localStudioLauncher(opts: LocalStudioOptions): ConversionLauncher;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// A ConversionLauncher for development: runs a template's workflow in a local
|
|
2
|
+
// Studio (a norsk-studio checkout's studio-editor) against a local engine,
|
|
3
|
+
// with the studio service's environment from the template's compose filled in
|
|
4
|
+
// from the launch values, as compose would at a real launch.
|
|
5
|
+
//
|
|
6
|
+
// macOS has no libfabric, so norsk-link's remote (tcp) transport does not run
|
|
7
|
+
// there. With `localLinks`, every norsk-link output in the workflow is moved
|
|
8
|
+
// to the local transport (and its discovery name dropped), so the harness can
|
|
9
|
+
// reach the return by name on the same engine. Use remote links, and a real
|
|
10
|
+
// launcher, on Linux.
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { parse as yamlParse, stringify as yamlStringify } from "yaml";
|
|
16
|
+
const REFERENCE = /\$\{([A-Za-z0-9_]+)(?::-([^}]*))?\}/g;
|
|
17
|
+
/** docker compose interpolation, for `${NAME}` and `${NAME:-default}`. */
|
|
18
|
+
export function interpolate(value, values) {
|
|
19
|
+
return value.replace(REFERENCE, (_, name, fallback) => values[name] || fallback || "");
|
|
20
|
+
}
|
|
21
|
+
export function withLocalLinks(workflowYaml) {
|
|
22
|
+
const doc = yamlParse(workflowYaml);
|
|
23
|
+
for (const c of doc.components) {
|
|
24
|
+
if (c.type !== "output.norskLink")
|
|
25
|
+
continue;
|
|
26
|
+
const { host: _h, port: _p, provider: _v, publishedName: _n, ...rest } = c.config;
|
|
27
|
+
c.config = { ...rest, transport: "local" };
|
|
28
|
+
}
|
|
29
|
+
return yamlStringify(doc, { aliasDuplicateObjects: false });
|
|
30
|
+
}
|
|
31
|
+
export function localStudioLauncher(opts) {
|
|
32
|
+
const port = opts.port ?? 8010;
|
|
33
|
+
const workDir = opts.workDir ?? mkdtempSync(join(tmpdir(), "conformance-studio-"));
|
|
34
|
+
const saves = join(workDir, "data", "studio-save-files");
|
|
35
|
+
mkdirSync(saves, { recursive: true });
|
|
36
|
+
mkdirSync(join(workDir, "logs"), { recursive: true });
|
|
37
|
+
writeFileSync(join(saves, "workflow.yml"), opts.localLinks ? withLocalLinks(opts.workflowYaml) : opts.workflowYaml);
|
|
38
|
+
const compose = yamlParse(opts.composeYaml);
|
|
39
|
+
let env = {};
|
|
40
|
+
let child;
|
|
41
|
+
const start = async () => {
|
|
42
|
+
const [cmd, ...args] = opts.command ?? ["npx", "studio-editor"];
|
|
43
|
+
child = spawn(cmd, args, {
|
|
44
|
+
cwd: opts.studioDir,
|
|
45
|
+
env: { ...process.env, ...env },
|
|
46
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
47
|
+
detached: true,
|
|
48
|
+
});
|
|
49
|
+
const deadline = Date.now() + (opts.readyTimeoutMs ?? 120_000);
|
|
50
|
+
while (Date.now() < deadline) {
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(`http://127.0.0.1:${port}/live/api/components`);
|
|
53
|
+
if (res.ok)
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`local Studio on :${port} not ready`);
|
|
60
|
+
};
|
|
61
|
+
const kill = async () => {
|
|
62
|
+
const pid = child?.pid;
|
|
63
|
+
child = undefined;
|
|
64
|
+
if (!pid)
|
|
65
|
+
return;
|
|
66
|
+
// The editor spawns its runner; take the whole group down.
|
|
67
|
+
try {
|
|
68
|
+
process.kill(-pid, "SIGTERM");
|
|
69
|
+
}
|
|
70
|
+
catch { }
|
|
71
|
+
const deadline = Date.now() + 10_000;
|
|
72
|
+
while (Date.now() < deadline) {
|
|
73
|
+
try {
|
|
74
|
+
await fetch(`http://127.0.0.1:${port}/live/api/components`);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
process.kill(-pid, "SIGKILL");
|
|
83
|
+
}
|
|
84
|
+
catch { }
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
async launch(values) {
|
|
88
|
+
env = {};
|
|
89
|
+
for (const [k, v] of Object.entries(compose.services.studio.environment ?? {})) {
|
|
90
|
+
if (k === "NORSK_HOST" || k === "NODE_CONFIG")
|
|
91
|
+
continue;
|
|
92
|
+
if (opts.localLinks && k.endsWith("_PUBLISHEDNAME"))
|
|
93
|
+
continue;
|
|
94
|
+
env[k] = interpolate(v, values);
|
|
95
|
+
}
|
|
96
|
+
env.NODE_CONFIG = JSON.stringify({
|
|
97
|
+
server: {
|
|
98
|
+
port,
|
|
99
|
+
working_directory: join(workDir, "data"),
|
|
100
|
+
logs: join(workDir, "logs"),
|
|
101
|
+
document: "workflow.yml",
|
|
102
|
+
library: opts.libraries,
|
|
103
|
+
developer_mode: false,
|
|
104
|
+
},
|
|
105
|
+
norsk: { host: opts.engine.host, api_port: opts.engine.apiPort, support_port: opts.engine.supportPort },
|
|
106
|
+
});
|
|
107
|
+
await start();
|
|
108
|
+
},
|
|
109
|
+
async restart() {
|
|
110
|
+
await kill();
|
|
111
|
+
await start();
|
|
112
|
+
},
|
|
113
|
+
async stop() {
|
|
114
|
+
await kill();
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MediaConversionV1 } from "@norskvideo/ctl-product-template-schema";
|
|
2
|
+
import { type Norsk, type NorskLinkTransport } from "@norskvideo/norsk-sdk";
|
|
3
|
+
import { type Check, type Observation } from "./evaluate.js";
|
|
4
|
+
export type ConversionLauncher = {
|
|
5
|
+
/** Start the template with these launch values. Resolves once it is launched;
|
|
6
|
+
* the harness waits for the return itself. */
|
|
7
|
+
launch(values: Record<string, string>): Promise<void>;
|
|
8
|
+
/** Restart the converter: its workflow, or the whole instance. */
|
|
9
|
+
restart(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export type ConformanceLinks = {
|
|
13
|
+
/** How the source is published, and the address the template pulls it from. */
|
|
14
|
+
source(name: string): {
|
|
15
|
+
transport: NorskLinkTransport;
|
|
16
|
+
sourceUrl: string;
|
|
17
|
+
};
|
|
18
|
+
/** How the harness dials the return, published under `returnName`. */
|
|
19
|
+
returnTransport(returnName: string): NorskLinkTransport;
|
|
20
|
+
};
|
|
21
|
+
export type ConformanceOptions = {
|
|
22
|
+
/** The engine the harness (the caller) runs on. */
|
|
23
|
+
norsk: Norsk;
|
|
24
|
+
declaration: MediaConversionV1;
|
|
25
|
+
/** The template's other parameters, as the operator would set them. Format
|
|
26
|
+
* references in the declaration are filled in from these. */
|
|
27
|
+
parameters: Record<string, string>;
|
|
28
|
+
launcher: ConversionLauncher;
|
|
29
|
+
links: ConformanceLinks;
|
|
30
|
+
/** Filled into the engineVersion binding, when the template declares one. */
|
|
31
|
+
engineVersion?: string;
|
|
32
|
+
/** How long to wait for the return after a launch or restart. */
|
|
33
|
+
arriveTimeoutMs?: number;
|
|
34
|
+
/** How long to watch the return in each phase. */
|
|
35
|
+
observeMs?: number;
|
|
36
|
+
restart?: boolean;
|
|
37
|
+
/** Names are made unique per run; this is their prefix. */
|
|
38
|
+
prefix?: string;
|
|
39
|
+
};
|
|
40
|
+
export type ConformanceResult = {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
checks: Check[];
|
|
43
|
+
values: Record<string, string>;
|
|
44
|
+
observation: Observation;
|
|
45
|
+
};
|
|
46
|
+
export declare function runMediaConversionConformance(opts: ConformanceOptions): Promise<ConformanceResult>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { selectAudio, selectVideo, } from "@norskvideo/norsk-sdk";
|
|
2
|
+
import { evaluateMediaConversion, } from "./evaluate.js";
|
|
3
|
+
const gcd = (a, b) => (b === 0n ? (a < 0n ? -a : a) : gcd(b, a % b));
|
|
4
|
+
// Exact, in lowest terms: the two sides may express one instant in different units.
|
|
5
|
+
function stamp(t) {
|
|
6
|
+
const n = BigInt(t.n);
|
|
7
|
+
const d = BigInt(t.d);
|
|
8
|
+
const g = gcd(n, d) || 1n;
|
|
9
|
+
return `${n / g}/${d / g}`;
|
|
10
|
+
}
|
|
11
|
+
const keyOf = (k) => `${k.sourceName}/${k.programNumber}/${k.streamId}/${k.renditionName}`;
|
|
12
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
13
|
+
async function startSources(norsk, prefix, declaration) {
|
|
14
|
+
if (declaration.inputs.length !== 1) {
|
|
15
|
+
throw new Error(`conformance: v1 drives exactly one input, the declaration has ${declaration.inputs.length}`);
|
|
16
|
+
}
|
|
17
|
+
const kinds = declaration.inputs[0]?.kinds ?? {};
|
|
18
|
+
const want = (kind) => {
|
|
19
|
+
const count = kinds[kind];
|
|
20
|
+
return typeof count === "number" ? count : (count?.min ?? 0);
|
|
21
|
+
};
|
|
22
|
+
const sources = [];
|
|
23
|
+
for (let i = 0; i < want("video"); i++) {
|
|
24
|
+
sources.push(await norsk.input.videoTestCard({
|
|
25
|
+
id: `${prefix}-video-${i}`,
|
|
26
|
+
sourceName: `${prefix}-video-${i}`,
|
|
27
|
+
resolution: { width: 1920, height: 1080 },
|
|
28
|
+
frameRate: { frames: 25, seconds: 1 },
|
|
29
|
+
pattern: "smpte75",
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
for (let i = 0; i < want("audio"); i++) {
|
|
33
|
+
sources.push(await norsk.input.audioSignal({
|
|
34
|
+
id: `${prefix}-audio-${i}`,
|
|
35
|
+
sourceName: `${prefix}-audio-${i}`,
|
|
36
|
+
channelLayout: "stereo",
|
|
37
|
+
sampleRate: 48000,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
for (const kind of ["subtitle", "ancillary"]) {
|
|
41
|
+
if (want(kind) > 0)
|
|
42
|
+
throw new Error(`conformance: no ${kind} test source yet`);
|
|
43
|
+
}
|
|
44
|
+
return sources;
|
|
45
|
+
}
|
|
46
|
+
export async function runMediaConversionConformance(opts) {
|
|
47
|
+
const { norsk, declaration, launcher, links } = opts;
|
|
48
|
+
const prefix = opts.prefix ?? `conformance-${Math.random().toString(36).slice(2, 8)}`;
|
|
49
|
+
const arriveTimeoutMs = opts.arriveTimeoutMs ?? 60_000;
|
|
50
|
+
const observeMs = opts.observeMs ?? 10_000;
|
|
51
|
+
const selectAll = (streams) => [...selectVideo(streams), ...selectAudio(streams)];
|
|
52
|
+
const sent = new Set();
|
|
53
|
+
const sources = await startSources(norsk, prefix, declaration);
|
|
54
|
+
const near = await norsk.inspect.streamTimestampReport({
|
|
55
|
+
id: `${prefix}-sent`,
|
|
56
|
+
onTimestamp: (_k, t) => {
|
|
57
|
+
sent.add(stamp(t));
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
near.subscribe(sources.map((source) => ({ source, sourceSelector: selectAll })));
|
|
61
|
+
const published = links.source(`${prefix}-source`);
|
|
62
|
+
const sourceLink = await norsk.output.norskLink({
|
|
63
|
+
id: `${prefix}-source`,
|
|
64
|
+
name: `${prefix}-source`,
|
|
65
|
+
transport: published.transport,
|
|
66
|
+
});
|
|
67
|
+
sourceLink.subscribe(sources.map((source) => ({ source, sourceSelector: selectAll })));
|
|
68
|
+
const bindings = declaration.bindings;
|
|
69
|
+
const returnName = `${prefix}-return`;
|
|
70
|
+
const values = {
|
|
71
|
+
...opts.parameters,
|
|
72
|
+
[bindings.sourceUrl]: published.sourceUrl,
|
|
73
|
+
[bindings.returnName]: returnName,
|
|
74
|
+
...(bindings.engineVersion && opts.engineVersion ? { [bindings.engineVersion]: opts.engineVersion } : {}),
|
|
75
|
+
...(bindings.conversionId ? { [bindings.conversionId]: prefix } : {}),
|
|
76
|
+
};
|
|
77
|
+
// What is coming back right now, per stream; cleared at each phase.
|
|
78
|
+
const kinds = new Map();
|
|
79
|
+
const formats = new Map();
|
|
80
|
+
let stamps = new Map();
|
|
81
|
+
const returned = await norsk.input.norskLink({
|
|
82
|
+
id: `${prefix}-return`,
|
|
83
|
+
sourceName: `${prefix}-returned`,
|
|
84
|
+
name: returnName,
|
|
85
|
+
transport: links.returnTransport(returnName),
|
|
86
|
+
// As a caller would: an inherited timeline is already the source's.
|
|
87
|
+
adoptInboundTimestamps: declaration.timeline === "inherit",
|
|
88
|
+
onOutboundContextChange: async (streams) => {
|
|
89
|
+
for (const s of streams) {
|
|
90
|
+
const kind = s.message.case;
|
|
91
|
+
if (!kind)
|
|
92
|
+
continue;
|
|
93
|
+
const key = keyOf(s.streamKey);
|
|
94
|
+
kinds.set(key, kind);
|
|
95
|
+
const format = {};
|
|
96
|
+
for (const [k, v] of Object.entries((s.message.value ?? {}))) {
|
|
97
|
+
if (typeof v === "string" || typeof v === "number")
|
|
98
|
+
format[k] = v;
|
|
99
|
+
}
|
|
100
|
+
formats.set(key, format);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
const far = await norsk.inspect.streamTimestampReport({
|
|
105
|
+
id: `${prefix}-received`,
|
|
106
|
+
onTimestamp: (k, t) => {
|
|
107
|
+
const key = keyOf(k);
|
|
108
|
+
const list = stamps.get(key) ?? [];
|
|
109
|
+
list.push(stamp(t));
|
|
110
|
+
stamps.set(key, list);
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
far.subscribe([{ source: returned, sourceSelector: selectAll }]);
|
|
114
|
+
const phases = [];
|
|
115
|
+
const observePhase = async (label) => {
|
|
116
|
+
stamps = new Map();
|
|
117
|
+
const deadline = Date.now() + arriveTimeoutMs;
|
|
118
|
+
while (stamps.size === 0 && Date.now() < deadline)
|
|
119
|
+
await sleep(250);
|
|
120
|
+
// Frames from before this phase (a restart's tail) are not this phase's.
|
|
121
|
+
stamps = new Map();
|
|
122
|
+
await sleep(observeMs);
|
|
123
|
+
const streams = [...stamps.entries()].map(([key, list]) => ({
|
|
124
|
+
kind: kinds.get(key) ?? "video",
|
|
125
|
+
format: formats.get(key) ?? {},
|
|
126
|
+
stamps: list,
|
|
127
|
+
}));
|
|
128
|
+
phases.push({ label, streams });
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
await launcher.launch(values);
|
|
132
|
+
await observePhase("initial");
|
|
133
|
+
if (opts.restart ?? true) {
|
|
134
|
+
await launcher.restart();
|
|
135
|
+
await observePhase("after restart");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
await launcher.stop().catch(() => { });
|
|
140
|
+
for (const node of [far, returned, sourceLink, near, ...sources])
|
|
141
|
+
await node.close().catch(() => { });
|
|
142
|
+
}
|
|
143
|
+
const observation = { sent, phases };
|
|
144
|
+
const checks = evaluateMediaConversion({
|
|
145
|
+
declaration,
|
|
146
|
+
parameters: values,
|
|
147
|
+
observation,
|
|
148
|
+
minFrames: Math.max(1, Math.floor(observeMs / 1000)),
|
|
149
|
+
});
|
|
150
|
+
return { ok: checks.every((c) => c.ok), checks, values, observation };
|
|
151
|
+
}
|
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.94",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -70,6 +70,10 @@
|
|
|
70
70
|
"./compose-advancing": {
|
|
71
71
|
"types": "./compose-advancing.d.ts",
|
|
72
72
|
"default": "./compose-advancing.js"
|
|
73
|
+
},
|
|
74
|
+
"./media-conversion": {
|
|
75
|
+
"types": "./media-conversion/index.d.ts",
|
|
76
|
+
"default": "./media-conversion/index.js"
|
|
73
77
|
}
|
|
74
78
|
},
|
|
75
79
|
"main": "./index.js",
|
|
@@ -79,19 +83,22 @@
|
|
|
79
83
|
"ctl-dev-loop": "./demo/dev-loop-cli.js"
|
|
80
84
|
},
|
|
81
85
|
"dependencies": {
|
|
86
|
+
"@norskvideo/ctl-product-template-schema": "^0.1.20",
|
|
82
87
|
"@norskvideo/ctl-sdk": "^0.1.0",
|
|
88
|
+
"yaml": "^2.8.0",
|
|
83
89
|
"zod": "4.4.3"
|
|
84
90
|
},
|
|
85
91
|
"peerDependencies": {
|
|
86
92
|
"@norskvideo/norsk-studio": "*",
|
|
87
|
-
"@norskvideo/norsk-studio-built-ins": "*"
|
|
93
|
+
"@norskvideo/norsk-studio-built-ins": "*",
|
|
94
|
+
"@norskvideo/norsk-sdk": "*"
|
|
88
95
|
},
|
|
89
96
|
"devDependencies": {
|
|
90
97
|
"@types/bun": "latest",
|
|
91
98
|
"@types/node": "^22.10.0",
|
|
92
|
-
"@norskvideo/norsk-studio": "1.30.0-2026-10-
|
|
93
|
-
"@norskvideo/norsk-studio-built-ins": "1.30.0-2026-10-
|
|
94
|
-
"@norskvideo/norsk-sdk": "1.3.1-2026-10-
|
|
99
|
+
"@norskvideo/norsk-studio": "1.30.0-2026-10-16-837e5d98",
|
|
100
|
+
"@norskvideo/norsk-studio-built-ins": "1.30.0-2026-10-16-837e5d98",
|
|
101
|
+
"@norskvideo/norsk-sdk": "1.3.1-2026-10-16-e43e0f90"
|
|
95
102
|
},
|
|
96
103
|
"peerDependenciesMeta": {
|
|
97
104
|
"@norskvideo/norsk-studio": {
|
|
@@ -99,6 +106,9 @@
|
|
|
99
106
|
},
|
|
100
107
|
"@norskvideo/norsk-studio-built-ins": {
|
|
101
108
|
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"@norskvideo/norsk-sdk": {
|
|
111
|
+
"optional": true
|
|
102
112
|
}
|
|
103
113
|
},
|
|
104
114
|
"publishConfig": {
|