@@ -108,23 +108,60 @@ public function testContextIsReleasedWithoutSuspension(string $mode, bool $fail)
108108 $ this ->assertSame ('parent ' , $ context ->current ());
109109 }
110110
111- public function testContextIsReleasedWhenAStreamIsAbandoned (): void
111+ #[DataProvider('modes ' )]
112+ public function testContextIsReleasedWhenAStreamIsAbandoned (string $ mode ): void
112113 {
113114 $ context = new RecordingFiberContext ();
114- $ server = $ this ->builder ($ context )->addTool (static function (RequestContext $ request ) use ($ context ): string {
115+ $ builder = $ this ->builder ($ context )->addTool (static function (RequestContext $ request ) use ($ context ): string {
115116 $ request ->getClientGateway ()->progress (1 , 2 );
116117
117118 return $ context ->current ();
118- }, name: 'probe ' )->buildStateless ();
119- $ response = $ this ->post ($ server , $ this ->call (true ));
120- $ this ->assertSame (1 , $ context ->created );
121- $ this ->assertSame (0 , $ context ->released );
119+ }, name: 'probe ' );
120+ $ server = 'standalone ' === $ mode ? $ builder ->buildStateless () : $ builder ->build ();
121+ $ session = 'legacy ' === $ mode ? $ this ->post ($ server , $ this ->initialize ())->getHeaderLine ('Mcp-Session-Id ' ) : null ;
122+ $ created = $ context ->created ;
123+ $ released = $ context ->released ;
124+
125+ $ response = $ this ->post ($ server , $ this ->call ('legacy ' !== $ mode ), $ session );
126+ $ this ->assertSame ($ created + 1 , $ context ->created );
127+ $ this ->assertSame ($ released , $ context ->released );
122128 unset($ response );
123129
124- $ this ->assertSame (1 , $ context ->released );
130+ $ this ->assertSame ($ released + 1 , $ context ->released );
125131 $ this ->assertSame ('parent ' , $ context ->current ());
126132 }
127133
134+ /**
135+ * @return iterable<string, array{string}>
136+ */
137+ public static function modes (): iterable
138+ {
139+ foreach (['legacy ' , 'modern ' , 'standalone ' ] as $ mode ) {
140+ yield $ mode => [$ mode ];
141+ }
142+ }
143+
144+ #[DataProvider('modes ' )]
145+ public function testAFailingWrapAnswersWithAnInternalError (string $ mode ): void
146+ {
147+ $ context = new RecordingFiberContext ();
148+ $ called = false ;
149+ $ builder = $ this ->builder ($ context )->addTool (static function () use (&$ called ): string {
150+ $ called = true ;
151+
152+ return 'unreachable ' ;
153+ }, name: 'probe ' );
154+ $ server = 'standalone ' === $ mode ? $ builder ->buildStateless () : $ builder ->build ();
155+ $ session = 'legacy ' === $ mode ? $ this ->post ($ server , $ this ->initialize ())->getHeaderLine ('Mcp-Session-Id ' ) : null ;
156+ $ context ->wrapFailure = new RuntimeException ('wrap failed ' );
157+
158+ $ body = $ this ->consume ($ this ->post ($ server , $ this ->call ('legacy ' !== $ mode ), $ session ));
159+
160+ $ this ->assertStringContainsString ('"code":-32603 ' , $ body );
161+ $ this ->assertStringNotContainsString ('wrap failed ' , $ body );
162+ $ this ->assertFalse ($ called );
163+ }
164+
128165 public function testContextIsReleasedWhenElicitationDiscardsTheFiber (): void
129166 {
130167 $ context = new RecordingFiberContext ();
@@ -147,7 +184,7 @@ public function testContextIsReleasedWhenElicitationDiscardsTheFiber(): void
147184 }
148185
149186 #[DataProvider('eras ' )]
150- public function testStdioUsesTheFactory (bool $ modern ): void
187+ public function testStdioUsesTheFiberContext (bool $ modern ): void
151188 {
152189 $ context = new RecordingFiberContext ();
153190 $ builder = $ this ->builder ($ context )->addTool (static function (RequestContext $ request ) use ($ context ): string {
0 commit comments