use std::path::PathBuf;
use super::*;
use crate::cli as path_crate_cli;
fn session(session_id: &str, project_root: impl Into<PathBuf>) -> RunningSession {
RunningSession {
session_id: session_id
.parse::<tau_proto::SessionId>()
.expect("known-safe SessionId must be valid"),
project_root: project_root.into(),
}
}
#[test]
fn human_output_preserves_running_session_list_contract() {
let output = render(
&[
session("z-session", "/work/z"),
session("a_session", "/work/a"),
session("a_session", "/work/duplicate"),
],
&path_crate_cli::SessionListArgs::default(),
)
.expect("human output");
assert_eq!(output, "a_session\nz-session\n");
}
#[test]
fn json_output_preserves_each_responsive_harness_record() {
let output = render(
&[
session("same-session", "/work/project"),
session("same-session", "/work/project"),
],
&crate::cli::SessionListArgs {
dir: None,
json: true,
},
)
.expect("JSON output");
let value: serde_json::Value = serde_json::from_str(&output).expect("valid JSON");
assert_eq!(
value,
serde_json::json!([
{
"session_id": "same-session",
"project_root": "/work/project"
},
{
"session_id": "same-session",
"project_root": "/work/project"
}
])
);
}
#[test]
fn directory_filter_matches_only_the_exact_project_root() {
let output = render(
&[
session("parent", "/work"),
session("exact", "/work/project"),
session("child", "/work/project/child"),
session("prefix", "/work/project-other"),
],
&crate::cli::SessionListArgs {
dir: Some(PathBuf::from("/work/project")),
json: false,
},
)
.expect("filtered output");
assert_eq!(output, "exact\n");
}
#[test]
fn complete_listing_has_no_warning() {
assert_eq!(incomplete_claim_warning(0), None);
}
#[test]
fn incomplete_listing_warning_is_counted_and_pluralized() {
assert_eq!(
incomplete_claim_warning(1).as_deref(),
Some(
"warning: omitted 1 contended runtime claim that did not complete compatible exact-session admission"
)
);
assert_eq!(
incomplete_claim_warning(3).as_deref(),
Some(
"warning: omitted 3 contended runtime claims that did not complete compatible exact-session admission"
)
);
}