diff --git a/radicle-cob/Cargo.toml b/radicle-cob/Cargo.toml index c95a97e2..3ae20686 100644 --- a/radicle-cob/Cargo.toml +++ b/radicle-cob/Cargo.toml @@ -12,6 +12,11 @@ edition = "2021" license = "MIT OR Apache-2.0" keywords = ["radicle", "cob", "cobs"] +[features] +default = [] +# Only used for testing. Ensures that commit ids are stable. +stable-commit-ids = [] + [dependencies] fastrand = { version = "2.0.0" } log = { version = "0.4.17" } diff --git a/radicle-cob/src/backend/git/change.rs b/radicle-cob/src/backend/git/change.rs index 4ca3e3ce..88ee1f01 100644 --- a/radicle-cob/src/backend/git/change.rs +++ b/radicle-cob/src/backend/git/change.rs @@ -261,6 +261,7 @@ fn write_commit( ) -> Result<(Oid, Timestamp), error::Create> { let trailers: Vec = vec![trailers::ResourceCommitTrailer::from(resource).into()]; let author = repo.signature()?; + #[allow(unused_variables)] let timestamp = author.when().seconds(); let mut headers = Headers::new(); @@ -273,6 +274,15 @@ fn write_commit( ); let author = Author::try_from(&author)?; + #[cfg(feature = "stable-commit-ids")] + // Ensures the commit id doesn't change on every run. + let (author, timestamp) = ( + Author { + time: git_ext::author::Time::new(1514817556, 0), + ..author + }, + 1514817556, + ); #[cfg(debug_assertions)] let (author, timestamp) = if let Ok(s) = std::env::var(crate::git::RAD_COMMIT_TIME) { // SAFETY: It's ok to panic here, since this is only enabled in debug mode. diff --git a/radicle/Cargo.toml b/radicle/Cargo.toml index b4885dfb..f9d81b50 100644 --- a/radicle/Cargo.toml +++ b/radicle/Cargo.toml @@ -64,3 +64,8 @@ qcheck = { version = "1", default-features = false } path = "../radicle-crypto" version = "0" features = ["test"] + +[dev-dependencies.radicle-cob] +path = "../radicle-cob" +version = "0" +features = ["stable-commit-ids"] diff --git a/radicle/src/test.rs b/radicle/src/test.rs index 7c9b69d7..8bc0cd9f 100644 --- a/radicle/src/test.rs +++ b/radicle/src/test.rs @@ -92,15 +92,13 @@ pub mod setup { fn default() -> Self { let root = tempfile::tempdir().unwrap(); - Self::new(root) + Self::new(root, MockSigner::default()) } } impl Node { - pub fn new(root: impl AsRef) -> Self { + pub fn new(root: impl AsRef, signer: MockSigner) -> Self { let root = root.as_ref().to_path_buf(); - let mut rng = fastrand::Rng::new(); - let signer = MockSigner::new(&mut rng); let home = root.join("home"); let paths = Home::new(home.as_path()).unwrap(); let storage = Storage::open(paths.storage()).unwrap(); @@ -138,10 +136,12 @@ pub mod setup { } impl NodeRepo { + #[track_caller] pub fn fetch(&self, from: &Node) -> Vec { super::fetch(&self.repo, from.signer.public_key(), Namespaces::All).unwrap() } + #[track_caller] pub fn checkout(&self) -> &NodeRepoCheckout { self.checkout.as_ref().unwrap() } @@ -240,9 +240,9 @@ pub mod setup { impl Default for Network { fn default() -> Self { let tmp = tempfile::tempdir().unwrap(); - let alice = Node::new(tmp.path().join("alice")); - let mut bob = Node::new(tmp.path().join("bob")); - let mut eve = Node::new(tmp.path().join("eve")); + let alice = Node::new(tmp.path().join("alice"), MockSigner::from_seed([!0; 32])); + let mut bob = Node::new(tmp.path().join("bob"), MockSigner::from_seed([!1; 32])); + let mut eve = Node::new(tmp.path().join("eve"), MockSigner::from_seed([!2; 32])); let repo = alice.project(); let rid = repo.id; diff --git a/radicle/src/test/fixtures.rs b/radicle/src/test/fixtures.rs index 50e28755..adb1c3bf 100644 --- a/radicle/src/test/fixtures.rs +++ b/radicle/src/test/fixtures.rs @@ -10,7 +10,7 @@ use crate::storage::git::Storage; use crate::storage::refs::SignedRefs; /// The birth of the radicle project, January 1st, 2018. -const RADICLE_EPOCH: i64 = 1514817556; +pub const RADICLE_EPOCH: i64 = 1514817556; /// Create a new storage with a project. pub fn storage, G: Signer>(path: P, signer: &G) -> Result {