crates/kernel/ents-testutil/src/lib.rs
| 1 | //! Shared test fixtures for `git-ents` crates: an in-memory ref store, an |
| 2 | //! in-memory object store, deterministic signing keys, a signed-commit |
| 3 | //! builder, and seeding helpers for members, results, and code-ref history. |
| 4 | //! |
| 5 | //! This is the integration harness the engineering conventions call for — |
| 6 | //! a dev-dependency-only crate, never linked into a shipping binary. It |
| 7 | //! exists so `ents-gate` and `ents-query` (and later `ents-receive`, |
| 8 | //! `ents-sync`, `ents-effect`) exercise the same fixture vocabulary instead |
| 9 | //! of each reinventing repos, keys, and commit plumbing. |
| 10 | //! |
| 11 | //! Everything here panics on setup failure (via `expect`) rather than |
| 12 | //! returning `Result`: a fixture that cannot be built is a broken test, |
| 13 | //! not a condition under test. |
| 14 | //! |
| 15 | //! # Examples |
| 16 | //! |
| 17 | //! A complete miniature forge: one member enrolled under |
| 18 | //! `refs/meta/member/*`, one signed mutation, both readable back through |
| 19 | //! the same read-half trait production code uses. |
| 20 | //! |
| 21 | //! ``` |
| 22 | //! use ents_model::Provenance; |
| 23 | //! use ents_testutil::{Keypair, MemRefStore, ObjectStore, enroll_member}; |
| 24 | //! use gix_ref_store::RefStoreRead; |
| 25 | //! |
| 26 | //! let refs = MemRefStore::default(); |
| 27 | //! let objects = ObjectStore::default(); |
| 28 | //! let key = Keypair::from_seed(1); |
| 29 | //! |
| 30 | //! let tip = enroll_member(&refs, &objects, "jdc", &key, Provenance::AdminRegistered, 1_000); |
| 31 | //! |
| 32 | //! let name: gix::refs::FullName = "refs/meta/member/jdc".try_into().expect("valid"); |
| 33 | //! assert_eq!(refs.get(name.as_ref()).expect("readable"), Some(tip)); |
| 34 | //! ``` |
| 35 | |
| 36 | #![expect( |
| 37 | clippy::expect_used, |
| 38 | reason = "test-support crate: fixtures panic on setup failure rather than returning Result" |
| 39 | )] |
| 40 | |
| 41 | pub use facet_git_tree::ObjectStore; |
| 42 | |
| 43 | mod commit; |
| 44 | mod counting; |
| 45 | mod keys; |
| 46 | mod refs; |
| 47 | mod seed; |
| 48 | |
| 49 | pub use commit::{CommitSpec, write_commit}; |
| 50 | pub use counting::CountingFind; |
| 51 | pub use keys::Keypair; |
| 52 | pub use refs::MemRefStore; |
| 53 | pub use seed::{ |
| 54 | advance_ref, empty_tree, enroll_member, record_result, write_member, write_meta_entity, |
| 55 | }; |
| 56 | |
| 57 | /// Read a ref from a fixture store, panicking on the (impossible for |
| 58 | /// [`MemRefStore`]) backend error. |
| 59 | pub(crate) fn refs_get( |
| 60 | refs: &MemRefStore, |
| 61 | name: &gix::refs::FullName, |
| 62 | ) -> Option<gix_hash::ObjectId> { |
| 63 | use gix_ref_store::RefStoreRead as _; |
| 64 | refs.get(name.as_ref()) |
| 65 | .expect("in-memory ref read cannot fail") |
| 66 | } |