use super::*;
use crate::boundary::config::ConfigFile;
use crate::boundary::config::Read;
use crate::config_edit::branch::edit::EditOrigin;
use crate::opslog::Origin;
use crate::start::Prepared;
fn config_shapes(named: &str) -> Vec<Gesture> {
let brazen = ConfigFile::Brazen {
workspace: named.to_owned(),
};
let branch = ConfigFile::Branch {
workspace: named.to_owned(),
lineage: "policy".to_owned(),
origin: EditOrigin::Advance,
path: "providers.yaml".to_owned(),
};
vec![
Gesture::Act(Action::ApplyConfig {
file: brazen.clone(),
text: String::new(),
}),
Gesture::Act(Action::ApplyConfig {
file: branch.clone(),
text: String::new(),
}),
Gesture::Ask(Query::Config(Read::File { file: brazen })),
Gesture::Ask(Query::Config(Read::File { file: branch })),
]
}
fn shapes(named: &str) -> Vec<Gesture> {
let prepared = Prepared {
workspace: named.to_owned(),
binding: None,
goal: String::new(),
origin: Origin::Conversation,
lineage: None,
};
vec![
Gesture::Act(Action::Scan {
workspace: named.to_owned(),
}),
Gesture::Act(Action::Monitor(crate::monitor::Verb::Disarm {
workspace: named.to_owned(),
})),
Gesture::Act(Action::Fleet(crate::fleet::Verb::Disarm {
workspace: named.to_owned(),
})),
Gesture::Act(Action::Prompt {
prepared,
goal: String::new(),
seed: None,
}),
Gesture::Ask(Query::Conversations {
workspace: named.to_owned(),
}),
]
}
#[test]
fn a_gesture_that_names_a_workspace_answers_with_it() {
for (gesture, other) in shapes("leaf").into_iter().zip(shapes("host")) {
assert_eq!(gesture.workspace().as_deref(), Some("leaf"), "{gesture:?}");
assert_eq!(other.workspace().as_deref(), Some("host"), "{other:?}");
assert_ne!(gesture, other, "the name is the only difference");
}
}
#[test]
fn a_config_gesture_is_addressed_by_the_wall_its_destination_names() {
for (gesture, other) in config_shapes("leaf").into_iter().zip(config_shapes("host")) {
assert_eq!(gesture.workspace().as_deref(), Some("leaf"), "{gesture:?}");
assert_eq!(other.workspace().as_deref(), Some("host"), "{other:?}");
assert_ne!(gesture, other, "the wall is the only difference");
}
}
#[test]
fn the_mapping_rewrites_a_config_gestures_nested_wall() {
let mut act = Action::ApplyConfig {
file: ConfigFile::Brazen {
workspace: "leaf".to_owned(),
},
text: "x".to_owned(),
};
*act.workspace_slot().expect("the family names a wall") = "host".to_owned();
assert_eq!(
act,
Action::ApplyConfig {
file: ConfigFile::Brazen {
workspace: "host".to_owned()
},
text: "x".to_owned(),
}
);
let mut ask = Query::Config(Read::File {
file: ConfigFile::Cadence,
});
assert!(
ask.workspace_slot().is_none(),
"a destination naming no world has nothing to rewrite"
);
}
#[test]
fn a_config_destination_naming_no_world_answers_none() {
for file in [
ConfigFile::LitanyModels,
ConfigFile::LitanyWorkflow {
name: "nightly".to_owned(),
},
ConfigFile::Cadence,
] {
let act = Gesture::Act(Action::ApplyConfig {
file: file.clone(),
text: String::new(),
});
let ask = Gesture::Ask(Query::Config(Read::File { file }));
assert_eq!(act.workspace(), None, "{act:?}");
assert_eq!(ask.workspace(), None, "{ask:?}");
}
}
#[test]
fn a_gesture_naming_no_workspace_answers_none() {
for gesture in [
Gesture::Act(Action::Ack),
Gesture::Act(Action::Advertise { tools: Vec::new() }),
Gesture::Ask(Query::Workspaces),
Gesture::Ask(Query::Invocations),
] {
assert_eq!(gesture.workspace(), None, "{gesture:?}");
}
}
#[test]
fn reading_the_name_leaves_the_gesture_holding_it() {
let gesture = Gesture::Act(Action::Scan {
workspace: "leaf".to_owned(),
});
assert_eq!(gesture.workspace().as_deref(), Some("leaf"));
assert_eq!(gesture.workspace().as_deref(), Some("leaf"));
}