Artifact 655ef89151a41e84cbb7cecf572bdacc2be28bd7b79bc6aa83f3b0d45c8a2219:
- File
checkout_update_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: 7394) [annotate] [blame] [check-ins using]
package libfossil_test import ( "os" "path/filepath" "strings" "testing" "github.com/danmestas/go-libfossil" ) // updateFixture creates a repo, commits two revs via Repo.Commit, then // creates a checkout (initialized to tip = rid2). Returns the second RID // so callers can pass it as a deliberate Update target. func updateFixture(t *testing.T) (*libfossil.Repo, *libfossil.Checkout, int64) { t.Helper() dir := t.TempDir() repoPath := filepath.Join(dir, "u.fossil") repo, err := libfossil.Create(repoPath, libfossil.CreateOpts{}) if err != nil { t.Fatalf("Create: %v", err) } t.Cleanup(func() { _ = repo.Close() }) // First commit (no parent — genesis). rid1, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "first", User: "test", Files: []libfossil.FileToCommit{{Name: "a.txt", Content: []byte("v1")}}, }) if err != nil { t.Fatalf("first Commit: %v", err) } // Second commit (parent = rid1). This becomes the tip. rid2, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "second", User: "test", ParentID: rid1, Files: []libfossil.FileToCommit{{Name: "a.txt", Content: []byte("v2")}}, }) if err != nil { t.Fatalf("second Commit: %v", err) } // CreateCheckout (NOT OpenCheckout — the dir is fresh) initializes the // working tree to the tip checkin (rid2). checkoutDir := filepath.Join(dir, "wt") checkout, err := repo.CreateCheckout(checkoutDir, libfossil.CheckoutCreateOpts{}) if err != nil { t.Fatalf("CreateCheckout: %v", err) } t.Cleanup(func() { _ = checkout.Close() }) return repo, checkout, rid2 } func TestCheckoutUpdate_TargetRID(t *testing.T) { _, checkout, rid := updateFixture(t) result, err := checkout.Update(libfossil.UpdateOpts{TargetRID: rid}) if err != nil { t.Fatalf("Update: %v", err) } if len(result.Conflicted) != 0 { t.Fatalf("expected clean update, got Conflicted=%v", result.Conflicted) } } func TestCheckoutUpdate_ZeroTargetRIDIsTipUpdate(t *testing.T) { // TargetRID=0 means "update to current branch tip" per checkout package. _, checkout, _ := updateFixture(t) result, err := checkout.Update(libfossil.UpdateOpts{TargetRID: 0}) if err != nil { t.Fatalf("Update(0): %v", err) } if len(result.Conflicted) != 0 { t.Fatalf("expected clean update, got Conflicted=%v", result.Conflicted) } } func TestCheckoutUpdate_NonexistentRIDErrors(t *testing.T) { _, checkout, _ := updateFixture(t) result, err := checkout.Update(libfossil.UpdateOpts{TargetRID: 999999}) if err == nil { t.Fatal("expected error for missing RID, got nil") } // A genuine failure must be distinguishable from a conflicted success: // no marker paths are reported for a failed update. if len(result.Conflicted) != 0 { t.Fatalf("expected empty Conflicted on failure, got %v", result.Conflicted) } } // TestCheckoutUpdate_CleanReportsWrittenPaths verifies the clean-success // outcome: err == nil, Conflicted empty, and the modified file's path shows // up in FilesWritten (not just a count). updateFixture's checkout starts at // tip (rid2), so this pins the checkout back to rid1 first via Extract to // force Update(TargetRID: rid2) to do real work. func TestCheckoutUpdate_CleanReportsWrittenPaths(t *testing.T) { dir := t.TempDir() repoPath := filepath.Join(dir, "clean.fossil") repo, err := libfossil.Create(repoPath, libfossil.CreateOpts{}) if err != nil { t.Fatalf("Create: %v", err) } t.Cleanup(func() { _ = repo.Close() }) rid1, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "first", User: "test", Files: []libfossil.FileToCommit{{Name: "a.txt", Content: []byte("v1")}}, }) if err != nil { t.Fatalf("first Commit: %v", err) } rid2, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "second", User: "test", ParentID: rid1, Files: []libfossil.FileToCommit{{Name: "a.txt", Content: []byte("v2")}}, }) if err != nil { t.Fatalf("second Commit: %v", err) } checkoutDir := filepath.Join(dir, "wt") checkout, err := repo.CreateCheckout(checkoutDir, libfossil.CheckoutCreateOpts{}) if err != nil { t.Fatalf("CreateCheckout: %v", err) } t.Cleanup(func() { _ = checkout.Close() }) // Pin the checkout to rid1 so Update(TargetRID: rid2) has real work to do. if err := checkout.Extract(rid1, libfossil.ExtractOpts{Force: true}); err != nil { t.Fatalf("Extract rid1: %v", err) } result, err := checkout.Update(libfossil.UpdateOpts{TargetRID: rid2}) if err != nil { t.Fatalf("Update: %v", err) } if len(result.Conflicted) != 0 { t.Fatalf("expected clean update, got Conflicted=%v", result.Conflicted) } found := false for _, p := range result.FilesWritten { if p == "a.txt" { found = true } } if !found { t.Fatalf("expected FilesWritten to contain a.txt, got %v", result.FilesWritten) } } // TestCheckoutUpdate_ConflictedSurfacesPaths builds a genuine fork at the // public API level — two commits from the same parent, both editing the // same line — and updates across it. The merge cannot resolve the // overlapping edit, so it writes conflict markers into the working file. // This is a SUCCESSFUL update (err == nil): the caller must be able to see // which paths now contain markers via Conflicted. func TestCheckoutUpdate_ConflictedSurfacesPaths(t *testing.T) { dir := t.TempDir() repoPath := filepath.Join(dir, "c.fossil") repo, err := libfossil.Create(repoPath, libfossil.CreateOpts{}) if err != nil { t.Fatalf("Create: %v", err) } t.Cleanup(func() { _ = repo.Close() }) ridBase, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "base", User: "test", Files: []libfossil.FileToCommit{{Name: "conflict.txt", Content: []byte("original\n")}}, }) if err != nil { t.Fatalf("base Commit: %v", err) } ridA, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "branch A", User: "test", ParentID: ridBase, Files: []libfossil.FileToCommit{{Name: "conflict.txt", Content: []byte("local version\n")}}, }) if err != nil { t.Fatalf("branch A Commit: %v", err) } ridB, _, err := repo.Commit(libfossil.CommitOpts{ Comment: "branch B", User: "test", ParentID: ridBase, Files: []libfossil.FileToCommit{{Name: "conflict.txt", Content: []byte("remote version\n")}}, }) if err != nil { t.Fatalf("branch B Commit: %v", err) } // CreateCheckout initializes to tip, which (last write wins in the // leaf table) is branch A here since it was committed first among the // two leaves and branch B follows — extract explicitly to branch A to // pin the starting point regardless of tip resolution. checkoutDir := filepath.Join(dir, "wt") checkout, err := repo.CreateCheckout(checkoutDir, libfossil.CheckoutCreateOpts{}) if err != nil { t.Fatalf("CreateCheckout: %v", err) } t.Cleanup(func() { _ = checkout.Close() }) if err := checkout.Extract(ridA, libfossil.ExtractOpts{Force: true}); err != nil { t.Fatalf("Extract ridA: %v", err) } result, err := checkout.Update(libfossil.UpdateOpts{TargetRID: ridB}) if err != nil { t.Fatalf("conflicted Update must still succeed (err==nil): %v", err) } if len(result.Conflicted) != 1 || result.Conflicted[0] != "conflict.txt" { t.Fatalf("expected Conflicted=[conflict.txt], got %v", result.Conflicted) } data, err := os.ReadFile(filepath.Join(checkoutDir, "conflict.txt")) if err != nil { t.Fatal(err) } if !strings.Contains(string(data), "<<<<<<<") { t.Fatalf("expected conflict markers written to disk, got %q", data) } }