From 1477ee531045388de9e7e797200e5cd14e4a6d0e Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Thu, 3 Sep 2026 02:34:25 +0000 Subject: Make the day's list a pull of committed work, not a push of everything unblocked due_date had been carrying two incompatible meanings: "this has a real deadline" (Bills, meds, a signup cutoff) and "this is when I intend to work on it." Chains leaned entirely on the second -- every step was stamped due_date = now the moment it unlocked -- so a five-minute call and a six-month certification both arrived looking overdue, and the only way to quiet them was to hand-reschedule. The list therefore always contained work that could not be finished that day, which made ending a day at zero impossible by construction rather than by effort. Splits the two apart: - due_date keeps only its real meaning: an externally-imposed deadline. - committed_date (new, migration 031) means "I chose this for today." Chain steps no longer get a due date on unlock (CreateChain, advanceChain, and the delete-promotion path), and are excluded from the undated list so they don't simply fall through to it instead. They reach the day only by being committed, via a "+ today" control on the chain card. Bucket-active items get the same control. BuildTimeline pulls in committed tasks, deduped against tasks already present for a different reason (committed and due-today are two reasons for one row, not two rows). Migration 031 also clears the auto-stamped due dates from open chain steps; completed steps keep theirs as historical record. Two supporting changes made while in here: - Extracted the native_tasks SELECT list into nativeTaskColumns. It had been copy-pasted into nine queries that must each agree exactly with scanNativeTasks' field order; adding committed_date meant editing all nine correctly or silently breaking whichever was missed. - Extracted templateFuncMap() and added TestTemplates_AllParse. New() only logs a warning when template parsing fails, so a malformed template shipped silently and surfaced as a broken page at runtime. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B --- internal/handlers/chains_timeline_test.go | 69 ++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'internal/handlers/chains_timeline_test.go') diff --git a/internal/handlers/chains_timeline_test.go b/internal/handlers/chains_timeline_test.go index e9c8a3a..d4bc369 100644 --- a/internal/handlers/chains_timeline_test.go +++ b/internal/handlers/chains_timeline_test.go @@ -5,10 +5,15 @@ import ( "testing" "time" + "task-dashboard/internal/config" "task-dashboard/internal/models" ) -func TestBuildTimeline_PopulatesChainBadgeForUnlockedTask(t *testing.T) { +// Chain steps carry no due date and are kept out of the undated list, so they +// stay off the day's timeline entirely until deliberately committed. This is the +// whole point of the pull model: the day contains what was chosen plus real +// deadlines, so finishing at zero is reachable. +func TestBuildTimeline_UnlockedChainTaskAbsentUntilCommitted(t *testing.T) { s, cleanup := setupTestDB(t) defer cleanup() @@ -23,6 +28,36 @@ func TestBuildTimeline_PopulatesChainBadgeForUnlockedTask(t *testing.T) { t.Fatal(err) } + now := time.Now() + items, err := BuildTimeline(context.Background(), s, now.Add(-time.Hour), now.Add(24*time.Hour)) + if err != nil { + t.Fatalf("BuildTimeline: %v", err) + } + for _, item := range items { + if item.ID == tasks[0].ID { + t.Error("uncommitted chain step appeared on the timeline; chain work should only arrive by being committed") + } + } +} + +func TestBuildTimeline_CommittedChainTaskAppearsWithBadge(t *testing.T) { + s, cleanup := setupTestDB(t) + defer cleanup() + + chain, err := s.CreateChain("Ham Radio Track", []models.ChainTaskInput{ + {Content: "Study Technician"}, {Content: "Pass exam"}, {Content: "Study General"}, + }) + if err != nil { + t.Fatal(err) + } + tasks, err := s.GetChainTasks(chain.ID) + if err != nil { + t.Fatal(err) + } + if err := s.SetTaskCommitted(tasks[0].ID, config.Now()); err != nil { + t.Fatal(err) + } + now := time.Now() items, err := BuildTimeline(context.Background(), s, now.Add(-time.Hour), now.Add(24*time.Hour)) if err != nil { @@ -42,6 +77,36 @@ func TestBuildTimeline_PopulatesChainBadgeForUnlockedTask(t *testing.T) { } } if !found { - t.Fatal("expected the unlocked chain task (position 0) to appear in the timeline") + t.Fatal("expected the committed chain step to appear on the timeline") + } +} + +// A task that is both committed and due today must appear once, not twice. +func TestBuildTimeline_CommittedAndDueTaskNotDuplicated(t *testing.T) { + s, cleanup := setupTestDB(t) + defer cleanup() + + due := config.Now() + if err := s.CreateNativeTask(models.Task{ID: "dual", Content: "Bills", DueDate: &due}); err != nil { + t.Fatal(err) + } + if err := s.SetTaskCommitted("dual", config.Now()); err != nil { + t.Fatal(err) + } + + now := time.Now() + items, err := BuildTimeline(context.Background(), s, now.Add(-24*time.Hour), now.Add(24*time.Hour)) + if err != nil { + t.Fatalf("BuildTimeline: %v", err) + } + + var count int + for _, item := range items { + if item.ID == "dual" { + count++ + } + } + if count != 1 { + t.Errorf("task appeared %d times, want exactly 1 (committed and due are two reasons for the same row)", count) } } -- cgit v1.2.3