From 5124bfd4cfbdaad2de340efe05bf1365557d0a26 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 10 Oct 2026 22:05:22 +1100 Subject: [PATCH] test(worktree): give each transport its own branch The four subtests share one bare repo but pushed the same feat/1-test branch. Their commits have the same tree, message, author and parent, so two commits in the same second hash identically and the second push is a no-op -- passing by luck -- while a second of clock drift makes it a non-fast-forward failure. One issue per subtest gives each its own branch. --- internal/worktree/http_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/worktree/http_test.go b/internal/worktree/http_test.go index ea9d053b7..80a8ba789 100644 --- a/internal/worktree/http_test.go +++ b/internal/worktree/http_test.go @@ -67,12 +67,16 @@ func TestForgeHTTPAuthentication(t *testing.T) { t.Fatal(err) } backend := &cgi.Handler{Path: gitPath, Args: []string{"http-backend"}, Env: []string{"GIT_PROJECT_ROOT=" + root, "GIT_HTTP_EXPORT_ALL=1"}} - for _, tc := range []struct { + for i, tc := range []struct { name string redirect, foreign, dumb bool }{ {name: "direct"}, {name: "same origin", redirect: true}, {name: "cross origin", foreign: true}, {name: "dumb HTTP", dumb: true}, } { + // One issue per transport: subtests share the bare repo, and a shared + // branch would make the second push a non-fast-forward (or, when two + // commits land in the same second, an identical-hash no-op). + issue := i + 1 t.Run(tc.name, func(t *testing.T) { target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("Authorization") != "" { @@ -107,7 +111,7 @@ func TestForgeHTTPAuthentication(t *testing.T) { m := *manager m.BaseURL = server.URL m.WorkDir = t.TempDir() - dir, branch, err := m.Prepare(t.Context(), "org", "repo", "main", 1, "test", "", "", Fresh) + dir, branch, err := m.Prepare(t.Context(), "org", "repo", "main", issue, "test", "", "", Fresh) if tc.foreign || tc.dumb { if err == nil { t.Fatal("unsupported or unauthenticated endpoint succeeded") @@ -136,7 +140,7 @@ func TestForgeHTTPAuthentication(t *testing.T) { if _, err := bare.Reference(plumbing.NewBranchReferenceName(branch), true); err != nil { t.Fatalf("pushed branch missing: %v", err) } - if _, _, err := m.Prepare(t.Context(), "org", "repo", "main", 1, "test", "", "", Target(branch)); err != nil { + if _, _, err := m.Prepare(t.Context(), "org", "repo", "main", issue, "test", "", "", Target(branch)); err != nil { t.Fatalf("authenticated fetch: %v", err) } })