use assert_cmd::Command; use assert_fs::TempDir; const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); /// The document as this test's binary carries it, so the print path is pinned to the /// file in the repo rather than to a description of it. const SKILL: &str = include_str!("../assets/SKILL.md"); /// `HOME` is redirected, so the suite never writes into the home of whoever runs it. /// A temp directory rather than the real one is also what makes the already-installed /// and the modified cases reachable at all. fn run(home: &TempDir, args: &[&str]) -> std::process::Output { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); cmd.env("HOME", home.path()).args(args); cmd.assert().get_output().clone() } fn installed(home: &TempDir) -> std::path::PathBuf { home.path().join(".claude/skills/worklane/SKILL.md") } /// Nothing about the skill needs a board, and it is wanted before there is one. #[test] fn the_skill_installs_outside_a_worklane_directory() { let home = TempDir::new().unwrap(); let out = run(&home, &["install-skill"]); let stdout = String::from_utf8_lossy(&out.stdout); assert_eq!(out.status.code(), Some(0), "{stdout}"); assert!(stdout.contains("Installed the worklane skill"), "{stdout}"); assert!(stdout.contains(".claude/skills/worklane/SKILL.md"), "{stdout}"); assert_eq!(std::fs::read_to_string(installed(&home)).unwrap(), SKILL); } #[test] fn a_second_install_says_it_is_already_up_to_date() { let home = TempDir::new().unwrap(); run(&home, &["install-skill"]); let out = run(&home, &["install-skill"]); let stdout = String::from_utf8_lossy(&out.stdout); assert_eq!(out.status.code(), Some(0), "{stdout}"); assert!(stdout.contains("Already up to date"), "{stdout}"); } /// A copy someone edited is theirs. The command says what to do next rather than /// discarding it, and only `--force` overwrites. #[test] fn a_modified_copy_is_reported_and_needs_force() { let home = TempDir::new().unwrap(); run(&home, &["install-skill"]); std::fs::write(installed(&home), "hand written\n").unwrap(); let out = run(&home, &["install-skill"]); let stdout = String::from_utf8_lossy(&out.stdout); assert_eq!(out.status.code(), Some(0), "{stdout}"); assert!(stdout.contains("Differs from the version in this binary"), "{stdout}"); assert!(stdout.contains("--force"), "{stdout}"); assert!(stdout.contains("--print"), "the message never says how to compare: {stdout}"); assert_eq!( std::fs::read_to_string(installed(&home)).unwrap(), "hand written\n", "the modified copy was overwritten anyway" ); let out = run(&home, &["install-skill", "--force"]); let stdout = String::from_utf8_lossy(&out.stdout); assert!(stdout.contains("Installed the worklane skill"), "{stdout}"); assert_eq!(std::fs::read_to_string(installed(&home)).unwrap(), SKILL); } /// The print path is what makes a modified copy diffable, so it has to be the document /// byte for byte and it must not install anything on the way past. #[test] fn print_writes_the_document_to_stdout_and_installs_nothing() { let home = TempDir::new().unwrap(); let out = run(&home, &["install-skill", "--print"]); assert_eq!(out.status.code(), Some(0)); assert_eq!(String::from_utf8_lossy(&out.stdout), SKILL); assert!(!installed(&home).exists(), "--print installed the skill anyway"); } /// The command has to be findable by someone who does not already know it exists. #[test] fn the_help_lists_the_install_skill_command() { let home = TempDir::new().unwrap(); let stdout = String::from_utf8_lossy(&run(&home, &["--help"]).stdout).to_string(); assert!(stdout.contains("install-skill"), "{stdout}"); }