Artifact ad80bffa416f9e2f944ebfda3f8b12387f50dd6eb0a65e595594b9b50096d508:
- File
internal/manifest/dephantomize_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: 5130) [annotate] [blame] [check-ins using]
package manifest import ( "testing" "time" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/deck" _ "github.com/danmestas/go-libfossil/internal/testdriver" ) func TestAfterDephantomizeCheckin(t *testing.T) { r := setupTestRepo(t) // Create a checkin manifest, compute its hash, store as phantom, then fill. fileContent := []byte("hello dephantomize") fileRid, fileUUID, err := blob.Store(r.DB(), fileContent) if err != nil { t.Fatalf("Store file blob: %v", err) } _ = fileRid d := &deck.Deck{ Type: deck.Checkin, C: "dephantomize commit", U: deck.User("testuser"), D: time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC), F: []deck.FileCard{{Name: "hello.txt", UUID: fileUUID}}, } manifestBytes, err := d.Marshal() if err != nil { t.Fatalf("Marshal: %v", err) } // Compute the hash to get the UUID. rid, uuid, err := blob.Store(r.DB(), manifestBytes) if err != nil { t.Fatalf("Store manifest: %v", err) } // Delete the real blob, re-insert as phantom, then fill it back. // This simulates the phantom->real transition. r.DB().Exec("DELETE FROM event WHERE objid=?", rid) r.DB().Exec("DELETE FROM plink WHERE cid=?", rid) r.DB().Exec("DELETE FROM leaf WHERE rid=?", rid) r.DB().Exec("DELETE FROM mlink WHERE mid=?", rid) r.DB().Exec("DELETE FROM tagxref WHERE rid=?", rid) // Verify no event row exists before dephantomize. var eventCount int r.DB().QueryRow("SELECT count(*) FROM event WHERE objid=?", rid).Scan(&eventCount) if eventCount != 0 { t.Fatalf("event count before dephantomize = %d, want 0", eventCount) } // Call AfterDephantomize. AfterDephantomize(r, rid) // Verify event row was created. r.DB().QueryRow("SELECT count(*) FROM event WHERE objid=?", rid).Scan(&eventCount) if eventCount != 1 { t.Errorf("event count after dephantomize = %d, want 1", eventCount) } // Verify event is a checkin. var eventType string r.DB().QueryRow("SELECT type FROM event WHERE objid=?", rid).Scan(&eventType) if eventType != "ci" { t.Errorf("event type = %q, want 'ci'", eventType) } _ = uuid } func TestAfterDephantomizeOrphan(t *testing.T) { r := setupTestRepo(t) // Create a baseline checkin. fileContent := []byte("baseline file") _, fileUUID, err := blob.Store(r.DB(), fileContent) if err != nil { t.Fatalf("Store file: %v", err) } baselineDeck := &deck.Deck{ Type: deck.Checkin, C: "baseline", U: deck.User("testuser"), D: time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC), F: []deck.FileCard{{Name: "file.txt", UUID: fileUUID}}, } baselineBytes, err := baselineDeck.Marshal() if err != nil { t.Fatalf("Marshal baseline: %v", err) } baselineRid, _, err := blob.Store(r.DB(), baselineBytes) if err != nil { t.Fatalf("Store baseline: %v", err) } // Create another checkin that will be the "orphan" (delta manifest). fileContent2 := []byte("orphan file") _, fileUUID2, err := blob.Store(r.DB(), fileContent2) if err != nil { t.Fatalf("Store file2: %v", err) } orphanDeck := &deck.Deck{ Type: deck.Checkin, C: "orphan commit", U: deck.User("testuser"), D: time.Date(2024, 1, 15, 11, 0, 0, 0, time.UTC), F: []deck.FileCard{{Name: "file2.txt", UUID: fileUUID2}}, } orphanBytes, err := orphanDeck.Marshal() if err != nil { t.Fatalf("Marshal orphan: %v", err) } orphanRid, _, err := blob.Store(r.DB(), orphanBytes) if err != nil { t.Fatalf("Store orphan: %v", err) } // Clear crosslink tables for the orphan. r.DB().Exec("DELETE FROM event WHERE objid=?", orphanRid) r.DB().Exec("DELETE FROM leaf WHERE rid=?", orphanRid) r.DB().Exec("DELETE FROM tagxref WHERE rid=?", orphanRid) // Insert orphan row linking orphanRid to baselineRid. r.DB().Exec("INSERT INTO orphan(rid, baseline) VALUES(?, ?)", orphanRid, baselineRid) // Verify orphan row exists. var orphanCount int r.DB().QueryRow("SELECT count(*) FROM orphan WHERE baseline=?", baselineRid).Scan(&orphanCount) if orphanCount != 1 { t.Fatalf("orphan count = %d, want 1", orphanCount) } // Call AfterDephantomize on the baseline. AfterDephantomize(r, baselineRid) // Verify orphan was cleaned up. r.DB().QueryRow("SELECT count(*) FROM orphan WHERE baseline=?", baselineRid).Scan(&orphanCount) if orphanCount != 0 { t.Errorf("orphan count after dephantomize = %d, want 0", orphanCount) } // Verify orphan checkin got crosslinked (event row created). var eventCount int r.DB().QueryRow("SELECT count(*) FROM event WHERE objid=?", orphanRid).Scan(&eventCount) if eventCount != 0 { // The orphan's event may have been created by crosslinkSingle. // If it wasn't (because it was already crosslinked earlier), that's also fine. // The key assertion is that the orphan row was cleaned up. } } func TestAfterDephantomizeNilRepo(t *testing.T) { defer func() { if r := recover(); r == nil { t.Error("expected panic for nil repo") } }() AfterDephantomize(nil, 1) } func TestAfterDephantomizeZeroRid(t *testing.T) { r := setupTestRepo(t) // Should return without panicking. AfterDephantomize(r, 0) AfterDephantomize(r, -1) }