summaryrefslogtreecommitdiff
path: root/internal/executor/container_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/executor/container_test.go')
-rw-r--r--internal/executor/container_test.go41
1 files changed, 22 insertions, 19 deletions
diff --git a/internal/executor/container_test.go b/internal/executor/container_test.go
index 8c00a0f..b06d153 100644
--- a/internal/executor/container_test.go
+++ b/internal/executor/container_test.go
@@ -620,9 +620,9 @@ func TestContainerRunner_ClonesStoryBranch(t *testing.T) {
runner.Run(context.Background(), tk, e, newStoreChannel(nil, tk.ID))
os.RemoveAll(e.SandboxDir)
- // Assert git checkout was called with the story branch name.
+ // Assert git checkout was called with the branch name.
if len(checkoutArgs) == 0 {
- t.Fatal("expected git checkout to be called for story branch, but it was not")
+ t.Fatal("expected git checkout to be called for branch, but it was not")
}
found := false
for _, a := range checkoutArgs {
@@ -741,27 +741,30 @@ func TestContainerRunner_ClonesFromLocalPathForCITask(t *testing.T) {
}
}
-func TestEnsureStoryBranch_CreatesMissingBranch(t *testing.T) {
+func TestEnsureBranch_CreatesMissingBranch(t *testing.T) {
// Set up a bare repo and a local clone to test branch creation.
dir := t.TempDir()
bare := filepath.Join(dir, "bare.git")
local := filepath.Join(dir, "local")
- // Create bare repo with an initial commit.
- if out, err := exec.Command("git", "init", "--bare", bare).CombinedOutput(); err != nil {
- t.Fatalf("git init bare: %v\n%s", err, out)
+ // Create bare repo with an initial commit on main.
+ if out, err := exec.Command("git", "init", "--bare", "--initial-branch=main", bare).CombinedOutput(); err != nil {
+ // Fallback for older git: init bare then update HEAD manually.
+ if out2, err2 := exec.Command("git", "init", "--bare", bare).CombinedOutput(); err2 != nil {
+ t.Fatalf("git init bare: %v\n%s", err2, out2)
+ }
+ if out2, err2 := exec.Command("git", "-C", bare, "symbolic-ref", "HEAD", "refs/heads/main").CombinedOutput(); err2 != nil {
+ t.Fatalf("set HEAD to main: %v\n%s\n%s", err, out, out2)
+ }
}
if out, err := exec.Command("git", "clone", bare, local).CombinedOutput(); err != nil {
t.Fatalf("git clone: %v\n%s", err, out)
}
- if out, err := exec.Command("git", "-C", local, "commit", "--allow-empty", "-m", "init").CombinedOutput(); err != nil {
+ if out, err := exec.Command("git", "-C", local, "-c", "user.email=test@test.com", "-c", "user.name=Test", "commit", "--allow-empty", "-m", "init").CombinedOutput(); err != nil {
t.Fatalf("git commit: %v\n%s", err, out)
}
if out, err := exec.Command("git", "-C", local, "push", "origin", "main").CombinedOutput(); err != nil {
- // try master
- if out2, err2 := exec.Command("git", "-C", local, "push", "origin", "HEAD:main").CombinedOutput(); err2 != nil {
- t.Fatalf("git push main: %v\n%s\n%s", err, out, out2)
- }
+ t.Fatalf("git push main: %v\n%s", err, out)
}
runner := &ContainerRunner{Logger: slog.Default()}
@@ -771,21 +774,21 @@ func TestEnsureStoryBranch_CreatesMissingBranch(t *testing.T) {
// Branch should not exist yet.
out, _ := exec.Command("git", "ls-remote", "--heads", bare, branch).CombinedOutput()
if len(strings.TrimSpace(string(out))) > 0 {
- t.Fatal("branch should not exist before ensureStoryBranch")
+ t.Fatal("branch should not exist before ensureBranch")
}
- if err := runner.ensureStoryBranch(context.Background(), bare, branch, ""); err != nil {
- t.Fatalf("ensureStoryBranch: %v", err)
+ if err := runner.ensureBranch(context.Background(), bare, branch, ""); err != nil {
+ t.Fatalf("ensureBranch: %v", err)
}
// Branch should now exist in the bare repo.
out, err := exec.Command("git", "ls-remote", "--heads", bare, branch).CombinedOutput()
if err != nil || len(strings.TrimSpace(string(out))) == 0 {
- t.Errorf("branch %q not found in bare repo after ensureStoryBranch: %s", branch, out)
+ t.Errorf("branch %q not found in bare repo after ensureBranch: %s", branch, out)
}
}
-func TestEnsureStoryBranch_IdempotentIfExists(t *testing.T) {
+func TestEnsureBranch_IdempotentIfExists(t *testing.T) {
dir := t.TempDir()
bare := filepath.Join(dir, "bare.git")
local := filepath.Join(dir, "local")
@@ -796,7 +799,7 @@ func TestEnsureStoryBranch_IdempotentIfExists(t *testing.T) {
if out, err := exec.Command("git", "clone", bare, local).CombinedOutput(); err != nil {
t.Fatalf("git clone: %v\n%s", err, out)
}
- if out, err := exec.Command("git", "-C", local, "commit", "--allow-empty", "-m", "init").CombinedOutput(); err != nil {
+ if out, err := exec.Command("git", "-C", local, "-c", "user.email=test@test.com", "-c", "user.name=Test", "commit", "--allow-empty", "-m", "init").CombinedOutput(); err != nil {
t.Fatalf("git commit: %v\n%s", err, out)
}
if _, err := exec.Command("git", "-C", local, "push", "origin", "HEAD:main").CombinedOutput(); err != nil {
@@ -815,8 +818,8 @@ func TestEnsureStoryBranch_IdempotentIfExists(t *testing.T) {
runner := &ContainerRunner{Logger: slog.Default()}
// Should be a no-op, not an error.
- if err := runner.ensureStoryBranch(context.Background(), bare, branch, ""); err != nil {
- t.Fatalf("ensureStoryBranch on existing branch: %v", err)
+ if err := runner.ensureBranch(context.Background(), bare, branch, ""); err != nil {
+ t.Fatalf("ensureBranch on existing branch: %v", err)
}
}