@@ -1077,7 +1077,7 @@ pub(super) fn aggregate_rows(
10771077mod tests {
10781078 use super :: * ;
10791079 use ccusage_cli:: NamedPiStore ;
1080- use ccusage_test_support:: { EnvVarGuard , EnvVarsGuard , fs_fixture} ;
1080+ use ccusage_test_support:: { EnvVarsGuard , fs_fixture} ;
10811081
10821082 fn usage_summary ( date : & str , input_tokens : u64 ) -> UsageSummary {
10831083 UsageSummary {
@@ -1110,10 +1110,23 @@ mod tests {
11101110 }
11111111
11121112 fn isolated_source_environment ( fixture : & ccusage_test_support:: Fixture ) -> EnvVarsGuard {
1113+ isolated_source_environment_with_pi_agent_dir ( fixture, "pi/sessions" )
1114+ }
1115+
1116+ fn isolated_source_environment_with_pi_agent_dir (
1117+ fixture : & ccusage_test_support:: Fixture ,
1118+ pi_agent_dir : & str ,
1119+ ) -> EnvVarsGuard {
11131120 let _ = fixture. create_dir_all ( "claude-config/projects" ) ;
11141121 let _ = fixture. create_dir_all ( "pi/sessions" ) ;
1122+ let _ = fixture. create_dir_all ( "empty-xdg-config" ) ;
1123+ let _ = fixture. create_dir_all ( "empty-xdg-data" ) ;
11151124 EnvVarsGuard :: set_many ( [
11161125 ( "HOME" , Some ( fixture. root ( ) . as_os_str ( ) . to_os_string ( ) ) ) ,
1126+ (
1127+ "USERPROFILE" ,
1128+ Some ( fixture. path ( "empty-userprofile" ) . into_os_string ( ) ) ,
1129+ ) ,
11171130 (
11181131 "CLAUDE_CONFIG_DIR" ,
11191132 Some ( fixture. path ( "claude-config" ) . into_os_string ( ) ) ,
@@ -1122,14 +1135,37 @@ mod tests {
11221135 "CODEX_HOME" ,
11231136 Some ( fixture. path ( "codex-home" ) . into_os_string ( ) ) ,
11241137 ) ,
1138+ ( "OPENCODE_DATA_DIR" , None ) ,
1139+ ( "AMP_DATA_DIR" , None ) ,
1140+ ( "DROID_SESSIONS_DIR" , None ) ,
1141+ ( "CODEBUFF_DATA_DIR" , None ) ,
1142+ ( "HERMES_HOME" , None ) ,
11251143 (
11261144 "PI_AGENT_DIR" ,
1127- Some ( fixture. path ( "pi/sessions" ) . into_os_string ( ) ) ,
1145+ Some ( fixture. path ( pi_agent_dir ) . into_os_string ( ) ) ,
11281146 ) ,
1147+ ( "GOOSE_PATH_ROOT" , None ) ,
11291148 (
11301149 "OPENCLAW_DIR" ,
11311150 Some ( fixture. path ( "openclaw-home" ) . into_os_string ( ) ) ,
11321151 ) ,
1152+ ( "KILO_DATA_DIR" , None ) ,
1153+ ( "COPILOT_OTEL_FILE_EXPORTER_PATH" , None ) ,
1154+ ( "COPILOT_HOME" , None ) ,
1155+ ( "GEMINI_DATA_DIR" , None ) ,
1156+ ( "KIMI_DATA_DIR" , None ) ,
1157+ ( "QWEN_DATA_DIR" , None ) ,
1158+ ( "GROK_HOME" , None ) ,
1159+ ( "ZCODE_HOME" , None ) ,
1160+ ( "ANTIGRAVITY_DATA_DIR" , None ) ,
1161+ (
1162+ "XDG_CONFIG_HOME" ,
1163+ Some ( fixture. path ( "empty-xdg-config" ) . into_os_string ( ) ) ,
1164+ ) ,
1165+ (
1166+ "XDG_DATA_HOME" ,
1167+ Some ( fixture. path ( "empty-xdg-data" ) . into_os_string ( ) ) ,
1168+ ) ,
11331169 ] )
11341170 }
11351171
@@ -1423,7 +1459,7 @@ mod tests {
14231459 "omp/sessions/project-a/agent_inside-session.jsonl" : r#"{"type":"message","timestamp":"2026-07-04T18:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":10,"output":1}}}"# ,
14241460 "omp/sessions/project-a/agent_outside-session.jsonl" : r#"{"type":"message","timestamp":"2026-07-05T18:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":20,"output":2}}}"# ,
14251461 } ) ;
1426- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture . path ( "empty-default" ) ) ;
1462+ let _environment = isolated_source_environment_with_pi_agent_dir ( & fixture , "empty-default" ) ;
14271463 let store_path = fixture. path ( "omp/sessions" ) . to_string_lossy ( ) . into_owned ( ) ;
14281464 let shared = SharedArgs {
14291465 json : true ,
@@ -1507,7 +1543,7 @@ mod tests {
15071543 "pi/sessions/project-a/agent_until-day.jsonl" : r#"{"type":"message","timestamp":"2026-07-04T18:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":10,"output":1}}}"# ,
15081544 "pi/sessions/project-a/agent_after-day.jsonl" : r#"{"type":"message","timestamp":"2026-07-05T18:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":20,"output":2}}}"# ,
15091545 } ) ;
1510- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture . path ( "pi/sessions" ) ) ;
1546+ let _environment = isolated_source_environment_with_pi_agent_dir ( & fixture , "pi/sessions" ) ;
15111547 let shared = SharedArgs {
15121548 json : true ,
15131549 mode : crate :: cli:: CostMode :: Display ,
@@ -1669,7 +1705,8 @@ mod tests {
16691705 let fixture = fs_fixture ! ( {
16701706 ".pi/agent/sessions/project-a/agent_pi-session.jsonl" : r#"{"type":"message","timestamp":"2099-01-02T00:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":10,"output":20}}}"# ,
16711707 } ) ;
1672- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture. path ( ".pi/agent/sessions" ) ) ;
1708+ let _environment =
1709+ isolated_source_environment_with_pi_agent_dir ( & fixture, ".pi/agent/sessions" ) ;
16731710 let shared = SharedArgs {
16741711 json : true ,
16751712 mode : crate :: cli:: CostMode :: Display ,
@@ -1706,7 +1743,7 @@ mod tests {
17061743 let fixture = fs_fixture ! ( {
17071744 "shared/sessions/project-a/agent_pi-session.jsonl" : r#"{"type":"message","timestamp":"2099-01-02T00:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":10,"output":20}}}"# ,
17081745 } ) ;
1709- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture . path ( "empty-default" ) ) ;
1746+ let _environment = isolated_source_environment_with_pi_agent_dir ( & fixture , "empty-default" ) ;
17101747 let path = fixture
17111748 . path ( "shared/sessions" )
17121749 . to_string_lossy ( )
@@ -1749,7 +1786,8 @@ mod tests {
17491786 let fixture = fs_fixture ! ( {
17501787 ".pi/agent/sessions/project-a/agent_pi-session.jsonl" : r#"{"type":"message","timestamp":"2099-01-02T00:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":10,"output":20}}}"# ,
17511788 } ) ;
1752- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture. path ( ".pi/agent/sessions" ) ) ;
1789+ let _environment =
1790+ isolated_source_environment_with_pi_agent_dir ( & fixture, ".pi/agent/sessions" ) ;
17531791 let shared = SharedArgs {
17541792 json : true ,
17551793 mode : crate :: cli:: CostMode :: Display ,
@@ -1786,7 +1824,7 @@ mod tests {
17861824 let fixture = fs_fixture ! ( {
17871825 "shared/sessions/project-a/agent_pi-session.jsonl" : r#"{"type":"message","timestamp":"2099-01-02T00:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":10,"output":20}}}"# ,
17881826 } ) ;
1789- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture . path ( "empty-default" ) ) ;
1827+ let _environment = isolated_source_environment_with_pi_agent_dir ( & fixture , "empty-default" ) ;
17901828 let shared_path = fixture
17911829 . path ( "shared/sessions" )
17921830 . to_string_lossy ( )
@@ -1830,7 +1868,7 @@ mod tests {
18301868 let fixture = fs_fixture ! ( {
18311869 "omp/sessions/project-a/agent_omp-session.jsonl" : r#"{"type":"message","timestamp":"2099-01-02T00:00:00.000Z","message":{"role":"assistant","model":"gpt-5","usage":{"input":30,"output":40}}}"# ,
18321870 } ) ;
1833- let _pi_agent_dir = EnvVarGuard :: set ( "PI_AGENT_DIR" , fixture . path ( "empty-default" ) ) ;
1871+ let _environment = isolated_source_environment_with_pi_agent_dir ( & fixture , "empty-default" ) ;
18341872 let shared = SharedArgs {
18351873 json : true ,
18361874 mode : crate :: cli:: CostMode :: Display ,
0 commit comments