Artifact b3d4f75917c05e67e9dc724df4c6eeda81a78e17b045d8dbcf9519569f283993:
- File
internal/sync/handler_uv_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: 4518) [annotate] [blame] [check-ins using]
package sync import ( "context" "testing" "github.com/danmestas/go-libfossil/internal/repo" "github.com/danmestas/go-libfossil/internal/uv" "github.com/danmestas/go-libfossil/internal/xfer" ) func handleReq(t *testing.T, r *repo.Repo, cards ...xfer.Card) *xfer.Message { t.Helper() req := &xfer.Message{Cards: cards} resp, err := HandleSync(context.Background(), r, req) if err != nil { t.Fatalf("HandleSync: %v", err) } return resp } func TestHandlerPragmaUVHash_Match(t *testing.T) { r := setupSyncTestRepo(t) if err := uv.EnsureSchema(r.DB()); err != nil { t.Fatalf("EnsureSchema: %v", err) } uv.Write(r.DB(), "test.txt", []byte("hello"), 100) h, _ := uv.ContentHash(r.DB()) // Send matching hash — should get no uvigot back. resp := handleReq(t, r, &xfer.PullCard{ServerCode: "s", ProjectCode: "p"}, &xfer.PragmaCard{Name: "uv-hash", Values: []string{h}}, ) for _, c := range resp.Cards { if _, ok := c.(*xfer.UVIGotCard); ok { t.Error("should not send uvigot when hashes match") } } } func TestHandlerPragmaUVHash_Mismatch(t *testing.T) { r := setupSyncTestRepo(t) if err := uv.EnsureSchema(r.DB()); err != nil { t.Fatalf("EnsureSchema: %v", err) } uv.Write(r.DB(), "a.txt", []byte("aaa"), 100) uv.Write(r.DB(), "b.txt", []byte("bbb"), 200) // Send wrong hash — should get uvigot for each file + pragma uv-push-ok. resp := handleReq(t, r, &xfer.PullCard{ServerCode: "s", ProjectCode: "p"}, &xfer.PragmaCard{Name: "uv-hash", Values: []string{"wrong"}}, ) uvigots := cardsByType(resp, xfer.CardUVIGot) if len(uvigots) != 2 { t.Errorf("expected 2 uvigot cards, got %d", len(uvigots)) } pragmas := cardsByType(resp, xfer.CardPragma) found := false for _, c := range pragmas { if c.(*xfer.PragmaCard).Name == "uv-push-ok" { found = true } } if !found { t.Error("expected pragma uv-push-ok") } } func TestHandlerUVGimme(t *testing.T) { r := setupSyncTestRepo(t) if err := uv.EnsureSchema(r.DB()); err != nil { t.Fatalf("EnsureSchema: %v", err) } uv.Write(r.DB(), "doc.txt", []byte("document content"), 100) resp := handleReq(t, r, &xfer.PullCard{ServerCode: "s", ProjectCode: "p"}, &xfer.UVGimmeCard{Name: "doc.txt"}, ) uvfiles := cardsByType(resp, xfer.CardUVFile) if len(uvfiles) != 1 { t.Fatalf("expected 1 uvfile, got %d", len(uvfiles)) } f := uvfiles[0].(*xfer.UVFileCard) if f.Name != "doc.txt" || string(f.Content) != "document content" { t.Errorf("uvfile = %+v", f) } } func TestHandlerUVFile_Accepted(t *testing.T) { r := setupSyncTestRepo(t) if err := uv.EnsureSchema(r.DB()); err != nil { t.Fatalf("EnsureSchema: %v", err) } resp := handleReq(t, r, &xfer.PushCard{ServerCode: "s", ProjectCode: "p"}, &xfer.UVFileCard{ Name: "new.txt", MTime: 100, Hash: "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", // sha1("hello") Size: 5, Flags: 0, Content: []byte("hello"), }, ) // Should not have errors. for _, c := range resp.Cards { if e, ok := c.(*xfer.ErrorCard); ok { t.Errorf("unexpected error: %s", e.Message) } } // Verify stored. content, mtime, hash, err := uv.Read(r.DB(), "new.txt") if err != nil { t.Fatalf("Read: %v", err) } if string(content) != "hello" || mtime != 100 || hash == "" { t.Errorf("stored = content=%q mtime=%d hash=%q", content, mtime, hash) } } func TestHandlerUVFile_Rejected_NoPush(t *testing.T) { r := setupSyncTestRepo(t) if err := uv.EnsureSchema(r.DB()); err != nil { t.Fatalf("EnsureSchema: %v", err) } // No push card — uvfile should be rejected. resp := handleReq(t, r, &xfer.UVFileCard{ Name: "new.txt", MTime: 100, Hash: "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", Size: 5, Flags: 0, Content: []byte("hello"), }, ) errors := cardsByType(resp, xfer.CardError) if len(errors) == 0 { t.Error("expected error card for uvfile without push") } } func TestHandlerUVIGot_ServerPulls(t *testing.T) { r := setupSyncTestRepo(t) if err := uv.EnsureSchema(r.DB()); err != nil { t.Fatalf("EnsureSchema: %v", err) } // Server has nothing — client announces a file via uvigot. resp := handleReq(t, r, &xfer.PullCard{ServerCode: "s", ProjectCode: "p"}, &xfer.UVIGotCard{Name: "client.txt", MTime: 100, Hash: "abc", Size: 10}, ) gimmes := cardsByType(resp, xfer.CardUVGimme) if len(gimmes) != 1 { t.Fatalf("expected 1 uvgimme, got %d", len(gimmes)) } if gimmes[0].(*xfer.UVGimmeCard).Name != "client.txt" { t.Errorf("wrong gimme name") } }