File tree Expand file tree Collapse file tree
packages/opencode/test/pty Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,43 +98,39 @@ describe("pty", () => {
9898 } )
9999 } )
100100
101- test ( "does not leak output when socket data mutates in-place " , async ( ) => {
101+ test ( "treats in-place socket data mutation as the same connection " , async ( ) => {
102102 await using dir = await tmpdir ( { git : true } )
103103
104104 await Instance . provide ( {
105105 directory : dir . path ,
106106 fn : async ( ) => {
107107 const a = await Pty . create ( { command : "cat" , title : "a" } )
108108 try {
109- const outA : string [ ] = [ ]
110- const outB : string [ ] = [ ]
109+ const out : string [ ] = [ ]
111110
112111 const ctx = { connId : 1 }
113112 const ws = {
114113 readyState : 1 ,
115114 data : ctx ,
116115 send : ( data : unknown ) => {
117- outA . push ( typeof data === "string" ? data : Buffer . from ( data as Uint8Array ) . toString ( "utf8" ) )
116+ out . push ( typeof data === "string" ? data : Buffer . from ( data as Uint8Array ) . toString ( "utf8" ) )
118117 } ,
119118 close : ( ) => {
120119 // no-op
121120 } ,
122121 }
123122
124123 Pty . connect ( a . id , ws as any )
125- outA . length = 0
124+ out . length = 0
126125
127- // Simulate the runtime mutating per-connection data without
128- // swapping the reference (ws.data stays the same object) .
126+ // Mutating fields on ws.data should not look like a new
127+ // connection lifecycle when the object identity stays stable .
129128 ctx . connId = 2
130- ws . send = ( data : unknown ) => {
131- outB . push ( typeof data === "string" ? data : Buffer . from ( data as Uint8Array ) . toString ( "utf8" ) )
132- }
133129
134130 Pty . write ( a . id , "AAA\n" )
135131 await Bun . sleep ( 100 )
136132
137- expect ( outB . join ( "" ) ) . not . toContain ( "AAA" )
133+ expect ( out . join ( "" ) ) . toContain ( "AAA" )
138134 } finally {
139135 await Pty . remove ( a . id )
140136 }
You can’t perform that action at this time.
0 commit comments