@@ -50,6 +50,7 @@ import { Truncate } from "@/tool/truncate"
5050import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
5151import { Ripgrep } from "@opencode-ai/core/ripgrep"
5252import { Format } from "../../src/format"
53+ import { TestConfig } from "../fixture/config"
5354import { TestInstance } from "../fixture/fixture"
5455import { awaitWithTimeout , pollWithTimeout , testEffect } from "../lib/effect"
5556import { reply , TestLLMServer } from "../lib/llm-server"
@@ -208,6 +209,13 @@ const promptRoot = LayerNode.group([
208209 RuntimeFlags . node ,
209210] )
210211
212+ const promptReplacement = [
213+ [ SessionSummary . node , summary ] ,
214+ [ LSP . node , lsp ] ,
215+ [ MCP . node , makeMcp ( ) ] ,
216+ [ RuntimeFlags . node , runtimeFlags ] ,
217+ ] as const
218+
211219function makePrompt ( input ?: { mcpInstructions ?: MCP . ServerInstructions [ ] ; processor ?: "blocking" } ) {
212220 const replacements = [
213221 [ SessionSummary . node , summary ] ,
@@ -239,6 +247,13 @@ function makeHttpNoLLMServer(input?: { mcpInstructions?: MCP.ServerInstructions[
239247 return makePrompt ( input )
240248}
241249
250+ const tinyImageServer = testEffect (
251+ LayerNode . compile ( promptRoot , [
252+ ...promptReplacement ,
253+ [ Config . node , TestConfig . layer ( { get : ( ) => Effect . succeed ( { attachment : { image : { max_base64_bytes : 1 } } } ) } ) ] ,
254+ ] as const ) ,
255+ )
256+
242257const it = testEffect ( makeHttp ( ) )
243258const noLLMServer = testEffect ( makeHttpNoLLMServer ( ) )
244259const raceNoLLMServer = testEffect ( makeHttpNoLLMServer ( { processor : "blocking" } ) )
@@ -2143,6 +2158,83 @@ noLLMServer.instance(
21432158 { config : cfg } ,
21442159)
21452160
2161+ tinyImageServer . instance (
2162+ "does not fail the prompt when an image attachment exceeds the size limit" ,
2163+ ( ) =>
2164+ Effect . gen ( function * ( ) {
2165+ const prompt = yield * SessionPrompt . Service
2166+ const sessions = yield * Session . Service
2167+ const session = yield * sessions . create ( { } )
2168+
2169+ // Valid 1x1 PNG — decodes fine but exceeds the 1-byte max_base64_bytes limit.
2170+ const png = Buffer . from (
2171+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==" ,
2172+ "base64" ,
2173+ ) . toString ( "base64" )
2174+ const msg = yield * prompt . prompt ( {
2175+ sessionID : session . id ,
2176+ agent : "build" ,
2177+ noReply : true ,
2178+ parts : [
2179+ { type : "text" , text : "please review this image" } ,
2180+ {
2181+ type : "file" ,
2182+ mime : "image/png" ,
2183+ url : `data:image/png;base64,${ png } ` ,
2184+ filename : "screenshot.png" ,
2185+ } ,
2186+ ] ,
2187+ } )
2188+
2189+ if ( msg . info . role !== "user" ) throw new Error ( "expected user message" )
2190+ const notice = msg . parts . find (
2191+ ( part ) =>
2192+ part . type === "text" && part . synthetic && part . text . includes ( "could not be processed" ) ,
2193+ )
2194+ expect ( notice ) . toBeDefined ( )
2195+ expect ( notice ?. type === "text" && notice . text . includes ( "screenshot.png" ) ) . toBe ( true )
2196+
2197+ yield * sessions . remove ( session . id )
2198+ } ) ,
2199+ { config : cfg } ,
2200+ )
2201+
2202+ noLLMServer . instance (
2203+ "does not fail the prompt when an image attachment has an invalid data URL" ,
2204+ ( ) =>
2205+ Effect . gen ( function * ( ) {
2206+ const prompt = yield * SessionPrompt . Service
2207+ const sessions = yield * Session . Service
2208+ const session = yield * sessions . create ( { } )
2209+
2210+ const msg = yield * prompt . prompt ( {
2211+ sessionID : session . id ,
2212+ agent : "build" ,
2213+ noReply : true ,
2214+ parts : [
2215+ { type : "text" , text : "please review this image" } ,
2216+ {
2217+ type : "file" ,
2218+ mime : "image/png" ,
2219+ url : "http://example.com/not-a-data-url.png" ,
2220+ filename : "screenshot.png" ,
2221+ } ,
2222+ ] ,
2223+ } )
2224+
2225+ if ( msg . info . role !== "user" ) throw new Error ( "expected user message" )
2226+ const notice = msg . parts . find (
2227+ ( part ) =>
2228+ part . type === "text" && part . synthetic && part . text . includes ( "could not be processed" ) ,
2229+ )
2230+ expect ( notice ) . toBeDefined ( )
2231+ expect ( notice ?. type === "text" && notice . text . includes ( "screenshot.png" ) ) . toBe ( true )
2232+
2233+ yield * sessions . remove ( session . id )
2234+ } ) ,
2235+ { config : cfg } ,
2236+ )
2237+
21462238noLLMServer . instance (
21472239 "does not fail the prompt when a file part is missing" ,
21482240 ( ) =>
0 commit comments