Reject task=translate on the server for models that cannot translate (D-044)
The UI already hid it; a direct API call to POST /api/transcribe or the live WebSocket could still get the source language back labelled as a translation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
96d100bd45
commit
3583d60847
4 files changed
+62
-4
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
createSidecar,
|
||||
createTranscribeHandlers,
|
||||
parseLanguageAndTask,
|
||||
translateNotSupported,
|
||||
type Sidecar,
|
||||
type SidecarSegment,
|
||||
type SidecarTranscribeRequest,
|
||||
@@ -262,6 +263,41 @@ describe("POST /api/transcribe", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("400 for translate on a model not trained for it; translate still works where it is (D-044)", async () => {
|
||||
const sidecar = fakeSidecar();
|
||||
const handlers = createTranscribeHandlers({
|
||||
sidecar,
|
||||
getSessionUser: sessionFromCookie,
|
||||
tempDir: await makeTempDir(),
|
||||
});
|
||||
for (const model of [
|
||||
"onnx-community/whisper-large-v3-turbo",
|
||||
"onnx-community/whisper-small.en",
|
||||
]) {
|
||||
const response = await handlers.post(
|
||||
postRequest(`?model=${model}&task=translate`, pcmBody([0.1]), { cookie: "sid=ok" }),
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
expect(await response.text()).toContain("cannot translate");
|
||||
}
|
||||
expect(sidecar.requests).toHaveLength(0);
|
||||
|
||||
const ok = await handlers.post(
|
||||
postRequest("?model=onnx-community/whisper-small&task=translate", pcmBody([0.1]), {
|
||||
cookie: "sid=ok",
|
||||
}),
|
||||
);
|
||||
expect(ok.status).toBe(200);
|
||||
});
|
||||
|
||||
test("translateNotSupported: the shared check for the HTTP and live routes", () => {
|
||||
expect(translateNotSupported("onnx-community/whisper-large-v3-turbo", "translate")).toContain(
|
||||
"cannot translate",
|
||||
);
|
||||
expect(translateNotSupported("onnx-community/whisper-large-v3-turbo", "transcribe")).toBeUndefined();
|
||||
expect(translateNotSupported("onnx-community/whisper-small", "translate")).toBeUndefined();
|
||||
});
|
||||
|
||||
test("503 with the reason when the sidecar is unavailable", async () => {
|
||||
const sidecar = fakeSidecar({ available: false, reason: "faster-whisper is not installed" });
|
||||
const handlers = createTranscribeHandlers({
|
||||
|
||||
Reference in new issue
Block a user