refactor(media): split audio helpers and attachment cache

This commit is contained in:
Peter Steinberger
2026-03-02 22:00:46 +00:00
parent 9bde7f4fde
commit 6545317a2c
18 changed files with 776 additions and 749 deletions

View File

@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { withEnvAsync } from "../test-utils/env.js";
import { MIN_AUDIO_FILE_BYTES } from "./defaults.js";
import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.js";
type MediaFixtureParams = {
@@ -49,12 +50,18 @@ export async function withAudioFixture(
filePrefix,
extension: "wav",
mediaType: "audio/wav",
fileContents: Buffer.alloc(2048, 0x52),
fileContents: createSafeAudioFixtureBuffer(2048, 0x52),
},
run,
);
}
export function createSafeAudioFixtureBuffer(size?: number, fill = 0xab): Buffer {
const minSafeSize = MIN_AUDIO_FILE_BYTES + 1;
const finalSize = Math.max(size ?? minSafeSize, minSafeSize);
return Buffer.alloc(finalSize, fill);
}
export async function withVideoFixture(
filePrefix: string,
run: (params: MediaFixtureParams) => Promise<void>,