v0.42.0 82578de

resident_cancellation_test.go RawHistoryFolder

1package subagents
2
3import (
4	"context"
5	"errors"
6	"path/filepath"
7	"testing"
8)
9
10func TestResidentCancellationPreservesInterruptedState(t *testing.T) {
11	for _, turnErr := range []error{context.Canceled, errors.Join(context.Canceled, errors.New("worker failed"))} {
12		t.Run(turnErr.Error(), func(t *testing.T) {
13			root := t.TempDir()
14			manager := NewResidentManager(root, func(ResidentChildSpec, *ResidentJournal) (ResidentTurnRunner, error) {
15				return func(context.Context, string) error { return turnErr }, nil
16			})
17			t.Cleanup(func() { _ = manager.Close(context.Background()) })
18			spec := ResidentChildSpec{ID: "canceled", InitialTurnID: "initial", SessionID: "session", Provider: "openai", Model: "test", Required: true}
19			completions := make(chan ResidentCompletion, 1)
20			manager.SetCompletionObserver(func(c ResidentCompletion) { completions <- c })
21			spawnCtx, cancel := context.WithCancel(t.Context())
22			defer cancel()
23			if _, err := manager.Spawn(spawnCtx, spec, "investigate"); err != nil {
24				t.Fatal(err)
25			}
26			cancel() // Accepted children outlive the caller's spawn context.
27			completion := awaitResidentCompletion(t, completions)
28			snapshot, ok := manager.SnapshotFor(spec.ID)
29			if !ok || snapshot.State != ResidentInterrupted || completion.Completion().Status != string(ResidentInterrupted) {
30				t.Fatalf("snapshot = %#v, completion = %#v", snapshot, completion)
31			}
32			result, err := manager.Result(spec.ID)
33			if err != nil || result.State != ResidentInterrupted || result.Handoff != "" || result.ErrorCode == residentV2ErrorBudgetExhausted {
34				t.Fatalf("result = %#v, error = %v", result, err)
35			}
36			if len(manager.UnmetRequired()) != 1 {
37				t.Fatal("cancellation satisfied required work")
38			}
39			if err := manager.Close(t.Context()); err != nil {
40				t.Fatal(err)
41			}
42			metadata, err := ReconcileResidentJournal(filepath.Join(root, spec.ID))
43			if err != nil || metadata.State != ResidentInterrupted {
44				t.Fatalf("reconciled metadata = %#v, error = %v", metadata, err)
45			}
46		})
47	}
48}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 477

↑↓ moveenter openesc close