1- import { describe , expect , test } from 'bun:test' ;
1+ import { homedir } from 'node:os' ;
2+ import { join } from 'node:path' ;
3+ import process from 'node:process' ;
4+ import { afterEach , beforeEach , describe , expect , test } from 'bun:test' ;
25import { createFixture } from 'fs-fixture' ;
36import {
47 calculateCostForEntry ,
58 formatDate ,
9+ getDefaultClaudePath ,
610 loadDailyUsageData ,
711 loadMonthlyUsageData ,
812 loadSessionData ,
@@ -29,6 +33,74 @@ describe('formatDate', () => {
2933 } ) ;
3034} ) ;
3135
36+ describe ( 'getDefaultClaudePath' , ( ) => {
37+ const originalEnv = process . env . CLAUDE_CONFIG_DIR ;
38+
39+ beforeEach ( ( ) => {
40+ // Clean up env var before each test
41+ delete process . env . CLAUDE_CONFIG_DIR ;
42+ } ) ;
43+
44+ afterEach ( ( ) => {
45+ // Restore original environment
46+ if ( originalEnv != null ) {
47+ process . env . CLAUDE_CONFIG_DIR = originalEnv ;
48+ }
49+ else {
50+ delete process . env . CLAUDE_CONFIG_DIR ;
51+ }
52+ } ) ;
53+
54+ test ( 'returns CLAUDE_CONFIG_DIR when environment variable is set' , async ( ) => {
55+ await using fixture = await createFixture ( {
56+ claude : { } ,
57+ } ) ;
58+ process . env . CLAUDE_CONFIG_DIR = fixture . path ;
59+
60+ expect ( getDefaultClaudePath ( ) ) . toBe ( fixture . path ) ;
61+ } ) ;
62+
63+ test ( 'returns default path when CLAUDE_CONFIG_DIR is not set' , ( ) => {
64+ // Ensure CLAUDE_CONFIG_DIR is not set
65+ delete process . env . CLAUDE_CONFIG_DIR ;
66+
67+ // Test that it returns the default path (which ends with .claude)
68+ const actualPath = getDefaultClaudePath ( ) ;
69+ expect ( actualPath ) . toMatch ( / \. c l a u d e $ / ) ;
70+ expect ( actualPath ) . toContain ( homedir ( ) ) ;
71+ } ) ;
72+
73+ test ( 'returns default path with trimmed CLAUDE_CONFIG_DIR' , async ( ) => {
74+ await using fixture = await createFixture ( {
75+ claude : { } ,
76+ } ) ;
77+ // Test with extra spaces
78+ process . env . CLAUDE_CONFIG_DIR = ` ${ fixture . path } ` ;
79+
80+ expect ( getDefaultClaudePath ( ) ) . toBe ( fixture . path ) ;
81+ } ) ;
82+
83+ test ( 'throws an error when CLAUDE_CONFIG_DIR is not a directory' , async ( ) => {
84+ await using fixture = await createFixture ( ) ;
85+ process . env . CLAUDE_CONFIG_DIR = join ( fixture . path , 'not-a-directory' ) ;
86+
87+ expect ( ( ) => getDefaultClaudePath ( ) ) . toThrow ( / C l a u d e d a t a d i r e c t o r y d o e s n o t e x i s t / ) ;
88+ } ) ;
89+
90+ test ( 'throws an error when CLAUDE_CONFIG_DIR does not exist' , async ( ) => {
91+ process . env . CLAUDE_CONFIG_DIR = '/nonexistent/path/that/does/not/exist' ;
92+
93+ expect ( ( ) => getDefaultClaudePath ( ) ) . toThrow ( / C l a u d e d a t a d i r e c t o r y d o e s n o t e x i s t / ) ;
94+ } ) ;
95+
96+ test ( 'throws an error when default path does not exist' , ( ) => {
97+ // Set to a non-existent path
98+ process . env . CLAUDE_CONFIG_DIR = '/nonexistent/path/.claude' ;
99+
100+ expect ( ( ) => getDefaultClaudePath ( ) ) . toThrow ( / C l a u d e d a t a d i r e c t o r y d o e s n o t e x i s t / ) ;
101+ } ) ;
102+ } ) ;
103+
32104describe ( 'loadDailyUsageData' , ( ) => {
33105 test ( 'returns empty array when no files found' , async ( ) => {
34106 await using fixture = await createFixture ( {
0 commit comments