Repository navigation
fix(server): name the cause of a failed git command #8645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 5 commits into
pingdotgg:main
from
walid-baharwal:fix/git-error-stderr-excerpt
Oct 5, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
61b8981
fix(server): name the cause of a failed git command
walid-baharwal 3a596fd
Merge remote-tracking branch 'origin/main' into pr-8645
juliusmarminge 1a2d288
fix(server): ignore remote-echoed ssh refusals when classifying git f…
juliusmarminge 99756d5
test(server): table-drive ssh refusal cases with it.effect.each
juliusmarminge bd57f54
Merge remote-tracking branch 'origin/main' into pr-8645
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1007,6 +1007,279 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => { | |
| assert.notInclude(error.message, secret); | ||
| assert.notProperty(error, "args"); | ||
| assert.notProperty(error, "stderr"); | ||
| assert.notProperty(error, "reason"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("names the branch conflict behind a failed worktree add", () => | ||
| Effect.gen(function* () { | ||
| const parent = yield* makeTmpDir(); | ||
| const pathService = yield* Path.Path; | ||
| const cwd = pathService.join(parent, "repo"); | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| yield* fileSystem.makeDirectory(cwd); | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* initRepoWithCommit(cwd); | ||
| const firstWorktree = pathService.join(parent, "first"); | ||
| yield* git(cwd, ["worktree", "add", firstWorktree, "-b", "shared-branch"]); | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.worktreeAddConflict", | ||
| cwd, | ||
| args: ["worktree", "add", pathService.join(parent, "second"), "shared-branch"], | ||
| env: { LC_ALL: "C" }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.deepInclude(error, { | ||
| _tag: "GitCommandError", | ||
| operation: "GitVcsDriver.test.worktreeAddConflict", | ||
| reason: "branch_checked_out_in_worktree", | ||
| }); | ||
| assert.include(error.message, "(branch_checked_out_in_worktree)"); | ||
| assert.notInclude(error.message, firstWorktree); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("names a missing repository behind a failed command", () => | ||
| Effect.gen(function* () { | ||
| const cwd = yield* makeTmpDir(); | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.notARepository", | ||
| cwd, | ||
| args: ["rev-parse", "--abbrev-ref", "HEAD"], | ||
| env: { LC_ALL: "C" }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.deepInclude(error, { | ||
| _tag: "GitCommandError", | ||
| operation: "GitVcsDriver.test.notARepository", | ||
| reason: "not_a_repository", | ||
| }); | ||
| assert.include(error.message, "(not_a_repository)"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("appends the reason tag to a caller-supplied detail", () => | ||
| Effect.gen(function* () { | ||
| const parent = yield* makeTmpDir(); | ||
| const pathService = yield* Path.Path; | ||
| const cwd = pathService.join(parent, "repo"); | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| yield* fileSystem.makeDirectory(cwd); | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* initRepoWithCommit(cwd); | ||
| yield* git(cwd, [ | ||
| "worktree", | ||
| "add", | ||
| pathService.join(parent, "taken"), | ||
| "-b", | ||
| "taken-branch", | ||
| ]); | ||
|
|
||
| const error = yield* driver | ||
| .createWorktree({ | ||
| cwd, | ||
| refName: "taken-branch", | ||
| path: pathService.join(parent, "second"), | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.equal(error.detail, "git worktree add failed"); | ||
| assert.include(error.message, "git worktree add failed (branch_checked_out_in_worktree)"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect.each([ | ||
| { | ||
| label: "a refused key", | ||
| sshMessage: "[email protected]: Permission denied (publickey).", | ||
| expectedReason: "authentication_failed" as const, | ||
| expectedText: "(authentication_failed)", | ||
| }, | ||
| { | ||
| label: "a refused key among several methods", | ||
| sshMessage: "[email protected]: Permission denied (publickey,password).", | ||
| expectedReason: "authentication_failed" as const, | ||
| expectedText: "(authentication_failed)", | ||
| }, | ||
| { | ||
| label: "a refused keyboard-interactive attempt", | ||
| sshMessage: "[email protected]: Permission denied (keyboard-interactive).", | ||
| expectedReason: "authentication_failed" as const, | ||
| expectedText: "(authentication_failed)", | ||
| }, | ||
| { | ||
| label: "a rejected password", | ||
| sshMessage: "Permission denied, please try again.", | ||
| expectedReason: "authentication_failed" as const, | ||
| expectedText: "(authentication_failed)", | ||
| }, | ||
| { | ||
| label: "an untrusted host key", | ||
| sshMessage: "Host key verification failed.", | ||
| expectedReason: "host_key_unverified" as const, | ||
| expectedText: "(host_key_unverified)", | ||
| }, | ||
| ])( | ||
| "names $label rather than an unreachable remote", | ||
| ({ sshMessage, expectedReason, expectedText }) => | ||
| Effect.gen(function* () { | ||
| const parent = yield* makeTmpDir(); | ||
| const pathService = yield* Path.Path; | ||
| const cwd = pathService.join(parent, "repo"); | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* fileSystem.makeDirectory(cwd); | ||
| yield* initRepoWithCommit(cwd); | ||
| yield* git(cwd, ["remote", "add", "origin", "[email protected]:owner/repo.git"]); | ||
| // Stands in for ssh, which prints its refusal unprefixed and leaves | ||
| // git to add only a generic "could not read" line after it. | ||
| const fakeSsh = pathService.join(parent, "fake-ssh"); | ||
| yield* writeTextFile( | ||
| parent, | ||
| "fake-ssh", | ||
| `#!/bin/sh\necho "${sshMessage}" >&2\nexit 255\n`, | ||
| ); | ||
| yield* fileSystem.chmod(fakeSsh, 0o755); | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.sshRefusal", | ||
| cwd, | ||
| args: ["fetch", "origin"], | ||
| env: { LC_ALL: "C", GIT_SSH_COMMAND: fakeSsh }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.deepInclude(error, { reason: expectedReason }); | ||
| assert.include(error.message, expectedText); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("does not read a filesystem permission error as an ssh refusal", () => | ||
| Effect.gen(function* () { | ||
| const parent = yield* makeTmpDir(); | ||
| const pathService = yield* Path.Path; | ||
| const cwd = pathService.join(parent, "repo"); | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* fileSystem.makeDirectory(cwd); | ||
| yield* initRepoWithCommit(cwd); | ||
| yield* git(cwd, ["remote", "add", "origin", "[email protected]:owner/repo.git"]); | ||
| const fakeSsh = pathService.join(parent, "fake-ssh"); | ||
| yield* writeTextFile( | ||
| parent, | ||
| "fake-ssh", | ||
| '#!/bin/sh\necho "fatal: cannot open backup file: Permission denied (os error 13)" >&2\nexit 255\n', | ||
| ); | ||
| yield* fileSystem.chmod(fakeSsh, 0o755); | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.osPermission", | ||
| cwd, | ||
| args: ["fetch", "origin"], | ||
| env: { LC_ALL: "C", GIT_SSH_COMMAND: fakeSsh }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.notInclude(error.message, "(authentication_failed)"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("does not read remote hook output as a git failure reason", () => | ||
| Effect.gen(function* () { | ||
| const parent = yield* makeTmpDir(); | ||
| const pathService = yield* Path.Path; | ||
| const remote = pathService.join(parent, "origin.git"); | ||
| const cwd = pathService.join(parent, "work"); | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* fileSystem.makeDirectory(cwd); | ||
| yield* initRepoWithCommit(cwd); | ||
| yield* git(cwd, ["init", "--bare", remote]); | ||
| yield* git(cwd, ["remote", "add", "origin", remote]); | ||
| // Git prefixes everything the server says with `remote:`, so a remote | ||
| // hook can put arbitrary text in front of the classifier. | ||
| const preReceive = pathService.join(remote, "hooks", "pre-receive"); | ||
| yield* writeTextFile( | ||
| remote, | ||
| "hooks/pre-receive", | ||
| '#!/bin/sh\necho "authentication failed" >&2\necho "Permission denied (publickey)." >&2\necho "Host key verification failed." >&2\nexit 1\n', | ||
| ); | ||
| yield* fileSystem.chmod(preReceive, 0o755); | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.remoteHookOutput", | ||
| cwd, | ||
| args: ["push", "origin", "HEAD"], | ||
| env: { LC_ALL: "C" }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.notProperty(error, "reason"); | ||
| assert.notInclude(error.message, "(authentication_failed)"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("does not read hook output as a git failure reason", () => | ||
| Effect.gen(function* () { | ||
| const parent = yield* makeTmpDir(); | ||
| const pathService = yield* Path.Path; | ||
| const remote = pathService.join(parent, "origin.git"); | ||
| const cwd = pathService.join(parent, "work"); | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* fileSystem.makeDirectory(cwd); | ||
| yield* initRepoWithCommit(cwd); | ||
| yield* git(cwd, ["init", "--bare", remote]); | ||
| yield* git(cwd, ["remote", "add", "origin", remote]); | ||
| yield* writeTextFile( | ||
| cwd, | ||
| ".git/hooks/pre-push", | ||
| '#!/bin/sh\necho "authentication failed" >&2\nexit 1\n', | ||
| ); | ||
| yield* fileSystem.chmod(pathService.join(cwd, ".git/hooks/pre-push"), 0o755); | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.hookOutput", | ||
| cwd, | ||
| args: ["push", "origin", "HEAD"], | ||
| env: { LC_ALL: "C" }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.notProperty(error, "reason"); | ||
| assert.notInclude(error.message, "(authentication_failed)"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("leaves a tag collision unclassified rather than calling it a path", () => | ||
| Effect.gen(function* () { | ||
| const cwd = yield* makeTmpDir(); | ||
| const driver = yield* GitVcsDriver.GitVcsDriver; | ||
| yield* initRepoWithCommit(cwd); | ||
| yield* git(cwd, ["tag", "v1"]); | ||
|
|
||
| const error = yield* driver | ||
| .execute({ | ||
| operation: "GitVcsDriver.test.tagCollision", | ||
| cwd, | ||
| args: ["tag", "v1"], | ||
| env: { LC_ALL: "C" }, | ||
| }) | ||
| .pipe(Effect.flip); | ||
|
|
||
| assert.notProperty(error, "reason"); | ||
| assert.notInclude(error.message, "(path_already_exists)"); | ||
| }), | ||
| ); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.