fix(source-control): handle self-hosted GitLab, multi-account GitHub auth & azure devops web url (#2480)

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Guilherme VieiraandJulius Marminge authored and GitHub committed 2026-06-04 15:13:04 -07:00
1 parent dfdb5a46db
commit 49c1b64687
14 files changed
+757 -48

No files matched your search

@@ -2,8 +2,10 @@ import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import { ChildProcessSpawner } from "effect/unstable/process";
import * as GitLabCli from "./GitLabCli.ts";
import { parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) {
@@ -107,3 +109,73 @@ it.effect("creates GitLab MRs through provider-neutral input names", () =>
});
}),
);
it("accepts authenticated GitLab hosts when another configured host fails", () => {
const auth = GitLabSourceControlProvider.discovery.parseAuth({
exitCode: ChildProcessSpawner.ExitCode(1),
stdout: `gitlab.com
x gitlab.com: API call failed: 401 Unauthorized
! No token found
self-hosted.example.test
✓ Logged in to self-hosted.example.test as gitlab-user
✓ Token found: ******
`,
stderr: "",
});
assert.deepStrictEqual(
{
status: auth.status,
account: auth.account,
host: auth.host,
},
{
status: "authenticated",
account: Option.some("gitlab-user"),
host: Option.some("self-hosted.example.test"),
},
);
});
it("refines unknown GitLab remotes with mixed-case provider hosts", () => {
const provider = GitLabSourceControlProvider.discovery.refineUnknownRemote?.({
cwd: "/repo",
context: {
provider: {
kind: "unknown",
name: "Self-Hosted.Example.Test",
baseUrl: "https://Self-Hosted.Example.Test",
},
remoteName: "origin",
remoteUrl: "https://Self-Hosted.Example.Test/group/project.git",
},
auth: {
exitCode: ChildProcessSpawner.ExitCode(0),
stdout: `self-hosted.example.test
✓ Logged in to self-hosted.example.test as gitlab-user
✓ Token found: ******
`,
stderr: "",
},
});
assert.deepStrictEqual(provider, {
kind: "gitlab",
name: "GitLab Self-Hosted",
baseUrl: "https://Self-Hosted.Example.Test",
});
});
it("parses authenticated GitLab auth status hosts with ports and single-label names", () => {
assert.deepStrictEqual(
parseGitLabAuthStatusHosts(`localhost:8080
✓ Logged in to localhost:8080 as local-user
selfhosted
✓ Logged in to selfhosted as single-label-user
`),
[
{ host: "localhost:8080", account: "local-user" },
{ host: "selfhosted", account: "single-label-user" },
],
);
});