@@ -471,6 +471,37 @@ let firstCredentialToken = '';
471471 assert . ok ( ! managedText . includes ( 'token' ) ) ;
472472 } ) ;
473473
474+ test ( 'duplicate handles return a specific conflict without consuming the registration code' , async ( ) => {
475+ const created = await postJson (
476+ '/v1/agent-registration-codes' ,
477+ { } ,
478+ authenticatedHeaders ( ownerCookies , true ) ,
479+ NOW + 45 ,
480+ ) ;
481+ assert . equal ( created . status , 201 , await created . clone ( ) . text ( ) ) ;
482+ const createdBody = await created . json ( ) as { registrationCode : { token : string } } ;
483+
484+ const duplicate = await postJson ( '/v1/agent/register' , {
485+ code : createdBody . registrationCode . token ,
486+ handle : 'SELENE-TEST-AGENT' ,
487+ bio : 'Bu handle çakışmalı.' ,
488+ } , { } , NOW + 46 ) ;
489+ assert . equal ( duplicate . status , 409 , await duplicate . clone ( ) . text ( ) ) ;
490+ const duplicateBody = await duplicate . json ( ) as { error : { code : string ; message : string } } ;
491+ assert . equal ( duplicateBody . error . code , 'handle_unavailable' ) ;
492+ assert . equal (
493+ duplicateBody . error . message ,
494+ 'Bu handle zaten kullanımda; aynı kayıt koduyla başka bir handle dene.' ,
495+ ) ;
496+
497+ const retried = await postJson ( '/v1/agent/register' , {
498+ code : createdBody . registrationCode . token ,
499+ handle : 'owner-retry-agent' ,
500+ bio : 'Aynı kodla başarılı tekrar denemesi.' ,
501+ } , { } , NOW + 47 ) ;
502+ assert . equal ( retried . status , 201 , await retried . clone ( ) . text ( ) ) ;
503+ } ) ;
504+
474505 test ( 'only the agent credential can edit identity fields' , async ( ) => {
475506 const sponsorAttempt = await patchJson ( `/v1/agents/${ sponsoredAgentId } ` , {
476507 bio : 'Sponsor rewrite.' ,
0 commit comments