Open History to see the last commit
1import {
2 parseGitRemoteHost,
3 unknownRemoteProvider,
4} from "@t3tools/source-control-core/shared/definition";
5import { refineUnknownRemoteProvider } from "@t3tools/source-control-core/server/discovery";
6import { processOutput } from "@t3tools/source-control-testing/TestSourceControlHost";
7import { assert, it } from "@effect/vitest";
8import * as Effect from "effect/Effect";
9import * as Option from "effect/Option";
10import { ChildProcessSpawner } from "effect/process";
11
12import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
13
14it("reads the account from glab output without status marks", () => {
15 const auth = GitLabSourceControlProvider.discovery.parseAuth(
16 processOutput(`gitlab.com
17Logged in to gitlab.com as gitlab-user
18`),
19 );
20 assert.strictEqual(auth.status, "authenticated");
21 assert.deepStrictEqual(auth.account, Option.some("gitlab-user"));
22});
23
24it.effect.each([
25 {
26 name: "without relying on host naming",
27 remoteUrl: "https://self-hosted.example.test/group/project.git",
28 host: "self-hosted.example.test",
29 stdout: `gitlab.com
30 x gitlab.com: API call failed: 401 Unauthorized
31 ! No token found
32self-hosted.example.test
33 ✓ Logged in to self-hosted.example.test as gitlab-user
34 ✓ Token found: ******
35`,
36 exitCode: 1,
37 },
38 {
39 name: "on a non-standard port",
40 remoteUrl: "https://self-hosted.example.test:8443/group/project.git",
41 host: "self-hosted.example.test:8443",
42 stdout: `self-hosted.example.test:8443
43 ✓ Logged in to self-hosted.example.test:8443 as gitlab-user
44 ✓ Token found: ******
45`,
46 exitCode: 0,
47 },
48] as const)("claims a self-hosted remote glab is signed in to $name", (scenario) =>
49 Effect.gen(function* () {
50 const remote = parseGitRemoteHost(scenario.remoteUrl);
51 assert.ok(remote);
52 const asked: Array<ReadonlyArray<string>> = [];
53 const verdict = yield* refineUnknownRemoteProvider({
54 specs: [GitLabSourceControlProvider.discovery],
55 cwd: "/repo",
56 context: {
57 provider: unknownRemoteProvider(remote),
58 remoteName: "origin",
59 remoteUrl: scenario.remoteUrl,
60 },
61 process: {
62 run: ({ command, args }) => {
63 asked.push([command, ...args]);
64 return Effect.succeed(
65 processOutput(scenario.stdout, {
66 exitCode: ChildProcessSpawner.ExitCode(scenario.exitCode),
67 }),
68 );
69 },
70 },
71 });
72 assert.deepStrictEqual(asked, [["glab", "auth", "status", "--hostname", scenario.host]]);
73 assert.strictEqual(verdict.provider?.kind, "gitlab");
74 assert.strictEqual(verdict.settled, true);
75 }),
76);