Artifact 67ba8a7853e3ee21900b9e58f7bbae4ef712e9a49fe975552676f657447ff11f:
- File
dst/invariants_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: 6612) [annotate] [blame] [check-ins using]
package dst import ( "path/filepath" "testing" "time" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/repo" "github.com/danmestas/go-libfossil/simio" ) func openTestRepo(t *testing.T, name string) *repo.Repo { t.Helper() path := filepath.Join(t.TempDir(), name+".fossil") r, err := repo.Create(path, "testuser", simio.CryptoRand{}, "") if err != nil { t.Fatalf("repo.Create: %v", err) } t.Cleanup(func() { r.Close() }) return r } func TestCheckBlobIntegrityCleanRepo(t *testing.T) { r := openTestRepo(t, "clean") // Store a valid blob. data := []byte("valid artifact") blob.Store(r.DB(), data) if err := CheckBlobIntegrity("test", r); err != nil { t.Fatalf("expected no error on clean repo: %v", err) } } func TestCheckBlobIntegrityCorrupt(t *testing.T) { r := openTestRepo(t, "corrupt") // Store a blob then corrupt its content directly. data := []byte("will be corrupted") rid, _, _ := blob.Store(r.DB(), data) // Overwrite the compressed content with garbage. r.DB().Exec("UPDATE blob SET content=X'DEADBEEF' WHERE rid=?", rid) err := CheckBlobIntegrity("test", r) if err == nil { t.Fatal("expected error on corrupt blob") } inv, ok := err.(*InvariantError) if !ok { t.Fatalf("expected *InvariantError, got %T: %v", err, err) } if inv.Invariant != "blob-integrity" { t.Fatalf("Invariant = %q, want blob-integrity", inv.Invariant) } } func TestCheckDeltaChainsClean(t *testing.T) { r := openTestRepo(t, "delta-clean") // Store base and delta blobs. base := []byte("base content for delta chain test") rid1, _, _ := blob.Store(r.DB(), base) derived := []byte("base content for delta chain TEST") // similar content blob.StoreDelta(r.DB(), derived, rid1) if err := CheckDeltaChains("test", r); err != nil { t.Fatalf("expected no error: %v", err) } } func TestCheckDeltaChainsDangling(t *testing.T) { r := openTestRepo(t, "delta-dangle") // Create a blob and a delta pointing to it. base := []byte("base") rid1, _, _ := blob.Store(r.DB(), base) derived := []byte("base modified") blob.StoreDelta(r.DB(), derived, rid1) // Delete the base blob to create a dangling reference. r.DB().Exec("DELETE FROM blob WHERE rid=?", rid1) err := CheckDeltaChains("test", r) if err == nil { t.Fatal("expected error for dangling delta") } inv, ok := err.(*InvariantError) if !ok { t.Fatalf("expected *InvariantError, got %T", err) } if inv.Invariant != "delta-chain" { t.Fatalf("Invariant = %q, want delta-chain", inv.Invariant) } } func TestCheckConvergenceMatching(t *testing.T) { master := openTestRepo(t, "master") leaf := openTestRepo(t, "leaf") // Store same artifact in both. data := []byte("shared artifact") blob.Store(master.DB(), data) blob.Store(leaf.DB(), data) leaves := map[NodeID]*repo.Repo{"leaf-0": leaf} if err := CheckConvergence(master, leaves); err != nil { t.Fatalf("expected convergence: %v", err) } } func TestCheckConvergenceMissing(t *testing.T) { master := openTestRepo(t, "master") leaf := openTestRepo(t, "leaf") // Store artifact only in master. data := []byte("only in master") blob.Store(master.DB(), data) leaves := map[NodeID]*repo.Repo{"leaf-0": leaf} err := CheckConvergence(master, leaves) if err == nil { t.Fatal("expected convergence error") } inv, ok := err.(*InvariantError) if !ok { t.Fatalf("expected *InvariantError, got %T", err) } if inv.Invariant != "convergence" { t.Fatalf("Invariant = %q, want convergence", inv.Invariant) } } func TestCheckConvergenceExtraInLeaf(t *testing.T) { master := openTestRepo(t, "master") leaf := openTestRepo(t, "leaf") // Store artifact only in leaf — divergence. data := []byte("only in leaf") blob.Store(leaf.DB(), data) leaves := map[NodeID]*repo.Repo{"leaf-0": leaf} err := CheckConvergence(master, leaves) if err == nil { t.Fatal("expected convergence error for extra leaf artifact") } } func TestCheckSubsetOfAllowsExtra(t *testing.T) { master := openTestRepo(t, "master") leaf := openTestRepo(t, "leaf") // Master has one artifact. blob.Store(master.DB(), []byte("shared")) // Leaf has master's artifact plus an extra. blob.Store(leaf.DB(), []byte("shared")) blob.Store(leaf.DB(), []byte("extra in leaf")) leaves := map[NodeID]*repo.Repo{"leaf-0": leaf} if err := CheckSubsetOf(master, leaves); err != nil { t.Fatalf("SubsetOf should allow extra leaf artifacts: %v", err) } } // --- Simulator integration --- func TestSimulatorCheckSafetyAfterRun(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) // Seed artifacts. for i := range 3 { mf.StoreArtifact([]byte("artifact " + string(rune('A'+i)))) } sim, err := New(SimConfig{ Seed: 42, NumLeaves: 2, PollInterval: 5 * time.Second, TmpDir: t.TempDir(), Upstream: mf, }) if err != nil { t.Fatalf("New: %v", err) } defer sim.Close() sim.Run(20) // Safety invariants should hold. if err := sim.CheckSafety(); err != nil { t.Fatalf("CheckSafety: %v", err) } } func TestSimulatorCheckConvergenceAfterRun(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) // Seed artifacts. for i := range 5 { mf.StoreArtifact([]byte("convergence artifact " + string(rune('A'+i)))) } sim, err := New(SimConfig{ Seed: 7, NumLeaves: 2, PollInterval: 5 * time.Second, TmpDir: t.TempDir(), Upstream: mf, }) if err != nil { t.Fatalf("New: %v", err) } defer sim.Close() // Run enough steps for convergence. sim.Run(30) // All leaves should have all master artifacts. if err := sim.CheckAllConverged(masterRepo); err != nil { t.Fatalf("CheckAllConverged: %v", err) } } func TestSimulatorSafetyWithBuggify(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) mf.StoreArtifact([]byte("buggify safety test")) sim, err := New(SimConfig{ Seed: 42, NumLeaves: 1, PollInterval: 1 * time.Second, TmpDir: t.TempDir(), Upstream: mf, Buggify: true, }) if err != nil { t.Fatalf("New: %v", err) } defer sim.Close() sim.Run(50) // Safety invariants should hold even with buggify. // Buggify may cause sync errors, but should not corrupt stored data // (the blob.Store is content-addressed, so corruption is detected). if err := sim.CheckSafety(); err != nil { t.Logf("Safety violation with buggify (may be expected from content.Expand buggify): %v", err) } t.Logf("Buggify safety: %d steps, %d syncs, %d errors", sim.Steps, sim.TotalSyncs, sim.TotalErrors) }