@@ -3,12 +3,22 @@ import { captureOutput } from "../testing";
33
44const mockLoadState = mock ( async ( ) => ( { } ) ) ;
55const mockSaveState = mock ( async ( _state : unknown ) => { } ) ;
6+ const mockLoadConfig = mock ( async ( ) => undefined as unknown ) ;
67
78mock . module ( "../state" , ( ) => ( {
89 loadState : mockLoadState ,
910 saveState : mockSaveState ,
1011} ) ) ;
1112
13+ mock . module ( "../config" , ( ) => ( {
14+ loadConfig : mockLoadConfig ,
15+ saveConfig : async ( ) => { } ,
16+ backupConfig : async ( ) => "" ,
17+ getConfigOrThrow : async ( ) => {
18+ throw new Error ( "No wallet configured." ) ;
19+ } ,
20+ } ) ) ;
21+
1222mock . module ( "node:child_process" , ( ) => ( {
1323 execSync : mock ( ( ) => { } ) ,
1424} ) ) ;
@@ -121,6 +131,7 @@ describe("checkAutoUpdate", () => {
121131 beforeEach ( ( ) => {
122132 mockLoadState . mockClear ( ) ;
123133 mockSaveState . mockClear ( ) ;
134+ mockLoadConfig . mockImplementation ( async ( ) => undefined ) ;
124135 fetchSpy = spyOn ( globalThis , "fetch" ) . mockResolvedValue ( {
125136 ok : true ,
126137 json : async ( ) => ( { version : "9.9.9" } ) ,
@@ -158,6 +169,23 @@ describe("checkAutoUpdate", () => {
158169 expect ( mockSaveState ) . toHaveBeenCalledTimes ( 1 ) ;
159170 } ) ;
160171
172+ test ( "skips when USE_AGENTLY_AUTO_UPDATE is 0 in config" , async ( ) => {
173+ mockLoadConfig . mockImplementation ( async ( ) => ( { env : { USE_AGENTLY_AUTO_UPDATE : 0 } } ) ) ;
174+
175+ await checkAutoUpdate ( ) ;
176+
177+ expect ( mockSaveState ) . not . toHaveBeenCalled ( ) ;
178+ expect ( fetchSpy ) . not . toHaveBeenCalled ( ) ;
179+ } ) ;
180+
181+ test ( "runs when USE_AGENTLY_AUTO_UPDATE is 1 in config" , async ( ) => {
182+ mockLoadConfig . mockImplementation ( async ( ) => ( { env : { USE_AGENTLY_AUTO_UPDATE : 1 } } ) ) ;
183+
184+ await checkAutoUpdate ( ) ;
185+
186+ expect ( mockSaveState ) . toHaveBeenCalledTimes ( 1 ) ;
187+ } ) ;
188+
161189 test ( "silently swallows errors" , async ( ) => {
162190 fetchSpy . mockResolvedValue ( { ok : false , status : 500 } as Response ) ;
163191 mockLoadState . mockImplementation ( async ( ) => ( { } ) ) ;
0 commit comments