use super::*;
use tempfile::TempDir;
#[test]
fn compose_session_instructions_declines_git_init_without_a_prompt() {
let tmp = TempDir::new().unwrap();
let dir = std::fs::canonicalize(tmp.path()).unwrap().join("project");
std::fs::create_dir_all(&dir).unwrap();
let (_, output, _) = compose_session_instructions_with_roster_and_init(&dir, None, None)
.expect("a plain directory still composes instructions");
assert!(output.claude_md_created);
assert!(dir.join("CLAUDE.md").is_file());
assert!(
!dir.join(".git").exists(),
"a None should_init must never create a repository"
);
}
#[test]
fn compose_session_instructions_runs_git_init_when_the_prompt_accepts() {
let tmp = TempDir::new().unwrap();
let dir = std::fs::canonicalize(tmp.path()).unwrap().join("project");
std::fs::create_dir_all(&dir).unwrap();
let mut accept = || true;
let (_, output, _) = compose_session_instructions_with_roster_and_init(
&dir,
None,
Some(&mut accept as &mut dyn FnMut() -> bool),
)
.expect("a plain directory still composes instructions");
assert!(output.claude_md_created);
assert!(dir.join("CLAUDE.md").is_file());
assert!(
dir.join(".git").is_dir(),
"an accepted offer must have actually run git init"
);
}
#[test]
fn compose_session_instructions_refuses_to_seed_when_git_init_fails() {
let tmp = TempDir::new().unwrap();
let dir = std::fs::canonicalize(tmp.path()).unwrap().join("project");
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join(".git"), "not a gitfile\n").unwrap();
let mut accept = || true;
let err = compose_session_instructions_with_roster_and_init(
&dir,
None,
Some(&mut accept as &mut dyn FnMut() -> bool),
)
.expect_err("a failed git init must refuse the seed");
assert!(format!("{err:#}").contains("`git init` failed"), "{err:#}");
assert!(
!dir.join("CLAUDE.md").exists(),
"no CLAUDE.md may be seeded after git init fails"
);
}
#[test]
fn stdin_git_init_prompt_is_none_under_the_test_harness() {
assert!(
stdin_git_init_prompt(std::path::Path::new("/tmp/7673-not-a-tty-probe")).is_none(),
"cargo test's stdin is never a TTY"
);
}
#[test]
fn git_init_prompt_text_names_the_directory() {
let text = git_init_prompt_text(std::path::Path::new("/Users/ada/projects"));
assert!(text.contains("/Users/ada/projects"), "{text}");
assert!(text.contains("initialise one? [y/N]"), "{text}");
}