summaryrefslogtreecommitdiff
path: root/internal/askcli/command_write_test.go
blob: e9229205062da3cbf447299019def95b4a7e5db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
package askcli

import (
	"bytes"
	"context"
	"errors"
	"io"
	"path/filepath"
	"strings"
	"testing"
	"time"
)

func useIsolatedTaskAliasCache(t *testing.T) time.Time {
	t.Helper()

	dir := t.TempDir()
	oldRoot := taskAliasCacheRoot
	oldNow := nowTaskAliasCache
	fixedNow := time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC)
	taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
	nowTaskAliasCache = func() time.Time { return fixedNow }
	t.Cleanup(func() {
		taskAliasCacheRoot = oldRoot
		nowTaskAliasCache = oldNow
	})
	return fixedNow
}

func TestHandleStart_AliasSelector(t *testing.T) {
	now := useIsolatedTaskAliasCache(t)

	writeTaskAliasCacheForTest(t, taskAliasCache{
		NextID: 1,
		Entries: []taskAliasCacheEntry{
			{UUID: "test-uuid", Alias: "0", CreatedAt: now},
		},
	})

	var capturedArgs []string
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		capturedArgs = args
		return 0, nil
	}})

	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"start", "0"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("start code = %d stderr = %q", code, stderr.String())
	}
	if len(capturedArgs) != 2 || capturedArgs[0] != "uuid:test-uuid" || capturedArgs[1] != "start" {
		t.Fatalf("capturedArgs = %v, want [uuid:test-uuid start]", capturedArgs)
	}
}

func TestHandleDenotate_Success(t *testing.T) {
	now := useIsolatedTaskAliasCache(t)

	writeTaskAliasCacheForTest(t, taskAliasCache{
		NextID: 1,
		Entries: []taskAliasCacheEntry{
			{UUID: "test-uuid", Alias: "0", CreatedAt: now},
		},
	})

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, err := d.Dispatch(context.Background(), []string{"denotate", "test-uuid", "old annotation"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("denotate code = %d, want 0", code)
	}
	if err != nil {
		t.Fatalf("denotate returned error: %v", err)
	}
	if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") {
		t.Fatalf("stdout = %q, want ok + alias only", stdout.String())
	}
}

func TestHandleDenotate_NumericID(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for numeric ID")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"denotate", "123", "text"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("denotate code = %d, want 1 for numeric ID", code)
	}
}

func TestHandleDenotate_MissingArgs(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for missing args")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"denotate", "uuid"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("denotate code = %d, want 1 for missing args", code)
	}
	if !strings.Contains(stderr.String(), "requires an ID or UUID") {
		t.Fatalf("stderr = %q, want ID-or-UUID message", stderr.String())
	}
}

func TestHandleModify_Success(t *testing.T) {
	now := useIsolatedTaskAliasCache(t)

	writeTaskAliasCacheForTest(t, taskAliasCache{
		NextID: 1,
		Entries: []taskAliasCacheEntry{
			{UUID: "test-uuid", Alias: "0", CreatedAt: now},
		},
	})

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"modify", "test-uuid", "priority:H"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("modify code = %d, want 0", code)
	}
	if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") {
		t.Fatalf("stdout = %q, want ok + alias only", stdout.String())
	}
}

func TestHandleModify_NumericID(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for numeric ID")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"modify", "123", "priority:H"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("modify code = %d, want 1 for numeric ID", code)
	}
}

func TestHandleAnnotate_Success(t *testing.T) {
	now := useIsolatedTaskAliasCache(t)

	writeTaskAliasCacheForTest(t, taskAliasCache{
		NextID: 1,
		Entries: []taskAliasCacheEntry{
			{UUID: "test-uuid", Alias: "0", CreatedAt: now},
		},
	})

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"annotate", "test-uuid", "new note"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("annotate code = %d, want 0", code)
	}
	if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") {
		t.Fatalf("stdout = %q, want ok + alias only", stdout.String())
	}
}

func TestHandleAnnotate_MissingArgs(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for missing args")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"annotate", "uuid"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("annotate code = %d, want 1 for missing args", code)
	}
	if !strings.Contains(stderr.String(), "requires an ID or UUID") {
		t.Fatalf("stderr = %q, want ID-or-UUID message", stderr.String())
	}
}

