@devries-cameron20 / t3code-1 / commits / 80b9620454
Fork 0

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

fix(gitlab): Create MR works with snap-installed glab (#31763)

Julius Marminge committed Nov 16, 2026 at 13:17 UTC 80b9620454f29df388659468eb7cc0b213a520ef
9 files changed +119 -8
packages/source-control-gitlab/package.json
+1
@@ -23,6 +23,7 @@
23 "effect": "catalog:"
24 },
25 "devDependencies": {
26 + "@effect/platform-node": "catalog:",
27 "@effect/vitest": "catalog:",
28 "@t3tools/source-control-testing": "workspace:*",
29 "@types/node": "catalog:",
packages/source-control-gitlab/src/server/GitLabCli.test.ts
+60 -4
@@ -1,6 +1,9 @@
1 +import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, it, afterEach, expect, vi } from "@effect/vitest";
3 import * as Effect from "effect/Effect";
4 +import * as FileSystem from "effect/FileSystem";
5 import * as Layer from "effect/Layer";
6 +import * as Path from "effect/Path";
7 import { ChildProcessSpawner } from "effect/process";
8
9 import { VcsProcessExitError } from "@t3tools/contracts";
@@ -11,7 +14,10 @@ import * as GitLabCli from "./GitLabCli.ts";
14
15 const mockedRun = vi.fn<SourceControlHost.SourceControlHost["Service"]["process"]["run"]>();
16 const layer = it.layer(
14 - GitLabCli.layer.pipe(Layer.provide(TestSourceControlHost.layer({ process: { run: mockedRun } }))),
17 + GitLabCli.layer.pipe(
18 + Layer.provide(TestSourceControlHost.layer({ process: { run: mockedRun } })),
19 + Layer.provideMerge(NodeServices.layer),
20 + ),
21 );
22
23 function processOutput(stdout: string): SourceControlHost.SourceControlProcessOutput {
@@ -98,6 +104,54 @@ layer("GitLabCli.layer", (it) => {
104 }),
105 );
106
107 + // A strictly confined glab (Snap) has a private /tmp, so it cannot open the server's body file.
108 + it.effect("sends the merge request description to glab on stdin, not as a file path", () =>
109 + Effect.gen(function* () {
110 + const fileSystem = yield* FileSystem.FileSystem;
111 + const path = yield* Path.Path;
112 + const bodyDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-gitlab-mr-body-" });
113 + const bodyFile = path.join(bodyDir, "t3code-pr-body.md");
114 + yield* fileSystem.writeFileString(bodyFile, "## Summary\n\nFixes the thing.\n");
115 + mockedRun.mockReturnValueOnce(Effect.succeed(processOutput("{}")));
116 +
117 + const glab = yield* GitLabCli.GitLabCli;
118 + yield* glab.createMergeRequest({
119 + cwd: "/repo",
120 + baseBranch: "main",
121 + headSelector: "feature/mr",
122 + title: "Add MR",
123 + bodyFile,
124 + });
125 +
126 + const call = mockedRun.mock.calls.at(-1)?.[0];
127 + expect(call?.args.join(" ")).not.toContain(bodyFile);
128 + expect(call?.args).toContain("description=@-");
129 + assert.strictEqual(call?.stdin, "## Summary\n\nFixes the thing.\n");
130 + }).pipe(Effect.scoped),
131 + );
132 +
133 + it.effect("fails with a typed error and skips glab when the description cannot be read", () =>
134 + Effect.gen(function* () {
135 + const fileSystem = yield* FileSystem.FileSystem;
136 + const path = yield* Path.Path;
137 + const bodyDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-gitlab-mr-body-" });
138 + const glab = yield* GitLabCli.GitLabCli;
139 + const error = yield* glab
140 + .createMergeRequest({
141 + cwd: "/repo",
142 + baseBranch: "main",
143 + headSelector: "feature/mr",
144 + title: "Add MR",
145 + bodyFile: path.join(bodyDir, "missing.md"),
146 + })
147 + .pipe(Effect.flip);
148 +
149 + assert.strictEqual(error._tag, "GitLabMergeRequestBodyReadError");
150 + assert.strictEqual(error.detail, "The merge request description could not be read.");
151 + expect(mockedRun).not.toHaveBeenCalled();
152 + }).pipe(Effect.scoped),
153 + );
154 +
155 it.effect("skips invalid entries when parsing MR lists", () =>
156 Effect.gen(function* () {
157 mockedRun.mockReturnValueOnce(
@@ -209,6 +263,8 @@ layer("GitLabCli.layer", (it) => {
263
264 it.effect("creates same-project MRs without a repository lookup", () =>
265 Effect.gen(function* () {
266 + const fileSystem = yield* FileSystem.FileSystem;
267 + const bodyFile = yield* fileSystem.makeTempFileScoped({ prefix: "t3-gitlab-mr-body-" });
268 mockedRun.mockReturnValueOnce(Effect.succeed(processOutput("{}")));
269 const glab = yield* GitLabCli.GitLabCli;
270 yield* glab.createMergeRequest({
@@ -216,7 +272,7 @@ layer("GitLabCli.layer", (it) => {
272 baseBranch: "main",
273 headSelector: "feature/fix",
274 title: "Fix remote flow",
219 - bodyFile: "/tmp/body.md",
275 + bodyFile,
276 });
277 expect(mockedRun).toHaveBeenCalledExactlyOnceWith(
278 expect.objectContaining({
@@ -232,11 +288,11 @@ layer("GitLabCli.layer", (it) => {
288 "--raw-field",
289 "title=Fix remote flow",
290 "--field",
235 - "description=@/tmp/body.md",
291 + "description=@-",
292 ],
293 }),
294 );
239 - }),
295 + }).pipe(Effect.scoped),
296 );
297
298 it.effect("surfaces a friendly error when the merge request is not found", () =>
packages/source-control-gitlab/src/server/GitLabCli.ts
+35 -1
@@ -1,6 +1,7 @@
1 import * as Context from "effect/Context";
2 import * as Effect from "effect/Effect";
3 import * as Exit from "effect/Exit";
4 +import * as FileSystem from "effect/FileSystem";
5 import * as Layer from "effect/Layer";
6 import * as Match from "effect/Match";
7 import * as Option from "effect/Option";
@@ -238,6 +239,24 @@ export class GitLabNamespaceDecodeError extends Schema.TaggedError<GitLabNamespa
239 }
240 }
241
242 +export class GitLabMergeRequestBodyReadError extends Schema.TaggedError<GitLabMergeRequestBodyReadError>()(
243 + "GitLabMergeRequestBodyReadError",
244 + {
245 + operation: Schema.Literal("createMergeRequest"),
246 + command: Schema.Literal("glab"),
247 + cwd: Schema.String,
248 + cause: Schema.Defect(),
249 + },
250 +) {
251 + get detail(): string {
252 + return "The merge request description could not be read.";
253 + }
254 +
255 + override get message(): string {
256 + return `GitLab CLI failed in ${this.operation}: ${this.detail}`;
257 + }
258 +}
259 +
260 export const GitLabCliError = Schema.Union([
261 GitLabCliUnavailableError,
262 GitLabCliAuthenticationError,
@@ -248,6 +267,7 @@ export const GitLabCliError = Schema.Union([
267 GitLabMergeRequestDecodeError,
268 GitLabRepositoryDecodeError,
269 GitLabNamespaceDecodeError,
270 + GitLabMergeRequestBodyReadError,
271 ]);
272 export type GitLabCliError = typeof GitLabCliError.Type;
273
@@ -459,6 +479,7 @@ const classifyGlabFailure = (stderr: string): VcsProcessExitFailureKind | null =
479 /** @public */
480 export const make = Effect.gen(function* () {
481 const { process } = yield* SourceControlHost.SourceControlHost;
482 + const fileSystem = yield* FileSystem.FileSystem;
483
484 const run = (
485 input: Parameters<GitLabCli["Service"]["execute"]>[0],
@@ -681,6 +702,18 @@ export const make = Effect.gen(function* () {
702 );
703 }),
704 createMergeRequest: Effect.fn("GitLabCli.createMergeRequest")(function* (input) {
705 + // A confined glab (Snap) has a private /tmp, so it cannot open the server's body file.
706 + const description = yield* fileSystem.readFileString(input.bodyFile).pipe(
707 + Effect.mapError(
708 + (cause) =>
709 + new GitLabMergeRequestBodyReadError({
710 + operation: "createMergeRequest",
711 + command: "glab",
712 + cwd: input.cwd,
713 + cause,
714 + }),
715 + ),
716 + );
717 let project = ":fullpath";
718 let targetProjectId: number | undefined;
719 if (input.source?.repository || input.source?.owner) {
@@ -718,8 +751,9 @@ export const make = Effect.gen(function* () {
751 "--raw-field",
752 `title=${input.title}`,
753 "--field",
721 - `description=@${input.bodyFile}`,
754 + "description=@-",
755 ],
756 + stdin: description,
757 });
758 }),
759 getDefaultBranch: Effect.fn("GitLabCli.getDefaultBranch")(function (input) {
packages/source-control-gitlab/src/server/GitLabPullRequestCli.legacy.test.ts
+2
@@ -1,5 +1,6 @@
1 import { afterEach, expect, it, vi } from "@effect/vitest";
2 import * as Effect from "effect/Effect";
3 +import * as FileSystem from "effect/FileSystem";
4 import * as Layer from "effect/Layer";
5 import { ChildProcessSpawner } from "effect/process";
6 import { VcsProcessExitError } from "@t3tools/contracts";
@@ -14,6 +15,7 @@ const layer = it.layer(
15 GitLabPullRequestCli.layer.pipe(
16 Layer.provide(GitLabCli.layer),
17 Layer.provide(TestSourceControlHost.layer({ process: { run } })),
18 + Layer.provide(FileSystem.layerNoop({})),
19 ),
20 );
21 const input = { cwd: "/repo", repository: "acme/nested/web", number: 7 };
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.rateLimit.test.ts
+2
@@ -1,6 +1,7 @@
1 import { VcsProcessExitError } from "@t3tools/contracts";
2 import { expect, it } from "@effect/vitest";
3 import * as Effect from "effect/Effect";
4 +import * as FileSystem from "effect/FileSystem";
5 import * as Layer from "effect/Layer";
6 import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
7
@@ -33,6 +34,7 @@ it.effect("reports activity as rate limited when only the reactions endpoint is"
34 },
35 }),
36 ),
37 + Layer.provide(FileSystem.layerNoop({})),
38 ),
39 ),
40 );
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts
+2 -1
@@ -1,5 +1,6 @@
1 import { assert, describe, expect, it } from "@effect/vitest";
2 import * as Effect from "effect/Effect";
3 +import * as FileSystem from "effect/FileSystem";
4 import * as Layer from "effect/Layer";
5 import * as TestClock from "effect/testing/TestClock";
6
@@ -75,7 +76,7 @@ it.effect.each(["merge", "disable-auto-merge"] as const)(
76 );
77 },
78 },
78 - }),
79 + }).pipe(Layer.merge(FileSystem.layerNoop({}))),
80 ),
81 );
82 const cli = yield* GitLabPullRequestCli.make.pipe(
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.git.test.ts
+2
@@ -7,6 +7,7 @@ import type { GitCommandError } from "@t3tools/contracts";
7
8 import { assert, expect, it } from "@effect/vitest";
9 import * as Effect from "effect/Effect";
10 +import * as FileSystem from "effect/FileSystem";
11 import * as Layer from "effect/Layer";
12 import * as Option from "effect/Option";
13 import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
@@ -59,6 +60,7 @@ it.effect("lists a nested-group fork's merge requests by source branch and names
60 },
61 }),
62 ),
63 + Layer.provide(FileSystem.layerNoop({})),
64 ),
65 ),
66 );
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts
+12 -2
@@ -4,6 +4,7 @@ import { refineUnknownRemoteProvider } from "@t3tools/source-control-core/server
4 import { processOutput } from "@t3tools/source-control-testing/TestSourceControlHost";
5 import { assert, it } from "@effect/vitest";
6 import * as Effect from "effect/Effect";
7 +import * as FileSystem from "effect/FileSystem";
8 import * as Layer from "effect/Layer";
9 import * as Option from "effect/Option";
10 import { ChildProcessSpawner } from "effect/process";
@@ -333,14 +334,23 @@ it.effect.each([
334 "--raw-field",
335 "title=Fix remote flow",
336 "--field",
336 - "description=@/tmp/body.md",
337 + "description=@-",
338 ]);
339 + assert.strictEqual(input.stdin, "Body");
340 return Effect.succeed(processOutput("{}"));
341 },
342 },
343 });
344 const provider = yield* GitLabSourceControlProvider.make.pipe(
343 - Effect.provide(Layer.merge(host, GitLabCli.layer.pipe(Layer.provide(host)))),
345 + Effect.provide(
346 + Layer.merge(
347 + host,
348 + GitLabCli.layer.pipe(
349 + Layer.provide(host),
350 + Layer.provide(FileSystem.layerNoop({ readFileString: () => Effect.succeed("Body") })),
351 + ),
352 + ),
353 + ),
354 );
355 yield* provider.createChangeRequest({
356 cwd: "/repo",
pnpm-lock.yaml
+3
@@ -2437,6 +2437,9 @@ importers:
2437 specifier: 4.1.3
2438 version: 4.1.3
2439 devDependencies:
2440 + '@effect/platform-node':
2441 + specifier: 4.1.2
2442 + version: 4.1.2(bufferutil@4.1.0)(effect@4.1.3)(redis@6.2.1)(utf-8-validate@6.0.6)
2443 '@effect/vitest':
2444 specifier: 4.1.2
2445 version: 4.1.2(patch_hash=299510b71c36537a832a67e9d160a5f112a5f326a29e95c41cb45fc8234e47c7)(@astrojs/compiler-rs@0.5.1)(@types/node@24.12.4)(@vitest/browser-playwright@5.0.5)(@vitest/ui@5.0.5)(@volar/typescript@2.4.28(typescript@6.0.3))(bufferutil@4.1.0)(effect@4.1.3)(esbuild@0.28.2)(jiti@2.7.0)(jsdom@30.1.0(@noble/hashes@1.8.0))(playwright@1.64.1)(terser@5.48.0)(typescript@6.0.3)(unrun@0.2.39)(utf-8-validate@6.0.6)(yaml@2.9.0)