Merge remote-tracking branch 'origin/main' into fix/checkpoints-v1.1-advance-after-sync · Entire

Merge remote-tracking branch 'origin/main' into fix/checkpoints-v1.1-advance-after-sync

a56d436→main·pfleidi·1mo ago·2 files·+141 added/-1 removed

Sessions

3dfee3839b09View transcript

?\ Centralize Checkpoint Metadata Mirror UpdatesCodex·GPT-5.5·1 step

Changes

2

15 unmodified lines

16
17
18
19
20
21
22
149 unmodified lines

172
173
174
174
175
176
177
178
179
180
181
182
183
184

15 unmodified lines

"github.com/entireio/cli/cmd/entire/cli/logging"
    "github.com/entireio/cli/cmd/entire/cli/paths"
    "github.com/entireio/cli/cmd/entire/cli/search"
    "github.com/entireio/cli/cmd/entire/cli/settings"
    "github.com/entireio/cli/cmd/entire/cli/trailers"
    "github.com/go-git/go-git/v6"
    "github.com/go-git/go-git/v6/plumbing"
149 unmodified lines

return nil, err
}

store := checkpoint.NewCommittedReadStore(ctx, repo)  
// The committed-read topology (and thus the v1.1 mirror opt-in) is resolved  
// from settings relative to the context's worktree root, which defaults to  
// the process cwd. repoRoot may be a different repo (--repo/RepoPaths) or  
// the cwd may not be a repo at all, so scope settings resolution to this  
// repo before consulting the topology.
repoCtx := settings.WithWorktreeRoot(ctx, repoRoot)
store := checkpoint.NewCommittedReadStore(repoCtx, repo)
infos, err := store.ListCommitted(ctx)
if err != nil {
    return nil, fmt.Errorf("list committed checkpoints: %w", err)
}

Mcmd/entire/cli/dispatch/mode_local.go+8/-1

11 unmodified lines

12
13
14
15
16
17
18
19
20
21
22
23
24
48 unmodified lines

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
51 unmodified lines

176
177
178
179
180
181
182
183
184
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
232
233
234
235
721 unmodified lines

957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993

11 unmodified lines

"github.com/entireio/cli/cmd/entire/cli/agent"
    "github.com/entireio/cli/cmd/entire/cli/checkpoint"
    checkpointid "github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
    "github.com/entireio/cli/cmd/entire/cli/paths"
    "github.com/entireio/cli/cmd/entire/cli/testutil"
    "github.com/entireio/cli/cmd/entire/cli/trailers"
    "github.com/entireio/cli/redact"
    "github.com/go-git/go-git/v6"
    "github.com/go-git/go-git/v6/config"
    "github.com/go-git/go-git/v6/plumbing"
    "github.com/go-git/go-git/v6/plumbing/object"
)

48 unmodified lines

}
}

func TestLocalMode_ReadsV1CustomRefWhenEnabled(t *testing.T) {
    dir := t.TempDir()
    stubGeneratedLocalDispatch(t)
testutil.InitRepo(t, dir)
testutil.WriteFile(t, dir, "a.txt", "x")
testutil.GitAdd(t, dir, "a.txt")
testutil.GitCommit(t, dir, "initial")
addOriginRemote(t, dir)

createdAt := time.Now().UTC()
    seedCommittedCheckpoint(t, dir, seededCheckpoint{
        id:           testCheckpointID,
        branch:       "main",
        createdAt:    createdAt,
        filesTouched: []string{"a.txt"},
        outcome:      testLocalFallbackText,
    })
    moveCheckpointsToCustomRefOnly(t, dir)

oldNow := nowUTC
    nowUTC = func() time.Time { return createdAt.Add(2 * time.Hour) }
    t.Cleanup(func() { nowUTC = oldNow })

t.Chdir(dir)
    opts := Options{Mode: ModeLocal, Since: "7d", Branches: []string{"main"}}

// Mirror disabled: the checkpoint lives only on the custom ref, so the v1 read finds nothing.
    got, err := Run(context.Background(), opts)
    if err != nil {
        t.Fatal(err)
    }
    if len(got.Repos) != 0 {
        t.Fatalf("expected no checkpoints with mirror disabled, got %+v", got.Repos)
    }

// Mirror enabled: reads resolve against the custom ref.
    writeV1CustomRefMirrorSettings(t, dir)
    got, err = Run(context.Background(), opts)
    if err != nil {
        t.Fatal(err)
    }
    if len(got.Repos) != 1 || got.Repos[0].Sections[0].Bullets[0].Text != testLocalFallbackText {
        t.Fatalf("expected checkpoint via custom ref, got %+v", got.Repos)
    }
}

