use assert_cmd::Command;
#[test]
fn help_lists_all_flags() {
let mut cmd = Command::cargo_bin("atproto-devtool").expect("bin not found");
let output = cmd
.arg("test")
.arg("labeler")
.arg("--help")
.output()
.expect("failed to run atproto-devtool");
assert!(
output.status.success(),
"--help should exit successfully, got {:?}",
output.status,
);
let stdout = String::from_utf8_lossy(&output.stdout);
for needle in [
"--did",
"--subscribe-timeout",
"--verbose",
"--no-color",
"--commit-report",
"--force-self-mint",
"--self-mint-curve",
"--report-subject-did",
"<TARGET>",
] {
assert!(
stdout.contains(needle),
"--help stdout missing expected token `{needle}`, got:\n{stdout}",
);
}
}
#[test]
fn bootstrap_failure_exits_two() {
let mut cmd = Command::cargo_bin("atproto-devtool").expect("bin not found");
let assert = cmd.arg("test").arg("labeler").assert();
assert.code(2);
}
#[test]
fn no_color_renders_without_ansi() {
let mut cmd = Command::cargo_bin("atproto-devtool").expect("bin not found");
cmd.env_remove("NO_COLOR");
cmd.arg("test")
.arg("labeler")
.arg("--no-color")
.arg("did:web:nonexistent.invalid");
let output = cmd.output().expect("failed to run atproto-devtool");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("\x1b["),
"Stdout must not contain ANSI escape sequences with --no-color, got:\n{stdout}",
);
assert!(
stdout.contains("== Identity =="),
"Stdout should contain a rendered identity section, got:\n{stdout}",
);
assert!(
stdout.contains("[FAIL]") || stdout.contains("[NET]"),
"Stdout should contain at least one failure or network-error check glyph, got:\n{stdout}",
);
}
#[test]
fn verbose_flag_emits_debug_tracing_to_stderr() {
let mut cmd = Command::cargo_bin("atproto-devtool").expect("bin not found");
cmd.arg("test")
.arg("labeler")
.arg("--verbose")
.arg("--no-color")
.arg("did:web:nonexistent.invalid");
let output = cmd.output().expect("failed to run atproto-devtool");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("DEBUG"),
"Stderr should contain DEBUG tracing output with --verbose, got:\n{stderr}",
);
}
#[test]
fn ac8_1_handle_without_app_password_fails() {
let output = Command::cargo_bin("atproto-devtool")
.expect("bin")
.args([
"test",
"labeler",
"alice.bsky.social",
"--handle",
"alice.bsky.social",
])
.output()
.expect("run");
assert!(
!output.status.success(),
"expected parse failure when --handle supplied without --app-password"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("--app-password") || stderr.contains("app_password"),
"stderr should mention missing --app-password, got: {stderr}"
);
}
#[test]
fn ac8_1_app_password_without_handle_fails() {
let output = Command::cargo_bin("atproto-devtool")
.expect("bin")
.args([
"test",
"labeler",
"alice.bsky.social",
"--app-password",
"xxxx-xxxx-xxxx-xxxx",
])
.output()
.expect("run");
assert!(
!output.status.success(),
"expected parse failure when --app-password supplied without --handle"
);
}
#[test]
fn ac8_4_unreachable_endpoint_nonzero_exit() {
let output = Command::cargo_bin("atproto-devtool")
.expect("bin")
.args(["test", "labeler", "https://doesnt-exist.example.test"])
.output()
.expect("run");
assert_ne!(
output.status.code(),
Some(0),
"expected non-zero exit code for unreachable endpoint"
);
}