func TestHandleStart_Success(t *testing.T) {
	now := useIsolatedTaskAliasCache(t)

	writeTaskAliasCacheForTest(t, taskAliasCache{
		NextID: 1,
		Entries: []taskAliasCacheEntry{
			{UUID: "test-uuid", Alias: "0", CreatedAt: now},
		},
	})

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"start", "test-uuid"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("start code = %d, want 0", code)
	}
	if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") {
		t.Fatalf("stdout = %q, want ok + alias only", stdout.String())
	}
}

func TestHandleStart_MissingUUID(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for missing UUID")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"start"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("start code = %d, want 1 for missing UUID", code)
	}
	if !strings.Contains(stderr.String(), "requires an ID or UUID") {
		t.Fatalf("stderr = %q, want ID-or-UUID message", stderr.String())
	}
}

func TestHandleStop_Success(t *testing.T) {
	useIsolatedTaskAliasCache(t)

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"stop", "test-uuid"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("stop code = %d, want 0", code)
	}
}

func TestHandleDone_Success(t *testing.T) {
	useIsolatedTaskAliasCache(t)

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"done", "test-uuid"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("done code = %d, want 0", code)
	}
}

func TestHandlePriority_Success(t *testing.T) {
	useIsolatedTaskAliasCache(t)

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"priority", "test-uuid", "H"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("priority code = %d, want 0", code)
	}
}

func TestHandlePriority_MissingArgs(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for missing args")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"priority", "uuid"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("priority code = %d, want 1 for missing args", code)
	}
	if !strings.Contains(stderr.String(), "requires an ID or UUID") {
		t.Fatalf("stderr = %q, want ID-or-UUID message", stderr.String())
	}
}

func TestHandleTag_Success(t *testing.T) {
	useIsolatedTaskAliasCache(t)

	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"tag", "test-uuid", "+cli"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 0 {
		t.Fatalf("tag code = %d, want 0", code)
	}
}

func TestHandleTag_NumericID(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called for numeric ID")
		return 0, nil
	}})
	var stdout, stderr bytes.Buffer
	code, _ := d.Dispatch(context.Background(), []string{"tag", "123", "+cli"}, &bytes.Buffer{}, &stdout, &stderr)
	if code != 1 {
		t.Fatalf("tag code = %d, want 1 for numeric ID", code)
	}
}

