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
19 changes: 19 additions & 0 deletions apps/server/src/project/ProjectCloneTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ describe("ProjectCloneTracker", () => {
}).pipe(Effect.provide(harness.layer));
});

it.effect("clamps a long failure without splitting a surrogate pair", () => {
const harness = makeHarness({
clone: () =>
Effect.fail(
new SourceControlRepositoryError({
operation: "cloneRepository",
provider: SourceControlProviderKind.make("unknown"),
detail: `${"e".repeat(998)}\u{1F680}tail`,
}),
),
});
return Effect.gen(function* () {
const tracker = yield* ProjectCloneTracker.ProjectCloneTracker;
yield* tracker.start(startInput, harness.hooks);
yield* Effect.yieldNow;
expect((yield* tracker.get(projectId))?.error).toBe(`${"e".repeat(998)}…`);
}).pipe(Effect.provide(harness.layer));
});

it.effect("cancel interrupts the clone and removes the partial checkout", () => {
const harness = makeHarness({ clone: () => Effect.never });
return Effect.gen(function* () {
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/project/ProjectCloneTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PROJECT_CLONE_ERROR_MAX_LENGTH,
SourceControlRepositoryError,
} from "@t3tools/contracts";
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
Expand Down Expand Up @@ -74,7 +75,9 @@ const DONE_RETENTION = "30 seconds";
const STALL_AFTER = "20 seconds";

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

const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
Expand Down
Loading