Artifact 77644aabbad836ea0adf51317dfe7064163dc81bb5a4ad779eba718c6da5d9af:
- File
internal/content/cache_chain_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: 4562) [annotate] [blame] [check-ins using]
package content import ( "bytes" "database/sql" "fmt" "strings" "testing" "github.com/danmestas/go-libfossil/db" "github.com/danmestas/go-libfossil/internal/blob" libfossil "github.com/danmestas/go-libfossil/internal/fsltype" ) // countingQuerier forwards to an inner Querier and counts the blob-content // reads, the single statement that dominates delta-chain expansion. type countingQuerier struct { inner db.Querier blobLoads int deltaWalks int } func (c *countingQuerier) Exec(q string, args ...any) (sql.Result, error) { return c.inner.Exec(q, args...) } func (c *countingQuerier) QueryRow(q string, args ...any) *sql.Row { switch { case strings.HasPrefix(q, "SELECT content, size FROM blob"): c.blobLoads++ case strings.HasPrefix(q, "SELECT srcid FROM delta"): c.deltaWalks++ } return c.inner.QueryRow(q, args...) } func (c *countingQuerier) Query(q string, args ...any) (*sql.Rows, error) { return c.inner.Query(q, args...) } // buildDeltaChain stores chainLen versions of a similar body and deltifies // each one against its successor, so version 0 sits at the deep end of a // chain rooted at the last version — the shape a real Fossil repository has // after content_deltify has rewritten older blobs as deltas of newer ones. func buildDeltaChain(t *testing.T, d *db.DB, chainLen int) ([]libfossil.FslID, [][]byte) { t.Helper() rids := make([]libfossil.FslID, chainLen) bodies := make([][]byte, chainLen) for i := range rids { var body bytes.Buffer for line := 0; line < 300; line++ { if line == i { fmt.Fprintf(&body, "line %04d: version %d\n", line, i) } else { fmt.Fprintf(&body, "line %04d: the quick brown fox jumps over the lazy dog\n", line) } } bodies[i] = body.Bytes() rid, _, err := blob.Store(d, bodies[i]) if err != nil { t.Fatalf("store version %d: %v", i, err) } rids[i] = rid } if err := d.WithTx(func(tx *db.Tx) error { for i := 0; i < chainLen-1; i++ { if _, err := Deltify(tx, rids[i], rids[i+1]); err != nil { return fmt.Errorf("deltify %d against %d: %w", i, i+1, err) } } return nil }); err != nil { t.Fatalf("build chain: %v", err) } var deltas int if err := d.QueryRow("SELECT count(*) FROM delta").Scan(&deltas); err != nil { t.Fatalf("count delta: %v", err) } if deltas != chainLen-1 { t.Fatalf("delta rows = %d, want %d — chain was not built", deltas, chainLen-1) } return rids, bodies } // TestCache_MemoizesChainInteriors pins the property Crosslink depends on: // walking a delta chain once must leave every node it materialized in the // cache, so expanding the whole chain costs a number of blob reads linear in // the chain length rather than quadratic. func TestCache_MemoizesChainInteriors(t *testing.T) { const chainLen = 40 d := setupTestDB(t) rids, bodies := buildDeltaChain(t, d, chainLen) q := &countingQuerier{inner: d} c := NewCache(8 << 20) // Ascending rid order is the order Crosslink sweeps in; rid[0] is the // deepest node, so its expansion materializes the entire chain. for i, rid := range rids { got, err := c.Expand(q, rid) if err != nil { t.Fatalf("Expand rid %d (version %d): %v", rid, i, err) } if !bytes.Equal(got, bodies[i]) { t.Fatalf("version %d: content mismatch", i) } } // Without interior memoization this is chainLen*(chainLen+1)/2 = 820. if q.blobLoads > 2*chainLen { t.Fatalf("blob content reads = %d, want <= %d for a %d-node chain", q.blobLoads, 2*chainLen, chainLen) } } // TestCache_ChainInteriorContentIsCorrect checks the memoized interiors are // served as their own content, not as a neighbour's. func TestCache_ChainInteriorContentIsCorrect(t *testing.T) { const chainLen = 12 d := setupTestDB(t) rids, bodies := buildDeltaChain(t, d, chainLen) c := NewCache(8 << 20) if _, err := c.Expand(d, rids[0]); err != nil { t.Fatalf("prime chain: %v", err) } for i := chainLen - 1; i >= 0; i-- { got, err := c.Expand(d, rids[i]) if err != nil { t.Fatalf("Expand version %d: %v", i, err) } if !bytes.Equal(got, bodies[i]) { t.Fatalf("version %d served wrong content", i) } } // Cached interiors must be independent buffers: mutating a returned // slice must not corrupt the next read of the same rid. first, err := c.Expand(d, rids[chainLen/2]) if err != nil { t.Fatal(err) } first[0] ^= 0xFF second, err := c.Expand(d, rids[chainLen/2]) if err != nil { t.Fatal(err) } if !bytes.Equal(second, bodies[chainLen/2]) { t.Fatal("mutating a returned slice corrupted the cached interior") } }