From 5b49734f3e2bba38e689f274d39e5ff3b52f529d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 29 May 2026 17:39:29 +0300 Subject: askcli: keep ask add successful when alias assignment fails --- internal/askcli/command_info_add_test.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'internal/askcli/command_info_add_test.go') diff --git a/internal/askcli/command_info_add_test.go b/internal/askcli/command_info_add_test.go index b6f0bd0..b918518 100644 --- a/internal/askcli/command_info_add_test.go +++ b/internal/askcli/command_info_add_test.go @@ -342,6 +342,12 @@ func TestHandleAdd_Success(t *testing.T) { } } +// TestHandleAdd_AliasAssignmentFailure verifies that when alias assignment +// fails after the task is already created in Taskwarrior, the command still +// exits 0 and prints "created task " on stdout (with the UUID as +// fallback identifier), while emitting the failure as a warning on stderr. +// This prevents the previous bug where the user saw exit 1 and retried, +// creating duplicate tasks. func TestHandleAdd_AliasAssignmentFailure(t *testing.T) { oldRoot := taskAliasCacheRoot taskAliasCacheRoot = func() (string, error) { return "", io.ErrUnexpectedEOF } @@ -354,14 +360,17 @@ func TestHandleAdd_AliasAssignmentFailure(t *testing.T) { var stdout, stderr bytes.Buffer code, _ := d.Dispatch(context.Background(), []string{"add", "New task description"}, nil, &stdout, &stderr) - if code != 1 { - t.Fatalf("add code = %d, want 1", code) + if code != 0 { + t.Fatalf("add code = %d, want 0 (task was created, alias failure is non-fatal)", code) + } + if got := strings.TrimSpace(stdout.String()); got != "created task abc-123-def" { + t.Fatalf("stdout = %q, want \"created task abc-123-def\" (UUID fallback)", stdout.String()) } - if stdout.Len() != 0 { - t.Fatalf("stdout = %q, want empty output on alias assignment failure", stdout.String()) + if !strings.Contains(stderr.String(), "warning: failed to assign task alias") { + t.Fatalf("stderr = %q, want warning about alias assignment failure", stderr.String()) } - if !strings.Contains(stderr.String(), "failed to assign task alias") { - t.Fatalf("stderr = %q, want alias assignment failure", stderr.String()) + if strings.Contains(stderr.String(), "error: failed to assign task alias") { + t.Fatalf("stderr = %q, alias failure should be a warning, not an error", stderr.String()) } } -- cgit v1.2.3