Skip to content

Commit a190324

Browse files
t3dotggclaude
andcommitted
fix(desktop): startup output tail never ends in half an emoji
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 20dad37 commit a190324

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ describe("DesktopBackendManager", () => {
583583
it.effect("reports a crash loop with the server output on the third restart", () =>
584584
Effect.scoped(
585585
Effect.gen(function* () {
586+
const message = "Error: Cannot find module 'zod/v4' in /Users/René";
586587
let exitCount = 0;
587588
const firstExit = yield* Deferred.make<void>();
588589
const reports = yield* Queue.unbounded<{
@@ -595,9 +596,12 @@ describe("DesktopBackendManager", () => {
595596
ChildProcessSpawner.make(() =>
596597
Effect.succeed(
597598
makeProcess({
598-
// "é" split across chunks must not decode as U+FFFD.
599+
// "é" split across chunks must not decode as U+FFFD, and the 4,000-char cut
600+
// lands inside the emoji's surrogate pair.
599601
stderr: Stream.make(
600-
new TextEncoder().encode("Error: Cannot find module 'zod/v4' in /Users/Ren"),
602+
new TextEncoder().encode(
603+
`😀${"x".repeat(3_999 - message.length)}${message.slice(0, -1)}`,
604+
),
601605
new Uint8Array([0xc3]),
602606
new Uint8Array([0xa9]),
603607
),
@@ -622,7 +626,8 @@ describe("DesktopBackendManager", () => {
622626
const { exitCount: exitsWhenReported, failure } = yield* Queue.take(reports);
623627
assert.equal(exitsWhenReported, 3);
624628
assert.equal(failure.reason, "The server could not start (code=1).");
625-
assert.include(failure.output, "Cannot find module 'zod/v4' in /Users/René");
629+
assert.isTrue(failure.output.endsWith(message));
630+
assert.isTrue(failure.output.isWellFormed());
626631
}).pipe(Effect.provide(TestClock.layer())),
627632
),
628633
);

‎apps/desktop/src/backend/DesktopBackendManager.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,10 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
949949
),
950950
onOutput: (streamName, chunk) =>
951951
Ref.update(outputTail, (tail) =>
952-
(tail + outputDecoders[streamName].decode(chunk, { stream: true })).slice(
953-
-STARTUP_FAILURE_OUTPUT_CHARS,
954-
),
952+
// A cut through a surrogate pair would make encodeURIComponent throw when rendering.
953+
(tail + outputDecoders[streamName].decode(chunk, { stream: true }))
954+
.slice(-STARTUP_FAILURE_OUTPUT_CHARS)
955+
.toWellFormed(),
955956
).pipe(Effect.andThen(backendOutputLog.writeOutputChunk(streamName, chunk))),
956957
}).pipe(
957958
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),

0 commit comments

Comments
 (0)