Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(media-server): extend audio probe integration tests

Richie McIlroy724c893f4ef6
diff --git a/apps/media-server/src/__tests__/lib/media-audio.integration.test.ts b/apps/media-server/src/__tests__/lib/media-audio.integration.test.ts
index 4101df813..30608519c 100644
--- a/apps/media-server/src/__tests__/lib/media-audio.integration.test.ts
+++ b/apps/media-server/src/__tests__/lib/media-audio.integration.test.ts
@@ -1,4 +1,6 @@
import { describe, expect, test } from "bun:test";
+import { mkdtemp, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
import { join } from "node:path";
import {
checkHasAudioTrack,
@@ -11,6 +13,41 @@ const FIXTURES_DIR = join(import.meta.dir, "..", "fixtures");
const TEST_VIDEO_WITH_AUDIO = `file://${join(FIXTURES_DIR, "test-with-audio.mp4")}`;
const TEST_VIDEO_NO_AUDIO = `file://${join(FIXTURES_DIR, "test-no-audio.mp4")}`;
+async function createHlsFixture(): Promise<string> {
+ const dirPath = await mkdtemp(join(tmpdir(), "cap-audio-hls-"));
+ const proc = Bun.spawn({
+ cmd: [
+ "ffmpeg",
+ "-hide_banner",
+ "-loglevel",
+ "error",
+ "-y",
+ "-i",
+ join(FIXTURES_DIR, "test-with-audio.mp4"),
+ "-c",
+ "copy",
+ "-hls_time",
+ "0.25",
+ "-hls_list_size",
+ "0",
+ "-hls_segment_filename",
+ join(dirPath, "segment-%03d.ts"),
+ join(dirPath, "manifest.m3u8"),
+ ],
+ stdout: "ignore",
+ stderr: "pipe",
+ });
+ const [stderr, exitCode] = await Promise.all([
+ new Response(proc.stderr).text(),
+ proc.exited,
+ ]);
+ if (exitCode !== 0) {
+ await rm(dirPath, { recursive: true, force: true });
+ throw new Error(`Failed to create HLS fixture: ${stderr}`);
+ }
+ return dirPath;
+}
+
async function readStream(stream: ReadableStream<Uint8Array>) {
const reader = stream.getReader();
const chunks: Uint8Array[] = [];
@@ -66,6 +103,53 @@ describe("mediaAudio integration tests", () => {
const hasAudio = await checkHasAudioTrack(TEST_VIDEO_NO_AUDIO);
expect(hasAudio).toBe(false);
});
+
+ test("inherits signed queries for relative HLS segments", async () => {
+ const dirPath = await createHlsFixture();
+ const requests: string[] = [];
+ const server = Bun.serve({
+ port: 0,
+ fetch(request) {
+ const url = new URL(request.url);
+ requests.push(`${url.pathname}${url.search}`);
+ if (
+ url.pathname !== "/manifest.m3u8" &&
+ url.searchParams.get("token") !== "signed"
+ ) {
+ return new Response("Forbidden", { status: 403 });
+ }
+ return new Response(Bun.file(join(dirPath, url.pathname.slice(1))));
+ },
+ });
+
+ try {
+ const hasAudio = await checkHasAudioTrack(
+ `${server.url}manifest.m3u8?token=signed`,
+ );
+ expect(hasAudio).toBe(true);
+ expect(requests).toContain("/segment-000.ts?token=signed");
+ } finally {
+ await server.stop(true);
+ await rm(dirPath, { recursive: true, force: true });
+ }
+ });
+
+ test("contains upstream failures without leaking the active operation", async () => {
+ const beforeCount = getActiveProcessCount();
+ const server = Bun.serve({
+ port: 0,
+ fetch: () => new Response("Unavailable", { status: 503 }),
+ });
+
+ try {
+ await expect(
+ checkHasAudioTrack(`${server.url}video.mp4`),
+ ).rejects.toThrow("FFprobe exited");
+ await waitForAudioOperations(beforeCount);
+ } finally {
+ await server.stop(true);
+ }
+ });
});
describe("extractAudio", () => {