@@ -2,15 +2,8 @@ import crypto from "node:crypto";
22import fs from "node:fs/promises" ;
33import os from "node:os" ;
44import path from "node:path" ;
5- import { afterEach , beforeAll , describe , expect , it , vi } from "vitest" ;
6-
7- const mocks = vi . hoisted ( ( ) => ( {
8- ensureAuthProfileStore : vi . fn ( ) ,
9- } ) ) ;
10-
11- vi . mock ( "openclaw/plugin-sdk/provider-auth" , ( ) => ( {
12- ensureAuthProfileStore : mocks . ensureAuthProfileStore ,
13- } ) ) ;
5+ import { saveAuthProfileStore } from "openclaw/plugin-sdk/agent-runtime" ;
6+ import { afterEach , beforeAll , describe , expect , it } from "vitest" ;
147
158let bridgeCodexAppServerStartOptions : typeof import ( "./auth-bridge.js" ) . bridgeCodexAppServerStartOptions ;
169
@@ -29,7 +22,6 @@ describe("bridgeCodexAppServerStartOptions", () => {
2922 } ) ;
3023
3124 afterEach ( async ( ) => {
32- mocks . ensureAuthProfileStore . mockReset ( ) ;
3325 await Promise . all (
3426 tempDirs . splice ( 0 ) . map ( ( dir ) => fs . rm ( dir , { recursive : true , force : true } ) ) ,
3527 ) ;
@@ -38,19 +30,22 @@ describe("bridgeCodexAppServerStartOptions", () => {
3830 it ( "bridges canonical OpenClaw oauth into an isolated CODEX_HOME" , async ( ) => {
3931 const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-codex-app-server-" ) ) ;
4032 tempDirs . push ( agentDir ) ;
41- mocks . ensureAuthProfileStore . mockReturnValue ( {
42- version : 1 ,
43- profiles : {
44- "openai-codex:default" : {
45- type : "oauth" ,
46- provider : "openai-codex" ,
47- access : "access-token" ,
48- refresh : "refresh-token" ,
49- expires : Date . now ( ) + 60_000 ,
50- accountId : "acct-123" ,
33+ saveAuthProfileStore (
34+ {
35+ version : 1 ,
36+ profiles : {
37+ "openai-codex:default" : {
38+ type : "oauth" ,
39+ provider : "openai-codex" ,
40+ access : "access-token" ,
41+ refresh : "refresh-token" ,
42+ expires : Date . now ( ) + 60_000 ,
43+ accountId : "acct-123" ,
44+ } ,
5145 } ,
5246 } ,
53- } ) ;
47+ agentDir ,
48+ ) ;
5449
5550 const result = await bridgeCodexAppServerStartOptions ( {
5651 startOptions : {
@@ -98,10 +93,7 @@ describe("bridgeCodexAppServerStartOptions", () => {
9893 args : [ "app-server" ] ,
9994 headers : { authorization : "Bearer dev-token" } ,
10095 } ;
101- mocks . ensureAuthProfileStore . mockReturnValue ( {
102- version : 1 ,
103- profiles : { } ,
104- } ) ;
96+ saveAuthProfileStore ( { version : 1 , profiles : { } } , agentDir ) ;
10597
10698 await expect (
10799 bridgeCodexAppServerStartOptions ( {
@@ -115,18 +107,21 @@ describe("bridgeCodexAppServerStartOptions", () => {
115107 it ( "refuses to overwrite a symlinked auth bridge file" , async ( ) => {
116108 const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-codex-app-server-" ) ) ;
117109 tempDirs . push ( agentDir ) ;
118- mocks . ensureAuthProfileStore . mockReturnValue ( {
119- version : 1 ,
120- profiles : {
121- "openai-codex:default" : {
122- type : "oauth" ,
123- provider : "openai-codex" ,
124- access : "access-token" ,
125- refresh : "refresh-token" ,
126- expires : Date . now ( ) + 60_000 ,
110+ saveAuthProfileStore (
111+ {
112+ version : 1 ,
113+ profiles : {
114+ "openai-codex:default" : {
115+ type : "oauth" ,
116+ provider : "openai-codex" ,
117+ access : "access-token" ,
118+ refresh : "refresh-token" ,
119+ expires : Date . now ( ) + 60_000 ,
120+ } ,
127121 } ,
128122 } ,
129- } ) ;
123+ agentDir ,
124+ ) ;
130125
131126 const codexHome = resolveHashedCodexHome ( agentDir , "openai-codex:default" ) ;
132127 await fs . mkdir ( codexHome , { recursive : true } ) ;
0 commit comments