Showing the changes to apps/server/src/sourceControl/GitLabSourceControlProvider.test.ts (1 of 14 files). Show all
Unified · Split
| @@ -2,8 +2,10 @@ import { assert, it } from "@effect/vitest"; · 1 unmodified line | |||
| 2 | import * as Effect from "effect/Effect"; | 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; | 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as Option from "effect/Option"; | 4 | import * as Option from "effect/Option"; |
| 5 | import { ChildProcessSpawner } from "effect/unstable/process"; | ||
| 5 | 6 | ||
| 6 | import * as GitLabCli from "./GitLabCli.ts"; | 7 | import * as GitLabCli from "./GitLabCli.ts"; |
| 8 | import { parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts"; | ||
| 7 | import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts"; | 9 | import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts"; |
| 8 | 10 | ||
| 9 | function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) { | 11 | function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) { |
| @@ -107,3 +109,73 @@ it.effect("creates GitLab MRs through provider-neutral input names", () => · 97 unmodified lines | |||
| 107 | }); | 109 | }); |
| 108 | }), | 110 | }), |
| 109 | ); | 111 | ); |
| 112 | |||
| 113 | it("accepts authenticated GitLab hosts when another configured host fails", () => { | ||
| 114 | const auth = GitLabSourceControlProvider.discovery.parseAuth({ | ||
| 115 | exitCode: ChildProcessSpawner.ExitCode(1), | ||
| 116 | stdout: `gitlab.com | ||
| 117 | x gitlab.com: API call failed: 401 Unauthorized | ||
| 118 | ! No token found | ||
| 119 | self-hosted.example.test | ||
| 120 | ✓ Logged in to self-hosted.example.test as gitlab-user | ||
| 121 | ✓ Token found: ****** | ||
| 122 | `, | ||
| 123 | stderr: "", | ||
| 124 | }); | ||
| 125 | |||
| 126 | assert.deepStrictEqual( | ||
| 127 | { | ||
| 128 | status: auth.status, | ||
| 129 | account: auth.account, | ||
| 130 | host: auth.host, | ||
| 131 | }, | ||
| 132 | { | ||
| 133 | status: "authenticated", | ||
| 134 | account: Option.some("gitlab-user"), | ||
| 135 | host: Option.some("self-hosted.example.test"), | ||
| 136 | }, | ||
| 137 | ); | ||
| 138 | }); | ||
| 139 | |||
| 140 | it("refines unknown GitLab remotes with mixed-case provider hosts", () => { | ||
| 141 | const provider = GitLabSourceControlProvider.discovery.refineUnknownRemote?.({ | ||
| 142 | cwd: "/repo", | ||
| 143 | context: { | ||
| 144 | provider: { | ||
| 145 | kind: "unknown", | ||
| 146 | name: "Self-Hosted.Example.Test", | ||
| 147 | baseUrl: "https://Self-Hosted.Example.Test", | ||
| 148 | }, | ||
| 149 | remoteName: "origin", | ||
| 150 | remoteUrl: "https://Self-Hosted.Example.Test/group/project.git", | ||
| 151 | }, | ||
| 152 | auth: { | ||
| 153 | exitCode: ChildProcessSpawner.ExitCode(0), | ||
| 154 | stdout: `self-hosted.example.test | ||
| 155 | ✓ Logged in to self-hosted.example.test as gitlab-user | ||
| 156 | ✓ Token found: ****** | ||
| 157 | `, | ||
| 158 | stderr: "", | ||
| 159 | }, | ||
| 160 | }); | ||
| 161 | |||
| 162 | assert.deepStrictEqual(provider, { | ||
| 163 | kind: "gitlab", | ||
| 164 | name: "GitLab Self-Hosted", | ||
| 165 | baseUrl: "https://Self-Hosted.Example.Test", | ||
| 166 | }); | ||
| 167 | }); | ||
| 168 | |||
| 169 | it("parses authenticated GitLab auth status hosts with ports and single-label names", () => { | ||
| 170 | assert.deepStrictEqual( | ||
| 171 | parseGitLabAuthStatusHosts(`localhost:8080 | ||
| 172 | ✓ Logged in to localhost:8080 as local-user | ||
| 173 | selfhosted | ||
| 174 | ✓ Logged in to selfhosted as single-label-user | ||
| 175 | `), | ||
| 176 | [ | ||
| 177 | { host: "localhost:8080", account: "local-user" }, | ||
| 178 | { host: "selfhosted", account: "single-label-user" }, | ||
| 179 | ], | ||
| 180 | ); | ||
| 181 | }); | ||