Artifact 9ae3490a0faeb53fd569e2c749fe47e693b38d6c75c899e3059e3739484117a6:
- File
dst/shun_private_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: 6631) [annotate] [blame] [check-ins using]
package dst import ( "context" "path/filepath" "testing" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/content" "github.com/danmestas/go-libfossil/internal/repo" "github.com/danmestas/go-libfossil/internal/shun" libsync "github.com/danmestas/go-libfossil/internal/sync" "github.com/danmestas/go-libfossil/simio" _ "github.com/danmestas/go-libfossil/internal/testdriver" ) // TestShunnedBlobDoesNotPropagate verifies that shunned and private blobs // are excluded from sync, while normal blobs propagate correctly. func TestShunnedBlobDoesNotPropagate(t *testing.T) { tmpDir := t.TempDir() // Create server repo and seed blobs. serverPath := filepath.Join(tmpDir, "server.fossil") serverRepo, err := repo.Create(serverPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("create server repo: %v", err) } t.Cleanup(func() { serverRepo.Close() }) // Store normal blob. _, normalUUID, err := blob.Store(serverRepo.DB(), []byte("normal-blob-content")) if err != nil { t.Fatalf("store normal blob: %v", err) } // Store shunned blob. _, shunnedUUID, err := blob.Store(serverRepo.DB(), []byte("shunned-blob-content")) if err != nil { t.Fatalf("store shunned blob: %v", err) } if err := shun.Add(serverRepo.DB(), shunnedUUID, "test shun"); err != nil { t.Fatalf("shun.Add: %v", err) } // Store private blob. privRid, _, err := blob.Store(serverRepo.DB(), []byte("private-blob-content")) if err != nil { t.Fatalf("store private blob: %v", err) } if err := content.MakePrivate(serverRepo.DB(), int64(privRid)); err != nil { t.Fatalf("MakePrivate: %v", err) } var privateUUID string if err := serverRepo.DB().QueryRow("SELECT uuid FROM blob WHERE rid=?", privRid).Scan(&privateUUID); err != nil { t.Fatalf("query private UUID: %v", err) } // Read server's project-code and server-code. var projCode, srvCode string serverRepo.DB().QueryRow("SELECT value FROM config WHERE name='project-code'").Scan(&projCode) serverRepo.DB().QueryRow("SELECT value FROM config WHERE name='server-code'").Scan(&srvCode) // Create client repo with matching project-code. clientPath := filepath.Join(tmpDir, "client.fossil") clientRepo, err := repo.Create(clientPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("create client repo: %v", err) } t.Cleanup(func() { clientRepo.Close() }) clientRepo.DB().Exec("UPDATE config SET value=? WHERE name='project-code'", projCode) // Sync client from server via MockFossil. mf := NewMockFossil(serverRepo) ctx := context.Background() for round := 0; round < 10; round++ { result, err := libsync.Sync(ctx, clientRepo, mf, libsync.SyncOpts{ Pull: true, ProjectCode: projCode, ServerCode: srvCode, }) if err != nil { t.Fatalf("sync round %d: %v", round, err) } if result.FilesSent == 0 && result.FilesRecvd == 0 { t.Logf("converged at round %d", round) break } } // Assert: client HAS the normal blob. if !HasBlob(clientRepo, normalUUID) { t.Error("client should have the normal blob") } // Assert: client does NOT have the shunned blob. if HasBlob(clientRepo, shunnedUUID) { t.Error("client should NOT have the shunned blob") } // Assert: client does NOT have the private blob. if HasBlob(clientRepo, privateUUID) { t.Error("client should NOT have the private blob") } } // TestPrivateBlobPropagatesWithFlag verifies that private blobs propagate // when Private=true is set in SyncOpts and the server grants 'x' capability, // while shunned blobs are always excluded regardless. func TestPrivateBlobPropagatesWithFlag(t *testing.T) { tmpDir := t.TempDir() // Create server repo and seed blobs. serverPath := filepath.Join(tmpDir, "server.fossil") serverRepo, err := repo.Create(serverPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("create server repo: %v", err) } t.Cleanup(func() { serverRepo.Close() }) // Grant 'x' capability to nobody for private sync. serverRepo.DB().Exec("UPDATE user SET cap='oix' WHERE login='nobody'") // Store normal blob. _, normalUUID, err := blob.Store(serverRepo.DB(), []byte("normal-blob-content")) if err != nil { t.Fatalf("store normal blob: %v", err) } // Store shunned blob. _, shunnedUUID, err := blob.Store(serverRepo.DB(), []byte("shunned-blob-content")) if err != nil { t.Fatalf("store shunned blob: %v", err) } if err := shun.Add(serverRepo.DB(), shunnedUUID, "test shun"); err != nil { t.Fatalf("shun.Add: %v", err) } // Store private blob. privRid, _, err := blob.Store(serverRepo.DB(), []byte("private-blob-content")) if err != nil { t.Fatalf("store private blob: %v", err) } if err := content.MakePrivate(serverRepo.DB(), int64(privRid)); err != nil { t.Fatalf("MakePrivate: %v", err) } var privateUUID string if err := serverRepo.DB().QueryRow("SELECT uuid FROM blob WHERE rid=?", privRid).Scan(&privateUUID); err != nil { t.Fatalf("query private UUID: %v", err) } // Read server's project-code and server-code. var projCode, srvCode string serverRepo.DB().QueryRow("SELECT value FROM config WHERE name='project-code'").Scan(&projCode) serverRepo.DB().QueryRow("SELECT value FROM config WHERE name='server-code'").Scan(&srvCode) // Create client repo with matching project-code. clientPath := filepath.Join(tmpDir, "client.fossil") clientRepo, err := repo.Create(clientPath, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("create client repo: %v", err) } t.Cleanup(func() { clientRepo.Close() }) clientRepo.DB().Exec("UPDATE config SET value=? WHERE name='project-code'", projCode) // Sync client from server with Private=true. mf := NewMockFossil(serverRepo) ctx := context.Background() for round := 0; round < 10; round++ { result, err := libsync.Sync(ctx, clientRepo, mf, libsync.SyncOpts{ Pull: true, Private: true, ProjectCode: projCode, ServerCode: srvCode, }) if err != nil { t.Fatalf("sync round %d: %v", round, err) } if result.FilesSent == 0 && result.FilesRecvd == 0 { t.Logf("converged at round %d", round) break } } // Assert: client HAS the normal blob. if !HasBlob(clientRepo, normalUUID) { t.Error("client should have the normal blob") } // Assert: client does NOT have the shunned blob (shun always blocks). if HasBlob(clientRepo, shunnedUUID) { t.Error("client should NOT have the shunned blob") } // Assert: client DOES have the private blob (Private flag allows it). if !HasBlob(clientRepo, privateUUID) { t.Error("client should have the private blob when Private=true") } }