From 58b26bdddaa6454c60f5ab22c4bc551e7ab81959 Mon Sep 17 00:00:00 2001 From: Vasist10 <155972527+Vasist10@users.noreply.github.com> Date: Fri, 23 Jan 2026 16:57:16 +0530 Subject: [PATCH] Fix dependency removal when multiple dependencies exist --- backend/utils/tw/edit_task.go | 11 +++-- backend/utils/tw/modify_task.go | 11 +++-- backend/utils/tw/taskwarrior_test.go | 71 ++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index 3207a5b6..580e1df3 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -96,9 +96,14 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st } // Handle depends - always set to ensure clearing works - dependsStr := strings.Join(depends, ",") - if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil { - return fmt.Errorf("failed to set depends %s: %v", dependsStr, err) + if err := utils.ExecCommand("task", taskID, "modify", "depends:"); err != nil { + return fmt.Errorf("failed to clear dependencies: %v", err) + } + if len(depends) > 0 { + dependsStr := strings.Join(depends, ",") + if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil { + return fmt.Errorf("failed to set dependencies %s: %v", dependsStr, err) + } } // Handle due date diff --git a/backend/utils/tw/modify_task.go b/backend/utils/tw/modify_task.go index e1050455..0172de4c 100644 --- a/backend/utils/tw/modify_task.go +++ b/backend/utils/tw/modify_task.go @@ -48,9 +48,14 @@ func ModifyTaskInTaskwarrior(uuid, description, project, priority, status, due, } // Handle dependencies - always set to ensure clearing works - dependsStr := strings.Join(depends, ",") - if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil { - return fmt.Errorf("failed to set dependencies %s: %v", dependsStr, err) + if err := utils.ExecCommand("task", taskID, "modify", "depends:"); err != nil { + return fmt.Errorf("failed to clear dependencies: %v", err) + } + if len(depends) > 0 { + dependsStr := strings.Join(depends, ",") + if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil { + return fmt.Errorf("failed to set dependencies %s: %v", dependsStr, err) + } } // escapedStatus := fmt.Sprintf(`status:%s`, strings.ReplaceAll(status, `"`, `\"`)) diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index 1a81451e..e980db18 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -236,3 +236,74 @@ func TestModifyTaskWithTags(t *testing.T) { fmt.Println("Modify task with tags passed") } } + +func TestRemoveDependencyFromMultipleDependencies(t *testing.T) { + taskID := "taskuuid" + email := "email" + secret := "encryptionSecret" + uuid := "uuid" + initialDeps := []string{"uuid-1", "uuid-2", "uuid-3"} + updatedDeps := []string{"uuid-1", "uuid-3"} + + err := ModifyTaskInTaskwarrior( + uuid, + "Test Task", + "project", + "H", + "pending", + "2025-03-03", + email, + secret, + taskID, + []string{}, + initialDeps, + ) + if err != nil { + t.Fatalf("failed to set initial dependencies: %v", err) + } + + err = ModifyTaskInTaskwarrior( + uuid, + "Test Task", + "project", + "H", + "pending", + "2025-03-03", + email, + secret, + taskID, + []string{}, + updatedDeps, + ) + if err != nil { + t.Fatalf("failed to update dependencies: %v", err) + } + tasks, err := ExportTasks("./") + if err != nil { + t.Fatalf("failed to export tasks: %v", err) + } + var found bool + expected := map[string]bool{ + "uuid-1": true, + "uuid-3": true, + } + + for _, task := range tasks { + if task.UUID == taskID { + found = true + + if len(task.Depends) != len(updatedDeps) { + t.Fatalf("expected %d dependencies, got %d", len(updatedDeps), len(task.Depends)) + } + + for _, d := range task.Depends { + if !expected[d] { + t.Fatalf("unexpected dependency found: %s", d) + } + } + } + } + if !found { + t.Fatalf("task %s not found in export", taskID) + } +}