use super::*;
use crate::boundary::deposit;
use serde_json::json;
use tempfile::tempdir;
#[test]
fn a_line_deposits_the_envelope_it_spells() {
let root = tempdir().unwrap();
let exit = run(
root.path(),
&[
"--project".into(),
"/proj".into(),
"--as".into(),
"alba".into(),
"/close bl-1".into(),
],
"g-line",
0,
&mut no_wait(),
);
assert_eq!(exit, TIMEOUT_EXIT, "nothing is running to answer it");
let pending = deposit::pending(root.path());
let [(id, path)] = pending.as_slice() else {
panic!("expected one deposit, got {pending:?}");
};
assert_eq!(id, "g-line-0");
let written: serde_json::Value =
serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
assert_eq!(
written,
json!({"op": "close", "project": "/proj", "id": "bl-1", "name": "alba"}),
"the line encodes to the envelope it spells"
);
}
#[test]
fn a_line_that_names_no_target_never_deposits() {
let root = tempdir().unwrap();
for args in [
vec!["/scan".to_owned()],
vec!["--ws".to_owned()],
vec!["--nope".to_owned(), "x".to_owned(), "/scan".to_owned()],
vec!["/enhance".to_owned()],
] {
assert_eq!(
run(root.path(), &args, "g", 1, &mut no_wait()),
USAGE_EXIT,
"{args:?}"
);
}
assert!(deposit::pending(root.path()).is_empty());
}
#[test]
fn the_context_flags_aim_a_line() {
let root = tempdir().unwrap();
run(
root.path(),
&[
"--ws".into(),
"/ws".into(),
"--agent".into(),
"c-1".into(),
"/message ship it".into(),
],
"g-msg",
0,
&mut no_wait(),
);
let pending = deposit::pending(root.path());
let [(_, path)] = pending.as_slice() else {
panic!("expected one deposit");
};
let written: serde_json::Value =
serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
assert_eq!(
written,
json!({"op": "message", "workspace": "/ws", "agent": "c-1", "content": "ship it"})
);
}
#[test]
fn every_refusal_names_the_flags_and_none_names_a_focus() {
for args in [
vec!["/conversations".to_owned()],
vec!["/scan".to_owned()],
vec!["--nope".to_owned(), "x".to_owned(), "/scan".to_owned()],
vec![],
vec!["not json".to_owned()],
] {
let why = argv::read_gesture("gesture", &args).expect_err("refused");
assert!(why.contains("--ws NAME"), "{args:?}: {why}");
assert!(why.contains("yog gesture --help"), "{args:?}: {why}");
assert!(
!why.contains("focus"),
"{args:?}: this seat has nothing to focus: {why}"
);
assert_eq!(
why.matches("usage: yog gesture").count(),
1,
"{args:?}: one usage line, not two: {why}"
);
}
}
#[test]
fn the_shared_sentence_states_the_fact_and_not_the_remedy() {
let why = argv::read_gesture("gesture", &["/conversations".to_owned()]).expect_err("refused");
assert!(
why.contains("/conversations: no workspace in context"),
"{why}"
);
assert!(!why.contains("envelope"), "{why}");
}