oapix / test /responseNormalization.test.js
woiceatus's picture
init
e43a4a9
import test from "node:test";
import assert from "node:assert/strict";
import { InMemoryMediaStore } from "../src/services/mediaStore.js";
import { createResponseNormalizationService } from "../src/services/responseNormalizationService.js";
test("adds proxy URLs for audio and data-url image outputs", () => {
const mediaStore = new InMemoryMediaStore({ ttlSeconds: 3600 });
const service = createResponseNormalizationService({ mediaStore });
const normalized = service.normalize({
choices: [
{
message: {
audio: {
data: "ZmFrZS1hdWRpbw=="
},
content: [
{
type: "image_url",
image_url: {
url: "data:image/png;base64,aW1hZ2U="
}
}
]
}
}
]
}, {
publicBaseUrl: "http://localhost:3000",
audioFormat: "mp3",
exposeMediaUrls: true
});
assert.match(normalized.choices[0].message.audio.url, /^http:\/\/localhost:3000\/v1\/media\//);
assert.match(normalized.choices[0].message.content[0].image_url.proxy_url, /^http:\/\/localhost:3000\/v1\/media\//);
assert.equal(normalized.proxy.media.length, 2);
});