func TestAllWriteHandlers_PassCorrectArgs(t *testing.T) {
	testCases := []struct {
		subcommand string
		args       []string
		wantArgs   []string
	}{
		// All commands use uuid:<uuid> as the filter so taskwarrior selects
		// the exact task; the action verb and any arguments follow.
		{"denotate", []string{"denotate", "my-uuid", "text"}, []string{"uuid:my-uuid", "denotate", "text"}},
		{"modify", []string{"modify", "my-uuid", "priority:H"}, []string{"uuid:my-uuid", "modify", "priority:H"}},
		{"annotate", []string{"annotate", "my-uuid", "note"}, []string{"uuid:my-uuid", "annotate", "note"}},
		{"start", []string{"start", "my-uuid"}, []string{"uuid:my-uuid", "start"}},
		{"stop", []string{"stop", "my-uuid"}, []string{"uuid:my-uuid", "stop"}},
		{"done", []string{"done", "my-uuid"}, []string{"uuid:my-uuid", "done"}},
		{"priority", []string{"priority", "my-uuid", "H"}, []string{"uuid:my-uuid", "modify", "priority:H"}},
		{"tag", []string{"tag", "my-uuid", "+cli"}, []string{"uuid:my-uuid", "modify", "+cli"}},
	}

	for _, tc := range testCases {
		t.Run(tc.subcommand, func(t *testing.T) {
			useIsolatedTaskAliasCache(t)

			var capturedArgs []string
			d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
				if len(args) == 2 && args[1] == "export" {
					_, _ = io.WriteString(stdout, `[{"uuid":"my-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
					return 0, nil
				}
				capturedArgs = args
				return 0, nil
			}})
			var stdout, stderr bytes.Buffer
			d.Dispatch(context.Background(), tc.args, &bytes.Buffer{}, &stdout, &stderr)
			if len(capturedArgs) != len(tc.wantArgs) {
				t.Fatalf("capturedArgs = %v, want %v", capturedArgs, tc.wantArgs)
			}
			for i, want := range tc.wantArgs {
				if capturedArgs[i] != want {
					t.Fatalf("capturedArgs[%d] = %q, want %q", i, capturedArgs[i], want)
				}
			}
		})
	}
}

// TestAllWriteHandlers_AcceptUUIDPrefix verifies that commands accept a
// "uuid:" prefixed argument (e.g. "uuid:my-uuid") and strip the prefix
// before building the taskwarrior filter, so the filter is never doubled.
func TestAllWriteHandlers_AcceptUUIDPrefix(t *testing.T) {
	testCases := []struct {
		subcommand string
		args       []string
		wantArgs   []string
	}{
		{"denotate", []string{"denotate", "uuid:my-uuid", "text"}, []string{"uuid:my-uuid", "denotate", "text"}},
		{"modify", []string{"modify", "uuid:my-uuid", "priority:H"}, []string{"uuid:my-uuid", "modify", "priority:H"}},
		{"annotate", []string{"annotate", "uuid:my-uuid", "note"}, []string{"uuid:my-uuid", "annotate", "note"}},
		{"start", []string{"start", "uuid:my-uuid"}, []string{"uuid:my-uuid", "start"}},
		{"stop", []string{"stop", "uuid:my-uuid"}, []string{"uuid:my-uuid", "stop"}},
		{"done", []string{"done", "uuid:my-uuid"}, []string{"uuid:my-uuid", "done"}},
		{"priority", []string{"priority", "uuid:my-uuid", "H"}, []string{"uuid:my-uuid", "modify", "priority:H"}},
		{"tag", []string{"tag", "uuid:my-uuid", "+cli"}, []string{"uuid:my-uuid", "modify", "+cli"}},
	}

	for _, tc := range testCases {
		t.Run(tc.subcommand, func(t *testing.T) {
			useIsolatedTaskAliasCache(t)

			var capturedArgs []string
			d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
				if len(args) == 2 && args[1] == "export" {
					_, _ = io.WriteString(stdout, `[{"uuid":"my-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
					return 0, nil
				}
				capturedArgs = args
				return 0, nil
			}})
			var stdout, stderr bytes.Buffer
			d.Dispatch(context.Background(), tc.args, &bytes.Buffer{}, &stdout, &stderr)
			if len(capturedArgs) != len(tc.wantArgs) {
				t.Fatalf("capturedArgs = %v, want %v", capturedArgs, tc.wantArgs)
			}
			for i, want := range tc.wantArgs {
				if capturedArgs[i] != want {
					t.Fatalf("capturedArgs[%d] = %q, want %q", i, capturedArgs[i], want)
				}
			}
		})
	}
}

func TestRunSingleTaskCommand_ResolveErrorWritesInfoError(t *testing.T) {
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		t.Fatal("runFn should not be called when selector resolution fails")
		return 0, nil
	}})

	var stdout, stderr bytes.Buffer
	code, err := d.runSingleTaskCommand(
		context.Background(),
		"123",
		&stdout,
		&stderr,
		func(resolved resolvedTaskSelector) []string {
			t.Fatal("buildArgs should not be called when selector resolution fails")
			return nil
		},
	)
	if code != 1 {
		t.Fatalf("runSingleTaskCommand code = %d, want 1", code)
	}
	if err != nil {
		t.Fatalf("runSingleTaskCommand returned error: %v", err)
	}
	if stdout.Len() != 0 {
		t.Fatalf("stdout = %q, want empty output", stdout.String())
	}
	if !strings.Contains(stderr.String(), "use a task alias ID or UUID") {
		t.Fatalf("stderr = %q, want numeric task ID error", stderr.String())
	}
}

func TestRunSingleTaskCommand_RunFailureDoesNotWriteSuccess(t *testing.T) {
	useIsolatedTaskAliasCache(t)

	runErr := errors.New("runner failed")
	d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
		if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" {
			_, _ = io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`)
			return 0, nil
		}
		return 2, runErr
	}})

	var stdout, stderr bytes.Buffer
	code, err := d.runSingleTaskCommand(
		context.Background(),
		"test-uuid",
		&stdout,
		&stderr,
		func(resolved resolvedTaskSelector) []string {
			return []string{"uuid:" + resolved.UUID, "start"}
		},
	)
	if code != 2 {
		t.Fatalf("runSingleTaskCommand code = %d, want 2", code)
	}
	if !errors.Is(err, runErr) {
		t.Fatalf("runSingleTaskCommand error = %v, want %v", err, runErr)
	}
	if stdout.Len() != 0 {
		t.Fatalf("stdout = %q, want empty output", stdout.String())
	}
	if stderr.Len() != 0 {
		t.Fatalf("stderr = %q, want empty output", stderr.String())
	}
}