diff --git a/crates/radicle-cli/examples/framework/home.md b/crates/radicle-cli/examples/framework/home.md index 66795003..7ee169eb 100644 --- a/crates/radicle-cli/examples/framework/home.md +++ b/crates/radicle-cli/examples/framework/home.md @@ -8,23 +8,23 @@ $ touch file.bin $ rad self --did did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk $ pwd -[..]/home/bob/.radicle +[..]/bob/.radicle $ mkdir src $ cd src $ pwd -[..]/home/bob/.radicle/src +[..]/bob/.radicle/src ``` ``` ~alice $ rad self --did did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi $ pwd -[..]/home/alice/.radicle +[..]/alice/.radicle ``` ``` ~bob $ pwd -[..]/home/bob/.radicle/src +[..]/bob/.radicle/src ``` ``` diff --git a/crates/radicle-cli/examples/rad-id-threshold.md b/crates/radicle-cli/examples/rad-id-threshold.md index 8860b53e..924a9005 100644 --- a/crates/radicle-cli/examples/rad-id-threshold.md +++ b/crates/radicle-cli/examples/rad-id-threshold.md @@ -176,7 +176,7 @@ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from the network, found 2 potential s ✓ Creating checkout in ./heartwood.. ✓ Remote alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi added ✓ Remote-tracking branch alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master created for z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi -✓ Repository successfully cloned under [..]/bob/heartwood/ +✓ Repository successfully cloned under [..]/bob/work/heartwood/ ╭────────────────────────────────────╮ │ heartwood │ │ Radicle Heartwood Protocol & Stack │ diff --git a/crates/radicle-cli/examples/rad-self.md b/crates/radicle-cli/examples/rad-self.md index 72cd06a1..440db13a 100644 --- a/crates/radicle-cli/examples/rad-self.md +++ b/crates/radicle-cli/examples/rad-self.md @@ -9,11 +9,11 @@ Node not running SSH not running ├╴Key (hash) SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA └╴Key (full) ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1 -Home [..]/home/alice/.radicle -├╴Config [..]/home/alice/.radicle/config.json -├╴Storage [..]/home/alice/.radicle/storage -├╴Keys [..]/home/alice/.radicle/keys -└╴Node [..]/home/alice/.radicle/node +Home [..]/alice/.radicle +├╴Config [..]/alice/.radicle/config.json +├╴Storage [..]/alice/.radicle/storage +├╴Keys [..]/alice/.radicle/keys +└╴Node [..]/alice/.radicle/node ``` If you need to display only your DID, Node ID, or SSH Public Key, you can use @@ -41,5 +41,5 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1 ``` $ rad self --home -[..]/home/alice/.radicle +[..]/alice/.radicle ``` diff --git a/crates/radicle-cli/tests/util/environment.rs b/crates/radicle-cli/tests/util/environment.rs index 5fc512e1..61f032a9 100644 --- a/crates/radicle-cli/tests/util/environment.rs +++ b/crates/radicle-cli/tests/util/environment.rs @@ -82,37 +82,37 @@ impl Default for Environment { impl Environment { /// Create a new test environment. - fn named(name: &'static str) -> Self { + pub fn new() -> Self { Self { - tempdir: tempfile::TempDir::with_prefix("radicle-".to_owned() + name).unwrap(), + tempdir: tempfile::TempDir::new().unwrap(), users: 0, } } - /// Create a new test environment. - pub fn new() -> Self { - Self::named("") - } - - /// Return the temp directory path. + /// Return the path of the temporary directory at which + /// this testing environment is rooted. pub fn tempdir(&self) -> PathBuf { self.tempdir.path().into() } - /// Path to the working directory designated for given alias. - pub fn work(&self, has_alias: &impl HasAlias) -> PathBuf { - self.tempdir().join("work").join(has_alias.alias().as_ref()) + /// Return the home directory of the user with the given alias. + /// This is in analogy to a Unix home directory. + pub fn unix_home(&self, has_alias: &impl HasAlias) -> PathBuf { + self.tempdir().join(has_alias.alias().to_string()) } - /// We don't have `RAD_HOME` or `HOME` to rely on to compute a home as usual. - pub fn home(&self, alias: &Alias) -> Home { - Home::new( - self.tempdir() - .join("home") - .join(alias.to_string()) - .join(".radicle"), - ) - .unwrap() + /// Return the Radicle path of the user with the given alias. + /// This is in analogy to `$RAD_HOME` and always a subdirectory of + /// the user's home directory (see [`Environment::unix_home`]). + pub fn rad_home(&self, has_alias: &impl HasAlias) -> Home { + Home::new(self.unix_home(has_alias).join(".radicle")).unwrap() + } + + /// Path to the working directory of the user with the given alias. + /// Tests that need to act on multiple repositories should crate + /// subdirecories within this directory. + pub fn work(&self, has_alias: &impl HasAlias) -> PathBuf { + self.unix_home(has_alias).join("work") } /// Create a new default configuration. @@ -135,7 +135,7 @@ impl Environment { /// is provided. pub fn profile_with(&mut self, config: profile::Config) -> Profile { let alias = config.alias().clone(); - let home = self.home(&alias); + let home = self.rad_home(&alias); let keypair = KeyPair::from_seed(Seed::from([!(self.users as u8); 32])); let policies_db = home.node().join(POLICIES_DB_FILE); let cobs_db = home.cobs().join(COBS_DB_FILE); @@ -224,7 +224,12 @@ impl Environment { self.node_with(config::seed(alias)) } - /// Convenience method for placing repository fixture. + /// Convenience method for placing repository fixture into the + /// directory returned by [`Environment::work`] for the user. + /// Use this only in tests that act on *a single repository* only. + /// For tests that need to act on multiple repositories, + /// create the repositories as subdirectories of the working + /// directory returned by [`Environment::work`]. pub fn repository( &self, has_alias: &impl HasAlias, @@ -236,24 +241,17 @@ impl Environment { pub fn test( &self, test_file: &'static str, - subject: &(impl HasAlias + HasHome), + subject: &impl HasAlias, ) -> Result<(), Box> { formula( self.work(subject).as_ref(), PathBuf::from("examples").join(test_file.to_owned() + ".md"), )? - .env( - "RAD_HOME", - subject.home().path().to_path_buf().to_string_lossy(), - ) + .env("USER", subject.alias().as_ref()) + .env("RAD_HOME", self.rad_home(subject).path().to_string_lossy()) .env( "JJ_CONFIG", - subject - .home() - .path() - .parent() - .unwrap() - .to_path_buf() + self.unix_home(subject) .join(".jjconfig.toml") .to_string_lossy(), ) @@ -262,10 +260,11 @@ impl Environment { Ok(()) } + /// Convenience method for executing multiple test formulas with standard configuration. pub fn tests( &self, test_files: impl IntoIterator, - subject: &(impl HasAlias + HasHome), + subject: &impl HasAlias, ) -> Result<(), Box> { for test_file in test_files { self.test(test_file, subject)?; @@ -288,6 +287,12 @@ pub trait HasAlias { fn alias(&self) -> &Alias; } +impl HasAlias for Alias { + fn alias(&self) -> &Alias { + self + } +} + impl HasAlias for Node { fn alias(&self) -> &Alias { &self.config.alias @@ -305,25 +310,3 @@ impl HasAlias for NodeHandle { &self.alias } } - -pub trait HasHome { - fn home(&self) -> &Home; -} - -impl HasHome for Profile { - fn home(&self) -> &Home { - &self.home - } -} - -impl HasHome for Node { - fn home(&self) -> &Home { - &self.home - } -} - -impl HasHome for NodeHandle { - fn home(&self) -> &Home { - &self.home - } -} diff --git a/crates/radicle-cli/tests/util/formula.rs b/crates/radicle-cli/tests/util/formula.rs index 7e75bc3d..7bffda73 100644 --- a/crates/radicle-cli/tests/util/formula.rs +++ b/crates/radicle-cli/tests/util/formula.rs @@ -28,7 +28,6 @@ pub(crate) fn formula( .env("EDITOR", "true") .env("TZ", "UTC") .env("LANG", "C") - .env("USER", "alice") .env(env::RAD_PASSPHRASE, "radicle") .env(env::RAD_KEYGEN_SEED, RAD_SEED) .env(env::RAD_RNG_SEED, "0")