Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Correctly update inventory with seed commands
cloudhead committed 1 year ago
commit f0e2018ac564746ad468ba6bc68c60b85eb804b6
parent fc55d67929ff7c706b1a0a7826ee7581eb8e8232
11 files changed +156 -25
added radicle-cli/examples/rad-init-no-seed.md
@@ -0,0 +1,29 @@
+
If we initialize a public repository without seeding it, it won't be advertized:
+
```
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed
+

+
Initializing public radicle 👾 repository in [..]
+

+
✓ Repository heartwood created.
+

+
Your Repository ID (RID) is rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK.
+
You can show it any time by running `rad .` from this directory.
+

+
Your repository will be announced to the network when you start your node.
+
You can start your node with `rad node start`.
+
To push changes, run `git push`.
+
```
+
```
+
$ rad node inventory
+
```
+

+
If we then seed it, it becomes advertized in our inventory:
+
```
+
$ rad seed rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
+
✓ Inventory updated with rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
+
✓ Seeding policy updated for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'all'
+
```
+
```
+
$ rad node inventory
+
rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
+
```
added radicle-cli/examples/rad-init-private-no-seed.md
@@ -0,0 +1,34 @@
+
Let's say we initialize a private repository and specify that we don't want it
+
to be seeded.
+
```
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed
+

+
Initializing private radicle 👾 repository in [..]
+

+
✓ Repository heartwood created.
+

+
Your Repository ID (RID) is rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu.
+
You can show it any time by running `rad .` from this directory.
+

+
You have created a private repository.
+
This repository will only be visible to you, and to peers you explicitly allow.
+

+
To make it public, run `rad publish`.
+
To push changes, run `git push`.
+
```
+

+
```
+
$ rad seed
+
No seeding policies to show.
+
```
+

+
We can decide to seed it later:
+
```
+
$ rad seed rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu
+
✓ Seeding policy updated for rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu with scope 'all'
+
```
+

+
But it still won't show up in our inventory, since it's private:
+
```
+
$ rad node inventory
+
```
modified radicle-cli/examples/rad-init-private.md
@@ -16,3 +16,15 @@ This repository will only be visible to you, and to peers you explicitly allow.
To make it public, run `rad publish`.
To push changes, run `git push`.
```
+

+
The repository does not show up in our inventory, since it is not advertized,
+
despite being seeded:
+
```
+
$ rad node inventory
+
$ rad seed
+
╭────────────────────────────────────────────────────────────────╮
+
│ Repository                          Name        Policy   Scope │
+
├────────────────────────────────────────────────────────────────┤
+
│ rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu   heartwood   allow    all   │
+
╰────────────────────────────────────────────────────────────────╯
+
```
modified radicle-cli/examples/rad-init.md
@@ -29,7 +29,7 @@ $ rad init
✗ Error: repository is already initialized with remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji
```

-
Projects can be listed with the `ls` command:
+
Repositories can be listed with the `ls` command:

```
$ rad ls
@@ -39,3 +39,10 @@ $ rad ls
│ heartwood   rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   public       f2de534   Radicle Heartwood Protocol & Stack │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
+

+
Public repositories are added to our inventory:
+

+
```
+
$ rad node inventory
+
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
```
modified radicle-cli/examples/rad-node.md
@@ -92,7 +92,7 @@ Note that if we unseed a repository, it is no longer part of our inventory:
```
$ rad unseed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
✓ Seeding policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji removed
-
$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
+
$ rad node inventory
```

Likewise, if we seed a repository we don't have locally, it won't show up as
@@ -100,20 +100,17 @@ part of our inventory:
```
$ rad seed rad:z3trNYnLWS11cJWC6BbxDs5niGo82
[...]
-
$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
+
$ rad node inventory
```

But if we start seeding the repository we have locally again, it'll show
up in our inventory:
```
$ rad seed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
-
[...]
-
$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
-
╭─────────────────────────────────────────────────────╮
-
│ RID                                 NID             │
-
├─────────────────────────────────────────────────────┤
-
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   z6MknSL…StBU8Vi │
-
╰─────────────────────────────────────────────────────╯
+
✓ Inventory updated with rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
+
$ rad node inventory
+
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
```

Some commands also give us a hint if the node isn't running:
modified radicle-cli/examples/rad-publish.md
@@ -3,13 +3,21 @@ Let's say we have a private repo. To make it public, we use the `publish` comman
```
$ rad inspect --visibility
private
+
$ rad node inventory
$ rad publish
+
✓ Updating inventory..
✓ Repository is now public
! Warning: Your node is not running. Start your node with `rad node start` to announce your repository to the network
$ rad inspect --visibility
public
```

+
The repository is now in our inventory:
+
```
+
$ rad node inventory
+
rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu
+
```
+

If we try to publish again, we get an error:

``` (fail)
modified radicle-cli/examples/rad-unseed.md
@@ -35,3 +35,11 @@ $ rad ls --all
│ heartwood   rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   local        f2de534   Radicle Heartwood Protocol & Stack │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
+

