summaryrefslogtreecommitdiff
path: root/internal/askcli/command_list_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-31 10:07:41 +0300
committerPaul Buetow <paul@buetow.org>2026-05-31 10:07:41 +0300
commit0dfcb0f3fe6db144f02506df95e68707d9b5091c (patch)
treeed6c0b976acca95b403a7939dd49c49de160003b /internal/askcli/command_list_test.go
parent168d3a1009066ba38a37fe8a2f8f40a649344eae (diff)
ask: add completed sub-command to list completed tasks
Diffstat (limited to 'internal/askcli/command_list_test.go')
-rw-r--r--internal/askcli/command_list_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/askcli/command_list_test.go b/internal/askcli/command_list_test.go
index e25293e..c7c7b8a 100644
--- a/internal/askcli/command_list_test.go
+++ b/internal/askcli/command_list_test.go
@@ -188,6 +188,44 @@ func TestHandleReady_Success(t *testing.T) {
}
}
+func TestHandleCompleted_Success(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: "uuid-done", Alias: "0", CreatedAt: nowTaskAliasCache()},
+ },
+ })
+
+ jsonData := `[{"uuid":"uuid-done","description":"Done task","status":"completed","priority":"M","tags":[],"urgency":0.0,"depends":[]}]`
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ for _, arg := range args {
+ if arg == "export" {
+ _, _ = io.WriteString(stdout, jsonData)
+ return 0, nil
+ }
+ }
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"completed"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("completed code = %d, want 0", code)
+ }
+ if !strings.Contains(stdout.String(), "0") || strings.Contains(stdout.String(), "uuid-done") {
+ t.Fatalf("output should show alias only: %s", stdout.String())
+ }
+}
+
func TestHandleList_PassesFilters(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) {