Artifact 47ec6d0cf37fd07fc06e2ff1132db90ccc781f7f59a3eea6f3e5313b823f9da3:
- File
internal/sync/observer_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: 6187) [annotate] [blame] [check-ins using]
package sync import ( "context" "path/filepath" "testing" "github.com/danmestas/go-libfossil/internal/repo" "github.com/danmestas/go-libfossil/internal/xfer" "github.com/danmestas/go-libfossil/simio" ) // recordingObserver records all lifecycle calls for test assertions. type recordingObserver struct { started int roundsStarted []int roundsCompleted []int roundStats []RoundStats completed int lastInfo SessionStart lastEnd SessionEnd lastErr error errors []error handleStarted int handleCompleted int } func (r *recordingObserver) Started(ctx context.Context, info SessionStart) context.Context { r.started++ r.lastInfo = info return ctx } func (r *recordingObserver) RoundStarted(ctx context.Context, round int) context.Context { r.roundsStarted = append(r.roundsStarted, round) return ctx } func (r *recordingObserver) RoundCompleted(ctx context.Context, round int, stats RoundStats) { r.roundsCompleted = append(r.roundsCompleted, round) r.roundStats = append(r.roundStats, stats) } func (r *recordingObserver) Completed(ctx context.Context, info SessionEnd, err error) { r.completed++ r.lastEnd = info r.lastErr = err } func (r *recordingObserver) Error(_ context.Context, err error) { r.errors = append(r.errors, err) } func (r *recordingObserver) HandleStarted(ctx context.Context, _ HandleStart) context.Context { r.handleStarted++ return ctx } func (r *recordingObserver) HandleCompleted(_ context.Context, _ HandleEnd) { r.handleCompleted++ } func (r *recordingObserver) TableSyncStarted(_ context.Context, _ TableSyncStart) {} func (r *recordingObserver) TableSyncCompleted(_ context.Context, _ TableSyncEnd) {} func TestNopObserverDoesNotPanic(t *testing.T) { var obs nopObserver ctx := context.Background() ctx = obs.Started(ctx, SessionStart{Operation: "sync"}) ctx = obs.RoundStarted(ctx, 0) obs.RoundCompleted(ctx, 0, RoundStats{FilesSent: 5, FilesReceived: 3}) obs.Completed(ctx, SessionEnd{Operation: "sync", Rounds: 1}, nil) obs.Error(ctx, nil) ctx = obs.HandleStarted(ctx, HandleStart{Operation: "sync"}) obs.HandleCompleted(ctx, HandleEnd{}) obs.TableSyncStarted(ctx, TableSyncStart{Table: "test", LocalRows: 10}) obs.TableSyncCompleted(ctx, TableSyncEnd{Table: "test", Sent: 5, Received: 3}) } func TestResolveObserverNil(t *testing.T) { obs := resolveObserver(nil) if obs == nil { t.Fatal("resolveObserver(nil) should return nopObserver, not nil") } // Should not panic ctx := obs.Started(context.Background(), SessionStart{}) obs.RoundStarted(ctx, 0) obs.RoundCompleted(ctx, 0, RoundStats{}) obs.Error(ctx, nil) ctx = obs.HandleStarted(ctx, HandleStart{}) obs.HandleCompleted(ctx, HandleEnd{}) obs.TableSyncStarted(ctx, TableSyncStart{}) obs.TableSyncCompleted(ctx, TableSyncEnd{}) } func TestSyncCallsObserverHooks(t *testing.T) { clientPath := filepath.Join(t.TempDir(), "client.fossil") serverPath := filepath.Join(t.TempDir(), "server.fossil") env := simio.RealEnv() server, err := repo.Create(serverPath, "test", env.Rand, "") if err != nil { t.Fatal(err) } defer server.Close() client, err := repo.Create(clientPath, "test", env.Rand, "") if err != nil { t.Fatal(err) } defer client.Close() var projCode, srvCode string client.DB().QueryRow("SELECT value FROM config WHERE name='project-code'").Scan(&projCode) client.DB().QueryRow("SELECT value FROM config WHERE name='server-code'").Scan(&srvCode) mt := &MockTransport{ Handler: func(req *xfer.Message) *xfer.Message { resp, _ := HandleSync(context.Background(), server, req) return resp }, } rec := &recordingObserver{} result, err := Sync(context.Background(), client, mt, SyncOpts{ Push: true, Pull: true, ProjectCode: projCode, ServerCode: srvCode, Observer: rec, }) if err != nil { t.Fatalf("Sync: %v", err) } if rec.started != 1 { t.Errorf("Started called %d times, want 1", rec.started) } if rec.completed != 1 { t.Errorf("Completed called %d times, want 1", rec.completed) } if len(rec.roundsStarted) != result.Rounds { t.Errorf("RoundStarted called %d times, want %d", len(rec.roundsStarted), result.Rounds) } if len(rec.roundsCompleted) != result.Rounds { t.Errorf("RoundCompleted called %d times, want %d", len(rec.roundsCompleted), result.Rounds) } if rec.lastInfo.Operation != "sync" { t.Errorf("Operation = %q, want %q", rec.lastInfo.Operation, "sync") } if rec.lastEnd.Rounds != result.Rounds { t.Errorf("SessionEnd.Rounds = %d, want %d", rec.lastEnd.Rounds, result.Rounds) } if rec.lastErr != nil { t.Errorf("SessionEnd err = %v, want nil", rec.lastErr) } } func TestCloneCallsObserverHooks(t *testing.T) { clonePath := filepath.Join(t.TempDir(), "clone.fossil") // Simple mock transport that simulates an empty clone (2 rounds minimum). round := 0 mt := &MockTransport{ Handler: func(req *xfer.Message) *xfer.Message { defer func() { round++ }() if round == 0 { // First round: send project-code, server-code, and seqno 0 return &xfer.Message{ Cards: []xfer.Card{ &xfer.PushCard{ ProjectCode: "test-project", ServerCode: "test-server", }, &xfer.CloneSeqNoCard{SeqNo: 0}, }, } } // Round 1+: empty response with seqno 0 to converge return &xfer.Message{ Cards: []xfer.Card{ &xfer.CloneSeqNoCard{SeqNo: 0}, }, } }, } rec := &recordingObserver{} r, result, err := Clone(context.Background(), clonePath, mt, CloneOpts{ Observer: rec, }) if err != nil { t.Fatalf("Clone: %v", err) } defer r.Close() if rec.started != 1 { t.Errorf("Started called %d times, want 1", rec.started) } if rec.completed != 1 { t.Errorf("Completed called %d times, want 1", rec.completed) } if len(rec.roundsStarted) != result.Rounds { t.Errorf("RoundStarted called %d times, want %d", len(rec.roundsStarted), result.Rounds) } if rec.lastInfo.Operation != "clone" { t.Errorf("Operation = %q, want %q", rec.lastInfo.Operation, "clone") } if rec.lastEnd.Rounds != result.Rounds { t.Errorf("SessionEnd.Rounds = %d, want %d", rec.lastEnd.Rounds, result.Rounds) } }