test(strategy): cover multi-pushurl deferral when any target is empty · Entire

test(strategy): cover multi-pushurl deferral when any target is empty

eca8e7f→main· ? Karthik Rameshkumar·3d ago·1 file·+55 added/-0 removed

Addresses Copilot's review note on #1744: a remote with multiple push destinations fans out to all of them, so an empty destination must force deferral even when another already has a branch. The narrowed guard (defer if any push target has no heads) already handles this; this test locks it in on both checkpoint backends.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

01KXFWQ0GQ3ZA2FP9WXTFKFBWCView transcript

Changes

1

118 unmodified lines

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

118 unmodified lines

}
    })
// TestGitPushWithHooks_DefersCheckpointsWhenAnyPushURLTargetIsEmpty covers a
// remote configured with multiple push destinations. `git push` writes to all
// of them, so as long as any one destination is still empty, publishing
// checkpoints could make entire/checkpoints/v1 its first (default) branch. The
// guard must defer until every push target has a branch.
func TestGitPushWithHooks_DefersCheckpointsWhenAnyPushURLTargetIsEmpty(t *testing.T) {
    t.Parallel()

ForEachBackend(t, func(t *testing.T, backend string) {
        env := NewFeatureBranchEnv(t)
        env.CheckpointStore = backend

// origin fetches from its own bare, but pushes fan out to two targets:
        // one that already has the user branch, and one that is still empty.
        _ = env.SetupBareRemote()
        populated := env.SetupNamedBareRemote("populated")
        empty := env.SetupEmptyNamedBareRemote("empty")
        for i, url := range []string{populated, empty} {
            args := []string{"remote", "set-url", "--push", "origin", url}
            if i > 0 {
                args = []string{"remote", "set-url", "--push", "--add", "origin", url}
            }
            cmd := exec.CommandContext(t.Context(), "git", args...)
            cmd.Dir = env.RepoDir
            cmd.Env = env.cliEnv()
            if output, err := cmd.CombinedOutput(); err != nil {
                t.Fatalf("set origin pushurl %q: %v\n%s", url, err, output)
            }
        }
        env.setGitConfigBaseline()

checkpointID := createCheckpointedCommit(t, env, "Add auth module", "auth.go", "package auth", "Add auth module")

// The empty push target must force deferral even though the other target
        // already has a branch.
        env.GitPushWithHooks("origin", "HEAD")
        if env.CheckpointsPresentOnRemote(empty) {
            t.Fatalf("[%s] checkpoints must be deferred while a push target is empty", backend)
        }
        if env.CheckpointsPresentOnRemote(populated) {
            t.Fatalf("[%s] checkpoints must be deferred on every target while any push target is empty", backend)
        }

// The first push gave the previously-empty target the user branch, so a
        // later push may publish to both.
        env.WriteFile("later.go", "package later")
        env.GitAdd("later.go")
        env.GitCommit("Later user commit")
        env.GitPushWithHooks("origin", "HEAD")
        if !env.CheckpointExistsOnRemote(empty, checkpointID) {
            t.Fatalf("[%s] deferred checkpoint %s should be published once every target has a branch", backend, checkpointID)
        }
    })
}

Mcmd/entire/cli/integration_test/real_hook_push_test.go+55