@norskvideo/ctl-test-harness 0.1.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-test-harness",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./daemon": {
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
@@ -23,6 +23,30 @@
23
23
  // alias: set NORSK_TEST_HOST=host.docker.internal there. Daemon-port fetches are
24
24
  // deliberately left on localhost — the daemon runs in-process with the tests.
25
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
+ }
26
50
  export async function fetchComponents(studioHostPort) {
27
51
  const r = await fetch(`http://${STUDIO_HOST}:${studioHostPort}/live/api/components`, {
28
52
  signal: AbortSignal.timeout(5000),
@@ -169,7 +193,7 @@ export async function assertMultivariantHasRenditions(opts) {
169
193
  if (!state?.url)
170
194
  return false;
171
195
  try {
172
- const r = await fetch(state.url, { signal: AbortSignal.timeout(5000) });
196
+ const r = await fetch(applyTestHost(state.url), { signal: AbortSignal.timeout(5000) });
173
197
  lastFetchStatus = r.status;
174
198
  if (!r.ok)
175
199
  return false;