Skip to content

Commit f2fc5b9

Browse files
authored
Merge pull request #1331 from entireio/checkpoints-v1.1-review-support
checkpoint review: v1.1 committed-read support
2 parents e858fb5 + 9ae2734 commit f2fc5b9

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

cmd/entire/cli/review_context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func reviewCommittedCheckpointContext(ctx context.Context, worktreeRoot string,
9898
return ""
9999
}
100100
defer repo.Close()
101-
store := checkpoint.NewGitStore(repo)
101+
checkpoint.SyncCommittedReadRef(ctx, repo)
102+
store := checkpoint.NewCommittedReadStore(ctx, repo)
102103

103104
var lines []string
104105
seen := map[checkpointid.CheckpointID]bool{}

cmd/entire/cli/review_context_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
git "github.com/go-git/go-git/v6"
16+
"github.com/go-git/go-git/v6/plumbing"
1617

1718
"github.com/entireio/cli/cmd/entire/cli/agent"
1819
"github.com/entireio/cli/cmd/entire/cli/agent/types"
@@ -76,6 +77,34 @@ func TestReviewCheckpointContext_IncludesSummaryAndPromptFallback(t *testing.T)
7677
}
7778
}
7879

80+
// Review committed-context reads resolve against the v1 custom ref when the
81+
// mirror is enabled, and the v1 branch otherwise. No t.Parallel: t.Chdir drives
82+
// settings.
83+
func TestReviewCheckpointContext_ReadsV1CustomRefWhenEnabled(t *testing.T) {
84+
repoRoot := newReviewContextRepo(t)
85+
t.Chdir(repoRoot)
86+
87+
const cpID = "c1d2e3f4a5b6"
88+
writeReviewContextCheckpointCustomRefOnly(t, repoRoot, cpID, reviewContextCheckpointOptions{
89+
agentType: agent.AgentTypeClaudeCode,
90+
summary: &checkpoint.Summary{Intent: "custom-ref-only checkpoint", Outcome: "read via custom ref"},
91+
})
92+
commitReviewContextChange(t, repoRoot, "cp.go", "cp\n", "cp change", "Entire-Checkpoint: "+cpID)
93+
94+
const wantDetail = "summary: custom-ref-only checkpoint; read via custom ref"
95+
96+
// Mirror disabled: reads hit the v1 branch, which no longer holds the checkpoint.
97+
if got := reviewCheckpointContext(context.Background(), repoRoot, "master"); strings.Contains(got, wantDetail) {
98+
t.Fatalf("checkpoint detail leaked with mirror disabled:\n%s", got)
99+
}
100+
101+
// Mirror enabled: reads hit the custom ref.
102+
enableV1CustomRefMirror(t, repoRoot)
103+
if got := reviewCheckpointContext(context.Background(), repoRoot, "master"); !strings.Contains(got, wantDetail) {
104+
t.Fatalf("checkpoint detail missing with mirror enabled:\n%s", got)
105+
}
106+
}
107+
79108
func TestReviewCheckpointContext_CapsCheckpointLines(t *testing.T) {
80109
t.Parallel()
81110

@@ -413,6 +442,44 @@ func writeReviewContextCheckpoint(t *testing.T, repoRoot string, checkpointID st
413442
}
414443
}
415444

445+
// writeReviewContextCheckpointCustomRefOnly writes a checkpoint, then points the
446+
// custom ref at it and drops the v1 branch so it is reachable only via the
447+
// custom ref.
448+
func writeReviewContextCheckpointCustomRefOnly(t *testing.T, repoRoot, checkpointID string, opts reviewContextCheckpointOptions) {
449+
t.Helper()
450+
writeReviewContextCheckpoint(t, repoRoot, checkpointID, opts)
451+
452+
repo, err := git.PlainOpen(repoRoot)
453+
if err != nil {
454+
t.Fatalf("open repo: %v", err)
455+
}
456+
v1Branch := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
457+
v1Ref, err := repo.Reference(v1Branch, true)
458+
if err != nil {
459+
t.Fatalf("resolve v1 metadata branch: %v", err)
460+
}
461+
customRef := plumbing.ReferenceName(paths.MetadataRefName)
462+
if err := repo.Storer.SetReference(plumbing.NewHashReference(customRef, v1Ref.Hash())); err != nil {
463+
t.Fatalf("point custom ref at v1 tip: %v", err)
464+
}
465+
if err := repo.Storer.RemoveReference(v1Branch); err != nil {
466+
t.Fatalf("remove v1 metadata branch: %v", err)
467+
}
468+
}
469+
470+
// enableV1CustomRefMirror enables the v1 custom-ref mirror in repo settings.
471+
func enableV1CustomRefMirror(t *testing.T, repoRoot string) {
472+
t.Helper()
473+
entireDir := filepath.Join(repoRoot, ".entire")
474+
if err := os.MkdirAll(entireDir, 0o750); err != nil {
475+
t.Fatalf("create .entire dir: %v", err)
476+
}
477+
body := `{"enabled":true,"strategy_options":{"checkpoints_version":"1.1"}}` + "\n"
478+
if err := os.WriteFile(filepath.Join(entireDir, paths.SettingsFileName), []byte(body), 0o600); err != nil {
479+
t.Fatalf("write settings: %v", err)
480+
}
481+
}
482+
416483
func installReviewContextClaudeHooks(t *testing.T) {
417484
t.Helper()
418485
ag, err := agent.Get(agent.AgentNameClaudeCode)

0 commit comments

Comments
 (0)