Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/server/src/project/WorktreeSetupTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,24 @@ describe("WorktreeSetupTracker", () => {
yield* Fiber.interrupt(fiber);
}),
);

it.effect("clamps stage detail and finish error without splitting surrogate pairs", () =>
Effect.gen(function* () {
const tracker = yield* WorktreeSetupTracker.make;
yield* tracker.begin({
threadId,
branch: null,
baseRef: null,
stages: ["agent"],
fiber: null,
});

yield* tracker.stageStatus(threadId, "agent", "running", `${"a".repeat(198)}\u{1F680}tail`);
yield* tracker.finish(threadId, "failed", `${"e".repeat(998)}\u{1F680}tail`);

const final = yield* tracker.get(threadId);
expect(final?.stages[0]?.detail).toBe(`${"a".repeat(198)}\u2026`);
expect(final?.error).toBe(`${"e".repeat(998)}\u2026`);
}),
);
});
5 changes: 4 additions & 1 deletion apps/server/src/project/WorktreeSetupTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WORKTREE_SETUP_STAGE_ORDER,
WORKTREE_SETUP_TAIL_LINE_MAX_LENGTH,
} from "@t3tools/contracts";
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
Expand Down Expand Up @@ -67,7 +68,9 @@ export class WorktreeSetupTracker extends Context.Service<
const TAIL_LINE_LIMIT = 4;

function clampText(text: string, maxLength: number): string {
return text.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}\u2026`;
if (text.length <= maxLength) return text;
const end = splitsSurrogatePair(text, maxLength - 1) ? maxLength - 2 : maxLength - 1;
return `${text.slice(0, end)}\u2026`;
}

const clampDetail = (detail: string | null): string | null =>
Expand Down
Loading