@@ -37,23 +37,24 @@ function writeOnboardConfig(home: string): void {
3737 ) ;
3838}
3939
40- function writeAuthProfileStoreSqlite ( agentDir : string , store : unknown ) : void {
41- fs . mkdirSync ( agentDir , { recursive : true } ) ;
42- const db = new DatabaseSync ( path . join ( agentDir , "openclaw-agent.sqlite" ) ) ;
40+ function writeSharedAuthProfileStoreSqlite ( home : string , store : unknown ) : void {
41+ const stateDir = path . join ( home , ".openclaw" , "state" ) ;
42+ fs . mkdirSync ( stateDir , { recursive : true } ) ;
43+ const db = new DatabaseSync ( path . join ( stateDir , "openclaw.sqlite" ) ) ;
4344 try {
4445 db . exec ( `
45- CREATE TABLE IF NOT EXISTS auth_profile_store (
46+ CREATE TABLE IF NOT EXISTS auth_profile_stores (
4647 store_key TEXT NOT NULL PRIMARY KEY,
4748 store_json TEXT NOT NULL,
4849 updated_at INTEGER NOT NULL
4950 );
5051 ` ) ;
5152 db . prepare (
5253 `
53- INSERT INTO auth_profile_store (store_key, store_json, updated_at)
54+ INSERT INTO auth_profile_stores (store_key, store_json, updated_at)
5455 VALUES (?, ?, ?)
5556 ` ,
56- ) . run ( "primary " , JSON . stringify ( store ) , Date . now ( ) ) ;
57+ ) . run ( "shared " , JSON . stringify ( store ) , Date . now ( ) ) ;
5758 } finally {
5859 db . close ( ) ;
5960 }
@@ -217,13 +218,13 @@ describe("npm onboard channel agent assertions", () => {
217218 }
218219 } ) ;
219220
220- it ( "validates OpenAI env refs from the SQLite auth profile store" , ( ) => {
221+ it ( "validates OpenAI env refs from the shared SQLite auth profile store" , ( ) => {
221222 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-onboard-assertions-" ) ) ;
222223 const agentDir = path . join ( tempDir , ".openclaw" , "agents" , "main" , "agent" ) ;
223224
224225 try {
225226 writeOnboardConfig ( tempDir ) ;
226- writeAuthProfileStoreSqlite ( agentDir , {
227+ writeSharedAuthProfileStoreSqlite ( tempDir , {
227228 version : 1 ,
228229 profiles : {
229230 "openai:api-key" : {
@@ -238,6 +239,7 @@ describe("npm onboard channel agent assertions", () => {
238239
239240 expect ( result . status ) . toBe ( 0 ) ;
240241 expect ( result . stderr ) . toBe ( "" ) ;
242+ expect ( fs . existsSync ( agentDir ) ) . toBe ( false ) ;
241243 expect ( fs . existsSync ( path . join ( agentDir , "auth-profiles.json" ) ) ) . toBe ( false ) ;
242244 } finally {
243245 fs . rmSync ( tempDir , { force : true , recursive : true } ) ;
@@ -257,11 +259,10 @@ describe("npm onboard channel agent assertions", () => {
257259
258260 for ( const store of cases ) {
259261 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-onboard-assertions-" ) ) ;
260- const agentDir = path . join ( tempDir , ".openclaw" , "agents" , "main" , "agent" ) ;
261262
262263 try {
263264 writeOnboardConfig ( tempDir ) ;
264- writeAuthProfileStoreSqlite ( agentDir , store ) ;
265+ writeSharedAuthProfileStoreSqlite ( tempDir , store ) ;
265266
266267 const result = runOnboardAssert ( tempDir ) ;
267268
@@ -275,11 +276,9 @@ describe("npm onboard channel agent assertions", () => {
275276
276277 it ( "rejects inline OpenAI keys in the SQLite auth profile store" , ( ) => {
277278 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-onboard-assertions-" ) ) ;
278- const agentDir = path . join ( tempDir , ".openclaw" , "agents" , "main" , "agent" ) ;
279-
280279 try {
281280 writeOnboardConfig ( tempDir ) ;
282- writeAuthProfileStoreSqlite ( agentDir , {
281+ writeSharedAuthProfileStoreSqlite ( tempDir , {
283282 version : 1 ,
284283 profiles : {
285284 "openai:api-key" : {
@@ -299,6 +298,34 @@ describe("npm onboard channel agent assertions", () => {
299298 }
300299 } ) ;
301300
301+ it ( "rejects a fresh install that recreates the retired main-agent auth database" , ( ) => {
302+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-onboard-assertions-" ) ) ;
303+ const legacyAgentDir = path . join ( tempDir , ".openclaw" , "agents" , "main" , "agent" ) ;
304+
305+ try {
306+ writeOnboardConfig ( tempDir ) ;
307+ writeSharedAuthProfileStoreSqlite ( tempDir , {
308+ version : 1 ,
309+ profiles : {
310+ "openai:api-key" : {
311+ type : "api_key" ,
312+ provider : "openai" ,
313+ keyRef : { source : "env" , provider : "default" , id : "OPENAI_API_KEY" } ,
314+ } ,
315+ } ,
316+ } ) ;
317+ fs . mkdirSync ( legacyAgentDir , { recursive : true } ) ;
318+ new DatabaseSync ( path . join ( legacyAgentDir , "openclaw-agent.sqlite" ) ) . close ( ) ;
319+
320+ const result = runOnboardAssert ( tempDir ) ;
321+
322+ expect ( result . status ) . not . toBe ( 0 ) ;
323+ expect ( result . stderr ) . toContain ( "onboard created the retired main-agent auth database" ) ;
324+ } finally {
325+ fs . rmSync ( tempDir , { force : true , recursive : true } ) ;
326+ }
327+ } ) ;
328+
302329 it ( "validates channel tokens in their canonical config fields" , ( ) => {
303330 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-channel-assertions-" ) ) ;
304331 try {
0 commit comments