Cover materialized fallback and add a CLI smoke test for --all-refs · Entire
Cover materialized fallback and add a CLI smoke test for --all-refs
ebfdd77→main·
Soph·2mo ago·2 files·+139 added/-0 removed
The two existing AllRefs integration tests both hit bootstrap (empty target). For non-empty targets, RefKindOther refs fail CanIncrementalRelay by design and fall through to the materialized executor — a code path that's kind-agnostic on push but had no end-to-end coverage with AllRefs. The new test pre-populates the target with the branch, adds a refs/notes/commits ref on source, and asserts: result.Pushed=1 (notes create only, branch is a skip), result.Relay=false (materialized, not relay), and the notes ref lands on target at the right hash.
The CLI smoke test goes through cmd/git-sync's cobra entry via run(...) with --all-refs --json, then walks the JSON for the notes ref entry to confirm kind=other and action=create. This pins the full pipeline (flag parsing → unstable client → bridge → syncer → receive-pack) against silent regressions where individual layers compile but the wiring breaks.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Sessions
63e589614284View transcript
Changes
2
cmd/git-sync
Mmain_test.go+80
internal/syncer
Mintegration_test.go+59
253 unmodified lines
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
253 unmodified lines
}
}
// TestRun_Sync_AllRefsSmokeTest exercises the full CLI pipeline with
// --all-refs: cobra flag parsing → unstable client → bridge → syncer →
// receive-pack. Confirms a custom-namespace ref (refs/notes/commits) on
// the source ends up on an empty target and shows up in the JSON output
// with the right shape, so future refactors that break the wiring don't
// pass tests until they reach the integration suite.
func TestRun_Sync_AllRefsSmokeTest(t *testing.T) {
sourceRepo, sourceFS := newSourceRepo(t)
makeCommits(t, sourceRepo, sourceFS, 2)
head, err := sourceRepo.Reference(plumbing.NewBranchReferenceName(testBranch), true)
if err != nil {
t.Fatalf("resolve source head: %v", err)
}
notesRef := plumbing.ReferenceName("refs/notes/commits")
if err := sourceRepo.Storer.SetReference(plumbing.NewHashReference(notesRef, head.Hash())); err != nil {
t.Fatalf("set source notes ref: %v", err)
}
targetRepo, err := git.Init(memory.NewStorage())
if err != nil {
t.Fatalf("init target repo: %v", err)
}
sourceServer := newSmartHTTPRepoServer(t, sourceRepo)
targetServer := newSmartHTTPRepoServer(t, targetRepo)
defer sourceServer.Close()
defer targetServer.Close()
output, err := captureStdout(func() error {
return run(context.Background(), []string{
"sync",
"--all-refs",
"--json",
sourceServer.RepoURL(),
targetServer.RepoURL(),
})
})
if err != nil {
t.Fatalf("run sync --all-refs: %v\noutput=%s", err, output)
}
var result map[string]any
if err := json.Unmarshal([]byte(output), &result); err != nil {
t.Fatalf("decode sync json: %v\noutput=%s", err, output)
}
plans, ok := result["plans"].([]any)
if !ok || len(plans) < 2 {
t.Fatalf("expected at least 2 plans (branch + notes), got %#v", result["plans"])
}
var foundNotesRef bool
for _, raw := range plans {
plan, ok := raw.(map[string]any)
if !ok {
continue
}
if plan["targetRef"] == "refs/notes/commits" {
if plan["kind"] != "other" {
t.Errorf("expected notes ref kind=other, got %#v", plan["kind"])
}
if plan["action"] != "create" {
t.Errorf("expected notes ref action=create, got %#v", plan["action"])
}
foundNotesRef = true
}
}
if !foundNotesRef {
t.Fatalf("refs/notes/commits not in plans output: %s", output)
}
gotNotes, err := targetRepo.Reference(notesRef, true)
if err != nil {
t.Fatalf("expected refs/notes/commits on target: %v", err)
}
if gotNotes.Hash() != head.Hash() {
t.Fatalf("target notes hash = %s, want %s", gotNotes.Hash(), head.Hash())
}
}
func TestRun_Replicate_SubcommandRejectsForce(t *testing.T) {
err := run(context.Background(), []string{
modeReplicate,