mirror of
https://github.com/anomalyco/opencode.git
synced 2026-09-09 12:24:35 +00:00
test(ai): reject unsupported bedrock image formats
This commit is contained in:
parent
7092b8a5b1
commit
277d7bf273
2 changed files with 15 additions and 1 deletions
|
|
@ -87,7 +87,7 @@ function mediaIssue(
|
|||
return typeof block.content === "string"
|
||||
? undefined
|
||||
: block.content.map(mediaIssue).find((issue) => issue !== undefined)
|
||||
if (block.type !== "image" && block.type !== "document") return
|
||||
if (block.type !== "image" && block.type !== "document") return undefined
|
||||
if (block.source.type === "url" || block.source.type === "file")
|
||||
return "Bedrock Messages does not support URL or file-ID media sources"
|
||||
if (
|
||||
|
|
@ -97,6 +97,7 @@ function mediaIssue(
|
|||
return "Bedrock Messages requires a JPEG, PNG, WebP, or GIF image"
|
||||
if (block.source.type === "base64" && Encoding.decodeBase64(block.source.data)._tag === "Failure")
|
||||
return "Bedrock Messages media data must be valid base64"
|
||||
return undefined
|
||||
}
|
||||
|
||||
export const route = Route.make({
|
||||
|
|
|
|||
|
|
@ -151,3 +151,16 @@ it.effect("rejects Anthropic file IDs", () =>
|
|||
expect(error.message).toContain("file-ID")
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("rejects unsupported image formats", () =>
|
||||
Effect.gen(function* () {
|
||||
const error = yield* compileRequest(
|
||||
LLM.request({
|
||||
model: AmazonBedrock.configure({ apiKey: "test" }).messages("claude"),
|
||||
messages: [Message.user({ type: "media", mediaType: "image/svg+xml", data: "AQID" })],
|
||||
}),
|
||||
).pipe(Effect.flip)
|
||||
expect(error.reason._tag).toBe("InvalidRequest")
|
||||
expect(error.message).toContain("JPEG, PNG, WebP, or GIF")
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue