@devries-cameron20 / t3code Mirror · read-only / commits / 9def583f8e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 05:45 UTC

fix(gitlab): a signed-out default glab host no longer hides other signed-in hosts (#27840)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 3, 2026 at 12:02 UTC 9def583f8e315f644708501ebcf1f3d4bb320444
3 files changed +125 -18
packages/source-control-core/src/server/discovery.ts
+34 -17
@@ -41,6 +41,8 @@ export type SourceControlCliDiscoverySpec = SourceControlDiscoverySpecBase & {
41 readonly executable: string;
42 readonly versionArgs: ReadonlyArray<string>;
43 readonly authArgs: ReadonlyArray<string>;
44 + /** Asked once when `authArgs` reports signed out; its answer counts only when it finds a sign-in. */
45 + readonly authRetryArgs?: ReadonlyArray<string>;
46 readonly remoteRefinementArgs?: (
47 context: SourceControlProvider.SourceControlProviderContext,
48 ) => ReadonlyArray<string>;
@@ -269,6 +271,37 @@ export function probeSourceControlProvider(input: {
271 }
272
273 const spec = input.spec;
274 + const runAuth = (args: ReadonlyArray<string>) =>
275 + input.process
276 + .run({
277 + operation: "source-control.discovery.auth",
278 + command: spec.executable,
279 + args,
280 + cwd: input.cwd,
281 + allowNonZeroExit: true,
282 + timeoutMs: probeTimeoutMs(spec),
283 + maxOutputBytes: 8_000,
284 + appendTruncationMarker: true,
285 + })
286 + .pipe(
287 + Effect.map(spec.parseAuth),
288 + Effect.catch((cause) =>
289 + Effect.succeed(unknownAuth(Option.getOrUndefined(detailFromCause(cause)))),
290 + ),
291 + );
292 + const retryArgs = spec.authRetryArgs;
293 + const auth =
294 + retryArgs === undefined
295 + ? runAuth(spec.authArgs)
296 + : runAuth(spec.authArgs).pipe(
297 + Effect.filterOrElse(
298 + (result) => result.status !== "unauthenticated",
299 + (signedOut) =>
300 + runAuth(retryArgs).pipe(
301 + Effect.map((retry) => (retry.status === "authenticated" ? retry : signedOut)),
302 + ),
303 + ),
304 + );
305
306 // The auth check does not depend on the version output, so both spawn at once.
307 return Effect.all(
@@ -278,23 +311,7 @@ export function probeSourceControlProvider(input: {
311 process: input.process,
312 cwd: input.cwd,
313 }),
281 - input.process
282 - .run({
283 - operation: "source-control.discovery.auth",
284 - command: spec.executable,
285 - args: spec.authArgs,
286 - cwd: input.cwd,
287 - allowNonZeroExit: true,
288 - timeoutMs: probeTimeoutMs(spec),
289 - maxOutputBytes: 8_000,
290 - appendTruncationMarker: true,
291 - })
292 - .pipe(
293 - Effect.map(spec.parseAuth),
294 - Effect.catch((cause) =>
295 - Effect.succeed(unknownAuth(Option.getOrUndefined(detailFromCause(cause)))),
296 - ),
297 - ),
314 + auth,
315 ],
316 { concurrency: "unbounded" },
317 ).pipe(
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts
+4
@@ -146,7 +146,11 @@ export const discovery = {
146 label: "GitLab",
147 executable: "glab",
148 versionArgs: ["--version"],
149 + // Without --all, glab 1.79+ checks only the current host unless that is gitlab.com; older
150 + // glab lists every host and rejects --all. --all waits on every host, so ask it only after
151 + // the current host reports signed out.
152 authArgs: ["auth", "status"],
153 + authRetryArgs: ["auth", "status", "--all"],
154 // glab host matching requires the remote's exact spelling.
155 remoteRefinementArgs: ({ provider, remoteUrl }) => {
156 const authority = /^[a-z][a-z0-9+.-]*:\/\/([^/]+)/iu.exec(remoteUrl.trim())?.[1];
packages/source-control-gitlab/src/server/gitLabDiscovery.test.ts
+87 -1
@@ -2,7 +2,10 @@ import {
2 parseGitRemoteHost,
3 unknownRemoteProvider,
4 } from "@t3tools/source-control-core/shared/definition";
5 -import { refineUnknownRemoteProvider } from "@t3tools/source-control-core/server/discovery";
5 +import {
6 + probeSourceControlProvider,
7 + refineUnknownRemoteProvider,
8 +} from "@t3tools/source-control-core/server/discovery";
9 import { processOutput } from "@t3tools/source-control-testing/TestSourceControlHost";
10 import { assert, it } from "@effect/vitest";
11 import * as Effect from "effect/Effect";
@@ -21,6 +24,89 @@ Logged in to gitlab.com as gitlab-user
24 assert.deepStrictEqual(auth.account, Option.some("gitlab-user"));
25 });
26
27 +// Without `--all`, glab 1.79+ checks only the current host unless that is gitlab.com.
28 +it.effect("reports a signed-in host when glab's default host is signed out", () =>
29 + Effect.gen(function* () {
30 + const defaultHostOnly = `gitlab.gnome.org
31 + x gitlab.gnome.org: API call failed: GET https://gitlab.gnome.org/api/v4/user: 401 {message: 401 Unauthorized}
32 +`;
33 + const allHosts = `gitlab.com
34 + ✓ Logged in to gitlab.com as gitlab-user (/home/user/.config/glab-cli/config.yml)
35 +${defaultHostOnly}`;
36 + const item = yield* probeSourceControlProvider({
37 + spec: GitLabSourceControlProvider.discovery,
38 + cwd: "/repo",
39 + process: {
40 + run: ({ args }) =>
41 + Effect.succeed(
42 + args[0] === "--version"
43 + ? processOutput("glab 1.124.0\n")
44 + : processOutput(args.includes("--all") ? allHosts : defaultHostOnly, {
45 + exitCode: ChildProcessSpawner.ExitCode(1),
46 + }),
47 + ),
48 + },
49 + });
50 + assert.strictEqual(item.auth.status, "authenticated");
51 + assert.deepStrictEqual(item.auth.account, Option.some("gitlab-user"));
52 + assert.deepStrictEqual(item.auth.host, Option.some("gitlab.com"));
53 + }),
54 +);
55 +
56 +it.effect("skips --all when the current glab host is signed in", () =>
57 + Effect.gen(function* () {
58 + const asked: Array<ReadonlyArray<string>> = [];
59 + const item = yield* probeSourceControlProvider({
60 + spec: GitLabSourceControlProvider.discovery,
61 + cwd: "/repo",
62 + process: {
63 + run: ({ args }) => {
64 + asked.push(args);
65 + return Effect.succeed(
66 + args[0] === "--version"
67 + ? processOutput("glab 1.124.0\n")
68 + : processOutput(`gitlab.example.test
69 + ✓ Logged in to gitlab.example.test as gitlab-user
70 +`),
71 + );
72 + },
73 + },
74 + });
75 + assert.strictEqual(item.auth.status, "authenticated");
76 + assert.isFalse(asked.some((args) => args.includes("--all")));
77 + }),
78 +);
79 +
80 +it.effect("keeps glab's own sign-out detail when glab predates --all", () =>
81 + Effect.gen(function* () {
82 + const item = yield* probeSourceControlProvider({
83 + spec: GitLabSourceControlProvider.discovery,
84 + cwd: "/repo",
85 + process: {
86 + run: ({ args }) =>
87 + Effect.succeed(
88 + args[0] === "--version"
89 + ? processOutput("glab 1.53.0\n")
90 + : args.includes("--all")
91 + ? processOutput("", {
92 + stderr: "unknown flag: --all\n",
93 + exitCode: ChildProcessSpawner.ExitCode(1),
94 + })
95 + : processOutput("", {
96 + stderr: "No GitLab instances have been authenticated with glab.\n",
97 + exitCode: ChildProcessSpawner.ExitCode(1),
98 + }),
99 + ),
100 + },
101 + });
102 + assert.strictEqual(item.auth.status, "unauthenticated");
103 + assert.deepStrictEqual(
104 + item.auth.detail,
105 + Option.some("No GitLab instances have been authenticated with glab."),
106 + );
107 + }),
108 +);
109 +
110 it.effect.each([
111 {
112 name: "without relying on host naming",