add a default archetype, preselected by the clients
This commit is contained in:
parent
a74d23d313
commit
8f7c45d40f
1 changed files with 253 additions and 47 deletions
|
|
@ -281,7 +281,9 @@ pub(crate) trait Actions {
|
|||
fn make_admin(&mut self, name: &str) -> Result<String>;
|
||||
/// `ruth`, with the permissions of a manager, declared `up`.
|
||||
fn declare_ruth(&mut self, hive: &str, exists: bool) -> Result<String>;
|
||||
fn create_agent(&mut self, name: &str, hive: &str) -> Result<String>;
|
||||
/// An agent of the `default` archetype, or a custom one with its own config
|
||||
/// repo when `custom`.
|
||||
fn create_agent(&mut self, name: &str, hive: &str, custom: bool) -> Result<String>;
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
|
@ -748,7 +750,12 @@ fn other_agent(ui: &mut impl Ui, actions: &mut impl Actions, session: &mut Sessi
|
|||
let hive = ask_valid(ui, "Hive", session.hive.as_deref(), |h| {
|
||||
crate::agent::parse_ident(h, "hive").map(drop)
|
||||
})?;
|
||||
let said = ui.working("creating the agent", || actions.create_agent(&name, &hive))?;
|
||||
let custom =
|
||||
ui.ask("Custom agent with its own config repo, instead of the default archetype? [y/N]: ")?;
|
||||
let custom = matches!(custom.trim().to_lowercase().as_str(), "y" | "yes");
|
||||
let said = ui.working("creating the agent", || {
|
||||
actions.create_agent(&name, &hive, custom)
|
||||
})?;
|
||||
session.hive = Some(hive);
|
||||
ui.say(Tone::Good, &format!("✔ {said}"));
|
||||
Ok(())
|
||||
|
|
@ -944,8 +951,8 @@ mod tests {
|
|||
Ok("ruth is declared up".to_owned())
|
||||
}
|
||||
|
||||
fn create_agent(&mut self, name: &str, hive: &str) -> Result<String> {
|
||||
self.note(&format!("create_agent:{name}:{hive}"));
|
||||
fn create_agent(&mut self, name: &str, hive: &str, custom: bool) -> Result<String> {
|
||||
self.note(&format!("create_agent:{name}:{hive}:custom={custom}"));
|
||||
self.world.others += 1;
|
||||
Ok("queued".to_owned())
|
||||
}
|
||||
|
|
@ -982,8 +989,8 @@ mod tests {
|
|||
fn declare_ruth(&mut self, _: &str, _: bool) -> Result<String> {
|
||||
Ok("declared".to_owned())
|
||||
}
|
||||
fn create_agent(&mut self, name: &str, hive: &str) -> Result<String> {
|
||||
self.0.create_agent(name, hive)
|
||||
fn create_agent(&mut self, name: &str, hive: &str, custom: bool) -> Result<String> {
|
||||
self.0.create_agent(name, hive, custom)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1445,6 +1452,22 @@ mod tests {
|
|||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn another_agent_is_a_default_archetype_agent_unless_asked_custom() {
|
||||
let created = |custom_answer: &'static str| {
|
||||
let log = log();
|
||||
let mut actions = Fake::new(World::fresh(), &log);
|
||||
let mut script: Vec<&str> = FULL_RUN[..FULL_RUN.len() - 1].to_vec();
|
||||
script.extend(["y", "scribe", "", custom_answer]);
|
||||
let mut ui = Script::new(&script, &log);
|
||||
run(&mut ui, &mut actions).expect("the run finishes");
|
||||
calls(&log, "create_agent")
|
||||
};
|
||||
assert_eq!(created(""), ["create_agent:scribe:firsthive:custom=false"]);
|
||||
assert_eq!(created("n"), ["create_agent:scribe:firsthive:custom=false"]);
|
||||
assert_eq!(created("y"), ["create_agent:scribe:firsthive:custom=true"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_step_that_the_check_still_finds_open_is_not_taken_as_done() {
|
||||
let log = log();
|
||||
|
|
|
|||
Loading…
Reference in a new issue