Skip to content

Commit dc88184

Browse files
IAmJSDcursoragent
andcommitted
fix(vcs): classify not-found before access-rights, stabilize locale
GitHub/GitLab SSH failures for a missing repo include both "not found" and the "access rights" footer; matching the footer first mislabeled them as auth. Also force LC_ALL=C on paths that classify failures so translated stderr cannot miss the English heuristics. Co-authored-by: Cursor <[email protected]>
1 parent b68ec7f commit dc88184

2 files changed

Lines changed: 78 additions & 9 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,19 +770,73 @@ for (const failure of localPermissionFailures) {
770770
});
771771
}
772772

773+
it.effect("prefers not-found over the access-rights footer git pairs with it", () => {
774+
// GitHub/GitLab SSH for a missing repo writes both lines. Matching
775+
// "access rights" first would call that authentication.
776+
const failing = makeFailingGitLayer(
777+
`ERROR: Repository not found.\n` +
778+
`fatal: Could not read from remote repository.\n` +
779+
`Please make sure you have the correct access rights\n` +
780+
`and the repository exists.\n`,
781+
);
782+
783+
return Effect.scoped(
784+
Effect.gen(function* () {
785+
const driver = yield* GitVcsDriver.GitVcsDriver;
786+
const cwd = yield* makeTmpDir();
787+
const error = yield* driver
788+
.execute({
789+
operation: "GitVcsDriver.test.notFoundWithAccessRights",
790+
cwd,
791+
args: ["clone", "[email protected]:owner/missing.git", "projects"],
792+
})
793+
.pipe(Effect.flip);
794+
795+
assert.equal(failing.spawns.length, 1);
796+
assert.instanceOf(error, GitCommandError);
797+
assert.equal(error.failureKind, "not-found");
798+
assert.notInclude(error.detail.toLowerCase(), "authentication");
799+
assert.notInclude(error.detail.toLowerCase(), "credentials");
800+
}),
801+
).pipe(Effect.provide(failing.layer));
802+
});
803+
773804
it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
774805
describe("process environment", () => {
775-
it.effect("preserves the caller locale for general Git subprocesses", () =>
806+
it.effect("preserves the caller locale when non-zero exits are returned raw", () =>
776807
Effect.gen(function* () {
777808
const cwd = yield* makeTmpDir();
809+
const driver = yield* GitVcsDriver.GitVcsDriver;
778810

779-
const locale = yield* git(
811+
// allowNonZeroExit skips classification, so the caller's locale rides
812+
// through with the raw stdout/stderr instead of being forced to C.
813+
const result = yield* driver.execute({
814+
operation: "GitVcsDriver.test.printLocale",
780815
cwd,
781-
["-c", 'alias.print-locale=!printf "%s" "$LC_ALL"', "print-locale"],
782-
{ LC_ALL: "zh_CN.UTF-8" },
783-
);
816+
args: ["-c", 'alias.print-locale=!printf "%s" "$LC_ALL"', "print-locale"],
817+
env: { LC_ALL: "zh_CN.UTF-8" },
818+
allowNonZeroExit: true,
819+
timeoutMs: 10_000,
820+
});
821+
822+
assert.equal(result.stdout.trim(), "zh_CN.UTF-8");
823+
}),
824+
);
825+
826+
it.effect("forces a stable locale when a failure will be classified", () =>
827+
Effect.gen(function* () {
828+
const cwd = yield* makeTmpDir();
829+
const driver = yield* GitVcsDriver.GitVcsDriver;
830+
831+
const result = yield* driver.execute({
832+
operation: "GitVcsDriver.test.printLocaleClassified",
833+
cwd,
834+
args: ["-c", 'alias.print-locale=!printf "%s" "$LC_ALL"', "print-locale"],
835+
env: { LC_ALL: "zh_CN.UTF-8" },
836+
timeoutMs: 10_000,
837+
});
784838

785-
assert.equal(locale, "zh_CN.UTF-8");
839+
assert.equal(result.stdout.trim(), "C");
786840
}),
787841
);
788842
});

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,6 @@ const classifyGitFailure = (stderr: string): VcsProcessExitFailureKind => {
413413
normalized.includes("could not read password") ||
414414
normalized.includes("invalid username or password") ||
415415
normalized.includes("authentication required") ||
416-
// "...make sure you have the correct access rights and the repository exists."
417-
normalized.includes("access rights") ||
418416
// ssh names the methods it tried: "Permission denied (publickey)." A bare
419417
// "permission denied" is a local filesystem error — `git init` into an
420418
// unwritable directory reaches this function too, and telling someone to
@@ -425,9 +423,16 @@ const classifyGitFailure = (stderr: string): VcsProcessExitFailureKind => {
425423
) {
426424
return "authentication";
427425
}
426+
// Before the generic "access rights" footer: GitHub/GitLab SSH failures for a
427+
// missing repo include both "Repository not found" and "correct access rights",
428+
// and the actionable classification is not-found.
428429
if (normalized.includes("not found") || normalized.includes("does not exist")) {
429430
return "not-found";
430431
}
432+
// "...make sure you have the correct access rights and the repository exists."
433+
if (normalized.includes("access rights")) {
434+
return "authentication";
435+
}
431436
return "command-failed";
432437
};
433438

@@ -815,13 +820,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
815820
}),
816821
),
817822
);
823+
// Classified failures match English stderr. When this path will turn a
824+
// non-zero exit into a failureKind, force a stable locale so translated
825+
// git text cannot miss every heuristic. allowNonZeroExit callers get
826+
// the caller's locale back with the raw output instead.
818827
const child = yield* commandSpawner
819828
.spawn(
820829
ChildProcess.make("git", commandInput.args, {
821830
cwd: commandInput.cwd,
822831
env: {
823832
...process.env,
824833
...input.env,
834+
...(input.allowNonZeroExit ? {} : { LC_ALL: "C" }),
825835
...trace2Monitor.env,
826836
},
827837
}),
@@ -956,8 +966,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
956966
operation,
957967
cwd,
958968
args,
969+
// execute always allows non-zero so this wrapper can classify; force a
970+
// stable locale whenever that classification will run (see executeRaw).
971+
env: {
972+
...options.env,
973+
...(options.allowNonZeroExit ? {} : { LC_ALL: "C" }),
974+
},
959975
...(options.stdin !== undefined ? { stdin: options.stdin } : {}),
960-
...(options.env !== undefined ? { env: options.env } : {}),
961976
allowNonZeroExit: true,
962977
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
963978
...(options.maxOutputBytes !== undefined ? { maxOutputBytes: options.maxOutputBytes } : {}),

0 commit comments

Comments
 (0)