mod common;
use tempfile::TempDir;
fn stdout( out : &std::process::Output ) -> String
{
String::from_utf8_lossy( &out.stdout ).into_owned()
}
fn stderr( out : &std::process::Output ) -> String
{
String::from_utf8_lossy( &out.stderr ).into_owned()
}
fn assert_exit( out : &std::process::Output, code : i32 )
{
assert_eq!(
out.status.code().unwrap_or( -1 ),
code,
"expected exit {code}, got {:?}; stderr: {}",
out.status.code(),
stderr( out )
);
}
#[ test ]
fn ec_1_agent_0_main_sessions_only()
{
let root = TempDir::new().unwrap();
common::write_test_session( root.path(), "proj-alpha", "main-session", 2 );
common::write_flat_agent_session( root.path(), "proj-alpha", "abc123", "main-session", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "agent::0" )
.output()
.unwrap();
assert_exit( &out, 0 );
let output = stdout( &out );
assert!(
!output.contains( "agent-abc123" ),
"EC-1: agent session must not appear with agent::0; got: {output}"
);
}
#[ test ]
fn ec_2_agent_1_agent_sessions_only()
{
let root = TempDir::new().unwrap();
common::write_test_session( root.path(), "proj-beta", "main-session", 2 );
common::write_flat_agent_session( root.path(), "proj-beta", "def456", "main-session", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "agent::1" )
.output()
.unwrap();
assert_exit( &out, 0 );
let output = stdout( &out );
assert!(
!output.contains( "main-session" ),
"EC-2: main session must not appear with agent::1; got: {output}"
);
}
#[ test ]
fn ec_3_agent_2_rejected()
{
let out = common::clg_cmd()
.arg( ".list" )
.arg( "agent::2" )
.output()
.unwrap();
assert_exit( &out, 1 );
let err = stderr( &out );
assert!(
!err.is_empty(),
"EC-3: expected non-empty error for agent::2 (out-of-range boolean); got empty stderr"
);
}
#[ test ]
fn ec_4_agent_yes_accepted()
{
let out = common::clg_cmd()
.arg( ".list" )
.arg( "agent::yes" )
.env( "CLAUDE_STORAGE_ROOT", "/tmp/claude_tests_empty" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_5_unset_returns_all_session_types()
{
let root = TempDir::new().unwrap();
common::write_test_session( root.path(), "proj-gamma", "main-session", 2 );
common::write_flat_agent_session( root.path(), "proj-gamma", "ghi789", "main-session", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_6_agent_1_auto_enables_sessions_display()
{
let root = TempDir::new().unwrap();
common::write_flat_agent_session( root.path(), "proj-delta", "jkl012", "parent-sess", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "agent::1" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_7_agent_0_auto_enables_sessions_display()
{
let root = TempDir::new().unwrap();
common::write_test_session( root.path(), "proj-epsilon", "main-sess", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "agent::0" )
.output()
.unwrap();
assert_exit( &out, 0 );
}