From 22ecff1fde5aa17d3053f43a8ac81f9ca49d8d56 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 7 May 2026 19:33:44 +0000 Subject: test(executor): verify explicit Claude commits are captured in execRecord Adds TestTeardownSandbox_CapturesExplicitCommits to cover the case where the agent explicitly commits changes (no autocommit needed). Previously only the autocommit path was tested; this confirms teardownSandbox populates Commits for any commits ahead of origin. https://claude.ai/code/session_01G4dT9JBWFFb8xGcSHenzRS --- internal/executor/claude_test.go | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'internal/executor') diff --git a/internal/executor/claude_test.go b/internal/executor/claude_test.go index b40c4ae..cbb5947 100644 --- a/internal/executor/claude_test.go +++ b/internal/executor/claude_test.go @@ -621,6 +621,58 @@ func TestTeardownSandbox_BuildSuccess_ProceedsToAutocommit(t *testing.T) { } +func TestTeardownSandbox_CapturesExplicitCommits(t *testing.T) { + bare := t.TempDir() + if out, err := exec.Command("git", "init", "--bare", "-b", "main", bare).CombinedOutput(); err != nil { + t.Fatalf("git init bare: %v\n%s", err, out) + } + + sandbox := t.TempDir() + initGitRepo(t, sandbox) + if out, err := exec.Command("git", "-c", "safe.directory=*", "-c", "commit.gpgsign=false", "-C", sandbox, "remote", "add", "origin", bare).CombinedOutput(); err != nil { + t.Fatalf("git remote add: %v\n%s", err, out) + } + if out, err := exec.Command("git", "-c", "safe.directory=*", "-c", "commit.gpgsign=false", "-C", sandbox, "push", "origin", "main").CombinedOutput(); err != nil { + t.Fatalf("git push initial: %v\n%s", err, out) + } + + headOut, err := exec.Command("git", "-c", "safe.directory=*", "-c", "commit.gpgsign=false", "-C", sandbox, "rev-parse", "HEAD").Output() + if err != nil { + t.Fatalf("rev-parse HEAD: %v", err) + } + startHEAD := strings.TrimSpace(string(headOut)) + + // Simulate Claude explicitly committing changes. + if err := os.WriteFile(filepath.Join(sandbox, "work.txt"), []byte("done"), 0644); err != nil { + t.Fatal(err) + } + for _, args := range [][]string{ + {"-c", "safe.directory=*", "-c", "commit.gpgsign=false", "-C", sandbox, "add", "-A"}, + {"-c", "safe.directory=*", "-c", "commit.gpgsign=false", "-C", sandbox, "commit", "-m", "feat: implement the feature"}, + } { + if out, err := exec.Command("git", args...).CombinedOutput(); err != nil { + t.Fatalf("git %v: %v\n%s", args, err, out) + } + } + + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) + execRecord := &storage.Execution{} + + if err := teardownSandbox("", sandbox, startHEAD, logger, execRecord); err != nil { + t.Fatalf("teardownSandbox: %v", err) + } + + if len(execRecord.Commits) == 0 { + t.Fatal("expected commits to be captured in execRecord") + } + if !strings.Contains(execRecord.Commits[0].Message, "feat: implement the feature") { + t.Errorf("unexpected commit message: %q", execRecord.Commits[0].Message) + } + if execRecord.Commits[0].Hash == "" { + t.Error("commit hash should not be empty") + } +} + func TestTeardownSandbox_CleanSandboxWithNoNewCommits_RemovesSandbox(t *testing.T) { src := t.TempDir() initGitRepo(t, src) -- cgit v1.2.3