@@ -40,6 +40,37 @@ async function collectStreamEvents(stream: AsyncIterable<unknown>): Promise<unkn
4040const requireRecord = createRequireRecord ( "object" , "expected-label" ) ;
4141
4242describe ( "wrapStreamFnPromoteStandaloneTextToolCalls" , ( ) => {
43+ it ( "supports writable non-configurable stream iterators" , async ( ) => {
44+ const resultMessage = {
45+ role : "assistant" ,
46+ content : [ { type : "text" , text : "plain response" } ] ,
47+ stopReason : "stop" ,
48+ } ;
49+ const baseStream = createFakeStream ( {
50+ events : [ { type : "done" , reason : "stop" , message : resultMessage } ] ,
51+ resultMessage,
52+ } ) ;
53+ const iterator = baseStream [ Symbol . asyncIterator ] ;
54+ Object . defineProperty ( baseStream , Symbol . asyncIterator , {
55+ configurable : false ,
56+ value : iterator ,
57+ writable : true ,
58+ } ) ;
59+ const wrapped = wrapStreamFnPromoteStandaloneTextToolCalls (
60+ ( ( ) => baseStream ) as never ,
61+ new Set ( [ "exec" ] ) ,
62+ ) ;
63+
64+ const stream = ( await Promise . resolve (
65+ wrapped ( { } as never , { } as never , { } as never ) ,
66+ ) ) as FakeWrappedStream ;
67+
68+ await expect ( collectStreamEvents ( stream ) ) . resolves . toEqual ( [
69+ { type : "done" , reason : "stop" , message : resultMessage } ,
70+ ] ) ;
71+ await expect ( stream . result ( ) ) . resolves . toEqual ( resultMessage ) ;
72+ } ) ;
73+
4374 it ( "preserves a fenced allowed-tool example in live and terminal output" , async ( ) => {
4475 const parts = [ "`" , "``json\n" , "[re" , 'ad]\n{"path":"example.txt"}\n[/read]\n' , "```" ] ;
4576 const rawText = parts . join ( "" ) ;
0 commit comments