@@ -195,6 +195,46 @@ describe("config io write", () => {
195195 } ,
196196 ) ;
197197
198+ it ( "keeps writes inside an OPENCLAW_STATE_DIR override even when the real home config exists" , async ( ) => {
199+ await withSuiteHome ( async ( home ) => {
200+ const liveConfigPath = path . join ( home , ".openclaw" , "openclaw.json" ) ;
201+ await fs . mkdir ( path . dirname ( liveConfigPath ) , { recursive : true } ) ;
202+ await fs . writeFile (
203+ liveConfigPath ,
204+ `${ JSON . stringify ( { gateway : { mode : "local" , port : 18789 } } , null , 2 ) } \n` ,
205+ "utf-8" ,
206+ ) ;
207+
208+ const overrideDir = path . join ( home , "isolated-state" ) ;
209+ const env = { OPENCLAW_STATE_DIR : overrideDir } as NodeJS . ProcessEnv ;
210+ const io = createConfigIO ( {
211+ env,
212+ homedir : ( ) => home ,
213+ logger : silentLogger ,
214+ } ) ;
215+
216+ expect ( io . configPath ) . toBe ( path . join ( overrideDir , "openclaw.json" ) ) ;
217+
218+ await io . writeConfigFile ( {
219+ agents : { list : [ { id : "main" , default : true } ] } ,
220+ gateway : { mode : "local" } ,
221+ session : { mainKey : "main" , store : path . join ( overrideDir , "sessions.json" ) } ,
222+ } ) ;
223+
224+ const livePersisted = JSON . parse ( await fs . readFile ( liveConfigPath , "utf-8" ) ) as {
225+ gateway ?: { mode ?: unknown ; port ?: unknown } ;
226+ } ;
227+ expect ( livePersisted . gateway ) . toEqual ( { mode : "local" , port : 18789 } ) ;
228+
229+ const overridePersisted = JSON . parse (
230+ await fs . readFile ( path . join ( overrideDir , "openclaw.json" ) , "utf-8" ) ,
231+ ) as {
232+ session ?: { store ?: unknown } ;
233+ } ;
234+ expect ( overridePersisted . session ?. store ) . toBe ( path . join ( overrideDir , "sessions.json" ) ) ;
235+ } ) ;
236+ } ) ;
237+
198238 it ( 'shows actionable guidance for dmPolicy="open" without wildcard allowFrom' , async ( ) => {
199239 await withSuiteHome ( async ( home ) => {
200240 const io = createConfigIO ( {
0 commit comments