GeezerVison is showing github.com — fix(vcs): keep emoji intact in review commit subjects (#43030) · patroza/t3code@b9b1f57
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.test.ts +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3759,6 +3759,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { | 3759 | 3759 | }), | 3760 | 3760 | ); | 3761 | 3761 |
| | 3762 | + it.effect("cuts long commit subjects without splitting an emoji", () => | | 3763 | + Effect.gen(function* () { | | 3764 | + const cwd = yield* makeTmpDir(); | | 3765 | + const { initialBranch } = yield* initRepoWithCommit(cwd); | | 3766 | + const driver = yield* GitVcsDriver.GitVcsDriver; | | 3767 | + yield* git(cwd, ["checkout", "-b", "feature/emoji-subject"]); | | 3768 | + yield* git(cwd, ["commit", "--allow-empty", "-m", `${"a".repeat(299)}😀 tail`]); | | 3769 | + const sha = yield* git(cwd, ["rev-parse", "HEAD"]); | | 3770 | + | | 3771 | + const branch = yield* driver.getReviewBranchCommits({ cwd, baseRef: initialBranch }); | | 3772 | + const preview = yield* driver.getReviewDiffPreview({ cwd, commitSha: sha }); | | 3773 | + const commitSubject = preview.sources.find( | | 3774 | + (candidate) => candidate.kind === "commit", | | 3775 | + )?.commitSubject; | | 3776 | + assert.deepStrictEqual( | | 3777 | + [branch.commits[0]?.subject, commitSubject], | | 3778 | + ["a".repeat(299), "a".repeat(299)], | | 3779 | + ); | | 3780 | + }), | | 3781 | + ); | | 3782 | + | 3762 | 3783 | it.effect("previews one selected commit, a merge against its first parent", () => | 3763 | 3784 | Effect.gen(function* () { | 3764 | 3785 | const cwd = yield* makeTmpDir(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.ts +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,7 @@ import { | 37 | 37 | trimAsciiWhitespace, | 38 | 38 | type VcsRef, | 39 | 39 | } from "@t3tools/contracts"; | | 40 | +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; | 40 | 41 | import { dedupeRemoteBranchesWithLocalMatches } from "@t3tools/shared/git"; | 41 | 42 | import * as HostProcess from "@t3tools/shared/HostProcess"; | 42 | 43 | import { compactTraceAttributes } from "@t3tools/shared/observability"; | @@ -104,6 +105,13 @@ const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024; | 104 | 105 | const GIT_IDENT_KEYWORD = /\$Id:[^$\n]*\$/g; | 105 | 106 | const REVIEW_BRANCH_COMMIT_LIMIT = 100; | 106 | 107 | const REVIEW_BRANCH_SUBJECT_LIMIT = 300; | | 108 | +const truncateReviewSubject = (subject: string) => | | 109 | + subject.slice( | | 110 | + 0, | | 111 | + splitsSurrogatePair(subject, REVIEW_BRANCH_SUBJECT_LIMIT) | | 112 | + ? REVIEW_BRANCH_SUBJECT_LIMIT - 1 | | 113 | + : REVIEW_BRANCH_SUBJECT_LIMIT, | | 114 | + ); | 107 | 115 | const REVIEW_BRANCH_COMMIT_MAX_OUTPUT_BYTES = 128 * 1024; | 108 | 116 | // Client patch parsers require a/ and b/ prefixes; override user diff prefix settings. | 109 | 117 | export const PATCH_RENDER_PREFIX_ARGS = ["--src-prefix=a/", "--dst-prefix=b/"] as const; | @@ -5011,7 +5019,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | 5011 | 5019 | ); | 5012 | 5020 | const endOfSubject = result.stdout.indexOf("\n"); | 5013 | 5021 | return { | 5014 | | - subject: result.stdout.slice(0, endOfSubject < 0 ? undefined : endOfSubject).slice(0, 300), | | 5022 | + subject: truncateReviewSubject( | | 5023 | + result.stdout.slice(0, endOfSubject < 0 ? undefined : endOfSubject), | | 5024 | + ), | 5015 | 5025 | }; | 5016 | 5026 | }); | 5017 | 5027 |
| @@ -5077,7 +5087,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | 5077 | 5087 | ) { | 5078 | 5088 | return yield* reviewCommitError(cwd, "Could not read branch commit metadata."); | 5079 | 5089 | } | 5080 | | - commits.push({ sha, subject: subject.slice(0, REVIEW_BRANCH_SUBJECT_LIMIT), committedAt }); | | 5090 | + commits.push({ sha, subject: truncateReviewSubject(subject), committedAt }); | 5081 | 5091 | } | 5082 | 5092 | if (result.stdoutTruncated && commits.length === 0) { | 5083 | 5093 | return yield* reviewCommitError(cwd, "Branch commit metadata exceeds the response limit."); | |
|