diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-06 09:02:07 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-06 09:02:07 +0300 |
| commit | dc17b7469c2055961892bbb3175d4ab0fb1d1180 (patch) | |
| tree | 541bf267994875abeedce0fddf399c95174d5fba /internal/askcli/command_edit_test.go | |
| parent | 1433f7a13ede0c819ec4f8fd4027ad3df8daa94f (diff) | |
Add 'ask edit ID' to edit task description in $EDITOR; bump to 0.41.0
Amp-Thread-ID: https://ampcode.com/threads/T-019e9b82-6ba0-77a4-b4a0-5c2cbf9bf39f
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'internal/askcli/command_edit_test.go')
| -rw-r--r-- | internal/askcli/command_edit_test.go | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/internal/askcli/command_edit_test.go b/internal/askcli/command_edit_test.go index 3f4b778..80cbd56 100644 --- a/internal/askcli/command_edit_test.go +++ b/internal/askcli/command_edit_test.go @@ -12,7 +12,7 @@ import ( func stubEditorCapture(t *testing.T, content string, err error) { t.Helper() old := captureFromEditor - captureFromEditor = func() (string, error) { + captureFromEditor = func(initial []byte) (string, error) { return content, err } t.Cleanup(func() { captureFromEditor = old }) @@ -49,6 +49,53 @@ func TestHandleEdit_Success(t *testing.T) { } } +func TestHandleEdit_ExistingTaskModifiesDescription(t *testing.T) { + now := useIsolatedTaskAliasCache(t) + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "existing-uuid", Alias: "0", CreatedAt: now}, + }, + }) + + var initialContent []byte + old := captureFromEditor + captureFromEditor = func(initial []byte) (string, error) { + initialContent = initial + return "updated description", nil + } + t.Cleanup(func() { captureFromEditor = old }) + + var capturedArgs []string + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + // First call: export to resolve selector. Subsequent: modify. + if len(args) >= 2 && args[1] == "export" { + _, _ = io.WriteString(stdout, `[{"uuid":"existing-uuid","description":"old description","status":"pending"}]`) + return 0, nil + } + capturedArgs = args + return 0, nil + }}) + + var stdout, stderr bytes.Buffer + code, _ := d.Dispatch(context.Background(), []string{"edit", "0"}, nil, &stdout, &stderr) + if code != 0 { + t.Fatalf("edit code = %d stderr = %q", code, stderr.String()) + } + if string(initialContent) != "old description" { + t.Fatalf("editor initial content = %q, want old description", initialContent) + } + want := []string{"uuid:existing-uuid", "modify", "updated description"} + if len(capturedArgs) != len(want) { + t.Fatalf("modify args = %v, want %v", capturedArgs, want) + } + for i := range want { + if capturedArgs[i] != want[i] { + t.Fatalf("modify args = %v, want %v", capturedArgs, want) + } + } +} + func TestHandleEdit_EmptyContentAborts(t *testing.T) { stubEditorCapture(t, "", nil) |
