summaryrefslogtreecommitdiff
path: root/internal/executor
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-05-07 19:33:44 +0000
committerClaude <noreply@anthropic.com>2026-05-07 19:33:44 +0000
commit22ecff1fde5aa17d3053f43a8ac81f9ca49d8d56 (patch)
tree67ac421b973cf748f9fa8ec9d6a629d74d88e576 /internal/executor
parentb32bfe1bc6bcbc45d7d1549d6ae6412bc3e4424f (diff)
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
Diffstat (limited to 'internal/executor')
-rw-r--r--internal/executor/claude_test.go52
1 files changed, 52 insertions, 0 deletions
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)