git-ents.gitmain
⌘K
foforge
lib.rs66 lines · 2.2 KB · rusthistorycomment on this file
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
41pub use facet_git_tree::ObjectStore;
42
43mod commit;
44mod counting;
45mod keys;
46mod refs;
47mod seed;
48
49pub use commit::{CommitSpec, write_commit};
50pub use counting::CountingFind;
51pub use keys::Keypair;
52pub use refs::MemRefStore;
53pub 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.
59pub(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}