mod common;
use std::fs;
use tempfile::TempDir;
#[test]
fn test_status_default_path()
{
let storage = TempDir::new().expect( "create temp storage" );
common::write_test_session( storage.path(), "status-proj-alpha", "s001", 2 );
common::write_test_session( storage.path(), "status-proj-beta", "s001", 2 );
let output = common::clg_cmd()
.args( [ ".status" ] )
.env( "CLAUDE_STORAGE_ROOT", storage.path() )
.output()
.expect( "Failed to execute .status" );
let stderr = String::from_utf8_lossy( &output.stderr );
let stdout = String::from_utf8_lossy( &output.stdout );
let combined = format!( "{stderr}{stdout}" );
assert!(
output.status.success(),
"Should succeed with default path via CLAUDE_STORAGE_ROOT. Got: {combined}"
);
assert!(
combined.to_lowercase().contains( "project" ) ||
combined.to_lowercase().contains( "storage" ),
"Should show storage information. Got: {combined}"
);
}
#[test]
fn test_status_custom_path()
{
let temp_dir = TempDir::new().expect( "Failed to create temp dir" );
let storage_path = temp_dir.path();
let projects_dir = storage_path.join( "projects" );
fs::create_dir_all( &projects_dir ).expect( "Failed to create projects dir" );
let output = common::clg_cmd()
.args( [ ".status", &format!( "path::{}", storage_path.display() ) ] )
.current_dir( env!( "CARGO_MANIFEST_DIR" ) )
.output()
.expect( "Failed to execute command" );
let stderr = String::from_utf8_lossy( &output.stderr );
let stdout = String::from_utf8_lossy( &output.stdout );
let combined = format!( "{stderr}{stdout}" );
assert!(
output.status.success(),
"Should succeed with custom path. Got: {combined}"
);
assert!(
combined.contains( '0' ) && combined.to_lowercase().contains( "project" ),
"Should show 0 projects in empty storage. Got: {combined}"
);
}
#[test]
fn test_status_nonexistent_path()
{
let output = common::clg_cmd()
.args( [ ".status", "path::/nonexistent/path/12345" ] )
.current_dir( env!( "CARGO_MANIFEST_DIR" ) )
.output()
.expect( "Failed to execute command" );
let stderr = String::from_utf8_lossy( &output.stderr );
let stdout = String::from_utf8_lossy( &output.stdout );
let combined = format!( "{stderr}{stdout}" );
assert!(
output.status.success(),
"Should succeed with nonexistent path. Got: {combined}"
);
assert!(
combined.contains( '0' ) && combined.to_lowercase().contains( "project" ),
"Should show 0 projects for nonexistent path. Got: {combined}"
);
}
#[test]
fn test_status_empty_path()
{
let output = common::clg_cmd()
.args( [ ".status", "path::" ] )
.current_dir( env!( "CARGO_MANIFEST_DIR" ) )
.output()
.expect( "Failed to execute command" );
let stderr = String::from_utf8_lossy( &output.stderr );
let stdout = String::from_utf8_lossy( &output.stdout );
let combined = format!( "{stderr}{stdout}" );
assert!(
!output.status.success(),
"Should fail with empty path. Got: {combined}"
);
assert!(
combined.to_lowercase().contains( "path" ) ||
combined.to_lowercase().contains( "expected value" ),
"Error should mention path validation. Got: {combined}"
);
}
#[test]
fn test_status_path_dot_resolves_to_cwd()
{
let manifest_dir = env!( "CARGO_MANIFEST_DIR" );
let output = common::clg_cmd()
.args( [ ".status", "path::." ] )
.current_dir( manifest_dir )
.output()
.expect( "Failed to execute command" );
let stdout = String::from_utf8_lossy( &output.stdout );
let stderr = String::from_utf8_lossy( &output.stderr );
let combined = format!( "{stdout}{stderr}" );
let has_literal_dot = combined.contains( r#"Storage: ".""# );
assert!(
!has_literal_dot,
"Bug: path::. not resolved, shows literal '.' in Storage.\n\
Expected: Resolved absolute path\n\
Got: {combined}"
);
}
#[test]
fn test_status_path_tilde_resolves_to_home()
{
let manifest_dir = env!( "CARGO_MANIFEST_DIR" );
let output = common::clg_cmd()
.args( [ ".status", "path::~" ] )
.current_dir( manifest_dir )
.output()
.expect( "Failed to execute command" );
let stdout = String::from_utf8_lossy( &output.stdout );
let stderr = String::from_utf8_lossy( &output.stderr );
let combined = format!( "{stdout}{stderr}" );
let has_literal_tilde = combined.contains( r#"Storage: "~""# );
assert!(
!has_literal_tilde,
"Bug: path::~ not resolved, shows literal '~' in Storage.\n\
Expected: Resolved home directory path\n\
Got: {combined}"
);
}
#[test]
fn test_status_path_with_verbosity()
{
let temp_dir = TempDir::new().expect( "Failed to create temp dir" );
let storage_path = temp_dir.path();
let projects_dir = storage_path.join( "projects" );
fs::create_dir_all( &projects_dir ).expect( "Failed to create projects dir" );
let output = common::clg_cmd()
.args( [ ".status", &format!( "path::{}", storage_path.display() ), "verbosity::2" ] )
.current_dir( env!( "CARGO_MANIFEST_DIR" ) )
.output()
.expect( "Failed to execute command" );
let stderr = String::from_utf8_lossy( &output.stderr );
let stdout = String::from_utf8_lossy( &output.stdout );
let combined = format!( "{stderr}{stdout}" );
assert!(
output.status.success(),
"Should succeed with path and verbosity. Got: {combined}"
);
assert!(
combined.to_lowercase().contains( "project" ) ||
combined.to_lowercase().contains( "storage" ),
"Should show storage information. Got: {combined}"
);
}
#[test]
fn test_status_verbosity2_user_assistant_counts_bug_reproducer_issue_020()
{
let storage = TempDir::new().expect( "create temp dir" );
common::write_test_session( storage.path(), "status-test-proj", "sess-count-a", 4 );
let output = common::clg_cmd()
.args( [ ".status", "v::2" ] )
.env( "CLAUDE_STORAGE_ROOT", storage.path() )
.output()
.expect( "Failed to execute .status" );
let stderr = String::from_utf8_lossy( &output.stderr );
let stdout = String::from_utf8_lossy( &output.stdout );
let combined = format!( "{stderr}{stdout}" );
assert!(
output.status.success(),
".status v::2 should succeed. Got: {combined}"
);
assert!(
!combined.contains( "User: 0, Assistant: 0" ),
".status v::2 must report non-zero user/assistant counts. Got: {combined}"
);
assert!(
combined.contains( "User: 2" ),
".status v::2 must report User: 2. Got: {combined}"
);
assert!(
combined.contains( "Assistant: 2" ),
".status v::2 must report Assistant: 2. Got: {combined}"
);
}