aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/party.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/party.rs')
-rw-r--r--src/federation/party.rs56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs
index a46b492..9e9591b 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -217,10 +217,11 @@ fn command() -> Command {
Arg::new("name")
.long("name")
.value_name("NAME")
- .required(true)
.help(
- "The federation's name, in its root: a rehearsal named otherwise is \
- another federation. 1 to 64 of A-Z a-z 0-9 . _ @ -",
+ "The federation's name, in its root, at revision 2 or later: a \
+ rehearsal named otherwise is another federation. 1 to 64 of A-Z \
+ a-z 0-9 . _ @ -. Without it, two federations differ by their \
+ parties, keys, nodes and rules alone",
),
)
.arg(
@@ -2307,12 +2308,13 @@ fn adding(name: &str) -> Result<Revision> {
Ok(feature.revision())
}
-/// The first version of a federation, as `found`'s arguments `sub` say: its name
+/// The first version of a federation, as `found`'s arguments `sub` say: its name, if any
/// (`--name`); its parties, each with its keys (`PARTY=KEY|FILE`, again for more), `since`
/// 0; their node lists (`--nodes PARTY=NODE,…`), empty where not given; its rules in order
/// (`--rule PATH=WRITER`, `nobody` writing `false`), each party writing under
-/// `home/{party}/` where none is given; and its revision (`--revision`), the one that gives
-/// a name where none is given. Checked as a first version.
+/// `home/{party}/` where none is given; and its revision (`--revision`), where none is given
+/// the one that gives a name with a name, else the base revision. Checked as a first
+/// version.
fn founded(sub: &ArgMatches) -> Result<JsonValue> {
let mut keys: std::collections::BTreeMap<String, Vec<String>> = Default::default();
for item in strings(sub, "parties") {
@@ -2378,22 +2380,27 @@ fn founded(sub: &ArgMatches) -> Result<JsonValue> {
"nodes": given(&nodes, "nodes"),
"rules": rules,
});
+ let name = sub.get_one::<String>("name");
let revision = match sub.get_one::<String>("revision") {
Some(feature) => adding(feature)?,
- None => Feature::FederationName.revision(),
+ None if name.is_some() => Feature::FederationName.revision(),
+ None => Revision::default(),
};
- if !revision.has(Feature::FederationName) {
- bail!(
- "{revision} gives a version no name: {} does, and those after it",
- Feature::FederationName.revision()
- );
+ if let Some(name) = name {
+ if !revision.has(Feature::FederationName) {
+ bail!(
+ "{revision} gives a version no name: {} does, and those after it",
+ Feature::FederationName.revision()
+ );
+ }
+ if !super::version::is_party(name) {
+ bail!("{name:?} is no name: 1 to 64 of A-Z a-z 0-9 . _ @ -, as a party's");
+ }
+ version["name"] = name.as_str().into();
}
- version["revision"] = revision.id().to_string().into();
- let name = sub.get_one::<String>("name").expect("required");
- if !super::version::is_party(name) {
- bail!("{name:?} is no name: 1 to 64 of A-Z a-z 0-9 . _ @ -, as a party's");
+ if revision != Revision::default() {
+ version["revision"] = revision.id().to_string().into();
}
- version["name"] = name.as_str().into();
let read = Version::read(&client::json(&version).map_err(|why| anyhow!(why))?)
.map_err(|why| anyhow!("no first version: {why}"))?;
read.changes_validly(None)
@@ -3053,8 +3060,9 @@ mod tests {
};
let tv_key = format!("tv={}", tv.key_line());
let lass_key = format!("lass={}", lass_file.display());
+ let nameless = founded;
let named = ["--name".to_owned(), "krebs".to_owned()];
- let founded = |args: &[String]| founded(&[&named[..], args].concat());
+ let founded = |args: &[String]| nameless(&[&named[..], args].concat());
let version = founded(&[
tv_key.clone(),
lass_key.clone(),
@@ -3096,8 +3104,16 @@ mod tests {
])
.unwrap_err();
assert!(why.to_string().contains("gives a version no name"), "{why}");
- let nameless = super::command().try_get_matches_from(["continuum-party", "found", &tv_key]);
- assert!(nameless.is_err());
+ // Without a name: none, at the base revision, or the revision given.
+ let unnamed = nameless(std::slice::from_ref(&tv_key)).unwrap();
+ assert!(unnamed.get("name").is_none() && unnamed.get("revision").is_none());
+ let merging = nameless(&[
+ tv_key.clone(),
+ "--revision".to_owned(),
+ "merge-events".to_owned(),
+ ])
+ .unwrap();
+ assert!(merging.get("name").is_none() && merging.get("revision").is_some());
assert!(founded(&[tv_key.clone(), tv_key.clone()]).is_err());
assert!(
founded(&[