@@ -3,7 +3,10 @@ import { create, toBinary } from "@bufbuild/protobuf";
33import { describe , expect , spyOn , test } from "bun:test" ;
44import {
55 AgentServerMessageSchema ,
6+ CreatePlanArgsSchema ,
7+ CreatePlanRequestQuerySchema ,
68 GetUsableModelsResponseSchema ,
9+ InteractionQuerySchema ,
710 KvServerMessageSchema ,
811 ModelDetailsSchema ,
912 TextDeltaUpdateSchema ,
@@ -78,6 +81,19 @@ describe("Cursor live-model discovery hardening", () => {
7881 expect ( result ) . toEqual ( { ok : true , models : [ "gpt-5.5-high" ] } ) ;
7982 } ) ;
8083
84+ test ( "rejects a cleartext non-loopback discovery URL before connecting" , async ( ) => {
85+ const result = await fetchCursorUsableModels ( {
86+ apiKey : "test-token" ,
87+ baseUrl : "http://api2.cursor.sh" ,
88+ } ) ;
89+
90+ expect ( result ) . toEqual ( {
91+ ok : false ,
92+ error : "transport" ,
93+ detail : "Cursor discovery URL must use HTTPS" ,
94+ } ) ;
95+ } ) ;
96+
8197 test ( "classifies authentication failures" , async ( ) => {
8298 const result = await withDiscoveryServer ( respond ( 401 ) , baseUrl =>
8399 fetchCursorUsableModels ( { apiKey : "bad-token" , baseUrl } ) ) ;
@@ -424,6 +440,57 @@ describe("Cursor live transport unexpected EOF", () => {
424440 } ) ;
425441 } ) ;
426442
443+ test ( "synthesizes done after createPlanRequestQuery text on clean Connect EOF" , async ( ) => {
444+ const planFrame = encodeConnectFrame ( toBinary ( AgentServerMessageSchema , create ( AgentServerMessageSchema , {
445+ message : {
446+ case : "interactionQuery" ,
447+ value : create ( InteractionQuerySchema , {
448+ id : 7 ,
449+ query : {
450+ case : "createPlanRequestQuery" ,
451+ value : create ( CreatePlanRequestQuerySchema , {
452+ args : create ( CreatePlanArgsSchema , {
453+ name : "Fix bridge" ,
454+ overview : "Two steps." ,
455+ plan : "1. read\n2. patch" ,
456+ } ) ,
457+ } ) ,
458+ } ,
459+ } ) ,
460+ } ,
461+ } ) ) ) ;
462+ const connectEnd = encodeConnectFrame ( new TextEncoder ( ) . encode ( "{}" ) , {
463+ flags : CONNECT_FLAG_END_STREAM ,
464+ } ) ;
465+
466+ await withDiscoveryServer ( stream => {
467+ stream . respond ( { ":status" : 200 , "content-type" : "application/connect+proto" } ) ;
468+ stream . end ( Buffer . from ( new Uint8Array ( [ ...planFrame , ...connectEnd ] ) ) ) ;
469+ } , async baseUrl => {
470+ const transport = createLiveCursorTransport ( {
471+ provider : { adapter : "cursor" , baseUrl, apiKey : "test-token" } ,
472+ translatorBudget : createTestTranslatorBudget ( ) ,
473+ firstFrameTimeoutMs : 2_000 ,
474+ } ) ;
475+ const messages : Array < { type : string ; text ?: string } > = [ ] ;
476+ try {
477+ for await ( const message of transport . run ( {
478+ modelId : "composer-2" ,
479+ conversationId : "cursor_plan_eof_test" ,
480+ system : [ ] ,
481+ messages : [ { role : "user" , content : "hello" } ] ,
482+ } ) ) {
483+ messages . push ( message ) ;
484+ }
485+ } finally {
486+ await transport . close ?.( ) ;
487+ }
488+
489+ expect ( messages . some ( message => message . type === "text" && message . text ?. includes ( "Fix bridge" ) ) ) . toBe ( true ) ;
490+ expect ( messages . at ( - 1 ) ) . toMatchObject ( { type : "done" } ) ;
491+ } ) ;
492+ } ) ;
493+
427494 test ( "zero-frame stream end surfaces as a transport error, not success" , async ( ) => {
428495 // Real h2c peer that accepts the request stream and immediately ends it with no
429496 // response frames — the shape the WP4 reviewer reproduced as a silent success.
0 commit comments