use crate::commands::install::{install_one, install_to};
#[test]
fn overwrite_artifact_refreshes_modified_file_without_force() {
let dir = tempfile::tempdir().unwrap();
let paths = trusty_mpm::core::paths::FrameworkPaths::under(dir.path());
let optimizer = paths.optimizer_config();
std::fs::create_dir_all(&paths.hooks).unwrap();
std::fs::write(&optimizer, "custom").unwrap();
let report = install_to(&paths, false).unwrap();
assert!(
report
.iter()
.any(|l| l.contains("optimizer.toml") && l.contains("refreshed")),
"expected a refreshed line for optimizer.toml, got: {report:?}"
);
assert_ne!(
std::fs::read_to_string(&optimizer).unwrap(),
"custom",
"Overwrite artifact must replace a modified file even without --force"
);
}
#[test]
fn seed_once_artifact_is_not_clobbered_without_force() {
let dir = tempfile::tempdir().unwrap();
let dest = dir.path().join("user-owned.md");
std::fs::write(&dest, "the user's own edits").unwrap();
let artifact = trusty_mpm::core::bundle::BundledArtifact {
rel_path: "user-owned.md",
contents: "shipped default content",
install: trusty_mpm::core::bundle::InstallPolicy::SeedOnce,
};
let line = install_one(&dest, &artifact, false).unwrap();
assert!(line.contains("preserved"), "unexpected report line: {line}");
assert_eq!(
std::fs::read_to_string(&dest).unwrap(),
"the user's own edits"
);
}
#[test]
fn seed_once_artifact_force_resets_to_shipped_default() {
let dir = tempfile::tempdir().unwrap();
let dest = dir.path().join("user-owned.md");
std::fs::write(&dest, "the user's own edits").unwrap();
let artifact = trusty_mpm::core::bundle::BundledArtifact {
rel_path: "user-owned.md",
contents: "shipped default content",
install: trusty_mpm::core::bundle::InstallPolicy::SeedOnce,
};
let line = install_one(&dest, &artifact, true).unwrap();
assert!(
line.contains("reset to shipped default"),
"unexpected report line: {line}"
);
assert_eq!(
std::fs::read_to_string(&dest).unwrap(),
"shipped default content"
);
}
#[test]
fn bundle_install_pass_never_touches_the_compiled_prompt() {
let dir = tempfile::tempdir().unwrap();
let paths = trusty_mpm::core::paths::FrameworkPaths::under(dir.path());
let compiled =
trusty_mpm::core::instruction_pipeline::compiled_prompt_path(dir.path(), "sess-1");
std::fs::create_dir_all(compiled.parent().unwrap()).unwrap();
const SENTINEL: &str = "SENTINEL-NOT-WRITTEN-BY-THE-BUNDLE-PASS";
std::fs::write(&compiled, SENTINEL).unwrap();
install_to(&paths, true).unwrap();
assert_eq!(
std::fs::read_to_string(&compiled).unwrap(),
SENTINEL,
"no bundled artifact may write {}",
compiled.display()
);
trusty_mpm::core::instruction_pipeline::write_compiled_prompt_to(
&compiled,
&trusty_mpm::core::instruction_pipeline::assemble_system_prompt(),
)
.unwrap();
assert_eq!(
std::fs::read_to_string(&compiled).unwrap(),
trusty_mpm::core::instruction_pipeline::assemble_system_prompt()
);
}