func TestLocalMode_ExplicitRepoUsesTargetRepoCheckpointSettings(t *testing.T) {
    cwdDir := t.TempDir()
targetDir := t.TempDir()
51 unmodified lines

}

// TestLocalMode_ExplicitRepoResolvesMirrorOptInFromTargetRepo guards against  
// resolving the committed-read topology from the process cwd instead of the  
// enumerated repo. The target repo opts into the v1.1 mirror and keeps its  
// checkpoint only on the custom ref; cwd is a separate repo with the mirror  
// off. If the opt-in were read from cwd, the checkpoint would be invisible.
func TestLocalMode_ExplicitRepoResolvesMirrorOptInFromTargetRepo(t *testing.T) {
    cwdDir := t.TempDir()
targetDir := t.TempDir()
stubGeneratedLocalDispatch(t)

// cwd repo: mirror explicitly disabled.
    testutil.InitRepo(t, cwdDir)
    testutil.WriteFile(t, cwdDir, ".entire/settings.json", `{"enabled": true}`)

testutil.InitRepo(t, targetDir)
    testutil.WriteFile(t, targetDir, "a.txt", "x")
    testutil.GitAdd(t, targetDir, "a.txt")
    testutil.GitCommit(t, targetDir, "initial")
    addOriginRemote(t, targetDir)

createdAt := time.Now().UTC()
    seedCommittedCheckpoint(t, targetDir, seededCheckpoint{
        id:           testCheckpointID,
        branch:       "main",
        createdAt:    createdAt,
        filesTouched: []string{"a.txt"},
        outcome:      testLocalFallbackText,
    })
    // Reachable only via the custom ref, and the target repo opts into the mirror.
    moveCheckpointsToCustomRefOnly(t, targetDir)
    writeV1CustomRefMirrorSettings(t, targetDir)

oldNow := nowUTC
    nowUTC = func() time.Time { return createdAt.Add(2 * time.Hour) }
    t.Cleanup(func() {
        nowUTC = oldNow
    })

t.Chdir(cwdDir)

got, err := Run(context.Background(), Options{
        Mode:      ModeLocal,
        RepoPaths: []string{targetDir},
        Since:     "7d",
        Branches:  []string{"main"},
    })
    if err != nil {
        t.Fatal(err)
    }
    if len(got.Repos) != 1 || got.Repos[0].Sections[0].Bullets[0].Text != testLocalFallbackText {
        t.Fatalf("expected target repo's v1.1 custom-ref checkpoint, got %+v", got.Repos)
    }
}

func TestLocalMode_UsesUntilWindow(t *testing.T) {
    dir := t.TempDir()
    stubGeneratedLocalDispatch(t)
721 unmodified lines

}

// moveCheckpointsToCustomRefOnly points the v1 custom ref at the v1 branch tip  
// and removes the v1 branch, so committed checkpoints are reachable only via the  
// custom ref.
func moveCheckpointsToCustomRefOnly(t *testing.T, repoDir string) {
    t.Helper()
    repo, err := git.PlainOpenWithOptions(repoDir, &git.PlainOpenOptions{DetectDotGit: true})
    if err != nil {
        t.Fatal(err)
    }
    v1Branch := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
v1Ref, err := repo.Reference(v1Branch, true)
    if err != nil {
        t.Fatal(err)
    }
    if err := repo.Storer.SetReference(plumbing.NewHashReference(plumbing.ReferenceName(paths.MetadataRefName), v1Ref.Hash())); err != nil {
        t.Fatal(err)
    }
    if err := repo.Storer.RemoveReference(v1Branch); err != nil {
        t.Fatal(err)
    }
}

// writeV1CustomRefMirrorSettings opts repoDir into the v1 custom-ref mirror.  
// "1.1" is the on-disk checkpoints_version encoding read by  
// settings.MirrorsToV1CustomRef.
func writeV1CustomRefMirrorSettings(t *testing.T, repoDir string) {
    t.Helper()
    testutil.WriteFile(t, repoDir, ".entire/settings.json",
        `{"enabled": true, "strategy_options": {"checkpoints_version": "1.1"}}`)
}

func addOriginRemote(t *testing.T, repoDir string) {
    t.Helper()