use assert_cmd::Command;
#[test]
fn first_run_mints_key_second_run_reuses_it() {
let dir = tempfile::tempdir().unwrap();
let out1 = Command::cargo_bin("mcpmesh")
.unwrap()
.env("XDG_CONFIG_HOME", dir.path())
.args(["internal", "id"])
.assert()
.success();
let id1 = String::from_utf8(out1.get_output().stdout.clone())
.unwrap()
.trim()
.to_string();
assert!(!id1.is_empty(), "internal id prints the endpoint id");
assert!(
dir.path().join("mcpmesh/device.key").exists(),
"first run mints the device key"
);
assert!(
id1.parse::<iroh::EndpointId>().is_ok(),
"internal id prints a parseable endpoint id: {id1}"
);
let out2 = Command::cargo_bin("mcpmesh")
.unwrap()
.env("XDG_CONFIG_HOME", dir.path())
.args(["internal", "id"])
.assert()
.success();
let id2 = String::from_utf8(out2.get_output().stdout.clone())
.unwrap()
.trim()
.to_string();
assert_eq!(
id1, id2,
"second run reuses the same identity, not a silent re-mint"
);
}