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_dep_test.go | 70 ++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'internal/askcli/command_dep_test.go') diff --git a/internal/askcli/command_dep_test.go b/internal/askcli/command_dep_test.go index 6139afa..8045df3 100644 --- a/internal/askcli/command_dep_test.go +++ b/internal/askcli/command_dep_test.go @@ -4,13 +4,24 @@ import ( "bytes" "context" "io" + "path/filepath" "strings" "testing" + "time" ) func TestHandleDep_AddSuccess(t *testing.T) { var capturedArgs []string d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + if len(args) == 2 && args[1] == "export" { + switch args[0] { + case "uuid:uuid-1": + io.WriteString(stdout, `[{"uuid":"uuid-1","description":"Task","status":"pending","priority":"M","tags":[],"urgency":10,"depends":[]}]`) + case "uuid:uuid-2": + io.WriteString(stdout, `[{"uuid":"uuid-2","description":"Task","status":"pending","priority":"M","tags":[],"urgency":10,"depends":[]}]`) + } + return 0, nil + } capturedArgs = args return 0, nil }}) @@ -30,6 +41,15 @@ func TestHandleDep_AddSuccess(t *testing.T) { func TestHandleDep_RmSuccess(t *testing.T) { d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + if len(args) == 2 && args[1] == "export" { + switch args[0] { + case "uuid:uuid-1": + io.WriteString(stdout, `[{"uuid":"uuid-1","description":"Task","status":"pending","priority":"M","tags":[],"urgency":10,"depends":[]}]`) + case "uuid:uuid-2": + io.WriteString(stdout, `[{"uuid":"uuid-2","description":"Task","status":"pending","priority":"M","tags":[],"urgency":10,"depends":[]}]`) + } + return 0, nil + } return 0, nil }}) var stdout, stderr bytes.Buffer @@ -84,8 +104,12 @@ func TestHandleDep_AcceptUUIDPrefix(t *testing.T) { var capturedArgs []string export := `[{"uuid":"uuid-1","description":"T","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + if len(args) == 2 && args[1] == "export" { + capturedArgs = args + io.WriteString(stdout, export) + return 0, nil + } capturedArgs = args - io.WriteString(stdout, export) return 0, nil }}) var stdout, stderr bytes.Buffer @@ -100,6 +124,50 @@ func TestHandleDep_AcceptUUIDPrefix(t *testing.T) { } } +func TestHandleDep_AliasSelectors(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: 2, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + {UUID: "uuid-2", Alias: "1", CreatedAt: nowTaskAliasCache()}, + }, + }) + + var capturedArgs []string + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + if len(args) == 2 && args[1] == "export" { + switch args[0] { + case "uuid:uuid-1": + io.WriteString(stdout, `[{"uuid":"uuid-1","description":"T1","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`) + case "uuid:uuid-2": + io.WriteString(stdout, `[{"uuid":"uuid-2","description":"T2","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`) + } + return 0, nil + } + capturedArgs = args + return 0, nil + }}) + + var stdout, stderr bytes.Buffer + code, _ := d.Dispatch(context.Background(), []string{"dep", "add", "0", "1"}, nil, &stdout, &stderr) + if code != 0 { + t.Fatalf("dep add code = %d stderr = %q", code, stderr.String()) + } + if len(capturedArgs) < 3 || capturedArgs[0] != "uuid:uuid-1" || capturedArgs[2] != "depends:uuid-2" { + t.Fatalf("capturedArgs = %v, want resolved alias UUIDs", capturedArgs) + } +} + func TestHandleDep_NumericUUID(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