use std::process::Command;
fn filament_bin() -> std::path::PathBuf {
let mut path = std::env::current_exe().unwrap();
path.pop(); path.pop(); path.push("filament");
path
}
#[test]
fn devices_empty_shows_message() {
let bin = filament_bin();
let output = Command::new(&bin)
.env("FILAMENT_CONFIG_DIR", std::env::temp_dir().join("filament-devices-test-empty"))
.arg("devices")
.output()
.expect("failed to execute filament");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("No devices yet."),
"Expected the empty devices message, got: {}",
stdout
);
}
#[test]
fn devices_shows_table_headers() {
let bin = filament_bin();
let config_dir = std::env::temp_dir().join("filament-devices-test-headers");
std::fs::create_dir_all(&config_dir).unwrap();
let devices_json = config_dir.join("devices.json");
std::fs::write(&devices_json, r#"[
{
"name": "test-device",
"secret": "abc123def456",
"lastSeen": 1700000000,
"overlayV6": "fd00::1"
}
]"#).unwrap();
let output = Command::new(&bin)
.env("FILAMENT_CONFIG_DIR", &config_dir)
.arg("devices")
.output()
.expect("failed to execute filament");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("NEEDS REVIEW") && stdout.contains("promote to continue"),
"Expected the needs-review listing, got: {}",
stdout
);
assert!(
stdout.contains("filament devices promote test-device"),
"Expected the promote command hint, got: {}",
stdout
);
assert!(
stdout.contains("test-device"),
"Expected 'test-device' in output, got: {}",
stdout
);
assert!(
stdout.contains("fd00::1"),
"Expected address 'fd00::1' in output, got: {}",
stdout
);
assert!(
stdout.contains("This is a local index; each device's own capability list is authoritative."),
"Expected the authoritative-list note, got: {}",
stdout
);
std::fs::remove_dir_all(&config_dir).ok();
}
#[test]
fn devices_json_includes_new_fields() {
let bin = filament_bin();
let config_dir = std::env::temp_dir().join("filament-devices-test-json");
std::fs::create_dir_all(&config_dir).unwrap();
let devices_json = config_dir.join("devices.json");
std::fs::write(&devices_json, r#"[
{
"name": "test-device",
"secret": "abc123def456",
"lastSeen": 1700000000,
"overlayV6": "fd00::1",
"caps": ["transfer", "shell"]
}
]"#).unwrap();
let output = Command::new(&bin)
.env("FILAMENT_CONFIG_DIR", &config_dir)
.arg("devices")
.arg("--json")
.output()
.expect("failed to execute filament");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.trim().starts_with('['),
"Expected JSON array, got: {}",
&stdout[..stdout.len().min(200)]
);
assert!(
stdout.contains("\"lastSeen\""),
"Expected 'lastSeen' field in JSON, got: {}",
stdout
);
assert!(
stdout.contains("\"address\""),
"Expected 'address' field in JSON, got: {}",
stdout
);
assert!(
stdout.contains("\"mesh\""),
"Expected 'mesh' field in JSON, got: {}",
stdout
);
assert!(
stdout.contains("test-device"),
"Expected 'test-device' in JSON, got: {}",
stdout
);
assert!(
stdout.contains("fd00::1"),
"Expected address in JSON, got: {}",
stdout
);
std::fs::remove_dir_all(&config_dir).ok();
}