@@ -374,6 +374,48 @@ func TestCommentUpdate(t *testing.T) {
374374 }
375375 })
376376
377+ t .Run ("preserves existing body when only attach is provided" , func (t * testing.T ) {
378+ tempDir := t .TempDir ()
379+ attachPath := writeTestAttachmentFile (t , tempDir , "update.txt" , "update" )
380+
381+ mock := NewMockClient ()
382+ mock .GetResponse = & client.APIResponse {
383+ StatusCode : 200 ,
384+ Data : map [string ]any {
385+ "id" : "comment-1" ,
386+ "body" : map [string ]any {
387+ "html" : "<p>Existing comment</p>" ,
388+ "plain_text" : "Existing comment" ,
389+ },
390+ },
391+ }
392+ mock .PatchResponse = & client.APIResponse {StatusCode : 200 , Data : map [string ]any {"id" : "comment-1" }}
393+ mock .UploadFileResponse = & client.APIResponse {StatusCode : 200 , Data : map [string ]any {"attachable_sgid" : "sgid-update" }}
394+
395+ SetTestModeWithSDK (mock )
396+ SetTestConfig ("token" , "account" , "https://api.example.com" )
397+ defer resetTest ()
398+
399+ commentUpdateCard = "42"
400+ commentUpdateAttach = []string {attachPath }
401+ err := commentUpdateCmd .RunE (commentUpdateCmd , []string {"comment-1" })
402+ commentUpdateCard = ""
403+ commentUpdateAttach = nil
404+
405+ assertExitCode (t , err , 0 )
406+ if len (mock .GetCalls ) == 0 || mock .GetCalls [0 ].Path != "/cards/42/comments/comment-1" {
407+ t .Fatalf ("expected existing comment fetch before update, got %#v" , mock .GetCalls )
408+ }
409+ body := mock .PatchCalls [0 ].Body .(map [string ]any )
410+ expected := strings .Join ([]string {
411+ "<p>Existing comment</p>" ,
412+ `<action-text-attachment sgid="sgid-update"></action-text-attachment>` ,
413+ }, "\n " )
414+ if body ["body" ] != expected {
415+ t .Errorf ("expected body %q, got %v" , expected , body ["body" ])
416+ }
417+ })
418+
377419 t .Run ("requires card flag" , func (t * testing.T ) {
378420 mock := NewMockClient ()
379421 SetTestModeWithSDK (mock )
0 commit comments