@@ -226,6 +226,37 @@ describe("codex doctor contract", () => {
226226 await fs . rm ( stateDir , { recursive : true , force : true } ) ;
227227 } ) ;
228228
229+ it ( "does not scan above stateDir when a session store sits at its parent" , async ( ) => {
230+ const outerDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-codex-doctor-outer-" ) ) ;
231+ const stateDir = path . join ( outerDir , "state" ) ;
232+ await fs . mkdir ( stateDir , { recursive : true } ) ;
233+ const strayDir = path . join ( outerDir , "unrelated" ) ;
234+ await fs . mkdir ( strayDir , { recursive : true } ) ;
235+ await fs . writeFile (
236+ path . join ( strayDir , "foreign.jsonl.codex-app-server.json" ) ,
237+ JSON . stringify ( { schemaVersion : 2 , threadId : "thread-foreign" } ) ,
238+ "utf8" ,
239+ ) ;
240+ const env = { ...process . env , OPENCLAW_STATE_DIR : stateDir } ;
241+ const params = {
242+ // The store dir is exactly the parent of stateDir; doctor must treat it
243+ // as an external store (indexed reads only), not a scannable state root.
244+ config : { session : { store : path . join ( outerDir , "sessions.json" ) } } ,
245+ env,
246+ stateDir,
247+ oauthDir : path . join ( stateDir , "oauth" ) ,
248+ context : createDoctorContext ( env ) ,
249+ } ;
250+ const migration = stateMigrations [ 0 ] ;
251+ if ( ! migration ) {
252+ throw new Error ( "missing Codex binding migration" ) ;
253+ }
254+
255+ await expect ( migration . detectLegacyState ( params ) ) . resolves . toBeNull ( ) ;
256+
257+ await fs . rm ( outerDir , { recursive : true , force : true } ) ;
258+ } ) ;
259+
229260 it ( "renames old approval-routed destructive plugin policy values" , ( ) => {
230261 const original = {
231262 plugins : {
0 commit comments