@norskvideo/ctl-test-harness 0.1.0 → 0.1.2
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/package.json +1 -1
- package/studio-state.d.ts +1 -0
- package/studio-state.js +36 -4
package/package.json
CHANGED
package/studio-state.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ComponentsResponse {
|
|
|
7
7
|
components: ComponentSummary[];
|
|
8
8
|
totalComponents: number;
|
|
9
9
|
}
|
|
10
|
+
export declare function applyTestHost(rawUrl: string): string;
|
|
10
11
|
export declare function fetchComponents(studioHostPort: number): Promise<ComponentsResponse | null>;
|
|
11
12
|
export declare function fetchComponentState(studioHostPort: number, componentId: string): Promise<unknown | null>;
|
|
12
13
|
/** SRT-listener state shape — see
|
package/studio-state.js
CHANGED
|
@@ -15,8 +15,40 @@
|
|
|
15
15
|
// fetchers). Extracted verbatim from the playout copy — the canonical text.
|
|
16
16
|
// Commentary's WHIP-driver tail (RemoteCommentary*, discoverCommentaryWhipUrls,
|
|
17
17
|
// assertCommentaryChannelOccupied) stays local to commentary.
|
|
18
|
+
// The host the studio port is reachable on. Normally the product template
|
|
19
|
+
// publishes it on the loopback of the machine running the tests, so localhost is
|
|
20
|
+
// right. When the test process itself runs inside a container that launches the
|
|
21
|
+
// studio as a HOST sibling (docker-outside-of-docker CI — e.g. the jankings
|
|
22
|
+
// runners), the published port lives on the host, reachable via the host-gateway
|
|
23
|
+
// alias: set NORSK_TEST_HOST=host.docker.internal there. Daemon-port fetches are
|
|
24
|
+
// deliberately left on localhost — the daemon runs in-process with the tests.
|
|
25
|
+
const STUDIO_HOST = process.env.NORSK_TEST_HOST ?? "localhost";
|
|
26
|
+
// Studio reports absolute playback URLs (the HLS multivariant, WHIP publish
|
|
27
|
+
// endpoints, ...) with the host it was configured with — loopback in a local
|
|
28
|
+
// run. In DooD CI the test process is inside a container and cannot reach that
|
|
29
|
+
// loopback; the published port lives on the host-gateway alias. Callers that
|
|
30
|
+
// fetch a server-reported URL verbatim must route it through here so a loopback
|
|
31
|
+
// host gets swapped for NORSK_TEST_HOST. No env / non-loopback host / unparseable
|
|
32
|
+
// input all pass through unchanged. Read from the env at call time (not the
|
|
33
|
+
// module-level STUDIO_HOST) so tests can toggle it.
|
|
34
|
+
export function applyTestHost(rawUrl) {
|
|
35
|
+
const testHost = process.env.NORSK_TEST_HOST;
|
|
36
|
+
if (!testHost)
|
|
37
|
+
return rawUrl;
|
|
38
|
+
try {
|
|
39
|
+
const u = new URL(rawUrl);
|
|
40
|
+
if (u.hostname === "localhost" || u.hostname === "127.0.0.1" || u.hostname === "::1") {
|
|
41
|
+
u.hostname = testHost;
|
|
42
|
+
return u.toString();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// not a parseable absolute URL — leave it for the caller's own error path
|
|
47
|
+
}
|
|
48
|
+
return rawUrl;
|
|
49
|
+
}
|
|
18
50
|
export async function fetchComponents(studioHostPort) {
|
|
19
|
-
const r = await fetch(`http
|
|
51
|
+
const r = await fetch(`http://${STUDIO_HOST}:${studioHostPort}/live/api/components`, {
|
|
20
52
|
signal: AbortSignal.timeout(5000),
|
|
21
53
|
});
|
|
22
54
|
if (r.status === 503)
|
|
@@ -26,7 +58,7 @@ export async function fetchComponents(studioHostPort) {
|
|
|
26
58
|
return (await r.json());
|
|
27
59
|
}
|
|
28
60
|
export async function fetchComponentState(studioHostPort, componentId) {
|
|
29
|
-
const r = await fetch(`http
|
|
61
|
+
const r = await fetch(`http://${STUDIO_HOST}:${studioHostPort}/live/api/${encodeURIComponent(componentId)}/state`, {
|
|
30
62
|
signal: AbortSignal.timeout(5000),
|
|
31
63
|
});
|
|
32
64
|
if (r.status === 503 || r.status === 404)
|
|
@@ -42,7 +74,7 @@ export function isSrtListenerState(value) {
|
|
|
42
74
|
return Array.isArray(v.connectedStreams) && typeof v.connectedAt === "object" && v.connectedAt !== null;
|
|
43
75
|
}
|
|
44
76
|
async function fetchComponentStreamRoute(studioHostPort, componentId, route) {
|
|
45
|
-
const r = await fetch(`http
|
|
77
|
+
const r = await fetch(`http://${STUDIO_HOST}:${studioHostPort}/live/api/${encodeURIComponent(componentId)}/streams/${route}`, { signal: AbortSignal.timeout(5000) });
|
|
46
78
|
if (r.status === 503 || r.status === 404)
|
|
47
79
|
return null;
|
|
48
80
|
if (!r.ok)
|
|
@@ -161,7 +193,7 @@ export async function assertMultivariantHasRenditions(opts) {
|
|
|
161
193
|
if (!state?.url)
|
|
162
194
|
return false;
|
|
163
195
|
try {
|
|
164
|
-
const r = await fetch(state.url, { signal: AbortSignal.timeout(5000) });
|
|
196
|
+
const r = await fetch(applyTestHost(state.url), { signal: AbortSignal.timeout(5000) });
|
|
165
197
|
lastFetchStatus = r.status;
|
|
166
198
|
if (!r.ok)
|
|
167
199
|
return false;
|