@@ -13,7 +13,7 @@ import {
1313} from '@agent-device/remote/remote-connection-state' ;
1414import type { AgentDeviceClient } from '@agent-device/command-surface' ;
1515import { resolveConnectProviderProfile } from '../cli/connection/connect-provider-adapters.ts' ;
16- import { AppError } from '@agent-device/kernel/errors' ;
16+ import { AppError , normalizeError } from '@agent-device/kernel/errors' ;
1717import { verifyLimrunConnection } from '@agent-device/provider-limrun' ;
1818import {
1919 verifyAwsDeviceFarmConnection ,
@@ -398,6 +398,34 @@ test('connect without remote config reports cloud profile authorization failures
398398 }
399399} ) ;
400400
401+ for ( const status of [ 429 , 503 ] ) {
402+ test ( `connect without remote config propagates cloud profile ${ status } failures` , async ( ) => {
403+ const tempRoot = mkdtempForTestSync ( `agent-device-connect-cloud-${ status } -` ) ;
404+ const stateDir = path . join ( tempRoot , '.state' ) ;
405+ mockedResolveCloudAccessForConnect . mockResolvedValue ( {
406+ accessToken : 'adc_agent_cloud' ,
407+ cloudBaseUrl : 'https://cloud.example' ,
408+ } ) ;
409+ vi . stubGlobal (
410+ 'fetch' ,
411+ vi . fn ( async ( ) => new Response ( '{"error":"secret"}' , { status } ) ) ,
412+ ) ;
413+ try {
414+ await assert . rejects ( connectWithGeneratedCloudProfile ( stateDir ) , ( error : unknown ) => {
415+ const normalized = normalizeError ( error ) ;
416+ assert . equal ( normalized . code , 'COMMAND_FAILED' ) ;
417+ assert . equal ( normalized . details ?. status , status ) ;
418+ assert . equal ( normalized . retriable , true ) ;
419+ return true ;
420+ } ) ;
421+ assert . equal ( readActiveConnectionState ( { stateDir } ) , null ) ;
422+ assert . equal ( fs . existsSync ( path . join ( stateDir , 'remote-connections' ) ) , false ) ;
423+ } finally {
424+ fs . rmSync ( tempRoot , { recursive : true , force : true } ) ;
425+ }
426+ } ) ;
427+ }
428+
401429test ( 'connect without remote config reports unsupported cloud profile keys' , async ( ) => {
402430 const tempRoot = mkdtempForTestSync ( 'agent-device-connect-cloud-invalid-' ) ;
403431 const stateDir = path . join ( tempRoot , '.state' ) ;
0 commit comments