@@ -17,8 +17,11 @@ const assert = require('assert');
1717const tmpHome = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'caveman-userhome-' ) ) ;
1818process . env . XDG_CONFIG_HOME = tmpHome ;
1919delete process . env . CAVEMAN_DEFAULT_MODE ;
20+ const APPDATA_SEGMENT = / A p p D a t a / ;
21+ const CONFIG_FILE_NAME = 'config.json' ;
22+ const WINDOWS_PLATFORM = 'win32' ;
2023
21- const { getDefaultMode, findRepoConfigPath } = require ( '../src/hooks/caveman-config' ) ;
24+ const { getDefaultMode, findRepoConfigPath, getConfigPath } = require ( '../src/hooks/caveman-config' ) ;
2225
2326let passed = 0 ;
2427let failed = 0 ;
@@ -123,6 +126,33 @@ test('falls through to user config when repo config absent', (tmp) => {
123126 }
124127} ) ;
125128
129+ test ( 'win32 without APPDATA falls back to ~/.config/caveman/config.json' , ( tmp ) => {
130+ const origXdg = process . env . XDG_CONFIG_HOME ;
131+ const origAppData = process . env . APPDATA ;
132+ const origPlatform = Object . getOwnPropertyDescriptor ( process , 'platform' ) ;
133+ const origHomedir = os . homedir ;
134+ const posixConfigDir = path . join ( tmp , '.config' , 'caveman' ) ;
135+ try {
136+ delete process . env . XDG_CONFIG_HOME ;
137+ delete process . env . APPDATA ;
138+ Object . defineProperty ( process , 'platform' , { value : WINDOWS_PLATFORM } ) ;
139+ os . homedir = ( ) => tmp ;
140+ fs . mkdirSync ( posixConfigDir , { recursive : true } ) ;
141+ fs . writeFileSync ( path . join ( posixConfigDir , CONFIG_FILE_NAME ) ,
142+ JSON . stringify ( { defaultMode : 'lite' } ) ) ;
143+
144+ assert . match ( getConfigPath ( ) , APPDATA_SEGMENT ) ;
145+ assert . strictEqual ( getDefaultMode ( ) , 'lite' ) ;
146+ } finally {
147+ if ( origXdg === undefined ) delete process . env . XDG_CONFIG_HOME ;
148+ else process . env . XDG_CONFIG_HOME = origXdg ;
149+ if ( origAppData === undefined ) delete process . env . APPDATA ;
150+ else process . env . APPDATA = origAppData ;
151+ Object . defineProperty ( process , 'platform' , origPlatform ) ;
152+ os . homedir = origHomedir ;
153+ }
154+ } ) ;
155+
126156test ( 'invalid mode in repo config falls through to default' , ( tmp ) => {
127157 fs . writeFileSync ( path . join ( tmp , '.caveman.json' ) ,
128158 JSON . stringify ( { defaultMode : 'definitely-not-a-mode' } ) ) ;
0 commit comments