use super::tests::EnvVarGuard;
use super::*;
use tempfile::tempdir;
#[test]
#[serial_test::serial]
fn prepare_session_continues_after_agent_deploy_failure() {
let tmp_home = tempdir().unwrap();
let _home = EnvVarGuard::set("HOME", tmp_home.path());
let tmp = tempdir().unwrap();
let project = tmp.path();
let fw = crate::core::paths::FrameworkPaths::under(tmp_home.path());
std::fs::create_dir_all(fw.agent_source_dir()).unwrap();
let agents_dir = fw.agent_deploy_dir();
std::fs::create_dir_all(&agents_dir).unwrap();
std::fs::write(
agents_dir.join(crate::core::agent_manifest::MANIFEST_FILE),
b"not valid json{{{",
)
.unwrap();
let report = prepare_session_inner(
&fw,
project,
None,
true,
None,
None,
dirs::home_dir().as_deref(),
)
.expect("a roster-deploy failure must not fail the whole preparation");
assert_eq!(
report.deploy,
crate::core::agent_deployer::DeployResult::default(),
"the agent deploy result must default out when the deploy step failed"
);
assert_eq!(
report.roster_errors.len(),
1,
"exactly the agent-deploy failure must be recorded: {:?}",
report.roster_errors
);
assert!(report.roster_errors[0].contains("agent deploy failed"));
let output_style = project
.join(".claude")
.join("output-styles")
.join("trusty-mpm.md");
assert!(
output_style.exists(),
"output style must still deploy despite the agent-deploy failure: {}",
output_style.display()
);
let settings = std::fs::read_to_string(project.join(".claude").join("settings.json")).unwrap();
assert!(
settings.contains("\"outputStyle\""),
"outputStyle key must still be written: {settings}"
);
}
#[test]
#[serial_test::serial]
fn prepare_session_continues_after_skill_deploy_failure() {
let tmp_home = tempdir().unwrap();
let _home = EnvVarGuard::set("HOME", tmp_home.path());
let tmp = tempdir().unwrap();
let project = tmp.path();
let fw = crate::core::paths::FrameworkPaths::under(tmp_home.path());
let skills_dir = fw.claude_skills_dir();
std::fs::create_dir_all(&skills_dir).unwrap();
std::fs::write(skills_dir.join("tm-doctor"), b"not a directory").unwrap();
let report = prepare_session_inner(
&fw,
project,
None,
true,
None,
None,
dirs::home_dir().as_deref(),
)
.expect("a roster-deploy failure must not fail the whole preparation");
assert_eq!(
report.skill_deploy,
crate::core::skill_deployer::DeployStats::default(),
"the skill deploy result must default out when the deploy step failed"
);
assert_eq!(
report.roster_errors.len(),
1,
"exactly the skill-deploy failure must be recorded: {:?}",
report.roster_errors
);
assert!(report.roster_errors[0].contains("skill deploy failed"));
let output_style = project
.join(".claude")
.join("output-styles")
.join("trusty-mpm.md");
assert!(
output_style.exists(),
"output style must still deploy despite the skill-deploy failure: {}",
output_style.display()
);
}