@@ -231,6 +231,47 @@ describe("accounts edge branches", () => {
231231 expect ( mockSaveAccounts ) . not . toHaveBeenCalled ( ) ;
232232 } ) ;
233233
234+ it ( "hydrates a missing local refresh token from an expired CLI cache entry" , async ( ) => {
235+ const now = Date . now ( ) ;
236+ const stored = buildStored ( [
237+ buildStoredAccount ( {
238+ refreshToken : "local-refresh-placeholder" ,
239+ email : "expired@example.com" ,
240+ accessToken : "local-access" ,
241+ expiresAt : now + 120_000 ,
242+ } ) ,
243+ ] ) ;
244+
245+ const { AccountManager } = await importAccountsModule ( ) ;
246+ const manager = new AccountManager ( undefined , stored as never ) ;
247+ const account = manager . getAccountByIndex ( 0 ) ! ;
248+ account . refreshToken = "" ;
249+
250+ mockLoadCodexCliState . mockResolvedValue ( {
251+ sourceUpdatedAtMs : now - 60_000 ,
252+ accounts : [
253+ {
254+ email : "expired@example.com" ,
255+ accessToken : "cached-access-old" ,
256+ expiresAt : now - 1 ,
257+ refreshToken : "cached-refresh-restored" ,
258+ accountId : "expired-account-id" ,
259+ } ,
260+ ] ,
261+ } ) ;
262+
263+ const hydrate = getPrivate < ( ) => Promise < void > > (
264+ manager as object ,
265+ "hydrateFromCodexCli" ,
266+ ) ;
267+ await hydrate . call ( manager ) ;
268+
269+ const snapshot = manager . getAccountsSnapshot ( ) ;
270+ expect ( snapshot [ 0 ] ?. refreshToken ) . toBe ( "cached-refresh-restored" ) ;
271+ expect ( snapshot [ 0 ] ?. access ) . toBe ( "local-access" ) ;
272+ expect ( snapshot [ 0 ] ?. accountId ) . toBe ( "expired-account-id" ) ;
273+ } ) ;
274+
234275 it ( "returns early when Codex CLI state has no usable cache entries" , async ( ) => {
235276 const stored = buildStored ( [
236277 buildStoredAccount ( {
0 commit comments