Artifact 27d9502fbd2764d84b062ff3d5b0407ac9396c06038f8373e8eb3467b179399a:
- File
dst/mock_fossil.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 2032) [annotate] [blame] [check-ins using]
package dst import ( "context" "github.com/danmestas/libfossil/internal/blob" "github.com/danmestas/libfossil/db" "github.com/danmestas/libfossil/internal/repo" libsync "github.com/danmestas/libfossil/internal/sync" "github.com/danmestas/libfossil/internal/xfer" ) // MockFossil simulates a Fossil master server using the real HandleSync // handler. It manages its own repo and implements sync.Transport by // dispatching xfer messages to HandleSyncWithOpts. type MockFossil struct { repo *repo.Repo buggify libsync.BuggifyChecker } // Verify interface compliance at compile time. var _ libsync.Transport = (*MockFossil)(nil) // NewMockFossil creates a MockFossil backed by the given repo. func NewMockFossil(r *repo.Repo) *MockFossil { if r == nil { panic("dst.NewMockFossil: r must not be nil") } return &MockFossil{repo: r} } // SetBuggify configures fault injection for the handler. func (f *MockFossil) SetBuggify(b libsync.BuggifyChecker) { f.buggify = b } // Repo returns the mock fossil's repository (for seeding and invariants). func (f *MockFossil) Repo() *repo.Repo { return f.repo } // Exchange handles one xfer request/response round by delegating to // the real HandleSyncWithOpts. This ensures the DST tests exercise the // same code path as production servers. func (f *MockFossil) Exchange(ctx context.Context, req *xfer.Message) (*xfer.Message, error) { if req == nil { panic("MockFossil.Exchange: req must not be nil") } return libsync.HandleSyncWithOpts(ctx, f.repo, req, libsync.HandleOpts{ Buggify: f.buggify, }) } // StoreArtifact adds a raw artifact to the mock fossil's repo. // Returns the UUID. Used by tests to seed the master with content. func (f *MockFossil) StoreArtifact(data []byte) (string, error) { if data == nil { panic("MockFossil.StoreArtifact: data must not be nil") } var uuid string err := f.repo.WithTx(func(tx *db.Tx) error { _, u, err := blob.Store(tx, data) if err != nil { return err } uuid = u return nil }) return uuid, err }