@@ -51,6 +51,52 @@ describe("AcpClientTerminals", () => { |
51 | 51 | ), |
52 | 52 | ); |
53 | 53 |
|
| 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 | + |
54 | 100 | it.live("resolves terminal environment from the requesting ACP session", () => |
55 | 101 | Effect.gen(function* () { |
56 | 102 | const terminals = yield* makeAcpClientTerminals({ |
@@ -96,14 +142,17 @@ describe("AcpClientTerminals", () => { |
96 | 142 | }).pipe(Effect.provide(NodeServices.layer), Effect.scoped), |
97 | 143 | ); |
98 | 144 |
|
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 }) => |
100 | 149 | withTerminals((terminals) => |
101 | 150 | Effect.gen(function* () { |
102 | 151 | const created = yield* terminals.create({ |
103 | 152 | sessionId: "session", |
104 | 153 | 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, |
107 | 156 | }); |
108 | 157 | yield* terminals.waitForExit({ sessionId: "session", terminalId: created.terminalId }); |
109 | 158 |
|
@@ -113,7 +162,8 @@ describe("AcpClientTerminals", () => { |
113 | 162 | }); |
114 | 163 | expect(output.truncated).toBe(true); |
115 | 164 | 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"); |
117 | 167 | }), |
118 | 168 | ), |
119 | 169 | ); |
|