diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-09-03 02:34:25 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-09-03 02:34:25 +0000 |
| commit | 1477ee531045388de9e7e797200e5cd14e4a6d0e (patch) | |
| tree | b5369768ed0da759d492fda7957ab25833759d78 /internal/store/chains_test.go | |
| parent | 699e31989e2c36513e02861f49672f8984ffe336 (diff) | |
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B
Diffstat (limited to 'internal/store/chains_test.go')
| -rw-r--r-- | internal/store/chains_test.go | 103 |
1 files changed, 93 insertions, 10 deletions
diff --git a/internal/store/chains_test.go b/internal/store/chains_test.go index d21490c..007fe78 100644 --- a/internal/store/chains_test.go +++ b/internal/store/chains_test.go @@ -38,8 +38,10 @@ func TestCreateChain_SeedsPositionsCorrectly(t *testing.T) { if len(tasks) != 3 { t.Fatalf("len(tasks) = %d, want 3", len(tasks)) } - if !tasks[0].ChainUnlocked || tasks[0].DueDate == nil { - t.Errorf("position 0: ChainUnlocked=%v DueDate=%v, want unlocked with a due date", tasks[0].ChainUnlocked, tasks[0].DueDate) + // Unlocked but with no due date: a chain step is a milestone, not a + // deadline (migration 031). It reaches the day's list by being committed. + if !tasks[0].ChainUnlocked || tasks[0].DueDate != nil { + t.Errorf("position 0: ChainUnlocked=%v DueDate=%v, want unlocked with no due date", tasks[0].ChainUnlocked, tasks[0].DueDate) } for i := 1; i < 3; i++ { if tasks[i].ChainUnlocked || tasks[i].DueDate != nil { @@ -71,8 +73,8 @@ func TestCompleteNativeTask_AdvancesChain(t *testing.T) { if err != nil { t.Fatal(err) } - if !after[1].ChainUnlocked || after[1].DueDate == nil { - t.Errorf("position 1 after completing position 0: ChainUnlocked=%v DueDate=%v, want unlocked with a due date", after[1].ChainUnlocked, after[1].DueDate) + if !after[1].ChainUnlocked || after[1].DueDate != nil { + t.Errorf("position 1 after completing position 0: ChainUnlocked=%v DueDate=%v, want unlocked with no due date", after[1].ChainUnlocked, after[1].DueDate) } updatedChain, err := s.GetChain(chain.ID) @@ -187,7 +189,12 @@ func TestCompleteNativeTask_LockedChainTask_ReturnsErrChainTaskLocked(t *testing } } -func TestSetChainStatus_ResumeWithNothingStuck_DoesNotResetDueDate(t *testing.T) { +// Chain steps no longer carry due dates, so the original form of this test (that +// resume must not reset the head's due date) no longer has a subject. The +// underlying property it guarded still matters though: a resume catch-up against +// a chain that was never stuck must be a no-op, not a re-unlock that disturbs +// existing state. +func TestSetChainStatus_ResumeWithNothingStuck_IsANoOp(t *testing.T) { s := newNativeTasksTestStore(t) chain, err := s.CreateChain("Track", chainTasks("Step 1", "Step 2")) @@ -198,7 +205,7 @@ func TestSetChainStatus_ResumeWithNothingStuck_DoesNotResetDueDate(t *testing.T) if err != nil { t.Fatal(err) } - originalDueDate := *tasks[0].DueDate + originalHeadID := tasks[0].ID // Pause and resume with nothing completed yet -- position 0 is already // unlocked and should be left untouched by the resume catch-up. @@ -213,8 +220,11 @@ func TestSetChainStatus_ResumeWithNothingStuck_DoesNotResetDueDate(t *testing.T) if err != nil { t.Fatal(err) } - if !after[0].DueDate.Equal(originalDueDate) { - t.Errorf("DueDate = %v, want unchanged %v (resume catch-up should be a no-op when nothing was stuck)", after[0].DueDate, originalDueDate) + if after[0].ID != originalHeadID || !after[0].ChainUnlocked { + t.Errorf("head after resume = %+v, want the same unlocked head (resume catch-up should be a no-op when nothing was stuck)", after[0]) + } + if after[1].ChainUnlocked { + t.Error("resume unlocked position 1 despite nothing being completed -- catch-up should not advance an unstuck chain") } } @@ -349,8 +359,8 @@ func TestDeleteNativeTask_UnlockedChainTask_PromotesSuccessor(t *testing.T) { if len(after) != 1 { t.Fatalf("len(after) = %d, want 1", len(after)) } - if !after[0].ChainUnlocked || after[0].DueDate == nil { - t.Errorf("Step 2 should be promoted to unlocked with a due date, got ChainUnlocked=%v DueDate=%v", after[0].ChainUnlocked, after[0].DueDate) + if !after[0].ChainUnlocked || after[0].DueDate != nil { + t.Errorf("Step 2 should be promoted to unlocked with no due date, got ChainUnlocked=%v DueDate=%v", after[0].ChainUnlocked, after[0].DueDate) } } @@ -484,3 +494,76 @@ func TestChainVisibilityPredicate_UsedEverywhereChainUnlockedIsFiltered(t *testi t.Errorf("visibleChainTaskClause referenced %d time(s), want >= 4 (declaration + the task queries); a query that stopped using it has drifted off the shared predicate", refs) } } + +// A chain step is a milestone, not a deadline. Stamping due_date on unlock made +// every step -- a five-minute call and a six-month certification alike -- arrive +// looking due today, which is what drove the hand-rescheduling that made the +// list untrustworthy. Steps now carry no due date; they reach the day's list +// only by being committed. +func TestCreateChain_HeadTaskHasNoDueDate(t *testing.T) { + s := newNativeTasksTestStore(t) + + chain, err := s.CreateChain("Track", chainTasks("Step 1", "Step 2")) + if err != nil { + t.Fatal(err) + } + tasks, err := s.GetChainTasks(chain.ID) + if err != nil { + t.Fatal(err) + } + if !tasks[0].ChainUnlocked { + t.Fatal("expected position 0 to be unlocked") + } + if tasks[0].DueDate != nil { + t.Errorf("head task DueDate = %v, want nil -- a chain step is a milestone, not a deadline", tasks[0].DueDate) + } +} + +func TestCompleteNativeTask_AdvancedStepHasNoDueDate(t *testing.T) { + s := newNativeTasksTestStore(t) + + chain, err := s.CreateChain("Track", chainTasks("Step 1", "Step 2")) + if err != nil { + t.Fatal(err) + } + tasks, err := s.GetChainTasks(chain.ID) + if err != nil { + t.Fatal(err) + } + if err := s.CompleteNativeTask(tasks[0].ID); err != nil { + t.Fatal(err) + } + + after, err := s.GetChainTasks(chain.ID) + if err != nil { + t.Fatal(err) + } + if !after[1].ChainUnlocked { + t.Fatal("expected position 1 to be unlocked after completing position 0") + } + if after[1].DueDate != nil { + t.Errorf("newly unlocked step DueDate = %v, want nil", after[1].DueDate) + } +} + +// With no due date, an unlocked chain step would otherwise fall into the undated +// bucket and show up on the timeline anyway -- defeating the point. Chain work +// reaches the day only via commitment. +func TestGetUndatedNativeTasks_ExcludesUnlockedChainSteps(t *testing.T) { + s := newNativeTasksTestStore(t) + + chain, err := s.CreateChain("Track", chainTasks("Step 1", "Step 2")) + if err != nil { + t.Fatal(err) + } + + undated, err := s.GetUndatedNativeTasks() + if err != nil { + t.Fatal(err) + } + for _, task := range undated { + if task.ChainID == chain.ID { + t.Errorf("chain step %q leaked into the undated list; chain work should surface via the chain summary and commitment only", task.Content) + } + } +} |
