@@ -92,28 +92,41 @@ func TestBuildAttachmentReadsHEICData(t *testing.T) {
9292 }
9393}
9494
95- func TestBuildAttachmentRejectsChangedFiles (t * testing.T ) {
95+ func TestBuildAttachmentAllowsCachedSizeMismatch (t * testing.T ) {
9696 tmpDir := t .TempDir ()
9797 path := filepath .Join (tmpDir , "vpn_error.png" )
98- if err := os .WriteFile (path , testPNGData , 0o644 ); err != nil {
98+ data := append ([]byte {}, testPNGData ... )
99+ data = append (data , 0x00 , 0x01 , 0x02 )
100+ if err := os .WriteFile (path , data , 0o644 ); err != nil {
99101 t .Fatalf ("write test attachment: %v" , err )
100102 }
101103
102- _ , err := validateMetadata ([]AttachmentMetadata {{
104+ raw , err := json . Marshal ([]AttachmentMetadata {{
103105 Name : "vpn_error.png" ,
104106 Path : path ,
105107 MimeType : "image/png" ,
106- SizeBytes : 999 ,
108+ SizeBytes : - 1 ,
107109 }})
108- if err == nil {
109- t .Fatalf ("expected size mismatch to fail" )
110+ if err != nil {
111+ t .Fatalf ("marshal attachments: %v" , err )
112+ }
113+
114+ attachments , err := LoadAttachments (string (raw ))
115+ if err != nil {
116+ t .Fatalf ("LoadAttachments returned error: %v" , err )
117+ }
118+ if len (attachments ) != 1 {
119+ t .Fatalf ("expected 1 attachment, got %d" , len (attachments ))
120+ }
121+ if string (attachments [0 ].Data ) != string (data ) {
122+ t .Fatalf ("attachment data mismatch: got %q want %q" , string (attachments [0 ].Data ), string (data ))
110123 }
111124}
112125
113- func TestBuildAttachmentRejectsZeroSizeBypass (t * testing.T ) {
126+ func TestBuildAttachmentRejectsEmptyFiles (t * testing.T ) {
114127 tmpDir := t .TempDir ()
115128 path := filepath .Join (tmpDir , "vpn_error.png" )
116- if err := os .WriteFile (path , testPNGData , 0o644 ); err != nil {
129+ if err := os .WriteFile (path , nil , 0o644 ); err != nil {
117130 t .Fatalf ("write test attachment: %v" , err )
118131 }
119132
@@ -123,8 +136,8 @@ func TestBuildAttachmentRejectsZeroSizeBypass(t *testing.T) {
123136 MimeType : "image/png" ,
124137 SizeBytes : 0 ,
125138 }})
126- if err == nil {
127- t .Fatalf ("expected missing exact size to fail" )
139+ if err == nil || ! strings . Contains ( err . Error (), "must not be empty" ) {
140+ t .Fatalf ("expected empty attachment error, got %v" , err )
128141 }
129142}
130143
@@ -169,7 +182,7 @@ func TestLoadAttachmentsRejectsTotalSizeOverLimit(t *testing.T) {
169182 Name : "huge.png" ,
170183 Path : path ,
171184 MimeType : "image/png" ,
172- SizeBytes : maxAttachmentBytes + 1 ,
185+ SizeBytes : int64 ( len ( testPNGData )) ,
173186 }})
174187 if err != nil {
175188 t .Fatalf ("marshal attachments: %v" , err )
0 commit comments