Artifact b7f9e2ab786ce8086e3ce71ccbc218ad5700219338156b5a8e764a47152f58e9:
- File
docs/site/content/docs/testing.md
— part of check-in
[e2a2f28861]
at
2026-04-26 07:52:11
on branch trunk
— docs site + landing + Cloudflare auto-deploy (#6)
* design: docs site + landing page + Cloudflare auto-deploy
Mirror dagnats's docs/landing infrastructure for libfossil: a single-page landing at site/index.html (forked CSS/HTML, content rewritten), a Hugo + Hextra docs site at docs/site/, gomarkdoc-generated SDK reference under docs/site/content/docs/reference/sdk/, llms.txt artifacts, and a wrangler.jsonc that lets Cloudflare's git integration auto-deploy on push to main. Existing docs/*.md files move under docs/site/content/docs/.
* design: correct landing-page path to Hugo layout override
dagnats's working landing page lives at docs/site/layouts/index.html (a Hugo home-page layout override), not at site/index.html. The top-level site/index.html in dagnats is an older draft that the build pipeline ignores. Match the working setup.
* design: align visual system + section list with live dagnats landing
The earlier description came from dagnats's stale top-level site/index.html (JetBrains Mono + Instrument Serif italic + ember/teal accents, 8 sections). The live Hugo layout that actually serves at / uses Geist Mono only, prefers-color-scheme dual-mode (warm cream / warm dark), a single ember accent, and 7 sections (Install, What it is, Why you might want it, How it fits together, Compared to neighbors, What it is not, Get going). Update the spec to match what we are actually mirroring.
* design: drop SDK regen from CF build to match dagnats exactly
Earlier draft had CF install Go + gomarkdoc and re-run docs-gen-sdk on every deploy. dagnats does not do that; it relies on the pre-commit hook to keep committed SDK pages in sync, and ships only Hugo + llms-gen + hugo --minify in the CF build. Match that: smaller, faster CF build, no Go-runtime assumption about Workers Builds, and a true 1:1 mirror.
* plan: docs site + landing + CF auto-deploy implementation steps
11 tasks covering Hugo+Hextra bootstrap, content moves, gomarkdoc SDK generation with pre-commit drift check, llms.txt artifacts, Makefile targets, landing page fork from dagnats's live Hugo home layout, wrangler.jsonc for CF Workers Static Assets, README update, and PR creation.
* docs(site): bootstrap Hugo + Hextra skeleton
* docs(site): move existing docs into Hugo content tree
* docs(site): fix links + H1s broken by docs-tree move
- Drop .md extensions on Hugo cross-doc links - Switch source-code references to absolute github.com/danmestas/libfossil URLs (relative ../ paths broke when files moved 3 dirs deeper) - Align H1 of architecture.md and migration-from-fossil.md with their frontmatter titles
* docs(site): add quickstart, examples, and SDK section stubs
* docs(site): tighten quickstart snippets + reference index
- Make the Sync example self-contained (open + sync, full main, real signatures) - Bridge from Clone to Open with a one-line prose link - Add a sentence to reference/_index.md so it does not render blank - Use the project's canonical "pure-Go, CGo-free" phrasing
* docs(site): add docs-gen-sdk Makefile target + commit generated SDK pages
* docs(site): pin gomarkdoc version + replace empty driver stubs with prose
- Add GOMARKDOC_VERSION Makefile variable so contributors don't drift on output format when a new gomarkdoc ships - Drop the two driver packages (modernc, ncruces) from gomarkdoc and hand-write _index.md pages explaining the register-on-import contract; the stubs were byte-stable but rendered as visibly broken documentation
* docs(site): add gen-llms-txt.sh + docs-gen-llms target
* docs(site): switch llms-full frontmatter strip from sed to awk
The sed range-negation pattern '/^---$/,/^---$/!p' silently re-opens a suppression range on any bare '---' in body content, eating Markdown horizontal rules and embedded YAML in fenced code blocks. The awk pattern strips the frontmatter only when it begins on line 1, leaving body content intact regardless of how many '---' lines it contains.
* hooks: pre-commit fails when SDK pages drift from code
* hooks: pre-commit re-installs gomarkdoc if it's the wrong version
The drift check's existing gate just looks for gomarkdoc on PATH. A contributor with an older gomarkdoc installed locally would have the gate pass and then run regeneration with their stale binary, producing either a silent false-negative or a confusing OUT-OF-DATE error with no version hint. Compare the installed version against GOMARKDOC_VERSION from Makefile and re-install on mismatch. Best-effort; offline contributors can still commit.
* docs(site): add docs-serve, docs-build, docs aggregate targets
* docs(site): make docs aggregate parallel-safe via explicit deps
The docs aggregate previously listed gen-sdk, gen-llms, and build as side-by-side prereqs. Make doesn't guarantee left-to-right ordering under -j, and gen-llms reads what gen-sdk writes, while build reads both. Encode the chain explicitly so 'make -j docs' is correct. Side benefit: 'make docs-build' standalone now produces a complete deployable site, matching contributor expectation.
* site(landing): fork dagnats home layout; rebrand chrome
* site(landing): rewrite §01–§07 content for libfossil
* site(landing): use .ascii class for diagram + fix §03 phrasing
* deploy: add wrangler.jsonc for CF Workers Static Assets
* docs: point README at the new docs site (user: [email protected], size: 6845) [annotate] [blame] [check-ins using]
title: Testing
weight: 50
Testing
This guide describes libfossil's test strategy for contributors adding tests or
investigating failures. For the module layout referenced throughout, see
architecture.md.
Overview
libfossil's test suite has three tiers:
- Unit tests — standard
go test ./...coverage for individual packages under the root module andinternal/.... - DST simulation tests — deterministic simulation scenarios under
./dst/...that drive multiple repos through a virtual clock with fault injection and invariant checks. - Dual-driver matrix — the whole suite runs against two SQLite drivers
(
moderncandncruces) to catch driver-specific behavior.
Running tests
The Makefile wraps the common targets:
make test— runsgo test ./... -count=1 -timeout=120swith the defaultmoderncdriver.make test-drivers— runs the full suite twice:go test ./... -count=1 -timeout=120sfollowed bygo test -tags test_ncruces ./... -count=1 -timeout=120s.make test-otel— runs the out-of-workspace OTel submodule withcd observer/otel && GOWORK=off go test ./... -count=1.make test-all— chainstest-drivers,test-otel, andgo build ./cmd/libfossil/. This is the target CI uses and what you should run before opening a PR.
make setup-hooks points core.hooksPath at .githooks/. The installed
pre-commit hook runs both drivers with -short, go vet, the OTel submodule,
and the CLI build in roughly 45 seconds. Skip with git commit --no-verify
only in emergencies.
Driver matrix
libfossil abstracts SQLite behind db/ and two driver submodules. Both must
pass identical tests:
modernc(default) — pure-Go port of SQLite. Used by every build that doesn't set a tag. Registered viainternal/testdriver/modernc.gounder//go:build !test_ncruces && !test_mattn.ncruces(wasm-capable) — selected with-tags test_ncruces, suitable for WASM targets. Registered viainternal/testdriver/ncruces.gounder//go:build test_ncruces.
GitHub Actions runs test and test-ncruces as parallel jobs (see
.github/workflows/test.yml). The ncruces job excludes cmd/libfossil because
the shipped binary only needs one driver built in; DST and unit tests are
executed under both. For the canonical invocation, use make test-drivers
rather than hand-rolling tag flags.
DST (Deterministic Simulation Testing)
DST is inspired by FoundationDB and TigerBeetle: run many repos in a single
process under a simulated clock, inject faults, and replay a failing seed
deterministically. The harness lives in dst/simulator.go and
dst/invariants.go.
Seeds and reproducibility
dst.SimConfig.Seed drives every random source used by the simulator: the
event queue, network fault decisions, and a SeededBuggify PRNG that gates
fault-injection sites. Any failure on seed N reproduces exactly on seed N.
dst/scenario_test.go exposes three flags driving TestDST:
go test ./dst -run TestDST -seed=42 -level=hostile -steps=10000
-seed=<int64>— seed passed toSimConfig.Seed(0 uses test-specific defaults).-level={normal,adversarial,hostile}— picks aseveritystruct settingDropRateandBuggify.normaldisables faults;hostileuses 20% drop and BUGGIFY.-steps=<int>— caps the number of events processed.
Seed-parameterized scenarios (e.g. TestCloneDSTSeedSweep in
dst/clone_test.go) loop over seeds via t.Run(fmt.Sprintf("seed_%d", seed),
...). To reproduce a single sub-seed: go test ./dst -run
TestCloneDSTSeedSweep/seed_7 -v.
Invariants
dst/invariants.go defines per-node and cross-node checks. Simulator.CheckSafety
runs the per-node set after every SafetyCheckInterval steps; convergence
checks run once the sim has quiesced:
- Safety (anytime):
CheckBlobIntegrity(UUID matches hash of expanded content),CheckDeltaChains(delta.srcidresolves to a blob),CheckNoOrphanPhantoms,CheckUVIntegrity,CheckTagxrefIntegrity,CheckTableSyncIntegrity. - Convergence (after fault-free sync):
CheckConvergence(leaves match master blob-for-blob),CheckSubsetOf,CheckUVConvergence,CheckTableSyncConvergence,CheckTombstoneConvergence.
Failures return a *InvariantError{Invariant, NodeID, Detail} so the failing
invariant, the offending node, and the seed are all in the log line.
BUGGIFY
BUGGIFY marks code points where faults can be injected — truncated batches, dropped cards, retries, corrupted nonces, byte-flipped content. In production the check is a single boolean read; under DST the seeded PRNG decides whether to fire.
Two styles appear in the tree:
- Process-global, used outside the sync path.
simio.Buggify(probability)consults a process-global state toggled bysimio.EnableBuggify(seed)/DisableBuggify()(seesimio/buggify.go). Example frominternal/content/content.go:
// BUGGIFY: flip a byte in expanded content to exercise UUID-mismatch detection.
if simio.Buggify(0.01) && len(content) > 0 {
corrupted := make([]byte, len(content))
copy(corrupted, content)
corrupted[0] ^= 0xFF
return corrupted, nil
}
- Scoped, passed through session options.
BuggifyCheckeris an interface (Check(site string, probability float64) bool) defined ininternal/sync/session.goand re-exported from the root aslibfossil.BuggifyChecker. Sync code threads a checker through so each site has a stable name:
// BUGGIFY: 5% chance drop the last gimme card.
if len(gimmes) > 1 && cs.opts.Buggify != nil &&
cs.opts.Buggify.Check("clone.buildRequest.dropGimme", 0.05) {
gimmes = gimmes[:len(gimmes)-1]
}
dst.SeededBuggify in dst/simulator.go implements BuggifyChecker with a
seeded *rand.Rand. Simulator.New enables both styles when SimConfig.Buggify
is true, wiring independent PRNG streams into the client, the server-side
MockFossil, and the global simio state.
Writing new tests
- Prefer table-driven tests in unit code; include success and failure rows.
- If you touch sync, merge, clone, or checkin, add a DST scenario under
dst/and run it across a seed range (seeTestCloneDSTSeedSweepfor the pattern). - Mark any new fault-sensitive code point with BUGGIFY. Use the scoped
BuggifyCheckerstyle when the site lives inside the sync session; reservesimio.Buggifyfor code that runs outside an explicit session scope. - Assert invariants. If the new behavior warrants one, add it to
dst/invariants.goand wire it intoCheckSafetyor a convergence helper. - Confirm tests pass under both drivers (
make test-drivers) before requesting review.