From 67c7dedd829dcfd8d7e51cc24e91948756f6c0c5 Mon Sep 17 00:00:00 2001 From: jeely Date: Sat, 16 May 2026 21:57:40 +0800 Subject: [PATCH 1/2] fix auth callback test timeout --- internal/auth/service_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/auth/service_test.go b/internal/auth/service_test.go index 7b39ba1..a1dc5bd 100644 --- a/internal/auth/service_test.go +++ b/internal/auth/service_test.go @@ -335,7 +335,9 @@ func TestServiceLoginAcceptsAutomaticLocalCallback(t *testing.T) { t.Fatalf("Listen() error = %v", err) } addr := l.Addr().String() - _ = l.Close() + t.Cleanup(func() { + _ = l.Close() + }) state := "state-1" store := &memoryTokenStore{} @@ -343,15 +345,14 @@ func TestServiceLoginAcceptsAutomaticLocalCallback(t *testing.T) { out := &bytes.Buffer{} manualIn, manualWriter := io.Pipe() defer manualWriter.Close() + listenerReady := make(chan struct{}) done := make(chan struct{}) go func() { defer close(done) - for len(browser.urls) == 0 { - time.Sleep(10 * time.Millisecond) - } + <-listenerReady callbackURL := "http://" + addr + "/callback?code=code-1&state=" + state - resp, err := http.Get(callbackURL) + resp, err := (&http.Client{Timeout: time.Second}).Get(callbackURL) if err != nil { t.Errorf("http.Get() error = %v", err) return @@ -359,6 +360,8 @@ func TestServiceLoginAcceptsAutomaticLocalCallback(t *testing.T) { _ = resp.Body.Close() }() + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() token, err := Service{ Exchanger: Exchanger{ HTTPClient: tokenServer.Client(), @@ -369,7 +372,14 @@ func TestServiceLoginAcceptsAutomaticLocalCallback(t *testing.T) { In: manualIn, Out: out, StateSource: func() string { return state }, - }.Login(context.Background(), LoginInput{ + Listen: func(network, address string) (net.Listener, error) { + if network != "tcp" || address != addr { + t.Fatalf("Listen(%q, %q), want tcp %s", network, address, addr) + } + close(listenerReady) + return l, nil + }, + }.Login(ctx, LoginInput{ ClientID: "client-1", ClientSecret: "secret-1", RedirectURL: "http://" + addr + "/callback", From 6cd392ee764cc6339a9a1538eca389ef05565330 Mon Sep 17 00:00:00 2001 From: jeely Date: Sat, 16 May 2026 22:11:18 +0800 Subject: [PATCH 2/2] Fix today task filtering --- internal/app/task.go | 5 ++++- internal/app/task_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/internal/app/task.go b/internal/app/task.go index 09847df..1bdc921 100644 --- a/internal/app/task.go +++ b/internal/app/task.go @@ -127,7 +127,10 @@ func (a TaskApp) findTask(ctx context.Context, ref string, projectRef string) (d } func (a TaskApp) Today(ctx context.Context) ([]domain.Task, map[string]string, error) { - return a.List(ctx, ListTasksInput{Today: true}) + return a.List(ctx, ListTasksInput{ + Statuses: []domain.TaskStatus{domain.StatusOpen}, + Today: true, + }) } func resolveTaskReference(ref string, tasks []domain.Task) (domain.Task, error) { diff --git a/internal/app/task_test.go b/internal/app/task_test.go index 2671b4d..a12cb11 100644 --- a/internal/app/task_test.go +++ b/internal/app/task_test.go @@ -161,6 +161,35 @@ func TestTaskAppListFiltersToday(t *testing.T) { } } +func TestTaskAppTodayRequestsOpenTasks(t *testing.T) { + now := time.Date(2026, 4, 9, 9, 0, 0, 0, time.Local) + due := time.Date(2026, 4, 9, 17, 0, 0, 0, time.Local) + client := &recordingTaskAPI{ + filterTasks: []domain.Task{ + {ID: "today", Title: "Today", ProjectID: "p1", Status: domain.StatusOpen, DueDate: &due}, + {ID: "completed", Title: "Done", ProjectID: "p1", Status: domain.StatusCompleted, DueDate: &due}, + }, + } + taskApp := TaskApp{ + Auth: stubTokenSource{}, + Client: client, + Now: func() time.Time { + return now + }, + } + + tasks, _, err := taskApp.Today(context.Background()) + if err != nil { + t.Fatalf("Today() error = %v", err) + } + if len(tasks) != 1 || tasks[0].ID != "today" { + t.Fatalf("tasks = %#v, want only open today task", tasks) + } + if got := client.lastFilter.StatusCodes(); len(got) != 1 || got[0] != int(domain.StatusOpen) { + t.Fatalf("lastFilter.StatusCodes() = %v, want [%d]", got, domain.StatusOpen) + } +} + func TestTaskAppListFiltersOverdue(t *testing.T) { now := time.Date(2026, 4, 9, 9, 0, 0, 0, time.Local) yesterday := time.Date(2026, 4, 8, 18, 0, 0, 0, time.Local)