MCPcopy Create free account
hub / github.com/Facets-cloud/flow / TestCmdEditNamespacePrefix

Function TestCmdEditNamespacePrefix

internal/app/edit_test.go:148–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

146}
147
148func 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
186func TestCmdEditTaskOnlyByDefault(t *testing.T) {
187 // When only a task exists, fuzzy ref resolves without prefix.

Callers

nothing calls this directly

Calls 6

showListEditDBFunction · 0.85
writeFakeEditorFunction · 0.85
captureStdoutFunction · 0.85
cmdEditFunction · 0.85
insertProjectFunction · 0.70
insertTaskFunction · 0.70

Tested by

no test coverage detected