@@ -73,6 +73,34 @@ describe("Anthropic vision executor", () => {
7373 oauthAccessError = undefined ;
7474 } ) ;
7575
76+ test . each ( [ 64 * 1024 , 80 * 1024 ] ) ( "keeps only complete partial description frames at %i bytes without waiting for cancel" , async ( size ) => {
77+ const prefix = `data: ${ JSON . stringify ( { type : "content_block_delta" , delta : { type : "text_delta" , text : "partial 한글" } } ) } \n\n` ;
78+ const tail = `data: ${ JSON . stringify ( { type : "content_block_delta" , delta : { type : "text_delta" , text : "discard" } } ) } ` ;
79+ const encoder = new TextEncoder ( ) ;
80+ const body = prefix + ":" + "x" . repeat ( 64 * 1024 - encoder . encode ( prefix + "\n\n" + tail ) . length - 1 ) + "\n\n" + tail ;
81+ let cancelled = false ;
82+ const out = await parseAnthropicVisionSSE ( new Response ( new ReadableStream < Uint8Array > ( {
83+ start ( controller ) { controller . enqueue ( encoder . encode ( body + "z" . repeat ( size - 64 * 1024 ) ) ) ; } ,
84+ cancel ( ) { cancelled = true ; return new Promise < void > ( ( ) => { } ) ; } ,
85+ } , { highWaterMark : 0 } ) ) ) ;
86+ expect ( cancelled ) . toBe ( true ) ;
87+ expect ( out ) . toEqual ( { text : "partial 한글" } ) ;
88+ } ) ;
89+
90+ test . each ( [ 401 , 503 ] ) ( "bounds HTTP %i error bodies even when cancellation never settles" , async ( status ) => {
91+ let reads = 0 ;
92+ let cancelled = false ;
93+ globalThis . fetch = ( async ( ) => new Response ( new ReadableStream < Uint8Array > ( {
94+ pull ( controller ) { reads += 1 ; controller . enqueue ( new Uint8Array ( 4096 ) . fill ( 120 ) ) ; } ,
95+ cancel ( ) { cancelled = true ; return new Promise < void > ( ( ) => { } ) ; } ,
96+ } , { highWaterMark : 0 } ) , { status } ) ) as typeof fetch ;
97+ const out = await describeImageAnthropic ( DATA_IMAGE , "high" , "" , "anthropic-vision-test" , anthropicProvider , settings ) ;
98+ expect ( reads ) . toBe ( 16 ) ;
99+ expect ( cancelled ) . toBe ( true ) ;
100+ expect ( out . error ) . toBe ( status === 401
101+ ? `anthropic vision sidecar auth failed: ${ PUBLIC_OAUTH_ERROR } ` : "anthropic vision sidecar HTTP 503" ) ;
102+ } ) ;
103+
76104 test ( "projects OAuth, upstream-auth, and transport failures onto safe replacement errors" , async ( ) => {
77105 oauthAccessError = new Error ( `credential read failed at ${ AUTH_ERROR_CANARY } ` ) ;
78106 const credentialFailure = await describeImageAnthropic (
0 commit comments