v0.29.1 d92a60f

resident_artifact_recovery_test.go RawHistoryFolder

1package subagents
2
3import (
4	"os"
5	"path/filepath"
6	"reflect"
7	"testing"
8)
9
10func TestReconcileResidentJournalRestoresCapturedArtifacts(t *testing.T) {
11	for _, damage := range []string{"missing", "corrupt"} {
12		for _, captured := range []bool{false, true} {
13			name := damage + "/without-capture"
14			if captured {
15				name = damage + "/with-capture"
16			}
17			t.Run(name, func(t *testing.T) {
18				root := t.TempDir()
19				spec := ResidentChildSpec{ID: "artifact-recovery", SessionID: "session", InitialTurnID: "initial", Provider: "openai", Model: "test"}
20				journal, err := OpenResidentJournal(root, spec.ID)
21				if err != nil {
22					t.Fatal(err)
23				}
24				t.Cleanup(func() { _ = journal.Close() })
25				if err := journal.Accept(spec, "inspect and change files"); err != nil {
26					t.Fatal(err)
27				}
28				if err := journal.RecordTurnStarted(spec, spec.InitialTurnID); err != nil {
29					t.Fatal(err)
30				}
31				var capture *WorkspaceCapture
32				if captured {
33					capture = &WorkspaceCapture{Patch: []byte("partial patch\n"), ChangedFiles: []string{"README.md", "file with spaces.go"}}
34				} else if err := writeResidentPatch(journal.Dir(), []byte("stale patch from an earlier turn\n")); err != nil {
35					t.Fatal(err)
36				}
37				if err := journal.RecordTurnFinishedWithCapture(spec, spec.InitialTurnID, ErrBudgetExceeded, capture); err != nil {
38					t.Fatal(err)
39				}
40				original, err := journal.Result()
41				if err != nil {
42					t.Fatal(err)
43				}
44				if captured && (original.PatchRef != PatchRef(spec.ID) || !reflect.DeepEqual(original.ChangedFiles, capture.ChangedFiles)) {
45					t.Fatalf("capture was not published: %#v", original)
46				}
47				if err := journal.Close(); err != nil {
48					t.Fatal(err)
49				}
50				dir := filepath.Join(root, spec.ID)
51				transcriptPath := filepath.Join(dir, residentTranscriptName)
52				before, err := os.ReadFile(transcriptPath)
53				if err != nil {
54					t.Fatal(err)
55				}
56				resultPath := filepath.Join(dir, residentResultName)
57				if damage == "missing" {
58					err = os.Remove(resultPath)
59				} else {
60					err = os.WriteFile(resultPath, []byte("invalid JSON"), 0o600)
61				}
62				if err != nil {
63					t.Fatal(err)
64				}
65				for range 2 {
66					if _, err := ReconcileResidentJournal(dir); err != nil {
67						t.Fatal(err)
68					}
69					result, err := ReadResidentResult(resultPath)
70					if err != nil {
71						t.Fatal(err)
72					}
73					if result.State != ResidentBudgetExhausted || result.TurnID != spec.InitialTurnID || result.ErrorCode != residentErrorBudgetExhausted || result.Handoff == "" || result.PatchRef != original.PatchRef || !reflect.DeepEqual(result.ChangedFiles, original.ChangedFiles) {
74						t.Fatalf("reconstructed result = %#v, original = %#v", result, original)
75					}
76				}
77				after, err := os.ReadFile(transcriptPath)
78				if err != nil || string(after) != string(before) {
79					t.Fatalf("reconciliation modified transcript: %v", err)
80				}
81				if captured {
82					patch, err := os.ReadFile(filepath.Join(dir, residentPatchName))
83					if err != nil || string(patch) != string(capture.Patch) {
84						t.Fatalf("patch = %q, error = %v", patch, err)
85					}
86				}
87			})
88		}
89	}
90}

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 476

↑↓ moveenter openesc close