@@ -778,3 +778,150 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
778778 } ) ,
779779 ) ;
780780} ) ;
781+
782+ const elicitationForm = {
783+ sessionId : "session-1" ,
784+ mode : "form" as const ,
785+ message : "Continue?" ,
786+ requestedSchema : {
787+ type : "object" as const ,
788+ properties : { choice : { type : "string" as const } } ,
789+ required : [ "choice" ] ,
790+ } ,
791+ } ;
792+ const decodeWireResponse = Schema . decodeEffect ( Schema . fromJsonString ( Schema . Unknown ) ) ;
793+ const decodeWireError = Schema . decodeEffect (
794+ Schema . fromJsonString ( Schema . Struct ( { error : Schema . Struct ( { code : Schema . Finite } ) } ) ) ,
795+ ) ;
796+
797+ it . effect . each ( [ "accept" , "decline" , "cancel" ] as const ) (
798+ "returns a flat %s action to the SDK and preserves the legacy response" ,
799+ ( action ) =>
800+ Effect . gen ( function * ( ) {
801+ for ( const method of [ "elicitation/create" , "session/elicitation" ] ) {
802+ const { stdio, input, output } = yield * makeInMemoryStdio ( ) ;
803+ const acp = yield * AcpClient . make ( stdio ) ;
804+ const answer = action === "accept" ? { action, content : { choice : "yes" } } : { action } ;
805+ const response = { action : answer , _meta : { trace : "fixture" } } ;
806+ yield * acp . handleElicitation ( ( request ) => {
807+ assert . deepEqual ( request , elicitationForm ) ;
808+ return Effect . succeed ( response ) ;
809+ } ) ;
810+ yield * Queue . offer (
811+ input ,
812+ yield * encodeJsonl ( jsonRpcRequest ( method , AcpSchema . ElicitationRequest ) , {
813+ jsonrpc : "2.0" ,
814+ id : 71 ,
815+ headers : [ ] ,
816+ method,
817+ params : elicitationForm ,
818+ } ) ,
819+ ) ;
820+ const received = yield * decodeWireResponse ( yield * Queue . take ( output ) ) ;
821+ assert . deepEqual ( received , {
822+ jsonrpc : "2.0" ,
823+ id : 71 ,
824+ result : method === "elicitation/create" ? { ...answer , _meta : response . _meta } : response ,
825+ } ) ;
826+ }
827+ } ) . pipe ( Effect . scoped ) ,
828+ ) ;
829+
830+ it . effect ( "dispatches SDK URL elicitation to the same registered handler" , ( ) =>
831+ Effect . gen ( function * ( ) {
832+ const { stdio, input, output } = yield * makeInMemoryStdio ( ) ;
833+ const acp = yield * AcpClient . make ( stdio ) ;
834+ const params = {
835+ sessionId : "session-1" ,
836+ mode : "url" as const ,
837+ message : "Sign in" ,
838+ elicitationId : "elicitation-1" ,
839+ url : "https://example.test/sign-in" ,
840+ } ;
841+ yield * acp . handleElicitation ( ( request ) => {
842+ assert . deepEqual ( request , params ) ;
843+ return Effect . succeed ( { action : { action : "accept" as const } } ) ;
844+ } ) ;
845+ yield * Queue . offer (
846+ input ,
847+ yield * encodeJsonl ( jsonRpcRequest ( "elicitation/create" , AcpSchema . ElicitationRequest ) , {
848+ jsonrpc : "2.0" ,
849+ id : 72 ,
850+ headers : [ ] ,
851+ method : "elicitation/create" ,
852+ params,
853+ } ) ,
854+ ) ;
855+ assert . deepEqual ( yield * decodeWireResponse ( yield * Queue . take ( output ) ) , {
856+ jsonrpc : "2.0" ,
857+ id : 72 ,
858+ result : { action : "accept" } ,
859+ } ) ;
860+ } ) . pipe ( Effect . scoped ) ,
861+ ) ;
862+
863+ it . effect . each ( [ "elicitation/complete" , "session/elicitation/complete" ] ) (
864+ "delivers %s notifications to the completion handler" ,
865+ ( method ) =>
866+ Effect . gen ( function * ( ) {
867+ const { stdio, input } = yield * makeInMemoryStdio ( ) ;
868+ const acp = yield * AcpClient . make ( stdio ) ;
869+ const received = yield * Deferred . make < AcpSchema . ElicitationCompleteNotification > ( ) ;
870+ yield * acp . handleElicitationComplete ( ( notification ) =>
871+ Deferred . succeed ( received , notification ) . pipe ( Effect . asVoid ) ,
872+ ) ;
873+ yield * Queue . offer (
874+ input ,
875+ yield * encodeJsonl ( jsonRpcNotification ( method , AcpSchema . ElicitationCompleteNotification ) , {
876+ jsonrpc : "2.0" ,
877+ method,
878+ params : { elicitationId : "elicitation-1" } ,
879+ } ) ,
880+ ) ;
881+ assert . deepEqual ( yield * Deferred . await ( received ) , { elicitationId : "elicitation-1" } ) ;
882+ } ) . pipe ( Effect . scoped ) ,
883+ ) ;
884+
885+ it . effect ( "rejects malformed SDK elicitation without calling the question handler" , ( ) =>
886+ Effect . gen ( function * ( ) {
887+ const { stdio, input, output } = yield * makeInMemoryStdio ( ) ;
888+ const acp = yield * AcpClient . make ( stdio ) ;
889+ let calls = 0 ;
890+ yield * acp . handleElicitation ( ( ) => {
891+ calls ++ ;
892+ return Effect . succeed ( { action : { action : "cancel" as const } } ) ;
893+ } ) ;
894+ yield * Queue . offer (
895+ input ,
896+ yield * encodeJsonl ( jsonRpcRequest ( "elicitation/create" , Schema . Unknown ) , {
897+ jsonrpc : "2.0" ,
898+ id : 73 ,
899+ headers : [ ] ,
900+ method : "elicitation/create" ,
901+ params : { ...elicitationForm , message : 123 } ,
902+ } ) ,
903+ ) ;
904+ const response = yield * decodeWireError ( yield * Queue . take ( output ) ) ;
905+ assert . equal ( response . error . code , - 32602 ) ;
906+ assert . equal ( calls , 0 ) ;
907+ } ) . pipe ( Effect . scoped ) ,
908+ ) ;
909+
910+ it . effect ( "returns method-not-found when SDK elicitation has no question handler" , ( ) =>
911+ Effect . gen ( function * ( ) {
912+ const { stdio, input, output } = yield * makeInMemoryStdio ( ) ;
913+ yield * AcpClient . make ( stdio ) ;
914+ yield * Queue . offer (
915+ input ,
916+ yield * encodeJsonl ( jsonRpcRequest ( "elicitation/create" , AcpSchema . ElicitationRequest ) , {
917+ jsonrpc : "2.0" ,
918+ id : 74 ,
919+ headers : [ ] ,
920+ method : "elicitation/create" ,
921+ params : elicitationForm ,
922+ } ) ,
923+ ) ;
924+ const response = yield * decodeWireError ( yield * Queue . take ( output ) ) ;
925+ assert . equal ( response . error . code , - 32601 ) ;
926+ } ) . pipe ( Effect . scoped ) ,
927+ ) ;
0 commit comments