summaryrefslogtreecommitdiff
path: root/internal/askcli/command_complete_uuids_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/askcli/command_complete_uuids_test.go')
-rw-r--r--internal/askcli/command_complete_uuids_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/askcli/command_complete_uuids_test.go b/internal/askcli/command_complete_uuids_test.go
index ff9d142..2c8fc34 100644
--- a/internal/askcli/command_complete_uuids_test.go
+++ b/internal/askcli/command_complete_uuids_test.go
@@ -4,11 +4,24 @@ import (
"bytes"
"context"
"io"
+ "os"
+ "path/filepath"
"strings"
"testing"
+ "time"
)
func TestHandleCompleteUUIDs_PrintsPendingUUIDs(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, " ") {
@@ -32,6 +45,18 @@ func TestHandleCompleteUUIDs_PrintsPendingUUIDs(t *testing.T) {
if stderr.Len() != 0 {
t.Fatalf("stderr = %q, want empty", stderr.String())
}
+
+ path, err := taskAliasCachePath()
+ if err != nil {
+ t.Fatalf("taskAliasCachePath: %v", err)
+ }
+ cache := readTaskAliasCacheForTest(t, path)
+ if got := findTaskAliasEntry(t, cache, "uuid-1").Alias; got != "0" {
+ t.Fatalf("uuid-1 alias = %q, want 0", got)
+ }
+ if got := findTaskAliasEntry(t, cache, "uuid-2").Alias; got != "1" {
+ t.Fatalf("uuid-2 alias = %q, want 1", got)
+ }
}
func TestHandleCompleteUUIDs_ParseError(t *testing.T) {
@@ -52,3 +77,41 @@ func TestHandleCompleteUUIDs_ParseError(t *testing.T) {
t.Fatalf("stderr = %q, want parse error", stderr.String())
}
}
+
+func TestHandleCompleteUUIDs_WarnsOnInvalidAliasCache(t *testing.T) {
+ dir := t.TempDir()
+ oldRoot := taskAliasCacheRoot
+ taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
+ defer func() { taskAliasCacheRoot = oldRoot }()
+
+ path, err := taskAliasCachePath()
+ if err != nil {
+ t.Fatalf("taskAliasCachePath: %v", err)
+ }
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatalf("MkdirAll: %v", err)
+ }
+ if err := os.WriteFile(path, []byte("{bad"), 0o600); err != nil {
+ t.Fatalf("WriteFile: %v", err)
+ }
+
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ _, _ = io.WriteString(stdout, `[{"uuid":"uuid-1"}]`)
+ return 0, nil
+ }})
+
+ var stdout, stderr bytes.Buffer
+ code, err := d.handleCompleteUUIDs(context.Background(), &stdout, &stderr)
+ if err != nil {
+ t.Fatalf("handleCompleteUUIDs returned error: %v", err)
+ }
+ if code != 0 {
+ t.Fatalf("handleCompleteUUIDs code = %d, want 0", code)
+ }
+ if got := stdout.String(); got != "uuid-1\n" {
+ t.Fatalf("stdout = %q, want UUID list", got)
+ }
+ if !strings.Contains(stderr.String(), "failed to update task alias cache") {
+ t.Fatalf("stderr = %q, want cache warning", stderr.String())
+ }
+}