88
99const callGateway = vi . hoisted ( ( ) => vi . fn ( ) ) ;
1010const isGatewayCredentialsRequiredError = vi . hoisted ( ( ) => vi . fn ( ( ) => false ) ) ;
11+ const isGatewaySecretRefUnavailableError = vi . hoisted ( ( ) => vi . fn ( ( ) => false ) ) ;
1112const probeGatewayStatus = vi . hoisted ( ( ) => vi . fn ( ) ) ;
1213const note = vi . hoisted ( ( ) => vi . fn ( ) ) ;
1314const TEST_GATEWAY_URL = "ws://127.0.0.1:18789" ;
@@ -28,6 +29,10 @@ vi.mock("../gateway/call.js", () => ({
2829 isGatewayCredentialsRequiredError,
2930} ) ) ;
3031
32+ vi . mock ( "../gateway/credentials.js" , ( ) => ( {
33+ isGatewaySecretRefUnavailableError,
34+ } ) ) ;
35+
3136vi . mock ( "../cli/daemon-cli/probe.js" , ( ) => ( {
3237 probeGatewayStatus,
3338} ) ) ;
@@ -49,6 +54,8 @@ describe("checkGatewayHealth", () => {
4954 callGateway . mockReset ( ) ;
5055 isGatewayCredentialsRequiredError . mockReset ( ) ;
5156 isGatewayCredentialsRequiredError . mockReturnValue ( false ) ;
57+ isGatewaySecretRefUnavailableError . mockReset ( ) ;
58+ isGatewaySecretRefUnavailableError . mockReturnValue ( false ) ;
5259 probeGatewayStatus . mockReset ( ) ;
5360 note . mockReset ( ) ;
5461 } ) ;
@@ -143,6 +150,38 @@ describe("checkGatewayHealth", () => {
143150 ) ;
144151 expect ( callGateway ) . toHaveBeenCalledTimes ( 1 ) ;
145152 } ) ;
153+
154+ it ( "reports credentials-required when status RPC auth SecretRefs are unavailable" , async ( ) => {
155+ const error = new Error ( "gateway.auth.password unavailable" ) ;
156+ callGateway . mockRejectedValueOnce ( error ) ;
157+ isGatewaySecretRefUnavailableError . mockReturnValueOnce ( true ) ;
158+ probeGatewayStatus . mockResolvedValueOnce ( {
159+ ok : false ,
160+ kind : "connect" ,
161+ error : TEST_AUTH_CLOSE_ERROR ,
162+ } ) ;
163+ const runtime = { log : vi . fn ( ) , error : vi . fn ( ) , exit : vi . fn ( ) } ;
164+
165+ await expect (
166+ checkGatewayHealth ( { runtime : runtime as never , cfg, timeoutMs : 3000 } ) ,
167+ ) . resolves . toEqual ( { authenticated : false , healthOk : true } ) ;
168+
169+ expect ( isGatewaySecretRefUnavailableError ) . toHaveBeenCalledWith ( error ) ;
170+ expect ( probeGatewayStatus ) . toHaveBeenCalledWith ( {
171+ url : TEST_GATEWAY_URL ,
172+ timeoutMs : 3000 ,
173+ tlsFingerprint : TEST_TLS_FINGERPRINT ,
174+ preauthHandshakeTimeoutMs : 4321 ,
175+ config : cfg ,
176+ json : true ,
177+ } ) ;
178+ expect ( runtime . error ) . not . toHaveBeenCalled ( ) ;
179+ expect ( note ) . toHaveBeenCalledWith (
180+ GATEWAY_HEALTH_CREDENTIALS_REQUIRED_MESSAGE ,
181+ GATEWAY_HEALTH_CREDENTIALS_REQUIRED_TITLE ,
182+ ) ;
183+ expect ( callGateway ) . toHaveBeenCalledTimes ( 1 ) ;
184+ } ) ;
146185} ) ;
147186
148187describe ( "probeGatewayMemoryStatus" , ( ) => {
0 commit comments