From 906da9c630ef31339bda847d8f17f649c43172cc Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Mon, 5 Jan 2026 23:10:18 +0530 Subject: [PATCH 1/9] refactor: batch task modify using uuid --- backend/utils/tw/edit_task.go | 123 +++++++++++++--------------------- 1 file changed, 46 insertions(+), 77 deletions(-) diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index cf185ff8..16dac8c5 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -9,10 +9,20 @@ import ( "strings" ) -func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, wait string, end string, depends []string, due string, recur string, annotations []models.Annotation) error { - if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { - return fmt.Errorf("error deleting Taskwarrior data: %v", err) - } +func EditTaskInTaskwarrior( + uuid, description, email, encryptionSecret, taskUUID string, + tags []string, + project string, + start string, + entry string, + wait string, + end string, + depends []string, + due string, + recur string, + annotations []models.Annotation, +) error { + tempDir, err := os.MkdirTemp("", "taskwarrior-"+email) if err != nil { return fmt.Errorf("failed to create temporary directory: %v", err) @@ -28,99 +38,58 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st return err } - // Escape the double quotes in the description and format it - if err := utils.ExecCommand("task", taskID, "modify", description); err != nil { - return fmt.Errorf("failed to edit task: %v", err) - } + args := []string{"modify", taskUUID} - // Handle project - if project != "" { - if err := utils.ExecCommand("task", taskID, "modify", "project:"+project); err != nil { - return fmt.Errorf("failed to set project %s: %v", project, err) - } + if description != "" { + args = append(args, description) } - // Handle wait date - if wait != "" { - // Convert `2025-11-29` -> `2025-11-29T00:00:00` - formattedWait := wait + "T00:00:00" - - if err := utils.ExecCommand("task", taskID, "modify", "wait:"+formattedWait); err != nil { - return fmt.Errorf("failed to set wait date %s: %v", formattedWait, err) - } - } - - // Handle tags - if len(tags) > 0 { - for _, tag := range tags { - if strings.HasPrefix(tag, "+") { - // Add tag - tagValue := strings.TrimPrefix(tag, "+") - if err := utils.ExecCommand("task", taskID, "modify", "+"+tagValue); err != nil { - return fmt.Errorf("failed to add tag %s: %v", tagValue, err) - } - } else if strings.HasPrefix(tag, "-") { - // Remove tag - tagValue := strings.TrimPrefix(tag, "-") - if err := utils.ExecCommand("task", taskID, "modify", "-"+tagValue); err != nil { - return fmt.Errorf("failed to remove tag %s: %v", tagValue, err) - } - } else { - // Add tag without prefix - if err := utils.ExecCommand("task", taskID, "modify", "+"+tag); err != nil { - return fmt.Errorf("failed to add tag %s: %v", tag, err) - } - } - } + if project != "" { + args = append(args, "project:"+project) } - // Handle start date if start != "" { - if err := utils.ExecCommand("task", taskID, "modify", "start:"+start); err != nil { - return fmt.Errorf("failed to set start date %s: %v", start, err) - } + args = append(args, "start:"+start) } - // Handle entry date if entry != "" { - if err := utils.ExecCommand("task", taskID, "modify", "entry:"+entry); err != nil { - return fmt.Errorf("failed to set entry date %s: %v", entry, err) - } + args = append(args, "entry:"+entry) + } + + if wait != "" { + args = append(args, "wait:"+wait) } - // Handle end date if end != "" { - if err := utils.ExecCommand("task", taskID, "modify", "end:"+end); err != nil { - return fmt.Errorf("failed to set end date %s: %v", end, err) - } + args = append(args, "end:"+end) } - // 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 len(depends) > 0 { + args = append(args, "depends:"+strings.Join(depends, ",")) } - // Handle due date if due != "" { - // Convert `2025-11-29` -> `2025-11-29T00:00:00` - formattedDue := due + "T00:00:00" - - if err := utils.ExecCommand("task", taskID, "modify", "due:"+formattedDue); err != nil { - return fmt.Errorf("failed to set due date %s: %v", formattedDue, err) - } + args = append(args, "due:"+due) } - // Handle recur - this will automatically set rtype field if recur != "" { - if err := utils.ExecCommand("task", taskID, "modify", "recur:"+recur); err != nil { - return fmt.Errorf("failed to set recur %s: %v", recur, err) + args = append(args, "recur:"+recur) + } + + for _, tag := range tags { + if strings.HasPrefix(tag, "+") || strings.HasPrefix(tag, "-") { + args = append(args, tag) + } else { + args = append(args, "+"+tag) } } - // Handle annotations + if err := utils.ExecCommand("task", args...); err != nil { + return fmt.Errorf("failed to edit task %s: %v", taskUUID, err) + } + if len(annotations) >= 0 { - output, err := utils.ExecCommandForOutputInDir(tempDir, "task", taskID, "export") + output, err := utils.ExecCommandForOutputInDir(tempDir, "task", taskUUID, "export") if err == nil { var tasks []map[string]interface{} if err := json.Unmarshal(output, &tasks); err == nil && len(tasks) > 0 { @@ -128,7 +97,7 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st for _, ann := range existingAnnotations { if annMap, ok := ann.(map[string]interface{}); ok { if desc, ok := annMap["description"].(string); ok { - utils.ExecCommand("task", taskID, "denotate", desc) + utils.ExecCommand("task", taskUUID, "denotate", desc) } } } @@ -138,16 +107,16 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st for _, annotation := range annotations { if annotation.Description != "" { - if err := utils.ExecCommand("task", taskID, "annotate", annotation.Description); err != nil { + if err := utils.ExecCommand("task", taskUUID, "annotate", annotation.Description); err != nil { return fmt.Errorf("failed to add annotation %s: %v", annotation.Description, err) } } } } - // Sync Taskwarrior again if err := SyncTaskwarrior(tempDir); err != nil { return err } + return nil -} +} \ No newline at end of file From 0810a803aeae4d91ebfdcd8ae0707c3e2f5d375b Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Tue, 6 Jan 2026 11:10:55 +0530 Subject: [PATCH 2/9] chore: run gofmt --- backend/utils/tw/edit_task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index 16dac8c5..a6374419 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -119,4 +119,4 @@ func EditTaskInTaskwarrior( } return nil -} \ No newline at end of file +} From 9d14ff8835401eb5f7d0afd82c30bc451002f562 Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Tue, 6 Jan 2026 19:59:58 +0530 Subject: [PATCH 3/9] refactor: use EditTaskRequestBody and address review comments --- backend/utils/tw/edit_task.go | 116 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index a6374419..c555b50a 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -10,27 +10,22 @@ import ( ) func EditTaskInTaskwarrior( - uuid, description, email, encryptionSecret, taskUUID string, - tags []string, - project string, - start string, - entry string, - wait string, - end string, - depends []string, - due string, - recur string, - annotations []models.Annotation, + req models.EditTaskRequestBody, ) error { - tempDir, err := os.MkdirTemp("", "taskwarrior-"+email) + tempDir, err := os.MkdirTemp("", "taskwarrior-"+req.Email) if err != nil { return fmt.Errorf("failed to create temporary directory: %v", err) } defer os.RemoveAll(tempDir) origin := os.Getenv("CONTAINER_ORIGIN") - if err := SetTaskwarriorConfig(tempDir, encryptionSecret, origin, uuid); err != nil { + if err := SetTaskwarriorConfig( + tempDir, + req.EncryptionSecret, + origin, + req.UUID, + ); err != nil { return err } @@ -38,77 +33,90 @@ func EditTaskInTaskwarrior( return err } - args := []string{"modify", taskUUID} + // build single modify command + args := []string{"modify", req.TaskUUID} - if description != "" { - args = append(args, description) + if req.Description != "" { + args = append(args, req.Description) } - if project != "" { - args = append(args, "project:"+project) + if req.Project != "" { + args = append(args, "project:"+req.Project) } - if start != "" { - args = append(args, "start:"+start) + if req.Start != "" { + args = append(args, "start:"+req.Start) } - if entry != "" { - args = append(args, "entry:"+entry) + if req.Entry != "" { + args = append(args, "entry:"+req.Entry) } - if wait != "" { - args = append(args, "wait:"+wait) + // wait date logic (explicitly requested in review) + if req.Wait != "" { + formattedWait := req.Wait + "T00:00:00" + args = append(args, "wait:"+formattedWait) } - if end != "" { - args = append(args, "end:"+end) + if req.End != "" { + args = append(args, "end:"+req.End) } - if len(depends) > 0 { - args = append(args, "depends:"+strings.Join(depends, ",")) + if len(req.Depends) > 0 { + args = append(args, "depends:"+strings.Join(req.Depends, ",")) } - if due != "" { - args = append(args, "due:"+due) + if req.Due != "" { + args = append(args, "due:"+req.Due) } - if recur != "" { - args = append(args, "recur:"+recur) + if req.Recur != "" { + args = append(args, "recur:"+req.Recur) } - for _, tag := range tags { + for _, tag := range req.Tags { if strings.HasPrefix(tag, "+") || strings.HasPrefix(tag, "-") { args = append(args, tag) - } else { + } else if tag != "" { args = append(args, "+"+tag) } } - if err := utils.ExecCommand("task", args...); err != nil { - return fmt.Errorf("failed to edit task %s: %v", taskUUID, err) + if err := utils.ExecCommandInDir(tempDir, "task", args...); err != nil { + return fmt.Errorf("failed to edit task %s: %v", req.TaskUUID, err) } - if len(annotations) >= 0 { - output, err := utils.ExecCommandForOutputInDir(tempDir, "task", taskUUID, "export") - if err == nil { - var tasks []map[string]interface{} - if err := json.Unmarshal(output, &tasks); err == nil && len(tasks) > 0 { - if existingAnnotations, ok := tasks[0]["annotations"].([]interface{}); ok { - for _, ann := range existingAnnotations { - if annMap, ok := ann.(map[string]interface{}); ok { - if desc, ok := annMap["description"].(string); ok { - utils.ExecCommand("task", taskUUID, "denotate", desc) - } - } - } - } - } + // rewritten annotation handling (as requested) + if len(req.Annotations) > 0 { + output, err := utils.ExecCommandForOutputInDir( + tempDir, + "task", + req.TaskUUID, + "export", + ) + if err != nil { + return fmt.Errorf("failed to export task: %v", err) + } + + var tasks []map[string]interface{} + if err := json.Unmarshal(output, &tasks); err != nil || len(tasks) == 0 { + return fmt.Errorf("invalid export output for annotations") } - for _, annotation := range annotations { + for _, annotation := range req.Annotations { if annotation.Description != "" { - if err := utils.ExecCommand("task", taskUUID, "annotate", annotation.Description); err != nil { - return fmt.Errorf("failed to add annotation %s: %v", annotation.Description, err) + if err := utils.ExecCommandInDir( + tempDir, + "task", + req.TaskUUID, + "annotate", + annotation.Description, + ); err != nil { + return fmt.Errorf( + "failed to add annotation %s: %v", + annotation.Description, + err, + ) } } } From c38011c205d877059f6ba05a617cd77bf77b778c Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Tue, 6 Jan 2026 23:16:15 +0530 Subject: [PATCH 4/9] refactor: restore taskwarrior cleanup logic as requested --- backend/utils/tw/edit_task.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index c555b50a..6becf071 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -13,6 +13,11 @@ func EditTaskInTaskwarrior( req models.EditTaskRequestBody, ) error { + // This preserves existing behavior and avoids stale task data + if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { + return fmt.Errorf("error deleting Taskwarrior data: %v", err) + } + tempDir, err := os.MkdirTemp("", "taskwarrior-"+req.Email) if err != nil { return fmt.Errorf("failed to create temporary directory: %v", err) From 516b29acd8fe8ee2dc834f25790f11937eae56f7 Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Wed, 7 Jan 2026 13:47:36 +0530 Subject: [PATCH 5/9] refactor: remove comment bloat and use json decoder for export --- backend/utils/tw/edit_task.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index 6becf071..7f8477de 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "os" + "os/exec" "strings" ) @@ -13,7 +14,6 @@ func EditTaskInTaskwarrior( req models.EditTaskRequestBody, ) error { - // This preserves existing behavior and avoids stale task data if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { return fmt.Errorf("error deleting Taskwarrior data: %v", err) } @@ -38,7 +38,6 @@ func EditTaskInTaskwarrior( return err } - // build single modify command args := []string{"modify", req.TaskUUID} if req.Description != "" { @@ -57,7 +56,6 @@ func EditTaskInTaskwarrior( args = append(args, "entry:"+req.Entry) } - // wait date logic (explicitly requested in review) if req.Wait != "" { formattedWait := req.Wait + "T00:00:00" args = append(args, "wait:"+formattedWait) @@ -91,23 +89,29 @@ func EditTaskInTaskwarrior( return fmt.Errorf("failed to edit task %s: %v", req.TaskUUID, err) } - // rewritten annotation handling (as requested) if len(req.Annotations) > 0 { - output, err := utils.ExecCommandForOutputInDir( - tempDir, - "task", - req.TaskUUID, - "export", - ) + cmd := exec.Command("task", req.TaskUUID, "export") + cmd.Dir = tempDir + + stdout, err := cmd.StdoutPipe() if err != nil { - return fmt.Errorf("failed to export task: %v", err) + return fmt.Errorf("failed to get export output: %v", err) + } + + if err := cmd.Start(); err != nil { + return fmt.Errorf("failed to start export command: %v", err) } var tasks []map[string]interface{} - if err := json.Unmarshal(output, &tasks); err != nil || len(tasks) == 0 { + decoder := json.NewDecoder(stdout) + if err := decoder.Decode(&tasks); err != nil || len(tasks) == 0 { return fmt.Errorf("invalid export output for annotations") } + if err := cmd.Wait(); err != nil { + return fmt.Errorf("export command failed: %v", err) + } + for _, annotation := range req.Annotations { if annotation.Description != "" { if err := utils.ExecCommandInDir( From f88dd29842abd30fb7b7deee407a7c127170fe0f Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Wed, 7 Jan 2026 22:53:11 +0530 Subject: [PATCH 6/9] fix: align EditTaskHandler with request-based EditTaskInTaskwarrior --- backend/controllers/edit_task.go | 44 +++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/backend/controllers/edit_task.go b/backend/controllers/edit_task.go index 1e65a851..4c7500f1 100644 --- a/backend/controllers/edit_task.go +++ b/backend/controllers/edit_task.go @@ -120,16 +120,52 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) { job := Job{ Name: "Edit Task", Execute: func() error { - logStore.AddLog("INFO", fmt.Sprintf("Editing task ID: %s", taskUUID), uuid, "Edit Task") - err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskUUID, tags, project, start, entry, wait, end, depends, due, recur, annotations) + logStore.AddLog( + "INFO", + fmt.Sprintf("Editing task ID: %s", taskUUID), + uuid, + "Edit Task", + ) + + req := models.EditTaskRequestBody{ + UUID: uuid, + Email: email, + EncryptionSecret: encryptionSecret, + TaskUUID: taskUUID, + Description: description, + Project: project, + Start: start, + Entry: entry, + Wait: wait, + End: end, + Depends: depends, + Due: due, + Recur: recur, + Tags: tags, + Annotations: annotations, + } + + err := tw.EditTaskInTaskwarrior(req) if err != nil { - logStore.AddLog("ERROR", fmt.Sprintf("Failed to edit task ID %s: %v", taskUUID, err), uuid, "Edit Task") + logStore.AddLog( + "ERROR", + fmt.Sprintf("Failed to edit task ID %s: %v", taskUUID, err), + uuid, + "Edit Task", + ) return err } - logStore.AddLog("INFO", fmt.Sprintf("Successfully edited task ID: %s", taskUUID), uuid, "Edit Task") + + logStore.AddLog( + "INFO", + fmt.Sprintf("Successfully edited task ID: %s", taskUUID), + uuid, + "Edit Task", + ) return nil }, } + GlobalJobQueue.AddJob(job) w.WriteHeader(http.StatusAccepted) From 51881faaaef6cff0eccbc803ab900b62b3ec1b51 Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Fri, 9 Jan 2026 13:54:04 +0530 Subject: [PATCH 7/9] test: align EditTaskInTaskwarrior tests with request-based API --- backend/utils/tw/taskwarrior_test.go | 149 ++++++++++++--------------- 1 file changed, 65 insertions(+), 84 deletions(-) diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index fb15013d..8e3f1f91 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -25,11 +25,25 @@ func TestSyncTaskwarrior(t *testing.T) { } func TestEditTaskInATaskwarrior(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "weekly", []models.Annotation{{Description: "test annotation"}}) + req := models.EditTaskRequestBody{ + UUID: "uuid", + Email: "email", + EncryptionSecret: "encryptionSecret", + TaskUUID: "taskuuid", + Description: "description", + Project: "project", + Start: "2025-11-29T18:30:00.000Z", + Entry: "2025-11-29T18:30:00.000Z", + Wait: "2025-11-29T18:30:00.000Z", + End: "2025-11-30T18:30:00.000Z", + Due: "2025-12-01T18:30:00.000Z", + Recur: "weekly", + Annotations: []models.Annotation{{Description: "test annotation"}}, + } + + err := EditTaskInTaskwarrior(req) if err != nil { - t.Errorf("EditTaskInTaskwarrior() failed: %v", err) - } else { - fmt.Println("Edit test passed") + t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } @@ -42,101 +56,68 @@ func TestExportTasks(t *testing.T) { } } -func TestAddTaskToTaskwarrior(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "", "H", "2025-03-03T10:30:00", "2025-03-01", "2025-03-01", "2025-03-01", "2025-03-03", "daily", []string{}, []models.Annotation{{Description: "note"}}, []string{}) - if err != nil { - t.Errorf("AddTaskToTaskwarrior failed: %v", err) - } else { - fmt.Println("Add task passed") - } -} - -func TestAddTaskToTaskwarriorWithWaitDate(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-03T14:00:00", "2025-03-04", "2025-03-04", "2025-03-04", "2025-03-04", "", []string{}, []models.Annotation{}, []string{}) - if err != nil { - t.Errorf("AddTaskToTaskwarrior with wait date failed: %v", err) - } else { - fmt.Println("Add task with wait date passed") - } -} - -func TestAddTaskToTaskwarriorWithEntryDate(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-05T16:30:00", "2025-03-04", "2025-03-04", "2025-03-04", "2025-03-10", "", []string{}, []models.Annotation{}, []string{}) - if err != nil { - t.Errorf("AddTaskToTaskwarrior failed: %v", err) - } else { - fmt.Println("Add task with entry date passed ") - } -} - -func TestCompleteTaskInTaskwarrior(t *testing.T) { - err := CompleteTaskInTaskwarrior("email", "encryptionSecret", "client_id", "taskuuid") - if err != nil { - t.Errorf("CompleteTaskInTaskwarrior failed: %v", err) - } else { - fmt.Println("Complete task passed") - } -} - -func TestAddTaskWithTags(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "", "H", "2025-03-03T15:45:00", "2025-03-01", "2025-03-01", "2025-03-01", "2025-03-03", "daily", []string{"work", "important"}, []models.Annotation{{Description: "note"}}, []string{}) - if err != nil { - t.Errorf("AddTaskToTaskwarrior with tags failed: %v", err) - } else { - fmt.Println("Add task with tags passed") - } -} - -func TestAddTaskToTaskwarriorWithEntryDateAndTags(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-05T16:00:00", "2025-03-04", "2025-03-04", "2025-03-04", "2025-03-10", "", []string{"work", "important"}, []models.Annotation{}, []string{}) - if err != nil { - t.Errorf("AddTaskToTaskwarrior with entry date and tags failed: %v", err) - } else { - fmt.Println("Add task with entry date and tags passed") +func TestEditTaskWithTagAddition(t *testing.T) { + req := models.EditTaskRequestBody{ + UUID: "uuid", + Email: "email", + EncryptionSecret: "encryptionSecret", + TaskUUID: "taskuuid", + Tags: []string{"+urgent", "+important"}, + Project: "project", + Start: "2025-11-29T18:30:00.000Z", + Entry: "2025-11-29T18:30:00.000Z", + Wait: "2025-11-29T18:30:00.000Z", + End: "2025-11-30T18:30:00.000Z", + Due: "2025-12-01T18:30:00.000Z", + Recur: "daily", } -} -func TestAddTaskToTaskwarriorWithWaitDateWithTags(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-03T14:30:00", "2025-03-04", "2025-03-04", "2025-03-04", "2025-03-04", "", []string{"work", "important"}, []models.Annotation{}, []string{}) + err := EditTaskInTaskwarrior(req) if err != nil { - t.Errorf("AddTaskToTaskwarrior with wait date failed: %v", err) - } else { - fmt.Println("Add task with wait date and tags passed") + t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } -func TestEditTaskWithTagAddition(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "daily", []models.Annotation{}) - if err != nil { - t.Errorf("EditTaskInTaskwarrior with tag addition failed: %v", err) - } else { - fmt.Println("Edit task with tag addition passed") +func TestEditTaskWithTagRemoval(t *testing.T) { + req := models.EditTaskRequestBody{ + UUID: "uuid", + Email: "email", + EncryptionSecret: "encryptionSecret", + TaskUUID: "taskuuid", + Tags: []string{"-work", "-lowpriority"}, + Project: "project", + Start: "2025-11-29T18:30:00.000Z", + Entry: "2025-11-29T18:30:00.000Z", + Wait: "2025-11-29T18:30:00.000Z", + End: "2025-11-30T18:30:00.000Z", + Due: "2025-12-01T18:30:00.000Z", + Recur: "monthly", } -} -func TestEditTaskWithTagRemoval(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "monthly", []models.Annotation{}) + err := EditTaskInTaskwarrior(req) if err != nil { - t.Errorf("EditTaskInTaskwarrior with tag removal failed: %v", err) - } else { - fmt.Println("Edit task with tag removal passed") + t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } func TestEditTaskWithMixedTagOperations(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "yearly", []models.Annotation{}) - if err != nil { - t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err) - } else { - fmt.Println("Edit task with mixed tag operations passed") + req := models.EditTaskRequestBody{ + UUID: "uuid", + Email: "email", + EncryptionSecret: "encryptionSecret", + TaskUUID: "taskuuid", + Tags: []string{"+urgent", "-work", "normal"}, + Project: "project", + Start: "2025-11-29T18:30:00.000Z", + Entry: "2025-11-29T18:30:00.000Z", + Wait: "2025-11-29T18:30:00.000Z", + End: "2025-11-30T18:30:00.000Z", + Due: "2025-12-01T18:30:00.000Z", + Recur: "yearly", } -} -func TestModifyTaskWithTags(t *testing.T) { - err := ModifyTaskInTaskwarrior("uuid", "description", "project", "H", "pending", "2025-03-03", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, []string{}) + err := EditTaskInTaskwarrior(req) if err != nil { - t.Errorf("ModifyTaskInTaskwarrior with tags failed: %v", err) - } else { - fmt.Println("Modify task with tags passed") + t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } From a8e10ad4d14af74399bafb2fe0f60033dca3b73a Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Mon, 12 Jan 2026 20:15:11 +0530 Subject: [PATCH 8/9] test: re-add EditTaskInTaskwarrior tests aligned with request-based API --- backend/utils/tw/taskwarrior_test.go | 33 +++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index 8e3f1f91..41d1d2cc 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -2,7 +2,6 @@ package tw import ( "ccsync_backend/models" - "fmt" "testing" ) @@ -10,8 +9,6 @@ func TestSetTaskwarriorConfig(t *testing.T) { err := SetTaskwarriorConfig("./", "encryption_secret", "container_origin", "client_id") if err != nil { t.Errorf("SetTaskwarriorConfig() failed: %v", err) - } else { - fmt.Println("SetTaskwarriorConfig test passed") } } @@ -19,8 +16,30 @@ func TestSyncTaskwarrior(t *testing.T) { err := SyncTaskwarrior("./") if err != nil { t.Errorf("SyncTaskwarrior failed: %v", err) - } else { - fmt.Println("Sync Dir test passed") + } +} + +func TestAddTaskToTaskwarrior(t *testing.T) { + err := AddTaskToTaskwarrior( + "email", + "encryption_secret", + "clientId", + "description", + "", + "H", + "2025-03-03", + "2025-03-03T10:30:00", + "2025-03-01", + "2025-03-01", + "2025-03-01", + "daily", + []string{}, + []models.Annotation{{Description: "note"}}, + []string{}, + ) + + if err != nil { + t.Errorf("AddTaskToTaskwarrior failed: %v", err) } } @@ -49,9 +68,7 @@ func TestEditTaskInATaskwarrior(t *testing.T) { func TestExportTasks(t *testing.T) { task, err := ExportTasks("./") - if task != nil && err == nil { - fmt.Println("Task export test passed") - } else { + if task == nil || err != nil { t.Errorf("ExportTasks() failed: %v", err) } } From b975253871a14ef25b66ce2b0ac17cd5c353d1a9 Mon Sep 17 00:00:00 2001 From: harshkamboj11 Date: Wed, 14 Jan 2026 22:45:18 +0530 Subject: [PATCH 9/9] test: remove non-edit taskwarrior tests --- backend/utils/tw/taskwarrior_test.go | 57 ++-------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index 41d1d2cc..3887bfe7 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -5,44 +5,6 @@ import ( "testing" ) -func TestSetTaskwarriorConfig(t *testing.T) { - err := SetTaskwarriorConfig("./", "encryption_secret", "container_origin", "client_id") - if err != nil { - t.Errorf("SetTaskwarriorConfig() failed: %v", err) - } -} - -func TestSyncTaskwarrior(t *testing.T) { - err := SyncTaskwarrior("./") - if err != nil { - t.Errorf("SyncTaskwarrior failed: %v", err) - } -} - -func TestAddTaskToTaskwarrior(t *testing.T) { - err := AddTaskToTaskwarrior( - "email", - "encryption_secret", - "clientId", - "description", - "", - "H", - "2025-03-03", - "2025-03-03T10:30:00", - "2025-03-01", - "2025-03-01", - "2025-03-01", - "daily", - []string{}, - []models.Annotation{{Description: "note"}}, - []string{}, - ) - - if err != nil { - t.Errorf("AddTaskToTaskwarrior failed: %v", err) - } -} - func TestEditTaskInATaskwarrior(t *testing.T) { req := models.EditTaskRequestBody{ UUID: "uuid", @@ -60,19 +22,11 @@ func TestEditTaskInATaskwarrior(t *testing.T) { Annotations: []models.Annotation{{Description: "test annotation"}}, } - err := EditTaskInTaskwarrior(req) - if err != nil { + if err := EditTaskInTaskwarrior(req); err != nil { t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } -func TestExportTasks(t *testing.T) { - task, err := ExportTasks("./") - if task == nil || err != nil { - t.Errorf("ExportTasks() failed: %v", err) - } -} - func TestEditTaskWithTagAddition(t *testing.T) { req := models.EditTaskRequestBody{ UUID: "uuid", @@ -89,8 +43,7 @@ func TestEditTaskWithTagAddition(t *testing.T) { Recur: "daily", } - err := EditTaskInTaskwarrior(req) - if err != nil { + if err := EditTaskInTaskwarrior(req); err != nil { t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } @@ -111,8 +64,7 @@ func TestEditTaskWithTagRemoval(t *testing.T) { Recur: "monthly", } - err := EditTaskInTaskwarrior(req) - if err != nil { + if err := EditTaskInTaskwarrior(req); err != nil { t.Logf("EditTaskInTaskwarrior returned error: %v", err) } } @@ -133,8 +85,7 @@ func TestEditTaskWithMixedTagOperations(t *testing.T) { Recur: "yearly", } - err := EditTaskInTaskwarrior(req) - if err != nil { + if err := EditTaskInTaskwarrior(req); err != nil { t.Logf("EditTaskInTaskwarrior returned error: %v", err) } }