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
21 changes: 21 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3759,6 +3759,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect("cuts long commit subjects without splitting an emoji", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(cwd);
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* git(cwd, ["checkout", "-b", "feature/emoji-subject"]);
yield* git(cwd, ["commit", "--allow-empty", "-m", `${"a".repeat(299)}😀 tail`]);
const sha = yield* git(cwd, ["rev-parse", "HEAD"]);

const branch = yield* driver.getReviewBranchCommits({ cwd, baseRef: initialBranch });
const preview = yield* driver.getReviewDiffPreview({ cwd, commitSha: sha });
const commitSubject = preview.sources.find(
(candidate) => candidate.kind === "commit",
)?.commitSubject;
assert.deepStrictEqual(
[branch.commits[0]?.subject, commitSubject],
["a".repeat(299), "a".repeat(299)],
);
}),
);

it.effect("previews one selected commit, a merge against its first parent", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
14 changes: 12 additions & 2 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
trimAsciiWhitespace,
type VcsRef,
} from "@t3tools/contracts";
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import { dedupeRemoteBranchesWithLocalMatches } from "@t3tools/shared/git";
import * as HostProcess from "@t3tools/shared/HostProcess";
import { compactTraceAttributes } from "@t3tools/shared/observability";
Expand Down Expand Up @@ -104,6 +105,13 @@ const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024;
const GIT_IDENT_KEYWORD = /\$Id:[^$\n]*\$/g;
const REVIEW_BRANCH_COMMIT_LIMIT = 100;
const REVIEW_BRANCH_SUBJECT_LIMIT = 300;
const truncateReviewSubject = (subject: string) =>
subject.slice(
0,
splitsSurrogatePair(subject, REVIEW_BRANCH_SUBJECT_LIMIT)
? REVIEW_BRANCH_SUBJECT_LIMIT - 1
: REVIEW_BRANCH_SUBJECT_LIMIT,
);
const REVIEW_BRANCH_COMMIT_MAX_OUTPUT_BYTES = 128 * 1024;
// Client patch parsers require a/ and b/ prefixes; override user diff prefix settings.
export const PATCH_RENDER_PREFIX_ARGS = ["--src-prefix=a/", "--dst-prefix=b/"] as const;
Expand Down Expand Up @@ -5011,7 +5019,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
);
const endOfSubject = result.stdout.indexOf("\n");
return {
subject: result.stdout.slice(0, endOfSubject < 0 ? undefined : endOfSubject).slice(0, 300),
subject: truncateReviewSubject(
result.stdout.slice(0, endOfSubject < 0 ? undefined : endOfSubject),
),
};
});

Expand Down Expand Up @@ -5077,7 +5087,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
) {
return yield* reviewCommitError(cwd, "Could not read branch commit metadata.");
}
commits.push({ sha, subject: subject.slice(0, REVIEW_BRANCH_SUBJECT_LIMIT), committedAt });
commits.push({ sha, subject: truncateReviewSubject(subject), committedAt });
}
if (result.stdoutTruncated && commits.length === 0) {
return yield* reviewCommitError(cwd, "Branch commit metadata exceeds the response limit.");
Expand Down
Loading