From 9aa79f6ac5b71f73fa2b22860e88c9d499c49539 Mon Sep 17 00:00:00 2001 From: Spirit of Light Date: Sun, 1 Nov 2026 18:09:21 -0500 Subject: [PATCH 1/4] Test(tasks): task list JSON, the Tasks view and new task notes match zn v0.18.1 These golden tests record the output of zn v0.18.1: `zn task list --json` byte for byte, the Tasks view groups, board columns and calendar order under both list orders, and the frontmatter of a newly created task note. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0171pE1tFQspTuCEpf1xvQiH --- internal/cli/tasks_test.go | 31 +++ internal/cli/testdata/default-tasks-all.json | 226 ++++++++++++++++++ internal/cli/testdata/default-tasks.json | 154 ++++++++++++ .../inbox/Daily Notes/2026-11-02.md | 4 + .../testdata/default-tasks/inbox/pay-rent.md | 10 + .../testdata/default-tasks/inbox/reference.md | 7 + .../cli/testdata/default-tasks/inbox/work.md | 20 ++ internal/tui/tasks_default_path_test.go | 203 ++++++++++++++++ .../tui/testdata/default-tasks-view.golden | 184 ++++++++++++++ 9 files changed, 839 insertions(+) create mode 100644 internal/cli/testdata/default-tasks-all.json create mode 100644 internal/cli/testdata/default-tasks.json create mode 100644 internal/cli/testdata/default-tasks/inbox/Daily Notes/2026-11-02.md create mode 100644 internal/cli/testdata/default-tasks/inbox/pay-rent.md create mode 100644 internal/cli/testdata/default-tasks/inbox/reference.md create mode 100644 internal/cli/testdata/default-tasks/inbox/work.md create mode 100644 internal/tui/tasks_default_path_test.go create mode 100644 internal/tui/testdata/default-tasks-view.golden diff --git a/internal/cli/tasks_test.go b/internal/cli/tasks_test.go index 42cf912..2d58439 100644 --- a/internal/cli/tasks_test.go +++ b/internal/cli/tasks_test.go @@ -77,3 +77,34 @@ func TestTaskTogglePrintsWhereARecurringTaskWent(t *testing.T) { t.Fatalf("%q", data) } } + +// A vault of checkbox tasks and task notes lists the same JSON bytes as zn +// v0.18.1, with and without --all. +func TestTaskListJSONMatchesReleasedForDefaultVault(t *testing.T) { + isolatedCLI(t) + root := t.TempDir() + if err := os.CopyFS(root, os.DirFS(filepath.Join("testdata", "default-tasks"))); err != nil { + t.Fatal(err) + } + for _, tc := range []struct { + golden string + flags []string + }{ + {"default-tasks.json", nil}, + {"default-tasks-all.json", []string{"--all"}}, + } { + want, err := os.ReadFile(filepath.Join("testdata", tc.golden)) + if err != nil { + t.Fatal(err) + } + args := append([]string{"task", "list", "--json", "--vault", root}, tc.flags...) + out := captureOutput(t, func() { + if code := Main(args); code != 0 { + t.Errorf("zn %v exited %d", args, code) + } + }) + if out != string(want) { + t.Errorf("zn %v differs from testdata/%s:\n%s", args, tc.golden, out) + } + } +} diff --git a/internal/cli/testdata/default-tasks-all.json b/internal/cli/testdata/default-tasks-all.json new file mode 100644 index 0000000..97e8c4b --- /dev/null +++ b/internal/cli/testdata/default-tasks-all.json @@ -0,0 +1,226 @@ +[ + { + "id": "inbox/Daily Notes/2026-11-02.md#0", + "sourcePath": "inbox/Daily Notes/2026-11-02.md", + "link": "zennotes://open?path=inbox/Daily%20Notes/2026-11-02.md", + "noteTitle": "2026-11-02", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water the plants", + "content": "Water the plants", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Daily Notes/2026-11-02.md#1", + "sourcePath": "inbox/Daily Notes/2026-11-02.md", + "link": "zennotes://open?path=inbox/Daily%20Notes/2026-11-02.md", + "noteTitle": "2026-11-02", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Review the week !med", + "content": "Review the week", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "priority": "med", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/pay-rent.md#task", + "sourcePath": "inbox/pay-rent.md", + "link": "zennotes://open?path=inbox/pay-rent.md", + "noteTitle": "pay-rent", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": -1, + "rawText": "", + "content": "pay-rent", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2026-11-07", + "priority": "high", + "waiting": false, + "status": "open", + "tags": [ + "finance" + ], + "kind": "file" + }, + { + "id": "inbox/work.md#0", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 6, + "taskIndex": 0, + "rawText": "- [ ] Send the invoice due:2026-11-03 !high #billing @key:acme", + "content": "Send the invoice #billing @key:acme", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-03", + "priority": "high", + "waiting": false, + "tags": [ + "billing" + ] + }, + { + "id": "inbox/work.md#1", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 7, + "taskIndex": 1, + "rawText": "- [ ] Call the bank @waiting due:2026-11-10", + "content": "Call the bank", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-10", + "waiting": true, + "tags": [] + }, + { + "id": "inbox/work.md#2", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 8, + "taskIndex": 2, + "rawText": "- [x] File the report due:2026-10-30 !med", + "content": "File the report", + "checked": true, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-10-30", + "priority": "med", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#3", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 9, + "taskIndex": 3, + "rawText": "- [-] Drop the old plan", + "content": "Drop the old plan", + "checked": false, + "cancelled": true, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#4", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 10, + "taskIndex": 4, + "rawText": "- [/] Draft the proposal !low #writing @owner:sam", + "content": "Draft the proposal #writing @owner:sam", + "checked": false, + "cancelled": false, + "inProgress": true, + "forwarded": false, + "priority": "low", + "waiting": false, + "tags": [ + "writing" + ] + }, + { + "id": "inbox/work.md#5", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 11, + "taskIndex": 5, + "rawText": "- [\u003e] Forwarded errand due:2026-11-05", + "content": "Forwarded errand", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": true, + "due": "2026-11-05", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#6", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 12, + "taskIndex": 6, + "rawText": "- [ ] Plain task without a date", + "content": "Plain task without a date", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#7", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 13, + "taskIndex": 7, + "rawText": " - [ ] Indented subtask due:2026-11-04", + "content": "Indented subtask", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-04", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#8", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 19, + "taskIndex": 8, + "rawText": "- [ ] Task after the fence #home", + "content": "Task after the fence #home", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [ + "home" + ] + } +] diff --git a/internal/cli/testdata/default-tasks.json b/internal/cli/testdata/default-tasks.json new file mode 100644 index 0000000..92a6db7 --- /dev/null +++ b/internal/cli/testdata/default-tasks.json @@ -0,0 +1,154 @@ +[ + { + "id": "inbox/Daily Notes/2026-11-02.md#0", + "sourcePath": "inbox/Daily Notes/2026-11-02.md", + "link": "zennotes://open?path=inbox/Daily%20Notes/2026-11-02.md", + "noteTitle": "2026-11-02", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water the plants", + "content": "Water the plants", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Daily Notes/2026-11-02.md#1", + "sourcePath": "inbox/Daily Notes/2026-11-02.md", + "link": "zennotes://open?path=inbox/Daily%20Notes/2026-11-02.md", + "noteTitle": "2026-11-02", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Review the week !med", + "content": "Review the week", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "priority": "med", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/pay-rent.md#task", + "sourcePath": "inbox/pay-rent.md", + "link": "zennotes://open?path=inbox/pay-rent.md", + "noteTitle": "pay-rent", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": -1, + "rawText": "", + "content": "pay-rent", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2026-11-07", + "priority": "high", + "waiting": false, + "status": "open", + "tags": [ + "finance" + ], + "kind": "file" + }, + { + "id": "inbox/work.md#0", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 6, + "taskIndex": 0, + "rawText": "- [ ] Send the invoice due:2026-11-03 !high #billing @key:acme", + "content": "Send the invoice #billing @key:acme", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-03", + "priority": "high", + "waiting": false, + "tags": [ + "billing" + ] + }, + { + "id": "inbox/work.md#4", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 10, + "taskIndex": 4, + "rawText": "- [/] Draft the proposal !low #writing @owner:sam", + "content": "Draft the proposal #writing @owner:sam", + "checked": false, + "cancelled": false, + "inProgress": true, + "forwarded": false, + "priority": "low", + "waiting": false, + "tags": [ + "writing" + ] + }, + { + "id": "inbox/work.md#6", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 12, + "taskIndex": 6, + "rawText": "- [ ] Plain task without a date", + "content": "Plain task without a date", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#7", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 13, + "taskIndex": 7, + "rawText": " - [ ] Indented subtask due:2026-11-04", + "content": "Indented subtask", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-04", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/work.md#8", + "sourcePath": "inbox/work.md", + "link": "zennotes://open?path=inbox/work.md", + "noteTitle": "work", + "noteFolder": "inbox", + "lineNumber": 19, + "taskIndex": 8, + "rawText": "- [ ] Task after the fence #home", + "content": "Task after the fence #home", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [ + "home" + ] + } +] diff --git a/internal/cli/testdata/default-tasks/inbox/Daily Notes/2026-11-02.md b/internal/cli/testdata/default-tasks/inbox/Daily Notes/2026-11-02.md new file mode 100644 index 0000000..ee3ae33 --- /dev/null +++ b/internal/cli/testdata/default-tasks/inbox/Daily Notes/2026-11-02.md @@ -0,0 +1,4 @@ +# Monday + +- [ ] Water the plants +- [ ] Review the week !med diff --git a/internal/cli/testdata/default-tasks/inbox/pay-rent.md b/internal/cli/testdata/default-tasks/inbox/pay-rent.md new file mode 100644 index 0000000..8784513 --- /dev/null +++ b/internal/cli/testdata/default-tasks/inbox/pay-rent.md @@ -0,0 +1,10 @@ +--- +tags: [task, finance] +status: open +due: 2026-11-07 +priority: high +--- + +# Pay rent + +Transfer on the first working day. diff --git a/internal/cli/testdata/default-tasks/inbox/reference.md b/internal/cli/testdata/default-tasks/inbox/reference.md new file mode 100644 index 0000000..7859f36 --- /dev/null +++ b/internal/cli/testdata/default-tasks/inbox/reference.md @@ -0,0 +1,7 @@ +--- +tasks: false +--- + +# Reference + +- [ ] A checkbox in a note that opts out of tasks diff --git a/internal/cli/testdata/default-tasks/inbox/work.md b/internal/cli/testdata/default-tasks/inbox/work.md new file mode 100644 index 0000000..4fbaac2 --- /dev/null +++ b/internal/cli/testdata/default-tasks/inbox/work.md @@ -0,0 +1,20 @@ +--- +tags: [work] +--- + +# Work + +- [ ] Send the invoice due:2026-11-03 !high #billing @key:acme +- [ ] Call the bank @waiting due:2026-11-10 +- [x] File the report due:2026-10-30 !med +- [-] Drop the old plan +- [/] Draft the proposal !low #writing @owner:sam +- [>] Forwarded errand due:2026-11-05 +- [ ] Plain task without a date + - [ ] Indented subtask due:2026-11-04 + +```md +- [ ] Not a task inside a fence due:2026-11-01 +``` + +- [ ] Task after the fence #home diff --git a/internal/tui/tasks_default_path_test.go b/internal/tui/tasks_default_path_test.go new file mode 100644 index 0000000..6ea32ec --- /dev/null +++ b/internal/tui/tasks_default_path_test.go @@ -0,0 +1,203 @@ +package tui + +import ( + "fmt" + "os" + "path/filepath" + "slices" + "strings" + "testing" + "time" + + "github.com/ZenNotes/tui/internal/vault" +) + +// relativeDay writes a date as "today", "today+3" or "today-1", so the golden +// file holds no calendar date and the test can run on any day. +func relativeDay(day string, now time.Time) string { + d, err := time.ParseInLocation("2006-01-02", day, time.Local) + if err != nil { + return day + } + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) + offset := int(d.Sub(today).Round(24*time.Hour).Hours() / 24) + switch { + case offset == 0: + return "today" + case offset > 0: + return fmt.Sprintf("today+%d", offset) + } + return fmt.Sprintf("today%d", offset) +} + +// defaultTasksVault writes notes that use only the task syntax of released zn, +// with dates relative to now: yesterday, today, three days after today, and no date. +func defaultTasksVault(t *testing.T, now time.Time) string { + t.Helper() + t.Setenv("ZENNOTES_CONFIG_DIR", t.TempDir()) + day := func(offset int) string { return vault.TodayISO(now.AddDate(0, 0, offset)) } + root := t.TempDir() + notes := map[string]string{ + "inbox/errands.md": strings.Join([]string{ + "- [ ] Overdue errand due:" + day(-1) + " !high", + "- [ ] Today errand due:" + day(0) + " !med", + "- [ ] Soon errand due:" + day(3) + " #home @place:shop", + "- [ ] Undated errand", + "- [ ] Waiting errand @waiting due:" + day(0), + "- [x] Finished errand due:" + day(-1), + "- [-] Cancelled errand", + "- [/] In progress errand due:" + day(0) + " !low", + "- [>] Forwarded errand", + "", + }, "\n"), + "inbox/work.md": strings.Join([]string{ + "---", + "tags: [work]", + "---", + "", + "- [ ] Low today due:" + day(0) + " !low", + "- [ ] High soon due:" + day(3) + " !high", + "- [ ] Medium undated !med", + "- [ ] Overdue medium due:" + day(-1) + " !med", + "", + "```", + "- [ ] Inside a fence due:" + day(0), + "```", + "", + }, "\n"), + "inbox/pay-rent.md": strings.Join([]string{ + "---", + "tags: [task, finance]", + "status: open", + "due: " + day(3), + "priority: high", + "---", + "", + "# Pay rent", + "", + }, "\n"), + "inbox/reference.md": "---\ntasks: false\n---\n\n- [ ] Opted out of tasks\n", + } + for rel, body := range notes { + abs := filepath.Join(root, filepath.FromSlash(rel)) + if err := os.MkdirAll(filepath.Dir(abs), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(abs, []byte(body), 0o644); err != nil { + t.Fatal(err) + } + } + return root +} + +// tasksViewReport renders what the Tasks view holds, in order: the list's +// headers and tasks, the board's columns and cards for each grouping, and the +// calendar's tasks per day. +func tasksViewReport(t *testing.T, a *App, now time.Time) string { + t.Helper() + var b strings.Builder + for _, order := range []string{"note", "priority"} { + a.prefs.TasksListOrder = order + fmt.Fprintf(&b, "== tasks_list_order %s ==\n", order) + v := newTasksView(a) + b.WriteString("-- list\n") + for _, row := range v.rows { + if row.task == nil { + fmt.Fprintf(&b, "%s\n", row.header) + continue + } + fmt.Fprintf(&b, " %s (%s)\n", row.task.Content, row.task.SourcePath) + } + for _, group := range []string{"status", "priority", "due"} { + a.prefs.KanbanGroupBy = group + v := newTasksView(a) + fmt.Fprintf(&b, "-- board by %s\n", group) + for _, col := range v.columns { + fmt.Fprintf(&b, "%s (%d)\n", col.title, len(col.cards)) + for _, card := range col.cards { + fmt.Fprintf(&b, " %s\n", card.Content) + } + } + } + b.WriteString("-- calendar\n") + byDay, undated := bucketCalendarEntries(v.tasks) + keys := []string{} + for day := range byDay { + keys = append(keys, day) + } + slices.Sort(keys) + for _, day := range keys { + fmt.Fprintf(&b, "%s\n", relativeDay(day, now)) + for _, entry := range byDay[day] { + marker := "" + if entry.scheduled { + marker = " (scheduled)" + } + fmt.Fprintf(&b, " %s%s\n", entry.task.Content, marker) + } + } + b.WriteString("no date\n") + for _, task := range undated { + fmt.Fprintf(&b, " %s\n", task.Content) + } + } + return b.String() +} + +// The Tasks view groups and orders these notes as zn v0.18.1 does, in the +// list, on the board and on the calendar. +func TestTasksViewGroupsAndOrderMatchReleased(t *testing.T) { + // The Tasks view reads the clock with time.Now and has no clock seam. + // If the test runs over midnight, the golden file can differ. + now := time.Now() + a := newSessionParityApp(t, defaultTasksVault(t, now)) + loadTasksForTest(t, a) + got := tasksViewReport(t, a, now) + golden := filepath.Join("testdata", "default-tasks-view.golden") + if os.Getenv("ZN_WRITE_DEFAULT_TASKS_GOLDEN") != "" { + if err := os.MkdirAll("testdata", 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(golden, []byte(got), 0o644); err != nil { + t.Fatal(err) + } + } + want, err := os.ReadFile(golden) + if err != nil { + t.Fatal(err) + } + if got != string(want) { + t.Fatalf("the Tasks view differs from released zn v0.18.1.\ngot:\n%s\nwant:\n%s", got, want) + } +} + +// loadTasksForTest fills the index with the tasks that the app scans when it starts. +func loadTasksForTest(t *testing.T, a *App) { + t.Helper() + msg := a.loadTasksCmd()().(tasksLoadedMsg) + if msg.err != nil { + t.Fatal(msg.err) + } + a.idx.tasks = msg.tasks +} + +// The new-task command writes a note tagged `task`, as zn v0.18.1 does. +func TestNewTaskNoteIsTaggedTask(t *testing.T) { + root := defaultTasksVault(t, time.Now()) + a := newSessionParityApp(t, root) + if err := a.newTaskFile(""); err != nil { + t.Fatal(err) + } + p, ok := a.overlay.(*prompt) + if !ok { + t.Fatal("the new-task command did not open its prompt") + } + p.onSubmit(a, "Buy milk") + got, err := os.ReadFile(filepath.Join(root, "inbox", "Buy milk.md")) + if err != nil { + t.Fatal(err) + } + if want := "---\ntags: [task]\nstatus: open\n---\n\n# Buy milk\n\n"; string(got) != want { + t.Fatalf("new task note = %q, want %q", got, want) + } +} diff --git a/internal/tui/testdata/default-tasks-view.golden b/internal/tui/testdata/default-tasks-view.golden new file mode 100644 index 0000000..3433de4 --- /dev/null +++ b/internal/tui/testdata/default-tasks-view.golden @@ -0,0 +1,184 @@ +== tasks_list_order note == +-- list +Today (5) · 2 overdue + Overdue errand (inbox/errands.md) + Today errand (inbox/errands.md) + In progress errand (inbox/errands.md) + Low today (inbox/work.md) + Overdue medium (inbox/work.md) +Upcoming (3) + Soon errand #home (inbox/errands.md) + pay-rent (inbox/pay-rent.md) + High soon (inbox/work.md) +No due date (2) + Undated errand (inbox/errands.md) + Medium undated (inbox/work.md) +Waiting (1) + Waiting errand (inbox/errands.md) +Done (1) + Finished errand (inbox/errands.md) +Forwarded (1) + Forwarded errand (inbox/errands.md) +Cancelled (1) + Cancelled errand (inbox/errands.md) +-- board by status +Today (4) + Overdue errand + Overdue medium + Today errand + Low today +Upcoming (3) + Soon errand #home + pay-rent + High soon +No due date (2) + Undated errand + Medium undated +In progress (1) + In progress errand +Waiting (1) + Waiting errand +Done (1) + Finished errand +-- board by priority +High (3) + Overdue errand + pay-rent + High soon +Medium (3) + Overdue medium + Today errand + Medium undated +Low (2) + In progress errand + Low today +No priority (3) + Waiting errand + Soon errand #home + Undated errand +-- board by due +Overdue (2) + Overdue errand + Overdue medium +Today (4) + Today errand + Waiting errand + In progress errand + Low today +Tomorrow (0) +This week (3) + Soon errand #home + pay-rent + High soon +Later (0) +No date (2) + Undated errand + Medium undated +-- calendar +today-1 + Overdue errand + Overdue medium +today + Today errand + Waiting errand + In progress errand + Low today +today+3 + Soon errand #home + pay-rent + High soon +no date + Medium undated + Undated errand +== tasks_list_order priority == +-- list +Today (5) · 2 overdue + Overdue errand (inbox/errands.md) + Overdue medium (inbox/work.md) + Today errand (inbox/errands.md) + In progress errand (inbox/errands.md) + Low today (inbox/work.md) +Upcoming (3) + pay-rent (inbox/pay-rent.md) + High soon (inbox/work.md) + Soon errand #home (inbox/errands.md) +No due date (2) + Medium undated (inbox/work.md) + Undated errand (inbox/errands.md) +Waiting (1) + Waiting errand (inbox/errands.md) +Done (1) + Finished errand (inbox/errands.md) +Forwarded (1) + Forwarded errand (inbox/errands.md) +Cancelled (1) + Cancelled errand (inbox/errands.md) +-- board by status +Today (4) + Overdue errand + Overdue medium + Today errand + Low today +Upcoming (3) + Soon errand #home + pay-rent + High soon +No due date (2) + Undated errand + Medium undated +In progress (1) + In progress errand +Waiting (1) + Waiting errand +Done (1) + Finished errand +-- board by priority +High (3) + Overdue errand + pay-rent + High soon +Medium (3) + Overdue medium + Today errand + Medium undated +Low (2) + In progress errand + Low today +No priority (3) + Waiting errand + Soon errand #home + Undated errand +-- board by due +Overdue (2) + Overdue errand + Overdue medium +Today (4) + Today errand + Waiting errand + In progress errand + Low today +Tomorrow (0) +This week (3) + Soon errand #home + pay-rent + High soon +Later (0) +No date (2) + Undated errand + Medium undated +-- calendar +today-1 + Overdue errand + Overdue medium +today + Today errand + Waiting errand + In progress errand + Low today +today+3 + Soon errand #home + pay-rent + High soon +no date + Medium undated + Undated errand From 09d9ccffbea71b66621d436569ad0e437f697819 Mon Sep 17 00:00:00 2001 From: Spirit of Light Date: Sun, 8 Nov 2026 13:50:54 -0500 Subject: [PATCH 2/4] Test(tasks): task list output with released @repeat: values matches zn v0.18.1 A new fixture holds `@repeat:` tasks that use only the values of released zn. The test compares the output of `zn task list` in text and in JSON, with and without `--all`, with golden files. The base is zn v0.18.1. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0171pE1tFQspTuCEpf1xvQiH --- internal/cli/tasks_test.go | 35 ++++ .../cli/testdata/released-repeat-all.json | 184 ++++++++++++++++++ internal/cli/testdata/released-repeat.json | 166 ++++++++++++++++ internal/cli/testdata/released-repeat.txt | 9 + .../testdata/released-repeat/inbox/chores.md | 11 ++ .../released-repeat/inbox/pay-rent.md | 8 + 6 files changed, 413 insertions(+) create mode 100644 internal/cli/testdata/released-repeat-all.json create mode 100644 internal/cli/testdata/released-repeat.json create mode 100644 internal/cli/testdata/released-repeat.txt create mode 100644 internal/cli/testdata/released-repeat/inbox/chores.md create mode 100644 internal/cli/testdata/released-repeat/inbox/pay-rent.md diff --git a/internal/cli/tasks_test.go b/internal/cli/tasks_test.go index 2d58439..e1f9ad8 100644 --- a/internal/cli/tasks_test.go +++ b/internal/cli/tasks_test.go @@ -108,3 +108,38 @@ func TestTaskListJSONMatchesReleasedForDefaultVault(t *testing.T) { } } } + +// This vault holds only the `@repeat:` values of released zn: daily, weekly, +// weekdays, `mon/thu` and `after-3d`. It also holds a date in `@remind:`. It +// lists the same text and JSON as zn v0.18.1. `zn task list`, `zn task list +// --json` and `zn task list --json --all` over testdata/released-repeat made +// the golden files. +func TestTaskListMatchesReleasedForUpstreamRepeat(t *testing.T) { + isolatedCLI(t) + root := t.TempDir() + if err := os.CopyFS(root, os.DirFS(filepath.Join("testdata", "released-repeat"))); err != nil { + t.Fatal(err) + } + for _, tc := range []struct { + golden string + flags []string + }{ + {"released-repeat.txt", nil}, + {"released-repeat.json", []string{"--json"}}, + {"released-repeat-all.json", []string{"--json", "--all"}}, + } { + want, err := os.ReadFile(filepath.Join("testdata", tc.golden)) + if err != nil { + t.Fatal(err) + } + args := append([]string{"task", "list", "--vault", root}, tc.flags...) + out := captureOutput(t, func() { + if code := Main(args); code != 0 { + t.Errorf("zn %v exited %d", args, code) + } + }) + if out != string(want) { + t.Errorf("zn %v differs from testdata/%s:\n%s", args, tc.golden, out) + } + } +} diff --git a/internal/cli/testdata/released-repeat-all.json b/internal/cli/testdata/released-repeat-all.json new file mode 100644 index 0000000..738c79f --- /dev/null +++ b/internal/cli/testdata/released-repeat-all.json @@ -0,0 +1,184 @@ +[ + { + "id": "inbox/chores.md#0", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water the plants @repeat:daily due:2027-03-08", + "content": "Water the plants @repeat:daily", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-08", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#1", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Take out the bins @repeat:weekly due:2027-03-09", + "content": "Take out the bins @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-09", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#2", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 4, + "taskIndex": 2, + "rawText": "- [ ] Gym @repeat:mon/thu due:2027-03-08", + "content": "Gym @repeat:mon/thu", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-08", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#3", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 5, + "taskIndex": 3, + "rawText": "- [ ] Change the filter @repeat:after-3d due:2027-03-10", + "content": "Change the filter @repeat:after-3d", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-10", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#4", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 6, + "taskIndex": 4, + "rawText": "- [ ] Back up the laptop @repeat:weekly", + "content": "Back up the laptop @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#5", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 7, + "taskIndex": 5, + "rawText": "- [ ] Stretch @repeat:daily", + "content": "Stretch @repeat:daily", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#6", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 8, + "taskIndex": 6, + "rawText": "- [ ] Tidy the desk @repeat:weekdays due:2027-03-08", + "content": "Tidy the desk @repeat:weekdays", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-08", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#7", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 9, + "taskIndex": 7, + "rawText": "- [ ] Call the bank @repeat:after-3d @remind:2027-03-09 due:2027-03-11", + "content": "Call the bank @repeat:after-3d @remind:2027-03-09", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-11", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#8", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 10, + "taskIndex": 8, + "rawText": "- [x] Finished chore @repeat:daily due:2027-03-07", + "content": "Finished chore @repeat:daily", + "checked": true, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-07", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/pay-rent.md#task", + "sourcePath": "inbox/pay-rent.md", + "link": "zennotes://open?path=inbox/pay-rent.md", + "noteTitle": "pay-rent", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": -1, + "rawText": "", + "content": "pay-rent", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2027-03-12", + "priority": "high", + "waiting": false, + "status": "open", + "tags": [ + "finance" + ], + "kind": "file" + } +] diff --git a/internal/cli/testdata/released-repeat.json b/internal/cli/testdata/released-repeat.json new file mode 100644 index 0000000..548ade0 --- /dev/null +++ b/internal/cli/testdata/released-repeat.json @@ -0,0 +1,166 @@ +[ + { + "id": "inbox/chores.md#0", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water the plants @repeat:daily due:2027-03-08", + "content": "Water the plants @repeat:daily", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-08", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#1", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Take out the bins @repeat:weekly due:2027-03-09", + "content": "Take out the bins @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-09", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#2", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 4, + "taskIndex": 2, + "rawText": "- [ ] Gym @repeat:mon/thu due:2027-03-08", + "content": "Gym @repeat:mon/thu", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-08", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#3", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 5, + "taskIndex": 3, + "rawText": "- [ ] Change the filter @repeat:after-3d due:2027-03-10", + "content": "Change the filter @repeat:after-3d", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-10", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#4", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 6, + "taskIndex": 4, + "rawText": "- [ ] Back up the laptop @repeat:weekly", + "content": "Back up the laptop @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#5", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 7, + "taskIndex": 5, + "rawText": "- [ ] Stretch @repeat:daily", + "content": "Stretch @repeat:daily", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#6", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 8, + "taskIndex": 6, + "rawText": "- [ ] Tidy the desk @repeat:weekdays due:2027-03-08", + "content": "Tidy the desk @repeat:weekdays", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-08", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/chores.md#7", + "sourcePath": "inbox/chores.md", + "link": "zennotes://open?path=inbox/chores.md", + "noteTitle": "chores", + "noteFolder": "inbox", + "lineNumber": 9, + "taskIndex": 7, + "rawText": "- [ ] Call the bank @repeat:after-3d @remind:2027-03-09 due:2027-03-11", + "content": "Call the bank @repeat:after-3d @remind:2027-03-09", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2027-03-11", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/pay-rent.md#task", + "sourcePath": "inbox/pay-rent.md", + "link": "zennotes://open?path=inbox/pay-rent.md", + "noteTitle": "pay-rent", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": -1, + "rawText": "", + "content": "pay-rent", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2027-03-12", + "priority": "high", + "waiting": false, + "status": "open", + "tags": [ + "finance" + ], + "kind": "file" + } +] diff --git a/internal/cli/testdata/released-repeat.txt b/internal/cli/testdata/released-repeat.txt new file mode 100644 index 0000000..496db89 --- /dev/null +++ b/internal/cli/testdata/released-repeat.txt @@ -0,0 +1,9 @@ +[ ] inbox/chores.md#0 Water the plants @repeat:daily due:2027-03-08 +[ ] inbox/chores.md#1 Take out the bins @repeat:weekly due:2027-03-09 +[ ] inbox/chores.md#2 Gym @repeat:mon/thu due:2027-03-08 +[ ] inbox/chores.md#3 Change the filter @repeat:after-3d due:2027-03-10 +[ ] inbox/chores.md#4 Back up the laptop @repeat:weekly +[ ] inbox/chores.md#5 Stretch @repeat:daily +[ ] inbox/chores.md#6 Tidy the desk @repeat:weekdays due:2027-03-08 +[ ] inbox/chores.md#7 Call the bank @repeat:after-3d @remind:2027-03-09 due:2027-03-11 +[ ] inbox/pay-rent.md#task pay-rent due:2027-03-12 !high diff --git a/internal/cli/testdata/released-repeat/inbox/chores.md b/internal/cli/testdata/released-repeat/inbox/chores.md new file mode 100644 index 0000000..af82396 --- /dev/null +++ b/internal/cli/testdata/released-repeat/inbox/chores.md @@ -0,0 +1,11 @@ +# Chores + +- [ ] Water the plants @repeat:daily due:2027-03-08 +- [ ] Take out the bins @repeat:weekly due:2027-03-09 +- [ ] Gym @repeat:mon/thu due:2027-03-08 +- [ ] Change the filter @repeat:after-3d due:2027-03-10 +- [ ] Back up the laptop @repeat:weekly +- [ ] Stretch @repeat:daily +- [ ] Tidy the desk @repeat:weekdays due:2027-03-08 +- [ ] Call the bank @repeat:after-3d @remind:2027-03-09 due:2027-03-11 +- [x] Finished chore @repeat:daily due:2027-03-07 diff --git a/internal/cli/testdata/released-repeat/inbox/pay-rent.md b/internal/cli/testdata/released-repeat/inbox/pay-rent.md new file mode 100644 index 0000000..2ddd459 --- /dev/null +++ b/internal/cli/testdata/released-repeat/inbox/pay-rent.md @@ -0,0 +1,8 @@ +--- +tags: [task, finance] +status: open +due: 2027-03-12 +priority: high +--- + +# Pay rent From 5b1d32267fff1b86b6fdae018feabf38f8b86058 Mon Sep 17 00:00:00 2001 From: Spirit of Light Date: Sat, 7 Nov 2026 20:25:23 -0500 Subject: [PATCH 3/4] Test(tasks): remote vaults and task lists keep their released behaviour These tests compare zn with the output of zn v0.18.1 and add no new behaviour. Against a server, `zn task list` in JSON and in text, and the MCP `list_tasks` tool, give the same bytes as zn v0.18.1. This includes a `scheduled` value that the server sends. A toggle of a `@repeat:` task on a remote vault writes the next open line and the finished line. The tests keep this behaviour in the CLI and in MCP. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0171pE1tFQspTuCEpf1xvQiH --- internal/cli/remote_parity_test.go | 150 ++++++++++++++++++ internal/cli/testdata/remote-tasks-all.json | 95 +++++++++++ internal/cli/testdata/remote-tasks.json | 60 +++++++ internal/cli/testdata/remote-tasks.txt | 3 + internal/cli/testdata/remote-tasks/notes.json | 4 + .../remote-tasks/notes/inbox/Essay.md | 8 + .../testdata/remote-tasks/notes/inbox/Work.md | 6 + .../cli/testdata/remote-tasks/settings.json | 1 + internal/cli/testdata/remote-tasks/tasks.json | 7 + internal/cli/testdata/remote-tasks/vault.json | 1 + internal/mcp/remote_fixture_test.go | 90 +++++++++++ .../mcp/testdata/remote-list-tasks-all.json | 95 +++++++++++ internal/mcp/testdata/remote-list-tasks.json | 60 +++++++ internal/mcp/tools_test.go | 60 +++++++ 14 files changed, 640 insertions(+) create mode 100644 internal/cli/remote_parity_test.go create mode 100644 internal/cli/testdata/remote-tasks-all.json create mode 100644 internal/cli/testdata/remote-tasks.json create mode 100644 internal/cli/testdata/remote-tasks.txt create mode 100644 internal/cli/testdata/remote-tasks/notes.json create mode 100644 internal/cli/testdata/remote-tasks/notes/inbox/Essay.md create mode 100644 internal/cli/testdata/remote-tasks/notes/inbox/Work.md create mode 100644 internal/cli/testdata/remote-tasks/settings.json create mode 100644 internal/cli/testdata/remote-tasks/tasks.json create mode 100644 internal/cli/testdata/remote-tasks/vault.json create mode 100644 internal/mcp/remote_fixture_test.go create mode 100644 internal/mcp/testdata/remote-list-tasks-all.json create mode 100644 internal/mcp/testdata/remote-list-tasks.json diff --git a/internal/cli/remote_parity_test.go b/internal/cli/remote_parity_test.go new file mode 100644 index 0000000..2bec78b --- /dev/null +++ b/internal/cli/remote_parity_test.go @@ -0,0 +1,150 @@ +package cli + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "reflect" + "sync" + "testing" +) + +// remoteServer serves the recorded responses in testdata/remote-tasks as a +// ZenNotes server and records each note body that a client writes. +type remoteServer struct { + URL string + mu sync.Mutex + writes []string +} + +func (s *remoteServer) Writes() []string { + s.mu.Lock() + defer s.mu.Unlock() + return append([]string(nil), s.writes...) +} + +func newRemoteServer(t *testing.T) *remoteServer { + t.Helper() + dir := filepath.Join("testdata", "remote-tasks") + file := func(name string) []byte { + b, err := os.ReadFile(filepath.Join(dir, name)) + if err != nil { + t.Fatal(err) + } + return b + } + var tasks []map[string]any + if err := json.Unmarshal(file("tasks.json"), &tasks); err != nil { + t.Fatal(err) + } + s := &remoteServer{} + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch r.URL.Path { + case "/api/vault": + _, _ = w.Write(file("vault.json")) + case "/api/vault/settings": + _, _ = w.Write(file("settings.json")) + case "/api/notes": + _, _ = w.Write(file("notes.json")) + case "/api/tasks": + _, _ = w.Write(file("tasks.json")) + case "/api/tasks/for": + out := []map[string]any{} + for _, task := range tasks { + if task["sourcePath"] == r.URL.Query().Get("path") { + out = append(out, task) + } + } + _ = json.NewEncoder(w).Encode(out) + case "/api/notes/read": + rel := r.URL.Query().Get("path") + var metas []map[string]any + _ = json.Unmarshal(file("notes.json"), &metas) + for _, meta := range metas { + if meta["path"] == rel { + meta["body"] = string(file(filepath.Join("notes", filepath.FromSlash(rel)))) + _ = json.NewEncoder(w).Encode(meta) + return + } + } + http.NotFound(w, r) + case "/api/notes/write": + var in map[string]string + _ = json.NewDecoder(r.Body).Decode(&in) + s.mu.Lock() + s.writes = append(s.writes, in["path"]+"\n"+in["body"]) + s.mu.Unlock() + _ = json.NewEncoder(w).Encode(map[string]any{ + "path": in["path"], "title": "x", "folder": "inbox", "tags": []string{}, "wikilinks": []string{}, + }) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(server.Close) + s.URL = server.URL + return s +} + +// useRemoteServer points zn at the server for the rest of the test. +func useRemoteServer(t *testing.T, s *remoteServer) { + t.Helper() + isolatedCLI(t) + t.Setenv("ZENNOTES_SERVER", s.URL) + t.Setenv("ZENNOTES_REMOTE_TOKEN", "token") +} + +// Against a server, `zn task list` prints the same bytes as zn v0.18.1 for +// a checkbox task with `@repeat:` and for a task note. The `scheduled` value +// that the server sends stays in the JSON. +func TestRemoteTaskListMatchesReleasedOutput(t *testing.T) { + s := newRemoteServer(t) + useRemoteServer(t, s) + for _, tc := range []struct { + golden string + flags []string + }{ + {"remote-tasks.json", []string{"--json"}}, + {"remote-tasks-all.json", []string{"--json", "--all"}}, + {"remote-tasks.txt", nil}, + } { + want, err := os.ReadFile(filepath.Join("testdata", tc.golden)) + if err != nil { + t.Fatal(err) + } + args := append([]string{"task", "list"}, tc.flags...) + out := captureOutput(t, func() { + if code := Main(args); code != 0 { + t.Errorf("zn %v exited %d", args, code) + } + }) + if out != string(want) { + t.Errorf("zn %v differs from testdata/%s:\n%s", args, tc.golden, out) + } + } +} + +// Against a server, `zn task toggle` of a `@repeat:` task writes the next +// open line and the finished line, as zn v0.18.1 does. +func TestRemoteToggleOfRepeatingTaskMakesNextOccurrence(t *testing.T) { + s := newRemoteServer(t) + useRemoteServer(t, s) + args := []string{"task", "toggle", "inbox/Work.md#0"} + captureOutput(t, func() { + if code := Main(args); code != 0 { + t.Errorf("zn %v exited %d", args, code) + } + }) + want := []string{"inbox/Work.md\n# Work\n\n" + + "- [ ] Water plants @repeat:weekly due:2099-01-12\n" + + "- [x] Water plants due:2099-01-05\n" + + "- [ ] Send the invoice due:2026-11-12\n" + + "- [x] Pay the bill due:2026-11-01\n" + + "- [-] Cancel the trip\n"} + if got := s.Writes(); !reflect.DeepEqual(got, want) { + t.Fatalf("writes:\n%q\nwant:\n%q", got, want) + } +} diff --git a/internal/cli/testdata/remote-tasks-all.json b/internal/cli/testdata/remote-tasks-all.json new file mode 100644 index 0000000..43dd0d5 --- /dev/null +++ b/internal/cli/testdata/remote-tasks-all.json @@ -0,0 +1,95 @@ +[ + { + "id": "inbox/Work.md#0", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water plants @repeat:weekly due:2099-01-05", + "content": "Water plants @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2099-01-05", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#1", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Send the invoice due:2026-11-12", + "content": "Send the invoice", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-12", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#2", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 4, + "taskIndex": 2, + "rawText": "- [x] Pay the bill due:2026-11-01", + "content": "Pay the bill", + "checked": true, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-01", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#3", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 5, + "taskIndex": 3, + "rawText": "- [-] Cancel the trip", + "content": "Cancel the trip", + "checked": false, + "cancelled": true, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Essay.md#task", + "sourcePath": "inbox/Essay.md", + "link": "zennotes://open?path=inbox/Essay.md", + "noteTitle": "Essay", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": 0, + "rawText": "Essay", + "content": "Essay", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2026-11-10", + "waiting": false, + "status": "open", + "tags": [ + "task" + ], + "kind": "file", + "scheduled": "2026-11-05" + } +] diff --git a/internal/cli/testdata/remote-tasks.json b/internal/cli/testdata/remote-tasks.json new file mode 100644 index 0000000..e313519 --- /dev/null +++ b/internal/cli/testdata/remote-tasks.json @@ -0,0 +1,60 @@ +[ + { + "id": "inbox/Work.md#0", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water plants @repeat:weekly due:2099-01-05", + "content": "Water plants @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2099-01-05", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#1", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Send the invoice due:2026-11-12", + "content": "Send the invoice", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-12", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Essay.md#task", + "sourcePath": "inbox/Essay.md", + "link": "zennotes://open?path=inbox/Essay.md", + "noteTitle": "Essay", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": 0, + "rawText": "Essay", + "content": "Essay", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2026-11-10", + "waiting": false, + "status": "open", + "tags": [ + "task" + ], + "kind": "file", + "scheduled": "2026-11-05" + } +] diff --git a/internal/cli/testdata/remote-tasks.txt b/internal/cli/testdata/remote-tasks.txt new file mode 100644 index 0000000..7cdc0ab --- /dev/null +++ b/internal/cli/testdata/remote-tasks.txt @@ -0,0 +1,3 @@ +[ ] inbox/Work.md#0 Water plants @repeat:weekly due:2099-01-05 +[ ] inbox/Work.md#1 Send the invoice due:2026-11-12 +[ ] inbox/Essay.md#task Essay due:2026-11-10 diff --git a/internal/cli/testdata/remote-tasks/notes.json b/internal/cli/testdata/remote-tasks/notes.json new file mode 100644 index 0000000..40ce823 --- /dev/null +++ b/internal/cli/testdata/remote-tasks/notes.json @@ -0,0 +1,4 @@ +[ + {"path":"inbox/Work.md","link":"","title":"Work","folder":"inbox","createdAt":1762000000000,"updatedAt":1762000000000,"size":120,"tags":[],"wikilinks":[]}, + {"path":"inbox/Essay.md","link":"","title":"Essay","folder":"inbox","createdAt":1762000000000,"updatedAt":1762000000000,"size":90,"tags":["task"],"wikilinks":[]} +] diff --git a/internal/cli/testdata/remote-tasks/notes/inbox/Essay.md b/internal/cli/testdata/remote-tasks/notes/inbox/Essay.md new file mode 100644 index 0000000..77de5ca --- /dev/null +++ b/internal/cli/testdata/remote-tasks/notes/inbox/Essay.md @@ -0,0 +1,8 @@ +--- +tags: [task] +status: open +scheduled: 2026-11-05 +due: 2026-11-10 +--- + +# Essay diff --git a/internal/cli/testdata/remote-tasks/notes/inbox/Work.md b/internal/cli/testdata/remote-tasks/notes/inbox/Work.md new file mode 100644 index 0000000..ade777d --- /dev/null +++ b/internal/cli/testdata/remote-tasks/notes/inbox/Work.md @@ -0,0 +1,6 @@ +# Work + +- [ ] Water plants @repeat:weekly due:2099-01-05 +- [ ] Send the invoice due:2026-11-12 +- [x] Pay the bill due:2026-11-01 +- [-] Cancel the trip diff --git a/internal/cli/testdata/remote-tasks/settings.json b/internal/cli/testdata/remote-tasks/settings.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/internal/cli/testdata/remote-tasks/settings.json @@ -0,0 +1 @@ +{} diff --git a/internal/cli/testdata/remote-tasks/tasks.json b/internal/cli/testdata/remote-tasks/tasks.json new file mode 100644 index 0000000..73ea745 --- /dev/null +++ b/internal/cli/testdata/remote-tasks/tasks.json @@ -0,0 +1,7 @@ +[ + {"id":"inbox/Work.md#0","sourcePath":"inbox/Work.md","link":"","noteTitle":"Work","noteFolder":"inbox","lineNumber":2,"taskIndex":0,"rawText":"- [ ] Water plants @repeat:weekly due:2099-01-05","content":"Water plants @repeat:weekly","checked":false,"cancelled":false,"inProgress":false,"forwarded":false,"due":"2099-01-05","waiting":false,"tags":[]}, + {"id":"inbox/Work.md#1","sourcePath":"inbox/Work.md","link":"","noteTitle":"Work","noteFolder":"inbox","lineNumber":3,"taskIndex":1,"rawText":"- [ ] Send the invoice due:2026-11-12","content":"Send the invoice","checked":false,"cancelled":false,"inProgress":false,"forwarded":false,"due":"2026-11-12","waiting":false,"tags":[]}, + {"id":"inbox/Work.md#2","sourcePath":"inbox/Work.md","link":"","noteTitle":"Work","noteFolder":"inbox","lineNumber":4,"taskIndex":2,"rawText":"- [x] Pay the bill due:2026-11-01","content":"Pay the bill","checked":true,"cancelled":false,"inProgress":false,"forwarded":false,"due":"2026-11-01","waiting":false,"tags":[]}, + {"id":"inbox/Work.md#3","sourcePath":"inbox/Work.md","link":"","noteTitle":"Work","noteFolder":"inbox","lineNumber":5,"taskIndex":3,"rawText":"- [-] Cancel the trip","content":"Cancel the trip","checked":false,"cancelled":true,"inProgress":false,"forwarded":false,"waiting":false,"tags":[]}, + {"id":"inbox/Essay.md#task","sourcePath":"inbox/Essay.md","link":"","noteTitle":"Essay","noteFolder":"inbox","lineNumber":0,"taskIndex":0,"rawText":"Essay","content":"Essay","checked":false,"cancelled":false,"inProgress":false,"due":"2026-11-10","waiting":false,"status":"open","tags":["task"],"kind":"file","scheduled":"2026-11-05"} +] diff --git a/internal/cli/testdata/remote-tasks/vault.json b/internal/cli/testdata/remote-tasks/vault.json new file mode 100644 index 0000000..a96a32d --- /dev/null +++ b/internal/cli/testdata/remote-tasks/vault.json @@ -0,0 +1 @@ +{"root":"/srv/notes","name":"notes"} diff --git a/internal/mcp/remote_fixture_test.go b/internal/mcp/remote_fixture_test.go new file mode 100644 index 0000000..8ee043e --- /dev/null +++ b/internal/mcp/remote_fixture_test.go @@ -0,0 +1,90 @@ +package mcp + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "sync" + "testing" +) + +// remoteFixture serves the recorded responses in +// internal/cli/testdata/remote-tasks as a ZenNotes server. It records each +// note body that a client writes. +type remoteFixture struct { + URL string + mu sync.Mutex + writes []string +} + +func (f *remoteFixture) Writes() []string { + f.mu.Lock() + defer f.mu.Unlock() + return append([]string(nil), f.writes...) +} + +func newRemoteFixture(t *testing.T) *remoteFixture { + t.Helper() + dir := filepath.Join("..", "cli", "testdata", "remote-tasks") + file := func(name string) []byte { + b, err := os.ReadFile(filepath.Join(dir, name)) + if err != nil { + t.Fatal(err) + } + return b + } + var tasks []map[string]any + if err := json.Unmarshal(file("tasks.json"), &tasks); err != nil { + t.Fatal(err) + } + f := &remoteFixture{} + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch r.URL.Path { + case "/api/vault": + _, _ = w.Write(file("vault.json")) + case "/api/vault/settings": + _, _ = w.Write(file("settings.json")) + case "/api/notes": + _, _ = w.Write(file("notes.json")) + case "/api/tasks": + _, _ = w.Write(file("tasks.json")) + case "/api/tasks/for": + out := []map[string]any{} + for _, task := range tasks { + if task["sourcePath"] == r.URL.Query().Get("path") { + out = append(out, task) + } + } + _ = json.NewEncoder(w).Encode(out) + case "/api/notes/read": + rel := r.URL.Query().Get("path") + var metas []map[string]any + _ = json.Unmarshal(file("notes.json"), &metas) + for _, meta := range metas { + if meta["path"] == rel { + meta["body"] = string(file(filepath.Join("notes", filepath.FromSlash(rel)))) + _ = json.NewEncoder(w).Encode(meta) + return + } + } + http.NotFound(w, r) + case "/api/notes/write": + var in map[string]string + _ = json.NewDecoder(r.Body).Decode(&in) + f.mu.Lock() + f.writes = append(f.writes, in["path"]+"\n"+in["body"]) + f.mu.Unlock() + _ = json.NewEncoder(w).Encode(map[string]any{ + "path": in["path"], "title": "x", "folder": "inbox", "tags": []string{}, "wikilinks": []string{}, + }) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(server.Close) + f.URL = server.URL + return f +} diff --git a/internal/mcp/testdata/remote-list-tasks-all.json b/internal/mcp/testdata/remote-list-tasks-all.json new file mode 100644 index 0000000..25cc878 --- /dev/null +++ b/internal/mcp/testdata/remote-list-tasks-all.json @@ -0,0 +1,95 @@ +[ + { + "id": "inbox/Work.md#0", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water plants @repeat:weekly due:2099-01-05", + "content": "Water plants @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2099-01-05", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#1", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Send the invoice due:2026-11-12", + "content": "Send the invoice", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-12", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#2", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 4, + "taskIndex": 2, + "rawText": "- [x] Pay the bill due:2026-11-01", + "content": "Pay the bill", + "checked": true, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-01", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#3", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 5, + "taskIndex": 3, + "rawText": "- [-] Cancel the trip", + "content": "Cancel the trip", + "checked": false, + "cancelled": true, + "inProgress": false, + "forwarded": false, + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Essay.md#task", + "sourcePath": "inbox/Essay.md", + "link": "zennotes://open?path=inbox/Essay.md", + "noteTitle": "Essay", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": 0, + "rawText": "Essay", + "content": "Essay", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2026-11-10", + "waiting": false, + "status": "open", + "tags": [ + "task" + ], + "kind": "file", + "scheduled": "2026-11-05" + } +] \ No newline at end of file diff --git a/internal/mcp/testdata/remote-list-tasks.json b/internal/mcp/testdata/remote-list-tasks.json new file mode 100644 index 0000000..e2dbbe1 --- /dev/null +++ b/internal/mcp/testdata/remote-list-tasks.json @@ -0,0 +1,60 @@ +[ + { + "id": "inbox/Work.md#0", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 2, + "taskIndex": 0, + "rawText": "- [ ] Water plants @repeat:weekly due:2099-01-05", + "content": "Water plants @repeat:weekly", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2099-01-05", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Work.md#1", + "sourcePath": "inbox/Work.md", + "link": "zennotes://open?path=inbox/Work.md", + "noteTitle": "Work", + "noteFolder": "inbox", + "lineNumber": 3, + "taskIndex": 1, + "rawText": "- [ ] Send the invoice due:2026-11-12", + "content": "Send the invoice", + "checked": false, + "cancelled": false, + "inProgress": false, + "forwarded": false, + "due": "2026-11-12", + "waiting": false, + "tags": [] + }, + { + "id": "inbox/Essay.md#task", + "sourcePath": "inbox/Essay.md", + "link": "zennotes://open?path=inbox/Essay.md", + "noteTitle": "Essay", + "noteFolder": "inbox", + "lineNumber": 0, + "taskIndex": 0, + "rawText": "Essay", + "content": "Essay", + "checked": false, + "cancelled": false, + "inProgress": false, + "due": "2026-11-10", + "waiting": false, + "status": "open", + "tags": [ + "task" + ], + "kind": "file", + "scheduled": "2026-11-05" + } +] \ No newline at end of file diff --git a/internal/mcp/tools_test.go b/internal/mcp/tools_test.go index ba007d0..fa339b7 100644 --- a/internal/mcp/tools_test.go +++ b/internal/mcp/tools_test.go @@ -3,8 +3,15 @@ package mcp import ( "bytes" "encoding/json" + "os" + "path/filepath" + "reflect" "strings" "testing" + + sdk "github.com/modelcontextprotocol/go-sdk/mcp" + + "github.com/ZenNotes/tui/internal/backend" ) // The desktop MCP server's tool names; the Go server must offer them all. @@ -88,3 +95,56 @@ func TestEncodedStringSize(t *testing.T) { t.Errorf("a bad byte: %d", got) } } + +func remoteSession(t *testing.T, f *remoteFixture) *sdk.ClientSession { + t.Helper() + return runServer(t, func() (backend.Target, error) { + return backend.Target{Kind: backend.KindRemote, BaseURL: f.URL, AuthToken: "token"}, nil + }) +} + +// Against a server, toggle_task of a `@repeat:` task writes the next open +// line and the finished line, as zn v0.18.1 does. +func TestRemoteToggleTaskToolMakesNextOccurrence(t *testing.T) { + f := newRemoteFixture(t) + cs := remoteSession(t, f) + text, isErr := callTool(t, cs, "toggle_task", map[string]any{"id": "inbox/Work.md#0"}) + if isErr { + t.Fatalf("toggle_task: %s", text) + } + want := []string{"inbox/Work.md\n# Work\n\n" + + "- [ ] Water plants @repeat:weekly due:2099-01-12\n" + + "- [x] Water plants due:2099-01-05\n" + + "- [ ] Send the invoice due:2026-11-12\n" + + "- [x] Pay the bill due:2026-11-01\n" + + "- [-] Cancel the trip\n"} + if got := f.Writes(); !reflect.DeepEqual(got, want) { + t.Fatalf("writes:\n%q\nwant:\n%q", got, want) + } +} + +// Against a server, list_tasks returns the same text as zn v0.18.1, with the +// `scheduled` value of the server kept. +func TestListTasksAgainstRemoteMatchesReleased(t *testing.T) { + f := newRemoteFixture(t) + cs := remoteSession(t, f) + for _, tc := range []struct { + golden string + args map[string]any + }{ + {"remote-list-tasks.json", nil}, + {"remote-list-tasks-all.json", map[string]any{"status": "all"}}, + } { + want, err := os.ReadFile(filepath.Join("testdata", tc.golden)) + if err != nil { + t.Fatal(err) + } + text, isErr := callTool(t, cs, "list_tasks", tc.args) + if isErr { + t.Fatalf("list_tasks: %s", text) + } + if text != string(want) { + t.Errorf("list_tasks %v differs from testdata/%s:\n%s", tc.args, tc.golden, text) + } + } +} From bbcf2bf48bb651789a0e8c05309946a221920904 Mon Sep 17 00:00:00 2001 From: Spirit of Light Date: Sat, 21 Nov 2026 08:48:41 -0500 Subject: [PATCH 4/4] Test(tasks): the new golden files keep LF on every platform Git on Windows can convert the golden files to CRLF. The tests then fail. Two lines in `.gitattributes` keep LF in `internal/cli/testdata` and in `internal/tui/testdata`. No test in this change makes a folder read-only, so no test must stop early on Windows. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0171pE1tFQspTuCEpf1xvQiH --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index 5b76391..5dcca2a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,5 @@ internal/remote/testdata/** text eol=lf internal/vault/testdata/** text eol=lf internal/mcp/testdata/** text eol=lf +internal/cli/testdata/** text eol=lf +internal/tui/testdata/** text eol=lf