align checkpoint policy push target · Entire
align checkpoint policy push target
8a30eb4→main·
pfleidi·3w ago·5 files·+49 added/-6 removed
Sync pre-push checkpoint policy from the same resolved push target used for checkpoint refs so configured checkpoint remotes are enforced consistently.
Thread the checkpoint logging context through policy checks that can block condensation or finalization.
Sessions
e77a0d40ac05View transcript
[?
Checkpoint Policy Enforcement and ValidationCodex·GPT-5.5·5 steps](/content/gh/entireio/cli/session/019efaa9-f5b2-72c0-bf9d-a2a75869ea82#timeline-e77a0d40ac05/index.html)
Changes
5
cmd/entire/cli/strategy
Mcheckpoint_policy.go+5/-3
Mcheckpoint_policy_test.go+41
Mmanual_commit_condensation.go+1/-1
Mmanual_commit_hooks.go+1/-1
Mmanual_commit_push.go+1/-1
8 unmodified lines
9
10
11
12
13
14
15
16 unmodified lines
32
33
34
34
35
36
37
38
3 unmodified lines
42
43
44
44
45
46
46
47
48
49
50
51
52
53
54
55
8 unmodified lines
"github.com/entireio/cli/cmd/entire/cli/checkpointpolicy"
"github.com/entireio/cli/cmd/entire/cli/interactive"
"github.com/entireio/cli/cmd/entire/cli/logging"
"github.com/entireio/cli/cmd/entire/cli/paths"
"github.com/entireio/cli/cmd/entire/cli/versioncheck"
"github.com/entireio/cli/cmd/entire/cli/versioninfo"
"github.com/go-git/go-git/v6"
16 unmodified lines
return errCommittedCheckpointWriteBlocked
}
func syncCheckpointPolicyForPrePush(ctx context.Context) bool {
func syncCheckpointPolicyForPrePush(ctx context.Context, ps pushSettings) bool {
repo, err := OpenRepository(ctx)
if err != nil {
logging.Warn(ctx, "checkpoint policy pre-push: failed to open repository; allowing checkpoint push",
3 unmodified lines
}
defer repo.Close()
target, err := checkpointpolicy.ResolveTarget(ctx)
dir, err := paths.WorktreeRoot(ctx)
if err != nil {
logging.Warn(ctx, "checkpoint policy pre-push: failed to resolve policy remote; allowing checkpoint push",
logging.Warn(ctx, "checkpoint policy pre-push: failed to resolve worktree root; allowing checkpoint push",
slog.String("error", err.Error()),
)
return true
}
target := checkpointpolicy.Target{Remote: ps.pushTarget(), Dir: dir}
state, err := checkpointpolicy.Sync(ctx, repo, target)
if err != nil {
warnOrLogCheckpointPolicySyncFailure(ctx, err)
Mcmd/entire/cli/strategy/checkpoint_policy.go+5/-3
184 unmodified lines
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
184 unmodified lines
require.Empty(t, strings.TrimSpace(out))
}
func TestSyncCheckpointPolicyForPrePushUsesPushTarget(t *testing.T) {
workDir := setupGitRepo(t)
originBareDir := filepath.Join(t.TempDir(), "origin.git")
_, err := git.PlainInit(originBareDir, true)
require.NoError(t, err)
runCheckpointPolicyGit(t, workDir, "remote", "add", "origin", originBareDir)
pushTargetDir := filepath.Join(t.TempDir(), "push-target.git")
_, err = git.PlainInit(pushTargetDir, true)
require.NoError(t, err)
repo, err := git.PlainOpen(workDir)
require.NoError(t, err)
t.Cleanup(func() {
_ = repo.Close()
})
_, err = checkpointpolicy.WriteLocal(t.Context(), repo, plumbing.ZeroHash, checkpointpolicy.Policy{
CheckpointVersion: "refs-v1",
CheckpointMinVersion: "branch-v1",
})
require.NoError(t, err)
runCheckpointPolicyGit(t, workDir, "push", originBareDir, checkpointpolicy.RefName.String()+":
checkpointpolicy.RefName.String())
targetHash, err := checkpointpolicy.WriteLocal(t.Context(), repo, plumbing.ZeroHash, checkpointpolicy.DefaultPolicy())
require.NoError(t, err)
runCheckpointPolicyGit(t, workDir, "push", pushTargetDir, checkpointpolicy.RefName.String()+":checkpointpolicy.RefName.String())
require.NoError(t, repo.Storer.RemoveReference(checkpointpolicy.RefName))
t.Chdir(workDir)
paths.ClearWorktreeRootCache()
require.True(t, syncCheckpointPolicyForPrePush(context.Background(), pushSettings{
remote: "origin",
checkpointURL: pushTargetDir,
}))
state, err := checkpointpolicy.ReadLocal(t.Context(), repo)
require.NoError(t, err)
require.Equal(t, targetHash, state.Hash)
}
func writeUnsupportedCheckpointPolicy(t *testing.T, repo *git.Repository) {
t.Helper()
_, err := checkpointpolicy.WriteLocal(t.Context(), repo, plumbing.ZeroHash, checkpointpolicy.Policy{
Mcmd/entire/cli/strategy/checkpoint_policy_test.go+41
146 unmodified lines
147
148
149
150
150
151
152
153
146 unmodified lines
}
logCtx := logging.WithComponent(ctx, "checkpoint")
condenseStart := time.Now()
if err := checkCommittedCheckpointWritePolicy(ctx, repo); err != nil {
if err := checkCommittedCheckpointWritePolicy(logCtx, repo); err != nil {
return nil, err
}
Mcmd/entire/cli/strategy/manual_commit_condensation.go+1/-1
2784 unmodified lines
2785
2786
2787
2788
2788
2789
2790
2791
2784 unmodified lines
return 1 // Count as error - all checkpoints will be skipped
}
defer repo.Close()
if err := checkCommittedCheckpointWritePolicy(ctx, repo); err != nil {
if err := checkCommittedCheckpointWritePolicy(logCtx, repo); err != nil {
return 1
}
Mcmd/entire/cli/strategy/manual_commit_hooks.go+1/-1
43 unmodified lines
44
45
46
47
47
48
49
50
43 unmodified lines
}
refs := checkpoint.ResolveRefs(ctx)
if !syncCheckpointPolicyForPrePush(ctx) {
if !syncCheckpointPolicyForPrePush(ctx, ps) {
return nil
}
}
Mcmd/entire/cli/strategy/manual_commit_push.go+1/-1