@@ -8,8 +8,12 @@ import {
88 GetUsableModelsResponseSchema ,
99 InteractionQuerySchema ,
1010 KvServerMessageSchema ,
11+ McpArgsSchema ,
12+ McpToolCallSchema ,
1113 ModelDetailsSchema ,
1214 TextDeltaUpdateSchema ,
15+ ToolCallSchema ,
16+ ToolCallStartedUpdateSchema ,
1317 InteractionUpdateSchema ,
1418} from "../src/adapters/cursor/gen/agent_pb" ;
1519import { CONNECT_FLAG_END_STREAM , encodeConnectFrame } from "../src/adapters/cursor/framing" ;
@@ -491,6 +495,73 @@ describe("Cursor live transport unexpected EOF", () => {
491495 } ) ;
492496 } ) ;
493497
498+ test ( "open tool call plus clean Connect EOF emits a truncation error, not a thrown failure" , async ( ) => {
499+ const startedFrame = encodeConnectFrame ( toBinary ( AgentServerMessageSchema , create ( AgentServerMessageSchema , {
500+ message : {
501+ case : "interactionUpdate" ,
502+ value : create ( InteractionUpdateSchema , {
503+ message : {
504+ case : "toolCallStarted" ,
505+ value : create ( ToolCallStartedUpdateSchema , {
506+ callId : "call_1" ,
507+ modelCallId : "model_1" ,
508+ toolCall : create ( ToolCallSchema , {
509+ tool : {
510+ case : "mcpToolCall" ,
511+ value : create ( McpToolCallSchema , {
512+ args : create ( McpArgsSchema , {
513+ name : "get_time" ,
514+ toolName : "get_time" ,
515+ toolCallId : "call_1" ,
516+ providerIdentifier : "opencodex-responses" ,
517+ } ) ,
518+ } ) ,
519+ } ,
520+ } ) ,
521+ } ) ,
522+ } ,
523+ } ) ,
524+ } ,
525+ } ) ) ) ;
526+ const connectEnd = encodeConnectFrame ( new TextEncoder ( ) . encode ( "{}" ) , {
527+ flags : CONNECT_FLAG_END_STREAM ,
528+ } ) ;
529+
530+ await withDiscoveryServer ( stream => {
531+ stream . respond ( { ":status" : 200 , "content-type" : "application/connect+proto" } ) ;
532+ stream . end ( Buffer . from ( new Uint8Array ( [ ...startedFrame , ...connectEnd ] ) ) ) ;
533+ } , async baseUrl => {
534+ const transport = createLiveCursorTransport ( {
535+ provider : { adapter : "cursor" , baseUrl, apiKey : "test-token" } ,
536+ translatorBudget : createTestTranslatorBudget ( ) ,
537+ firstFrameTimeoutMs : 2_000 ,
538+ } ) ;
539+ const messages : Array < { type : string ; message ?: string } > = [ ] ;
540+ let failure : Error | undefined ;
541+ try {
542+ for await ( const message of transport . run ( {
543+ modelId : "composer-2" ,
544+ conversationId : "cursor_open_tool_eof_test" ,
545+ system : [ ] ,
546+ messages : [ { role : "user" , content : "hello" } ] ,
547+ tools : [ { name : "get_time" , description : "t" , parameters : { type : "object" , properties : { } } } ] ,
548+ } ) ) {
549+ messages . push ( message ) ;
550+ }
551+ } catch ( err ) {
552+ failure = err instanceof Error ? err : new Error ( String ( err ) ) ;
553+ } finally {
554+ await transport . close ?.( ) ;
555+ }
556+
557+ expect ( failure ) . toBeUndefined ( ) ;
558+ expect ( messages . at ( - 1 ) ) . toMatchObject ( {
559+ type : "error" ,
560+ message : expect . stringContaining ( "incomplete tool call" ) ,
561+ } ) ;
562+ } ) ;
563+ } ) ;
564+
494565 test ( "zero-frame stream end surfaces as a transport error, not success" , async ( ) => {
495566 // Real h2c peer that accepts the request stream and immediately ends it with no
496567 // response frames — the shape the WP4 reviewer reproduced as a silent success.
0 commit comments