@@ -51,6 +51,52 @@ describe("AcpClientTerminals", () => {
5151 ) ,
5252 ) ;
5353
54+ it . effect ( "preserves UTF-8 when stderr interleaves a split stdout character" , ( ) =>
55+ Effect . gen ( function * ( ) {
56+ const stdoutStarted = yield * Deferred . make < void > ( ) ;
57+ const stderrWritten = yield * Deferred . make < void > ( ) ;
58+ const child = ChildProcessSpawner . makeHandle ( {
59+ pid : ChildProcessSpawner . ProcessId ( 1 ) ,
60+ exitCode : Effect . succeed ( ChildProcessSpawner . ExitCode ( 0 ) ) ,
61+ isRunning : Effect . succeed ( false ) ,
62+ kill : ( ) => Effect . void ,
63+ stdin : Sink . drain ,
64+ stdout : Stream . make ( new Uint8Array ( [ 0xe2 ] ) ) . pipe (
65+ Stream . concat ( Stream . fromEffectDrain ( Deferred . succeed ( stdoutStarted , undefined ) ) ) ,
66+ Stream . concat ( Stream . fromEffectDrain ( Deferred . await ( stderrWritten ) ) ) ,
67+ Stream . concat ( Stream . make ( new Uint8Array ( [ 0x82 , 0xac ] ) ) ) ,
68+ ) ,
69+ stderr : Stream . fromEffectDrain ( Deferred . await ( stdoutStarted ) ) . pipe (
70+ Stream . concat ( Stream . make ( new Uint8Array ( [ 0x58 ] ) ) ) ,
71+ Stream . concat ( Stream . fromEffectDrain ( Deferred . succeed ( stderrWritten , undefined ) ) ) ,
72+ ) ,
73+ all : Stream . empty ,
74+ getInputFd : ( ) => Sink . drain ,
75+ getOutputFd : ( ) => Stream . empty ,
76+ unref : Effect . succeed ( Effect . void ) ,
77+ } ) ;
78+ const terminals = yield * makeAcpClientTerminals ( { defaultCwd : process . cwd ( ) } ) . pipe (
79+ Effect . provideService (
80+ ChildProcessSpawner . ChildProcessSpawner ,
81+ ChildProcessSpawner . make ( ( ) => Effect . succeed ( child ) ) ,
82+ ) ,
83+ ) ;
84+ yield * Effect . addFinalizer ( ( ) => terminals . disposeAll ) ;
85+ const terminal = yield * terminals . create ( { sessionId : "session" , command : "fixture" } ) ;
86+ const request = { sessionId : "session" , ...terminal } ;
87+ yield * terminals . waitForExit ( request ) ;
88+
89+ const output = yield * terminals . output ( request ) ;
90+ expect ( output . output ) . toContain ( "€" ) ;
91+ expect ( output . output ) . toContain ( "X" ) ;
92+ expect ( output . output ) . not . toContain ( "\uFFFD" ) ;
93+ expect ( output . truncated ) . toBe ( false ) ;
94+ expect ( terminals . readOutputSnapshot ( "session" , terminal . terminalId ) ?. output ) . toBe (
95+ output . output ,
96+ ) ;
97+ } ) . pipe ( Effect . scoped ) ,
98+ ) ;
99+
54100 it . live ( "resolves terminal environment from the requesting ACP session" , ( ) =>
55101 Effect . gen ( function * ( ) {
56102 const terminals = yield * makeAcpClientTerminals ( {
@@ -96,14 +142,17 @@ describe("AcpClientTerminals", () => {
96142 } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
97143 ) ;
98144
99- it . live ( "truncates buffered output from the beginning at the byte limit" , ( ) =>
145+ it . live . each ( [
146+ { text : "a" . repeat ( 64 ) + "TAIL" , limit : 16 } ,
147+ { text : "€" . repeat ( 16 ) + "TAIL" , limit : 6 } ,
148+ ] ) ( "truncates buffered output from the beginning at the $limit byte limit" , ( { text, limit } ) =>
100149 withTerminals ( ( terminals ) =>
101150 Effect . gen ( function * ( ) {
102151 const created = yield * terminals . create ( {
103152 sessionId : "session" ,
104153 command : process . execPath ,
105- args : [ "-e" , " process.stdout.write('a'.repeat(64) + 'TAIL');" ] ,
106- outputByteLimit : 16 ,
154+ args : [ "-e" , ` process.stdout.write(${ JSON . stringify ( text ) } );` ] ,
155+ outputByteLimit : limit ,
107156 } ) ;
108157 yield * terminals . waitForExit ( { sessionId : "session" , terminalId : created . terminalId } ) ;
109158
@@ -113,7 +162,8 @@ describe("AcpClientTerminals", () => {
113162 } ) ;
114163 expect ( output . truncated ) . toBe ( true ) ;
115164 expect ( output . output . endsWith ( "TAIL" ) ) . toBe ( true ) ;
116- expect ( output . output . length ) . toBeLessThanOrEqual ( 16 ) ;
165+ expect ( Buffer . byteLength ( output . output ) ) . toBeLessThanOrEqual ( limit ) ;
166+ expect ( output . output ) . not . toContain ( "\uFFFD" ) ;
117167 } ) ,
118168 ) ,
119169 ) ;
0 commit comments