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_project_absolute_path_resolves()
{
let root = TempDir::new().unwrap();
let project_path = std::path::PathBuf::from( "/home/alice/projects/myproject" );
common::write_path_project_session( root.path(), &project_path, "sess-abc", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".show" )
.arg( "project::/home/alice/projects/myproject" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_2_project_encoded_id_resolves()
{
let root = TempDir::new().unwrap();
let project_path = std::path::PathBuf::from( "/home/alice/projects/myproject" );
let encoded = common::write_path_project_session( root.path(), &project_path, "sess-abc", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".show" )
.arg( format!( "project::{encoded}" ) )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_3_project_uuid_format_resolves()
{
let root = TempDir::new().unwrap();
let uuid = "8d795a1c-c81d-4010-8d29-b4e678272419";
common::write_test_session( root.path(), uuid, "sess-uuid", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".show" )
.arg( format!( "project::{uuid}" ) )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_4_project_path_form_resolves()
{
let root = TempDir::new().unwrap();
let project_path = std::path::PathBuf::from( "/home/alice/projects/myproject" );
common::write_path_project_session( root.path(), &project_path, "sess-abc", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".show" )
.arg( r#"project::Path("/home/alice/projects/myproject")"# )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_5_project_unknown_exits_with_error()
{
let root = TempDir::new().unwrap();
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".show" )
.arg( "project::nonexistent-project-zzz" )
.output()
.unwrap();
assert_exit( &out, 1 );
let combined = format!( "{}{}", stderr( &out ), stdout( &out ) );
assert!(
combined.contains( "project" ) && ( combined.contains( "not found" ) || combined.contains( "nonexistent" ) ),
"EC-5: error must mention 'project not found'; got: {combined}"
);
}
#[ test ]
fn ec_6_project_empty_rejected()
{
let out = common::clg_cmd()
.arg( ".show" )
.arg( "project::" )
.output()
.unwrap();
assert_exit( &out, 1 );
let combined = format!( "{}{}", stderr( &out ), stdout( &out ) );
assert!(
combined.contains( "project" ),
"EC-6: error must mention 'project'; got: {combined}"
);
}
#[ test ]
fn ec_7_project_default_resolves_to_cwd()
{
let root = TempDir::new().unwrap();
let project_dir = TempDir::new().unwrap();
common::write_path_project_session( root.path(), project_dir.path(), "sess", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.current_dir( project_dir.path() )
.arg( ".show" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_8_project_default_no_project_exits_2()
{
let root = TempDir::new().unwrap();
let empty_dir = TempDir::new().unwrap();
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.current_dir( empty_dir.path() )
.arg( ".show" )
.output()
.unwrap();
assert_exit( &out, 1 );
}