Artifact f858da08e9fd1fa213a3124141406667d958307ab1a0e5c3025663acee944793:
- File
internal/sync/cluster_integration_test.go
— part of check-in
[6273a0750d]
at
2026-07-22 23:03:24
on branch trunk
— fix: correct go.mod module path to go-libfossil (#76) (#117)
* fix: correct go.mod module path to go-libfossil (#76)
The module directive still declared github.com/danmestas/libfossil after the repository was renamed to go-libfossil. pkg.go.dev/godoc scraping matches the declared module path against its hosting path, so the stale path broke SDK doc generation.
Rename the module path across all four in-repo modules (root, the two db/driver submodules, observer/otel, and docs/site) and every internal import, plus the release workflow, the doc-generation script, and the docs.
No tag has been published under the go-libfossil path yet, so the cross-module requires cannot resolve from the proxy. Add replace directives pointing the in-repo requires at their local directories so GOWORK=off builds and the CI matrix resolve without a published version. These replaces are ignored by downstream consumers and can be dropped once new-path tags are cut.
* Guard releases against replace directives; regenerate SDK docs
The go-libfossil rename bridges the in-repo modules with `replace` directives. Go refuses a main module that carries them, so a tag cut while they are present breaks `go install .../cmd/libfossil@<tag>` and every `@version` fetch of the driver submodules. Add a Release workflow step that fails the job before anything is published if any tracked go.mod still contains a replace directive, so the bridge is a CI-enforced TODO rather than a silent landmine. The step comment records what unblocks a release: re-tag the submodules with the corrected module paths, bump the root requires, then drop the replace blocks.
Regenerate the SDK reference docs. The previous pass only substituted URLs over the pre-existing generated files, leaving stale signatures (Repo.Timeline was still documented as taking LogOpts rather than TimelineOpts). Note that gomarkdoc must be run outside a git worktree — inside one it silently strips every source link.
Also reword the README rename note, which read as though the import path had not changed, and re-sort the ncruces require block. (user: [email protected], size: 5455) [annotate] [blame] [check-ins using]
package sync import ( "context" "fmt" "path/filepath" "testing" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/repo" _ "github.com/danmestas/go-libfossil/internal/testdriver" "github.com/danmestas/go-libfossil/internal/xfer" "github.com/danmestas/go-libfossil/simio" ) // TestPushOnly_DrainsServerGimmes verifies that when the client pushes // without pulling (SyncOpts{Push:true, Pull:false}), the server still // requests blobs it does not have via gimme cards and the client services // them across multiple rounds. // // Regression: in v0.4.0 the server only emitted gimme cards when pullOK // was true (driven by the client's pull card). Push-only clients exited // after one round even when the server was missing artifacts, leaving // the server with an incomplete blob store. func TestPushOnly_DrainsServerGimmes(t *testing.T) { clientPath := filepath.Join(t.TempDir(), "client.fossil") clientRepo, err := repo.Create(clientPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("repo.Create client: %v", err) } t.Cleanup(func() { clientRepo.Close() }) const numBlobs = 50 for i := range numBlobs { content := []byte(fmt.Sprintf("push-only-blob-%04d", i)) if _, _, err := blob.Store(clientRepo.DB(), content); err != nil { t.Fatalf("blob.Store[%d]: %v", i, err) } } serverPath := filepath.Join(t.TempDir(), "server.fossil") serverRepo, err := repo.Create(serverPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("repo.Create server: %v", err) } t.Cleanup(func() { serverRepo.Close() }) transport := &MockTransport{ Handler: func(req *xfer.Message) *xfer.Message { resp, err := HandleSync(context.Background(), serverRepo, req) if err != nil { t.Fatalf("HandleSync: %v", err) } return resp }, } var projCode, srvCode string clientRepo.DB().QueryRow("SELECT value FROM config WHERE name='project-code'").Scan(&projCode) clientRepo.DB().QueryRow("SELECT value FROM config WHERE name='server-code'").Scan(&srvCode) result, err := Sync(context.Background(), clientRepo, transport, SyncOpts{ Push: true, Pull: false, ProjectCode: projCode, ServerCode: srvCode, }) if err != nil { t.Fatalf("Sync: %v", err) } var serverCount int if err := serverRepo.DB().QueryRow("SELECT count(*) FROM blob WHERE size >= 0").Scan(&serverCount); err != nil { t.Fatalf("count blobs: %v", err) } t.Logf("push-only sync completed: rounds=%d sent=%d server_blobs=%d", result.Rounds, result.FilesSent, serverCount) if serverCount < numBlobs { t.Fatalf("server has %d blobs, want >= %d (push-only did not drain server gimmes)", serverCount, numBlobs) } if result.FilesSent < numBlobs { t.Fatalf("FilesSent = %d, want >= %d (multi-round push-only failed to send all)", result.FilesSent, numBlobs) } // Multi-round behaviour: the protocol needs at least 2 rounds (igot then file). if result.Rounds < 2 { t.Fatalf("Rounds = %d, want >= 2 (push-only converged before draining gimmes)", result.Rounds) } } // TestClusterSync_RoundTrip creates a client repo with 200 blobs, syncs them // to an empty server repo via MockTransport wrapping HandleSync, and verifies // all 200 blobs arrive within 10 rounds. func TestClusterSync_RoundTrip(t *testing.T) { // --- Setup: client repo with 200 blobs --- clientPath := filepath.Join(t.TempDir(), "client.fossil") clientRepo, err := repo.Create(clientPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("repo.Create client: %v", err) } t.Cleanup(func() { clientRepo.Close() }) for i := range 200 { content := []byte(fmt.Sprintf("cluster-roundtrip-blob-%04d", i)) _, _, err := blob.Store(clientRepo.DB(), content) if err != nil { t.Fatalf("blob.Store[%d]: %v", i, err) } } // --- Setup: empty server repo --- serverPath := filepath.Join(t.TempDir(), "server.fossil") serverRepo, err := repo.Create(serverPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("repo.Create server: %v", err) } t.Cleanup(func() { serverRepo.Close() }) // --- Transport: MockTransport wrapping HandleSync --- transport := &MockTransport{ Handler: func(req *xfer.Message) *xfer.Message { resp, err := HandleSync(context.Background(), serverRepo, req) if err != nil { t.Fatalf("HandleSync: %v", err) } return resp }, } // --- Sync: client pushes to server --- var projCode, srvCode string clientRepo.DB().QueryRow("SELECT value FROM config WHERE name='project-code'").Scan(&projCode) clientRepo.DB().QueryRow("SELECT value FROM config WHERE name='server-code'").Scan(&srvCode) result, err := Sync(context.Background(), clientRepo, transport, SyncOpts{ Push: true, Pull: true, ProjectCode: projCode, ServerCode: srvCode, }) if err != nil { t.Fatalf("Sync: %v", err) } // --- Verify: all 200 blobs arrived --- var serverCount int err = serverRepo.DB().QueryRow("SELECT count(*) FROM blob WHERE size >= 0").Scan(&serverCount) if err != nil { t.Fatalf("count blobs: %v", err) } t.Logf("sync completed: rounds=%d sent=%d recv=%d server_blobs=%d", result.Rounds, result.FilesSent, result.FilesRecvd, serverCount) if serverCount < 200 { t.Fatalf("server has %d blobs, want >= 200", serverCount) } // --- Verify: converged within 10 rounds --- if result.Rounds > 10 { t.Fatalf("took %d rounds, want <= 10", result.Rounds) } }