Artifact 9ca2a2f7aa422b26fa7a84086f2273b5fee383ecaa20de20c9caa1edadc0a2f6:
- File
dst/e2e_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: 6333) [annotate] [blame] [check-ins using]
package dst import ( "path/filepath" "testing" "time" "github.com/danmestas/go-libfossil/db" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/repo" "github.com/danmestas/go-libfossil/simio" _ "github.com/danmestas/go-libfossil/internal/testdriver" ) func createMasterRepo(t *testing.T) *repo.Repo { t.Helper() path := filepath.Join(t.TempDir(), "master.fossil") r, err := repo.Create(path, "master", simio.CryptoRand{}, "") if err != nil { t.Fatalf("repo.Create master: %v", err) } t.Cleanup(func() { r.Close() }) return r } // TestE2EPullFromMaster seeds artifacts in the mock fossil master, // runs the simulation, and verifies that all leaves converge. func TestE2EPullFromMaster(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) // Seed 5 artifacts in the master. seeded := make(map[string][]byte) for i := range 5 { data := []byte("master artifact " + string(rune('A'+i))) uuid, err := mf.StoreArtifact(data) if err != nil { t.Fatalf("StoreArtifact %d: %v", i, err) } seeded[uuid] = data } 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() // Run enough steps for convergence (each leaf needs ~3 rounds per sync: // round 1: pull → igot; round 2: gimme → file; round 3: converge). if err := sim.Run(20); err != nil { t.Fatalf("Run: %v", err) } t.Logf("Simulation: %d steps, %d syncs, %d errors", sim.Steps, sim.TotalSyncs, sim.TotalErrors) // Verify: every seeded artifact should be in every leaf repo. for _, leafID := range sim.LeafIDs() { leafRepo := sim.Leaf(leafID).Repo() for uuid := range seeded { _, exists := blob.Exists(leafRepo.DB(), uuid) if !exists { t.Errorf("leaf %s missing artifact %s", leafID, uuid) } } } } // TestE2EPushFromLeaf stores an artifact in a leaf repo, runs the simulation, // and verifies it arrives at the master. func TestE2EPushFromLeaf(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) sim, err := New(SimConfig{ Seed: 99, NumLeaves: 1, PollInterval: 5 * time.Second, TmpDir: t.TempDir(), Upstream: mf, }) if err != nil { t.Fatalf("New: %v", err) } defer sim.Close() // Store an artifact directly in the leaf's repo. leafID := sim.LeafIDs()[0] leafRepo := sim.Leaf(leafID).Repo() data := []byte("artifact pushed from leaf") var uuid string err = leafRepo.WithTx(func(tx *db.Tx) error { rid, u, err := blob.Store(tx, data) if err != nil { return err } uuid = u _, err = tx.Exec("INSERT OR IGNORE INTO unsent(rid) VALUES(?)", rid) return err }) if err != nil { t.Fatalf("store in leaf: %v", err) } // Run simulation. if err := sim.Run(20); err != nil { t.Fatalf("Run: %v", err) } t.Logf("Simulation: %d steps, %d syncs, %d errors", sim.Steps, sim.TotalSyncs, sim.TotalErrors) // Verify: artifact should be in the master repo. _, exists := blob.Exists(mf.Repo().DB(), uuid) if !exists { t.Errorf("master missing artifact %s pushed from leaf", uuid) } } // TestE2EBidirectional tests both push and pull in the same simulation. func TestE2EBidirectional(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) // Seed artifact in master. masterData := []byte("from master for bidirectional") masterUUID, _ := mf.StoreArtifact(masterData) 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() // Seed artifact in leaf-0. leaf0Repo := sim.Leaf("leaf-0").Repo() leafData := []byte("from leaf-0 for bidirectional") var leafUUID string leaf0Repo.WithTx(func(tx *db.Tx) error { rid, u, err := blob.Store(tx, leafData) if err != nil { return err } leafUUID = u tx.Exec("INSERT OR IGNORE INTO unsent(rid) VALUES(?)", rid) return nil }) // Run enough steps. if err := sim.Run(40); err != nil { t.Fatalf("Run: %v", err) } t.Logf("Simulation: %d steps, %d syncs, %d errors", sim.Steps, sim.TotalSyncs, sim.TotalErrors) // Master artifact should be in both leaves. for _, id := range sim.LeafIDs() { _, exists := blob.Exists(sim.Leaf(id).Repo().DB(), masterUUID) if !exists { t.Errorf("leaf %s missing master artifact %s", id, masterUUID) } } // Leaf-0 artifact should be in master. _, exists := blob.Exists(mf.Repo().DB(), leafUUID) if !exists { t.Errorf("master missing leaf-0 artifact %s", leafUUID) } // Leaf-0 artifact should also be in leaf-1 (via master relay). // This requires leaf-1 to pull after master received it from leaf-0. _, exists = blob.Exists(sim.Leaf("leaf-1").Repo().DB(), leafUUID) if !exists { t.Logf("NOTE: leaf-1 hasn't received leaf-0's artifact yet (may need more rounds)") } } // TestE2EPartitionAndHeal tests that a partitioned leaf catches up after healing. func TestE2EPartitionAndHeal(t *testing.T) { masterRepo := createMasterRepo(t) mf := NewMockFossil(masterRepo) masterData := []byte("artifact before partition") masterUUID, _ := mf.StoreArtifact(masterData) sim, err := New(SimConfig{ Seed: 123, NumLeaves: 2, PollInterval: 5 * time.Second, TmpDir: t.TempDir(), Upstream: mf, }) if err != nil { t.Fatalf("New: %v", err) } defer sim.Close() // Partition leaf-1. sim.Network().Partition("leaf-1") // Run some steps — leaf-0 should sync, leaf-1 should fail. sim.Run(10) // leaf-0 should have the artifact. _, exists := blob.Exists(sim.Leaf("leaf-0").Repo().DB(), masterUUID) if !exists { t.Fatal("leaf-0 should have master artifact after 10 steps") } // leaf-1 should NOT have the artifact. _, exists = blob.Exists(sim.Leaf("leaf-1").Repo().DB(), masterUUID) if exists { t.Fatal("leaf-1 should NOT have master artifact while partitioned") } // Heal and run more steps. sim.Network().Heal("leaf-1") sim.Run(10) // Now leaf-1 should have caught up. _, exists = blob.Exists(sim.Leaf("leaf-1").Repo().DB(), masterUUID) if !exists { t.Error("leaf-1 should have master artifact after healing") } }