summaryrefslogtreecommitdiff
path: root/internal/askcli/command_complete_uuids_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-08 10:17:56 +0300
committerPaul Buetow <paul@buetow.org>2026-04-08 10:17:56 +0300
commit66811bb5c21fa674b19767f34ff7d27004f838b4 (patch)
tree1535208ed3fe4ad3a0d30520d00ee1f3f015f77e /internal/askcli/command_complete_uuids_test.go
parent385278639394e3672bce678b49e51f14ac72638c (diff)
fish: complete task selectors with short aliases only
Add complete-aliases subcommand that emits tab-separated alias lines without UUID duplicates. Wire embedded Fish script (__do_task_selectors) to call complete-aliases; keep complete-uuids unchanged for scripts and tests. Made-with: Cursor
Diffstat (limited to 'internal/askcli/command_complete_uuids_test.go')
-rw-r--r--internal/askcli/command_complete_uuids_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/askcli/command_complete_uuids_test.go b/internal/askcli/command_complete_uuids_test.go
index 92bf244..0859acc 100644
--- a/internal/askcli/command_complete_uuids_test.go
+++ b/internal/askcli/command_complete_uuids_test.go
@@ -146,6 +146,62 @@ func TestTaskCompletionSelectors_SkipsMissingAndDuplicateAliases(t *testing.T) {
}
}
+func TestTaskCompletionAliasItems_OnlyShortAliases(t *testing.T) {
+ tasks := []TaskExport{
+ {UUID: "uuid-1", Description: "First task"},
+ {UUID: "", Description: "Ignored"},
+ {UUID: "uuid-2", Description: "Second task"},
+ }
+ aliases := map[string]string{
+ "uuid-1": "0",
+ "uuid-2": "uuid-2", // same as UUID: no alias-only line (use complete-uuids for UUID)
+ }
+
+ got := taskCompletionAliasItems(tasks, aliases)
+ want := []string{
+ "0\tFirst task",
+ }
+ if strings.Join(got, "\n") != strings.Join(want, "\n") {
+ t.Fatalf("taskCompletionAliasItems = %v, want %v", got, want)
+ }
+}
+
+func TestHandleCompleteAliases_PrintsAliasesOnly(t *testing.T) {
+ dir := t.TempDir()
+ oldNow := nowTaskAliasCache
+ oldRoot := taskAliasCacheRoot
+ nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) }
+ taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
+ defer func() {
+ nowTaskAliasCache = oldNow
+ taskAliasCacheRoot = oldRoot
+ }()
+
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ want := []string{"status:pending", "export"}
+ if strings.Join(args, " ") != strings.Join(want, " ") {
+ t.Fatalf("args = %v, want %v", args, want)
+ }
+ _, _ = io.WriteString(stdout, `[{"uuid":"uuid-1","description":"First task"},{"uuid":"uuid-2","description":"Second task"},{"uuid":""}]`)
+ return 0, nil
+ }})
+
+ var stdout, stderr bytes.Buffer
+ code, err := d.handleCompleteAliases(context.Background(), nil, &stdout, &stderr)
+ if err != nil {
+ t.Fatalf("handleCompleteAliases returned error: %v", err)
+ }
+ if code != 0 {
+ t.Fatalf("handleCompleteAliases code = %d, want 0", code)
+ }
+ if got := stdout.String(); got != "0\tFirst task\n1\tSecond task\n" {
+ t.Fatalf("stdout = %q, want alias-only tab-separated list", got)
+ }
+ if stderr.Len() != 0 {
+ t.Fatalf("stderr = %q, want empty", stderr.String())
+ }
+}
+
func TestTaskCompletionItems_IncludesDescriptions(t *testing.T) {
tasks := []TaskExport{
{UUID: "uuid-1", Description: "First task"},