Files
OmniRoute/tests/unit/guardrails/videoBridgeTranscriptProvenance.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

149 lines
4.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
describeVideoPart,
normalizeVideoTranscript,
type VideoCaptionFrame,
} from "../../../src/lib/guardrails/videoBridgeHelpers";
test("accepts only provenance-bearing transcript cues and deduplicates exact repeats", () => {
const cues = normalizeVideoTranscript(
{
cues: [
{ text: "hello", start: 1, end: 3, source: "client", confidence: 0.8 },
{ text: "hello", start: 1, end: 3, source: "client", confidence: 0.8 },
{ text: "world", startSeconds: 3, endSeconds: 5, source: "audio-bridge" },
],
},
10
);
assert.deepEqual(cues, [
{ text: "hello", startSeconds: 1, endSeconds: 3, source: "client", confidence: 0.8 },
{ text: "world", startSeconds: 3, endSeconds: 5, source: "audio-bridge", confidence: 1 },
]);
});
test("rejects untrusted sources, malformed cues, and out-of-range timestamps", () => {
assert.throws(
() =>
normalizeVideoTranscript({ cues: [{ text: "x", start: 1, end: 2, source: "unknown" }] }, 10),
/source/i
);
assert.throws(
() =>
normalizeVideoTranscript({ cues: [{ text: "x", start: -1, end: 2, source: "client" }] }, 10),
/timestamp|range/i
);
assert.throws(
() =>
normalizeVideoTranscript({ cues: [{ text: "x", start: 4, end: 4, source: "embedded" }] }, 10),
/timestamp|range/i
);
assert.throws(
() =>
normalizeVideoTranscript(
{ cues: [{ text: "x", start: 9, end: 11, source: "embedded" }] },
10
),
/timestamp|range/i
);
});
test("keeps transcript provenance attached to the described video output", async () => {
const frames: VideoCaptionFrame[] = [
{ dataUri: "data:image/jpeg;base64,AA==", timestampSeconds: 2 },
{ dataUri: "data:image/jpeg;base64,AA==", timestampSeconds: 8 },
];
const described = await describeVideoPart(
{
container: "messages",
messageIndex: 0,
partIndex: 0,
ref: "data:video/mp4;base64,AA==",
shape: "data_uri_string",
transcript: {
cues: [{ text: "spoken words", start: 1, end: 3, source: "audio-bridge", confidence: 0.9 }],
},
},
{ frameCount: 2, timeoutMs: 1000 },
async () => "a scene",
{
extractFrames: async () => ({ durationSeconds: 10, frames }),
}
);
assert.equal(described.transcriptCues?.length, 1);
assert.match(described.description, /transcript\[source=audio-bridge;confidence=0\.90/);
assert.match(described.description, /spoken words/);
});
test("fuses an explicitly supplied audio-bridge track without starting STT", async () => {
let captionCalls = 0;
const described = await describeVideoPart(
{
container: "messages",
messageIndex: 0,
partIndex: 0,
ref: "data:video/mp4;base64,AA==",
shape: "data_uri_string",
audioTranscript: {
cues: [{ text: "audio cue", start: 1, end: 3, source: "audio-bridge" }],
},
},
{ frameCount: 1, timeoutMs: 1000 },
async () => {
captionCalls += 1;
return "visual cue";
},
{
extractFrames: async () => ({
durationSeconds: 5,
frames: [{ dataUri: "data:image/jpeg;base64,AA==", timestampSeconds: 2 }],
}),
}
);
assert.equal(captionCalls, 1);
assert.equal(described.transcriptCues?.[0]?.source, "audio-bridge");
assert.match(described.description, /audio cue/);
assert.deepEqual(described.fusion, {
audioAvailable: true,
videoAvailable: true,
partial: false,
});
});
test("an invalid audioTranscript degrades to a partial fusion and keeps the visual description", async () => {
const described = await describeVideoPart(
{
container: "messages",
messageIndex: 0,
partIndex: 0,
ref: "data:video/mp4;base64,AA==",
shape: "data_uri_string",
audioTranscript: {
cues: [{ text: "late cue", start: 1, end: 99, source: "audio-bridge" }],
},
},
{ frameCount: 1, timeoutMs: 1000 },
async () => "visual cue",
{
extractFrames: async () => ({
durationSeconds: 5,
frames: [{ dataUri: "data:image/jpeg;base64,AA==", timestampSeconds: 2 }],
}),
}
);
assert.match(described.description, /visual cue/);
assert.equal(described.transcriptCues, undefined, "invalid audio must not add transcript cues");
assert.deepEqual(described.fusion, {
audioAvailable: false,
videoAvailable: true,
partial: true,
failures: { audio: "FAILED" },
});
});