@@ -222,6 +222,147 @@ describe("CursorAdapterV2", () => {
222222 ) ,
223223 ) ;
224224
225+ it . effect . each ( [
226+ {
227+ reason : "the error Cursor's run ended with" ,
228+ wait : Effect . succeed ( {
229+ id : "native-cursor-run" ,
230+ requestId : "native-request" ,
231+ status : "error" as const ,
232+ error : {
233+ message : "Model Blocked Please ask your admin to enable access to Claude Fable 5." ,
234+ } ,
235+ model : { id : "claude-fable-5" } ,
236+ durationMs : 1 ,
237+ } ) ,
238+ failure : {
239+ class : "provider_error" ,
240+ message : "Model Blocked Please ask your admin to enable access to Claude Fable 5." ,
241+ } ,
242+ } ,
243+ {
244+ reason : "the SDK error that broke the run" ,
245+ wait : Effect . fail (
246+ new CursorAgentSdk . CursorAgentSdkRunnerError ( {
247+ method : "run.wait" ,
248+ cause : Object . assign ( new Error ( "Too many requests" ) , {
249+ code : "resource_exhausted" ,
250+ status : 429 ,
251+ } ) ,
252+ } ) ,
253+ ) ,
254+ failure : {
255+ class : "transport_error" ,
256+ message :
257+ "Cursor Agent SDK run.wait failed: Too many requests (resource_exhausted, HTTP 429)" ,
258+ } ,
259+ } ,
260+ ] ) ( "fails the turn with $reason" , ( { wait, failure } ) =>
261+ Effect . gen ( function * ( ) {
262+ const fileSystem = yield * FileSystem . FileSystem ;
263+ const workspace = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "cursor-v2-failure-" } ) ;
264+ const instanceId = ProviderInstanceId . make ( "cursor" ) ;
265+ const threadId = ThreadId . make ( "cursor-failure-thread" ) ;
266+ const modelSelection = { instanceId, model : "claude-fable-5" } ;
267+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
268+ runtimeMode : "full-access" ,
269+ interactionMode : "default" ,
270+ cwd : workspace ,
271+ } ) ;
272+ const adapter = yield * makeCursorAdapterV2 ( {
273+ instanceId,
274+ settings : yield * decodeCursorSettings ( { } ) ,
275+ environment : { HOME : workspace } ,
276+ } ) . pipe (
277+ Effect . provideService ( CursorAgentSdk . CursorAgentSdkRunner , {
278+ assertComplete : Effect . void ,
279+ open : ( ) =>
280+ Effect . succeed ( {
281+ agentId : "native-cursor-failure" ,
282+ listMessages : Effect . succeed ( [ ] ) ,
283+ close : Effect . void ,
284+ send : ( ) =>
285+ Effect . succeed ( {
286+ agentId : "native-cursor-failure" ,
287+ runId : "native-cursor-run" ,
288+ wait,
289+ cancel : Effect . void ,
290+ } ) ,
291+ } ) ,
292+ } ) ,
293+ Effect . provide ( TestProviderHost . layer ( { cwd : workspace } ) ) ,
294+ ) ;
295+ const runtime = yield * adapter . openSession ( {
296+ threadId,
297+ providerSessionId : ProviderSessionId . make ( "cursor-failure-session" ) ,
298+ modelSelection,
299+ runtimePolicy,
300+ } ) ;
301+ const providerThread = yield * runtime . ensureThread ( {
302+ threadId,
303+ modelSelection,
304+ runtimePolicy,
305+ } ) ;
306+ const now = yield * DateTime . now ;
307+ yield * runtime . startTurn ( {
308+ threadId,
309+ providerThread,
310+ modelSelection,
311+ runtimePolicy,
312+ runId : RunId . make ( "cursor-failure-run" ) ,
313+ runOrdinal : 1 ,
314+ providerTurnOrdinal : 1 ,
315+ attemptId : RunAttemptId . make ( "cursor-failure-attempt" ) ,
316+ rootNodeId : NodeId . make ( "cursor-failure-root" ) ,
317+ appThread : {
318+ id : threadId ,
319+ projectId : ProjectId . make ( "cursor-failure-project" ) ,
320+ createdBy : "user" ,
321+ creationSource : "web" ,
322+ title : "Cursor failure" ,
323+ providerInstanceId : instanceId ,
324+ modelSelection,
325+ runtimeMode : "full-access" ,
326+ interactionMode : "default" ,
327+ branch : null ,
328+ worktreePath : null ,
329+ activeProviderThreadId : providerThread . id ,
330+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
331+ forkedFrom : null ,
332+ createdAt : now ,
333+ updatedAt : now ,
334+ archivedAt : null ,
335+ settledOverride : null ,
336+ settledAt : null ,
337+ lastVisitedAt : null ,
338+ deletedAt : null ,
339+ } ,
340+ message : {
341+ messageId : MessageId . make ( "cursor-failure-message" ) ,
342+ createdBy : "user" ,
343+ creationSource : "web" ,
344+ text : "hi" ,
345+ attachments : [ ] ,
346+ } ,
347+ } ) ;
348+ const terminal = yield * runtime . events . pipe (
349+ Stream . filter ( ( event ) => event . type === "turn.terminal" ) ,
350+ Stream . runHead ,
351+ ) ;
352+ assert . isTrue ( Option . isSome ( terminal ) ) ;
353+ if ( Option . isSome ( terminal ) ) {
354+ assert . equal ( terminal . value . status , "failed" ) ;
355+ assert . equal ( terminal . value . failure ?. class , failure . class ) ;
356+ assert . equal ( terminal . value . failure ?. message , failure . message ) ;
357+ }
358+ } ) . pipe (
359+ Effect . scoped ,
360+ Effect . provide (
361+ Layer . mergeAll ( NodeServices . layer , IdAllocator . layer , McpProviderSessions . layer ) ,
362+ ) ,
363+ ) ,
364+ ) ;
365+
225366 it . effect ( "fails standalone SDK transport diagnostics and sends compaction as /compress" , ( ) =>
226367 Effect . gen ( function * ( ) {
227368 const fileSystem = yield * FileSystem . FileSystem ;
0 commit comments