@@ -363,6 +363,55 @@ describe("normalizeDispatchCommand attachments", () => {
363363} ) ;
364364
365365describe ( "question attachments" , ( ) => {
366+ it . effect ( "enforces the total response limit and claims duplicate filenames independently" , ( ) =>
367+ Effect . gen ( function * ( ) {
368+ const config = yield * ServerConfig . ServerConfig ;
369+ const id = `pending-${ attachmentUuid } -txt` ;
370+ NodeFS . writeFileSync ( NodePath . join ( config . attachmentsDir , `${ id } .txt` ) , "report" ) ;
371+ const attachment = {
372+ type : "file" as const ,
373+ id,
374+ name : 'notes "final" ü.txt' ,
375+ mimeType : "text/plain" ,
376+ sizeBytes : 6 ,
377+ } ;
378+ const command : ClientOrchestrationCommand = {
379+ type : "thread.user-input.respond" ,
380+ commandId : CommandId . make ( "answer-cap" ) ,
381+ threadId : ThreadId . make ( "thread-1" ) ,
382+ requestId : ApprovalRequestId . make ( "request-cap" ) ,
383+ answers : { first : "" , second : "" } ,
384+ createdAt : "2026-08-01T00:00:00.000Z" ,
385+ attachmentsByQuestionId : {
386+ first : Array . from ( { length : 4 } , ( ) => attachment ) ,
387+ second : Array . from ( { length : 5 } , ( ) => attachment ) ,
388+ } ,
389+ } ;
390+ const failure = yield * normalizeDispatchCommand ( command ) . pipe ( Effect . flip ) ;
391+ expect ( failure . message ) . toContain ( "up to 8" ) ;
392+ expect ( NodeFS . readdirSync ( config . attachmentsDir ) ) . toEqual ( [ `${ id } .txt` ] ) ;
393+ const accepted = {
394+ ...command ,
395+ attachmentsByQuestionId : {
396+ ...command . attachmentsByQuestionId ,
397+ second : Array . from ( { length : 4 } , ( ) => attachment ) ,
398+ } ,
399+ } ;
400+ const normalized = yield * normalizeDispatchCommand ( accepted ) ;
401+ if ( normalized . type !== "thread.user-input.respond" ) throw new Error ( "Wrong command" ) ;
402+ const attachments = Object . values ( normalized . attachmentsByQuestionId ! ) . flat ( ) ;
403+ expect ( attachments ) . toHaveLength ( 8 ) ;
404+ expect ( new Set ( attachments . map ( ( item ) => item . id ) ) . size ) . toBe ( 8 ) ;
405+ for ( const item of attachments ) {
406+ expect ( item . name ) . toBe ( attachment . name ) ;
407+ expect (
408+ NodeFS . readFileSync ( NodePath . join ( config . attachmentsDir , `${ item . id } .txt` ) , "utf8" ) ,
409+ ) . toBe ( "report" ) ;
410+ }
411+ yield * cleanupFailedUploadedAttachments ( accepted , normalized ) ;
412+ expect ( NodeFS . readdirSync ( config . attachmentsDir ) ) . toEqual ( [ `${ id } .txt` ] ) ;
413+ } ) . pipe ( Effect . provide ( testLayer ) ) ,
414+ ) ;
366415 it ( "requires uploaded metadata for question images, including pasted images" , ( ) => {
367416 expect (
368417 isClientCommand ( {
0 commit comments