@@ -77,6 +77,49 @@ describe("shared auth store relocation", () => {
7777 } ;
7878 }
7979
80+ async function createEmptyFixture ( createSourceDatabase : boolean ) {
81+ const stateDir = tempDirs . make ( "openclaw-shared-auth-empty-" ) ;
82+ vi . stubEnv ( "OPENCLAW_STATE_DIR" , stateDir ) ;
83+ vi . stubEnv ( "OPENCLAW_AGENT_DIR" , "" ) ;
84+ const env = { ...process . env , OPENCLAW_STATE_DIR : stateDir , OPENCLAW_AGENT_DIR : undefined } ;
85+ const [ paths , ownership , sqlite , migration ] = await Promise . all ( [
86+ import ( "../agents/auth-profiles/shared-main-dir.js" ) ,
87+ import ( "../agents/auth-profiles/path-resolve.js" ) ,
88+ import ( "../agents/auth-profiles/sqlite.js" ) ,
89+ import ( "./state-migrations.shared-auth-store.js" ) ,
90+ ] ) ;
91+ const mainAgentDir = paths . resolveSharedMainAuthAgentDir ( env ) ;
92+ const sourcePath = sqlite . resolveAuthProfileDatabasePath ( mainAgentDir ) ;
93+ if ( createSourceDatabase ) {
94+ sqlite . writePersistedAuthProfileStoreRaw ( { version : 1 , profiles : { } } , mainAgentDir ) ;
95+ sqlite . deletePersistedAuthProfileStoreRaw ( mainAgentDir ) ;
96+ }
97+ return { env, stateDir, sourcePath, ownership, migration } ;
98+ }
99+
100+ it . each ( [
101+ { label : "fresh profile" , createSourceDatabase : false } ,
102+ { label : "legacy profile with an empty source database" , createSourceDatabase : true } ,
103+ ] ) ( "records ownership without reporting relocation for a $label" , async ( testCase ) => {
104+ const fixture = await createEmptyFixture ( testCase . createSourceDatabase ) ;
105+ expect ( fs . existsSync ( fixture . sourcePath ) ) . toBe ( testCase . createSourceDatabase ) ;
106+
107+ const detected = fixture . migration . detectSharedAuthStoreMigration ( {
108+ stateDir : fixture . stateDir ,
109+ doctorOnlyStateMigrations : true ,
110+ } ) ;
111+ expect ( detected . hasLegacy ) . toBe ( true ) ;
112+ expect (
113+ await fixture . migration . migrateSharedAuthStore ( {
114+ detected,
115+ stateDir : fixture . stateDir ,
116+ } ) ,
117+ ) . toEqual ( { changes : [ ] , warnings : [ ] } ) ;
118+ expect ( fixture . ownership . resolveSharedAuthStoreOwnership ( fixture . env ) ) . toEqual ( {
119+ location : "state-db" ,
120+ } ) ;
121+ } ) ;
122+
80123 it ( "moves exact rows, preserves every effective agent store, and records receipts" , async ( ) => {
81124 const fixture = await createFixture ( ) ;
82125 const effectiveBytes = ( agentDir : string ) => {
0 commit comments