From b67069c110c210b05507fca839d45b43431f5e86 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 26 Mar 2026 23:45:09 +0200 Subject: askcli: resolve aliases for selector task 0b9480fe-ec1b-4c0e-a8b0-88f1f08b56d3 --- internal/askcli/command_info_add_test.go | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (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 9bc13df..46996f7 100644 --- a/internal/askcli/command_info_add_test.go +++ b/internal/askcli/command_info_add_test.go @@ -4,8 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" "strings" "testing" + "time" ) func TestHandleInfo_Success(t *testing.T) { @@ -34,6 +36,42 @@ func TestHandleInfo_Success(t *testing.T) { } } +func TestHandleInfo_AliasSelector(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "test-uuid", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + + jsonData := `[{"uuid":"test-uuid","description":"Test task","status":"pending","priority":"H","tags":["cli"],"urgency":15.0,"depends":[]}]` + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + if len(args) > 0 && strings.HasPrefix(args[0], "uuid:test-uuid") { + io.WriteString(stdout, jsonData) + } + return 0, nil + }}) + + var stdout, stderr bytes.Buffer + code, _ := d.Dispatch(context.Background(), []string{"info", "0"}, nil, &stdout, &stderr) + if code != 0 { + t.Fatalf("info code = %d, want 0", code) + } + if !strings.Contains(stdout.String(), "test-uuid") { + t.Fatalf("stdout = %q, want resolved UUID", stdout.String()) + } +} + func TestHandleInfo_NumericID(t *testing.T) { d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { return 0, nil -- cgit v1.2.3