(t *testing.T)
| 146 | } |
| 147 | |
| 148 | func TestCmdEditNamespacePrefix(t *testing.T) { |
| 149 | // task/<slug> and project/<slug> prefixes disambiguate. |
| 150 | root, db := showListEditDB(t) |
| 151 | insertProject(t, db, "twin", "Twin", filepath.Join(root, "x"), "medium") |
| 152 | insertTask(t, db, "twin", "Twin", "backlog", "medium", filepath.Join(root, "x"), nil) |
| 153 | |
| 154 | // Pre-create both briefs. |
| 155 | for _, kind := range []string{"tasks", "projects"} { |
| 156 | p := filepath.Join(root, kind, "twin", "brief.md") |
| 157 | if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { |
| 158 | t.Fatal(err) |
| 159 | } |
| 160 | if err := os.WriteFile(p, []byte("."), 0o644); err != nil { |
| 161 | t.Fatal(err) |
| 162 | } |
| 163 | } |
| 164 | script := writeFakeEditor(t, t.TempDir()) |
| 165 | os.Setenv("EDITOR", script) |
| 166 | t.Cleanup(func() { os.Unsetenv("EDITOR") }) |
| 167 | |
| 168 | out := captureStdout(t, func() { |
| 169 | if rc := cmdEdit([]string{"task/twin"}); rc != 0 { |
| 170 | t.Errorf("rc=%d", rc) |
| 171 | } |
| 172 | }) |
| 173 | if !strings.Contains(out, "Edited task twin") { |
| 174 | t.Errorf("task prefix failed; out=%q", out) |
| 175 | } |
| 176 | out = captureStdout(t, func() { |
| 177 | if rc := cmdEdit([]string{"project/twin"}); rc != 0 { |
| 178 | t.Errorf("rc=%d", rc) |
| 179 | } |
| 180 | }) |
| 181 | if !strings.Contains(out, "Edited project twin") { |
| 182 | t.Errorf("project prefix failed; out=%q", out) |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | func TestCmdEditTaskOnlyByDefault(t *testing.T) { |
| 187 | // When only a task exists, fuzzy ref resolves without prefix. |
nothing calls this directly
no test coverage detected