@@ -366,40 +366,12 @@ test('connect without remote config rejects legacy remoteConfig string profile r
366366 }
367367} ) ;
368368
369- test ( 'connect without remote config reports cloud profile authorization failures' , async ( ) => {
370- const tempRoot = mkdtempForTestSync ( 'agent-device-connect-cloud-denied-' ) ;
371- const stateDir = path . join ( tempRoot , '.state' ) ;
372- mockedResolveCloudAccessForConnect . mockResolvedValue ( {
373- accessToken : 'adc_agent_cloud' ,
374- cloudBaseUrl : 'https://cloud.example' ,
375- } ) ;
376- vi . stubGlobal (
377- 'fetch' ,
378- vi . fn (
379- async ( ) =>
380- new Response ( JSON . stringify ( { error : 'forbidden' } ) , {
381- status : 403 ,
382- headers : { 'content-type' : 'application/json' } ,
383- } ) ,
384- ) ,
385- ) ;
386-
387- try {
388- await assert . rejects ( connectWithGeneratedCloudProfile ( stateDir ) , ( error : unknown ) => {
389- assert . equal ( ( error as { code ?: string } ) . code , 'UNAUTHORIZED' ) ;
390- assert . match (
391- ( error as Error ) . message ,
392- / C l o u d c o n n e c t i o n p r o f i l e e n d p o i n t r e j e c t e d t h e r e q u e s t / ,
393- ) ;
394- return true ;
395- } ) ;
396- } finally {
397- fs . rmSync ( tempRoot , { recursive : true , force : true } ) ;
398- }
399- } ) ;
400-
401- for ( const status of [ 429 , 503 ] ) {
402- test ( `connect without remote config propagates cloud profile ${ status } failures` , async ( ) => {
369+ for ( const [ status , code ] of [
370+ [ 403 , 'UNAUTHORIZED' ] ,
371+ [ 429 , 'COMMAND_FAILED' ] ,
372+ [ 503 , 'COMMAND_FAILED' ] ,
373+ ] as const ) {
374+ test ( `connect without remote config preserves cloud profile ${ status } failures` , async ( ) => {
403375 const tempRoot = mkdtempForTestSync ( `agent-device-connect-cloud-${ status } -` ) ;
404376 const stateDir = path . join ( tempRoot , '.state' ) ;
405377 mockedResolveCloudAccessForConnect . mockResolvedValue ( {
@@ -408,14 +380,16 @@ for (const status of [429, 503]) {
408380 } ) ;
409381 vi . stubGlobal (
410382 'fetch' ,
411- vi . fn ( async ( ) => new Response ( '{"error":" secret"} ' , { status } ) ) ,
383+ vi . fn ( async ( ) => new Response ( '<html>private-body- secret</html> ' , { status } ) ) ,
412384 ) ;
413385 try {
414386 await assert . rejects ( connectWithGeneratedCloudProfile ( stateDir ) , ( error : unknown ) => {
415387 const normalized = normalizeError ( error ) ;
416- assert . equal ( normalized . code , 'COMMAND_FAILED' ) ;
388+ assert . equal ( normalized . code , code ) ;
417389 assert . equal ( normalized . details ?. status , status ) ;
418- assert . equal ( normalized . retriable , true ) ;
390+ if ( code === 'COMMAND_FAILED' ) assert . equal ( normalized . retriable , true ) ;
391+ assert . match ( normalized . message , / C l o u d c o n n e c t i o n p r o f i l e e n d p o i n t r e j e c t e d t h e r e q u e s t / ) ;
392+ assert . doesNotMatch ( JSON . stringify ( normalized ) , / p r i v a t e - b o d y - s e c r e t / ) ;
419393 return true ;
420394 } ) ;
421395 assert . equal ( readActiveConnectionState ( { stateDir } ) , null ) ;
0 commit comments