+
Hence, we also see that it isn't in our inventory and isn't seeded:
+

+
```
+
$ rad node inventory
+
$ rad seed
+
No seeding policies to show.
+
```
modified radicle-cli/src/commands/publish.rs
@@ -114,18 +114,19 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        }
        anyhow::bail!("fatal: repository storage is corrupt");
    }
+
    let mut node = radicle::Node::new(profile.socket());
+
    let spinner = term::spinner("Updating inventory..");
+

+
    // The repository is now part of our inventory.
+
    profile.add_inventory(rid, &mut node)?;
+
    spinner.finish();

    term::success!(
        "Repository is now {}",
        term::format::visibility(&doc.visibility)
    );

-
    let mut node = radicle::Node::new(profile.socket());
-
    if node.is_running() {
-
        let spinner = term::spinner("Announcing to network..");
-
        node.announce_inventory()?;
-
        spinner.finish();
-
    } else {
+
    if !node.is_running() {
        term::warning(format!(
            "Your node is not running. Start your node with {} to announce your repository \
            to the network",
modified radicle-cli/src/commands/seed.rs
@@ -137,6 +137,13 @@ pub fn update(
    let updated = profile.seed(rid, scope, node)?;
    let outcome = if updated { "updated" } else { "exists" };

+
    if let Ok(repo) = profile.storage.repository(rid) {
+
        if repo.identity_doc()?.visibility.is_public() {
+
            profile.add_inventory(rid, node)?;
+
            term::success!("Inventory updated with {}", term::format::tertiary(rid));
+
        }
+
    }
+

    term::success!(
        "Seeding policy {outcome} for {} with scope '{scope}'",
        term::format::tertiary(rid),
modified radicle-cli/tests/commands.rs
@@ -202,6 +202,23 @@ fn rad_init() {
}

#[test]
+
fn rad_init_no_seed() {
+
    let mut environment = Environment::new();
+
    let alice = environment.node(Config::test(Alias::new("alice")));
+
    let working = environment.tmp().join("working");
+

+
    fixtures::repository(working.join("alice"));
+

+
    test(
+
        "examples/rad-init-no-seed.md",
+
        working.join("alice"),
+
        Some(&alice.home),
+
        [],
+
    )
+
    .unwrap();
+
}
+

+
#[test]
fn rad_init_with_existing_remote() {
    let mut environment = Environment::new();
    let profile = environment.profile(config::profile("alice"));
@@ -2169,6 +2186,23 @@ fn rad_init_private() {
}

#[test]
+
fn rad_init_private_no_seed() {
+
    let mut environment = Environment::new();
+
    let alice = environment.node(Config::test(Alias::new("alice")));
+
    let working = environment.tmp().join("working");
+

+
    fixtures::repository(working.join("alice"));
+

+
    test(
+
        "examples/rad-init-private-no-seed.md",
+
        working.join("alice"),
+
        Some(&alice.home),
+
        [],
+
    )
+
    .unwrap();
+
}
+

+
#[test]
fn rad_init_private_seed() {
    let mut environment = Environment::new();
    let alice = environment.node(Config::test(Alias::new("alice")));
modified radicle/src/profile.rs
@@ -32,7 +32,7 @@ use crate::node::{
use crate::prelude::{Did, NodeId, RepoId};
use crate::storage::git::transport;
use crate::storage::git::Storage;
-
use crate::storage::{ReadRepository, ReadStorage};
+
use crate::storage::ReadRepository;
use crate::{cli, cob, git, node, storage, web};

/// Environment variables used by radicle.
@@ -453,15 +453,9 @@ impl Profile {
            Ok(updated) => Ok(updated),
            Err(e) if e.is_connection_err() => {
                let mut config = self.policies_mut()?;
-
                let result = config.seed(&rid, scope)?;
+
                let updated = config.seed(&rid, scope)?;

-
                if result && self.storage.contains(&rid)? {
-
                    let now = LocalTime::now();
-
                    let mut db = self.database_mut()?;
-

-
                    node::routing::Store::add_inventory(&mut db, [&rid], *self.id(), now.into())?;
-
                }
-
                Ok(result)
+
                Ok(updated)
            }
            Err(e) => Err(e.into()),
        }