Artifact 1cd8cd2b298e5f0209aeb67c26fe342502976c5a26864317714b9ac107a80755:
- File
hub/commit_tags_test.go
— part of check-in
[754914fd82]
at
2026-05-13 20:27:25
on branch trunk
— refactor(hub): register modernc SQL driver internally (#166)
The hub package promised consumers wouldn't need to import libfossil directly, but they still had to blank-import libfossil's SQL driver to satisfy the underlying db layer's registration requirement. Move the blank import into hub itself (hub/driver.go) so the package fulfills its own dependency.
Consumers like sesh can now reduce their main.go to a plain `import "github.com/danmestas/EdgeSync/hub"` (or whatever wrapper they use) without taking a direct dep on libfossil's internal SQL machinery.
modernc is registered as the production default. If a consumer ever needs ncruces (WASM/WASI), an escape hatch can be added then.
Tests in hub/ drop their now-redundant blank imports.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> (user: [email protected], size: 4029) [annotate] [blame] [check-ins using]
package hub import ( "context" "testing" ) // TestCommit_BranchTags_LandsOnNamedBranch verifies that supplying the fossil // branch tag pair (branch=<name> + sym-<name>=*) on CommitOpts.Tags lands the // checkin on that branch. After the commit, BranchTip(name) resolves to the // new commit and trunk's tip is unchanged. func TestCommit_BranchTags_LandsOnNamedBranch(t *testing.T) { h := newTestHub(t) ctx := context.Background() trunkRev, err := h.Commit(ctx, CommitOpts{ Files: []FileToCommit{{Name: "seed.txt", Content: []byte("seed\n")}}, Message: "seed trunk", Author: "hub", }) if err != nil { t.Fatalf("seed Commit: %v", err) } r := h.Repo().handle trunkTipBefore, err := r.BranchTip("trunk") if err != nil { t.Fatalf("BranchTip(trunk) before: %v", err) } const branch = "feature/x" branchRev, err := h.Commit(ctx, CommitOpts{ Files: []FileToCommit{{Name: "branch.txt", Content: []byte("on branch\n")}}, Message: "first commit on " + branch, Author: "hub", Tags: []TagSpec{ {Name: "branch", Value: branch}, {Name: "sym-" + branch, Value: "*"}, }, }) if err != nil { t.Fatalf("branch Commit: %v", err) } if branchRev == trunkRev { t.Fatalf("branch commit produced the same RevID as trunk seed: %s", branchRev) } branchTip, err := r.BranchTip(branch) if err != nil { t.Fatalf("BranchTip(%q): %v", branch, err) } branchRID, err := r.ResolveVersion(string(branchRev)) if err != nil { t.Fatalf("ResolveVersion(%s): %v", branchRev, err) } if branchTip != branchRID { t.Errorf("BranchTip(%q) = %d, want %d (the new commit)", branch, branchTip, branchRID) } trunkTipAfter, err := r.BranchTip("trunk") if err != nil { t.Fatalf("BranchTip(trunk) after: %v", err) } if trunkTipAfter != trunkTipBefore { t.Errorf("trunk tip moved: was %d, now %d — branch commit must not advance trunk", trunkTipBefore, trunkTipAfter) } got, err := h.ReadAt(ctx, branchRev, "branch.txt") if err != nil { t.Fatalf("ReadAt(branchRev): %v", err) } if string(got) != "on branch\n" { t.Errorf("ReadAt(branchRev) = %q, want %q", got, "on branch\n") } } // TestCommit_BranchTags_PropagateForward verifies that a second commit // carrying the same branch tag pair lands on the branch's tip (parented // by the previous branch commit), not on trunk. This is the propagation // path: subsequent commits don't fork unless explicitly told to. func TestCommit_BranchTags_PropagateForward(t *testing.T) { h := newTestHub(t) ctx := context.Background() if _, err := h.Commit(ctx, CommitOpts{ Files: []FileToCommit{{Name: "seed.txt", Content: []byte("seed\n")}}, Message: "seed trunk", Author: "hub", }); err != nil { t.Fatalf("seed Commit: %v", err) } const branch = "feature/y" branchTags := []TagSpec{ {Name: "branch", Value: branch}, {Name: "sym-" + branch, Value: "*"}, } first, err := h.Commit(ctx, CommitOpts{ Files: []FileToCommit{{Name: "f.txt", Content: []byte("v1\n")}}, Message: "first on branch", Author: "hub", Tags: branchTags, }) if err != nil { t.Fatalf("first branch Commit: %v", err) } second, err := h.Commit(ctx, CommitOpts{ Files: []FileToCommit{{Name: "f.txt", Content: []byte("v2\n")}}, Message: "second on branch", Author: "hub", Tags: branchTags, }) if err != nil { t.Fatalf("second branch Commit: %v", err) } if first == second { t.Fatalf("second commit returned same RevID as first: %s", first) } r := h.Repo().handle tip, err := r.BranchTip(branch) if err != nil { t.Fatalf("BranchTip(%q): %v", branch, err) } secondRID, err := r.ResolveVersion(string(second)) if err != nil { t.Fatalf("ResolveVersion(second): %v", err) } if tip != secondRID { t.Errorf("BranchTip(%q) = %d, want %d (the second commit)", branch, tip, secondRID) } got, err := h.ReadAt(ctx, RevID(branch), "f.txt") if err != nil { t.Fatalf("ReadAt(branch symbolic): %v", err) } if string(got) != "v2\n" { t.Errorf("ReadAt(%q, f.txt) = %q, want %q", branch, got, "v2\n") } }