fix(image): fail over on empty output

This commit is contained in:
Peter Steinberger
2026-01-12 18:45:46 +00:00
parent 523f91758d
commit 0be62c3542
2 changed files with 148 additions and 4 deletions

View File

@@ -150,3 +150,101 @@ describe("image tool data URL support", () => {
).toThrow(/Unsupported data URL type/i);
});
});
describe("image tool response validation", () => {
it("rejects image-model responses with no final text", () => {
expect(() =>
__testing.coerceImageAssistantText({
provider: "openai",
model: "gpt-5-mini",
message: {
role: "assistant",
api: "openai-responses",
provider: "openai",
model: "gpt-5-mini",
stopReason: "stop",
timestamp: Date.now(),
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
total: 0,
},
},
content: [{ type: "thinking", thinking: "hmm" }],
},
}),
).toThrow(/returned no text/i);
});
it("surfaces provider errors from image-model responses", () => {
expect(() =>
__testing.coerceImageAssistantText({
provider: "openai",
model: "gpt-5-mini",
message: {
role: "assistant",
api: "openai-responses",
provider: "openai",
model: "gpt-5-mini",
stopReason: "error",
errorMessage: "boom",
timestamp: Date.now(),
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
total: 0,
},
},
content: [],
},
}),
).toThrow(/boom/i);
});
it("returns trimmed text from image-model responses", () => {
const text = __testing.coerceImageAssistantText({
provider: "anthropic",
model: "claude-opus-4-5",
message: {
role: "assistant",
api: "anthropic-messages",
provider: "anthropic",
model: "claude-opus-4-5",
stopReason: "stop",
timestamp: Date.now(),
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
total: 0,
},
},
content: [{ type: "text", text: " hello " }],
},
});
expect(text).toBe("hello");
});
});