Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitManager.test.ts

746 lines23.6 KB

1import fs from "node:fs";
2import path from "node:path";
3​
4import * as NodeServices from "@effect/platform-node/NodeServices";
5import { it } from "@effect/vitest";
6import { Effect, FileSystem, Layer, PlatformError, Scope } from "effect";
7import { expect } from "vitest";
8​
9import { GitCommandError, GitHubCliError, TextGenerationError } from "../Errors.ts";
10import { type GitManagerShape } from "../Services/GitManager.ts";
11import {
12 type GitHubCliShape,
13 type GitHubPullRequestSummary,
14 GitHubCli,
15} from "../Services/GitHubCli.ts";
16import { type TextGenerationShape, TextGeneration } from "../Services/TextGeneration.ts";
17import { GitServiceLive } from "./GitService.ts";
18import { GitService } from "../Services/GitService.ts";
19import { GitCoreLive } from "./GitCore.ts";
20import { makeGitManager } from "./GitManager.ts";
21​
22interface FakeGhScenario {
23 prListSequence?: string[];
24 createdPrUrl?: string;
25 defaultBranch?: string;
26 failWith?: GitHubCliError;
28​
29interface FakeGitTextGeneration {
30 generateCommitMessage: (input: {
31 cwd: string;
32 branch: string | null;
33 stagedSummary: string;
34 stagedPatch: string;
35 }) => Effect.Effect<{ subject: string; body: string }, TextGenerationError>;
36 generatePrContent: (input: {
37 cwd: string;
38 baseBranch: string;
39 headBranch: string;
40 commitSummary: string;
41 diffSummary: string;
42 diffPatch: string;
43 }) => Effect.Effect<{ title: string; body: string }, TextGenerationError>;
44 generateBranchName: (input: {
45 cwd: string;
46 message: string;
47 }) => Effect.Effect<{ branch: string }, TextGenerationError>;
49​
50function makeTempDir(
51 prefix: string,
52): Effect.Effect<string, PlatformError.PlatformError, FileSystem.FileSystem | Scope.Scope> {
53 return Effect.gen(function* () {
54 const fileSystem = yield* FileSystem.FileSystem;
55 return yield* fileSystem.makeTempDirectoryScoped({ prefix });
56 });
58​
59function runGit(
60 cwd: string,
61 args: readonly string[],
62 allowNonZeroExit = false,
63): Effect.Effect<
64 { readonly code: number; readonly stdout: string; readonly stderr: string },
65 GitCommandError,
66 GitService
67> {
68 return Effect.gen(function* () {
69 const gitService = yield* GitService;
70 return yield* gitService.execute({
71 operation: "GitManager.test.runGit",
72 cwd,
73 args,
74 allowNonZeroExit,
75 });
76 });
78​
79function initRepo(
80 cwd: string,
81): Effect.Effect<void, PlatformError.PlatformError | GitCommandError, FileSystem.FileSystem | Scope.Scope | GitService> {
82 return Effect.gen(function* () {
83 const fs = yield* FileSystem.FileSystem;
84 yield* runGit(cwd, ["init", "--initial-branch=main"]);
85 yield* runGit(cwd, ["config", "user.email", "test@example.com"]);
86 yield* runGit(cwd, ["config", "user.name", "Test User"]);
87 yield* fs.writeFileString(path.join(cwd, "README.md"), "hello\n");
88 yield* runGit(cwd, ["add", "README.md"]);
89 yield* runGit(cwd, ["commit", "-m", "Initial commit"]);
90 });
92​
93function createBareRemote(): Effect.Effect<
94 string,
95 PlatformError.PlatformError | GitCommandError,
96 FileSystem.FileSystem | Scope.Scope | GitService
97> {
98 return Effect.gen(function* () {
99 const remoteDir = yield* makeTempDir("t3code-git-remote-");
100 yield* runGit(remoteDir, ["init", "--bare"]);
101 return remoteDir;
102 });
104​
105function createTextGeneration(overrides: Partial<FakeGitTextGeneration> = {}): TextGenerationShape {
106 const implementation: FakeGitTextGeneration = {
107 generateCommitMessage: () =>
108 Effect.succeed({
109 subject: "Implement stacked git actions",
110 body: "",
111 }),
112 generatePrContent: () =>
113 Effect.succeed({
114 title: "Add stacked git actions",
115 body: "## Summary\n- Add stacked git workflow\n\n## Testing\n- Not run",
116 }),
117 generateBranchName: () =>
118 Effect.succeed({
119 branch: "update-workflow",
120 }),
121 ...overrides,
122 };
123​
124 return {
125 generateCommitMessage: (input) =>
126 implementation.generateCommitMessage(input).pipe(
127 Effect.mapError(
128 (cause) =>
129 new TextGenerationError({
130 operation: "generateCommitMessage",
131 detail: "fake text generation failed",
132 ...(cause !== undefined ? { cause } : {}),
133 }),
134 ),
135 ),
136 generatePrContent: (input) =>
137 implementation.generatePrContent(input).pipe(
138 Effect.mapError(
139 (cause) =>
140 new TextGenerationError({
141 operation: "generatePrContent",
142 detail: "fake text generation failed",
143 ...(cause !== undefined ? { cause } : {}),
144 }),
145 ),
146 ),
147 generateBranchName: (input) =>
148 implementation.generateBranchName(input).pipe(
149 Effect.mapError(
150 (cause) =>
151 new TextGenerationError({
152 operation: "generateBranchName",
153 detail: "fake text generation failed",
154 ...(cause !== undefined ? { cause } : {}),
155 }),
156 ),
157 ),
158 };
160​
161function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
162 service: GitHubCliShape;
163 ghCalls: string[];
164} {
165 const prListQueue = [...(scenario.prListSequence ?? [])];
166 const ghCalls: string[] = [];
167​
168 const execute: GitHubCliShape["execute"] = (input) => {
169 const args = [...input.args];
170 ghCalls.push(args.join(" "));
171​
172 if (scenario.failWith) {
173 return Effect.fail(scenario.failWith);
174 }
175​
176 if (args[0] === "pr" && args[1] === "list") {
177 const stdout = (prListQueue.shift() ?? "[]") + "\n";
178 return Effect.succeed({
179 stdout,
180 stderr: "",
181 code: 0,
182 signal: null,
183 timedOut: false,
184 });
185 }
186​
187 if (args[0] === "pr" && args[1] === "create") {
188 return Effect.succeed({
189 stdout:
190 (scenario.createdPrUrl ?? "https://github.com/pingdotgg/codething-mvp/pull/101") + "\n",
191 stderr: "",
192 code: 0,
193 signal: null,
194 timedOut: false,
195 });
196 }
197​
198 if (args[0] === "pr" && args[1] === "view") {
199 return Effect.succeed({
200 stdout: "",
201 stderr: "",
202 code: 0,
203 signal: null,
204 timedOut: false,
205 });
206 }
207​
208 if (args[0] === "repo" && args[1] === "view") {
209 return Effect.succeed({
210 stdout: `${scenario.defaultBranch ?? "main"}\n`,
211 stderr: "",
212 code: 0,
213 signal: null,
214 timedOut: false,
215 });
216 }
217​
218 return Effect.fail(
219 new GitHubCliError({
220 operation: "execute",
221 detail: `Unexpected gh command: ${args.join(" ")}`,
222 }),
223 );
224 };
225​
226 return {
227 service: {
228 execute,
229 listOpenPullRequests: (input) =>
230 execute({
231 cwd: input.cwd,
232 args: [
233 "pr",
234 "list",
235 "--head",
236 input.headBranch,
237 "--state",
238 "open",
239 "--limit",
240 String(input.limit ?? 1),
241 "--json",
242 "number,title,url,baseRefName,headRefName",
243 ],
244 }).pipe(
245 Effect.map(
246 (result) => JSON.parse(result.stdout) as ReadonlyArray<GitHubPullRequestSummary>,
247 ),
248 ),
249 createPullRequest: (input) =>
250 execute({
251 cwd: input.cwd,
252 args: [
253 "pr",
254 "create",
255 "--base",
256 input.baseBranch,
257 "--head",
258 input.headBranch,
259 "--title",
260 input.title,
261 "--body-file",
262 input.bodyFile,
263 ],
264 }).pipe(Effect.asVoid),
265 getDefaultBranch: (input) =>
266 execute({
267 cwd: input.cwd,
268 args: ["repo", "view", "--json", "defaultBranchRef", "--jq", ".defaultBranchRef.name"],
269 }).pipe(
270 Effect.map((result) => {
271 const value = result.stdout.trim();
272 return value.length > 0 ? value : null;
273 }),
274 ),
275 },
276 ghCalls,
277 };
279​
280function runStackedAction(
281 manager: GitManagerShape,
282 input: {
283 cwd: string;
284 action: "commit" | "commit_push" | "commit_push_pr";
285 commitMessage?: string;
286 },
287) {
288 return manager.runStackedAction(input);
290​
291function makeManager(input?: {
292 ghScenario?: FakeGhScenario;
293 textGeneration?: Partial<FakeGitTextGeneration>;
294}) {
295 const { service: gitHubCli, ghCalls } = createGitHubCliWithFakeGh(input?.ghScenario);
296 const textGeneration = createTextGeneration(input?.textGeneration);
297​
298 const gitCoreLayer = GitCoreLive.pipe(
299 Layer.provideMerge(GitServiceLive),
300 Layer.provideMerge(NodeServices.layer),
301 );
302​
303 const managerLayer = Layer.mergeAll(
304 Layer.succeed(GitHubCli, gitHubCli),
305 Layer.succeed(TextGeneration, textGeneration),
306 gitCoreLayer,
307 NodeServices.layer,
308 );
309​
310 return makeGitManager.pipe(
311 Effect.provide(managerLayer),
312 Effect.map((manager) => ({ manager, ghCalls })),
313 );
315​
316const GitManagerTestLayer = Layer.provideMerge(GitServiceLive, NodeServices.layer);
317​
318it.layer(GitManagerTestLayer)("GitManager", (it) => {
319 it.effect("status includes PR metadata when branch already has an open PR", () =>
320 Effect.gen(function* () {
321 const repoDir = yield* makeTempDir("t3code-git-manager-");
322 yield* initRepo(repoDir);
323 yield* runGit(repoDir, ["checkout", "-b", "feature/status-open-pr"]);
324 const remoteDir = yield* createBareRemote();
325 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
326 yield* runGit(repoDir, ["push", "-u", "origin", "feature/status-open-pr"]);
327​
328 const { manager } = yield* makeManager({
329 ghScenario: {
330 prListSequence: [
331 JSON.stringify([
332 {
333 number: 13,
334 title: "Existing PR",
335 url: "https://github.com/pingdotgg/codething-mvp/pull/13",
336 baseRefName: "main",
337 headRefName: "feature/status-open-pr",
338 },
339 ]),
340 ],
341 },
342 });
343​
344 const status = yield* manager.status({ cwd: repoDir });
345 expect(status.branch).toBe("feature/status-open-pr");
346 expect(status.pr).toEqual({
347 number: 13,
348 title: "Existing PR",
349 url: "https://github.com/pingdotgg/codething-mvp/pull/13",
350 baseBranch: "main",
351 headBranch: "feature/status-open-pr",
352 state: "open",
353 });
354 }),
355 );
356​
357 it.effect("status returns merged PR state when latest PR was merged", () =>
358 Effect.gen(function* () {
359 const repoDir = yield* makeTempDir("t3code-git-manager-");
360 yield* initRepo(repoDir);
361 yield* runGit(repoDir, ["checkout", "-b", "feature/status-merged-pr"]);
362​
363 const { manager } = yield* makeManager({
364 ghScenario: {
365 prListSequence: [
366 JSON.stringify([
367 {
368 number: 22,
369 title: "Merged PR",
370 url: "https://github.com/pingdotgg/codething-mvp/pull/22",
371 baseRefName: "main",
372 headRefName: "feature/status-merged-pr",
373 state: "MERGED",
374 mergedAt: "2026-01-30T10:00:00Z",
375 updatedAt: "2026-01-30T10:00:00Z",
376 },
377 ]),
378 ],
379 },
380 });
381​
382 const status = yield* manager.status({ cwd: repoDir });
383 expect(status.branch).toBe("feature/status-merged-pr");
384 expect(status.pr).toEqual({
385 number: 22,
386 title: "Merged PR",
387 url: "https://github.com/pingdotgg/codething-mvp/pull/22",
388 baseBranch: "main",
389 headBranch: "feature/status-merged-pr",
390 state: "merged",
391 });
392 }),
393 );
394​
395 it.effect("status prefers open PR when merged PR has newer updatedAt", () =>
396 Effect.gen(function* () {
397 const repoDir = yield* makeTempDir("t3code-git-manager-");
398 yield* initRepo(repoDir);
399 yield* runGit(repoDir, ["checkout", "-b", "feature/status-open-over-merged"]);
400​
401 const { manager } = yield* makeManager({
402 ghScenario: {
403 prListSequence: [
404 JSON.stringify([
405 {
406 number: 45,
407 title: "Merged PR",
408 url: "https://github.com/pingdotgg/codething-mvp/pull/45",
409 baseRefName: "main",
410 headRefName: "feature/status-open-over-merged",
411 state: "MERGED",
412 mergedAt: "2026-01-31T10:00:00Z",
413 updatedAt: "2026-02-01T10:00:00Z",
414 },
415 {
416 number: 46,
417 title: "Open PR",
418 url: "https://github.com/pingdotgg/codething-mvp/pull/46",
419 baseRefName: "main",
420 headRefName: "feature/status-open-over-merged",
421 state: "OPEN",
422 updatedAt: "2026-01-30T10:00:00Z",
423 },
424 ]),
425 ],
426 },
427 });
428​
429 const status = yield* manager.status({ cwd: repoDir });
430 expect(status.branch).toBe("feature/status-open-over-merged");
431 expect(status.pr).toEqual({
432 number: 46,
433 title: "Open PR",
434 url: "https://github.com/pingdotgg/codething-mvp/pull/46",
435 baseBranch: "main",
436 headBranch: "feature/status-open-over-merged",
437 state: "open",
438 });
439 }),
440 );
441​
442 it.effect("status is resilient to gh lookup failures and returns pr null", () =>
443 Effect.gen(function* () {
444 const repoDir = yield* makeTempDir("t3code-git-manager-");
445 yield* initRepo(repoDir);
446 yield* runGit(repoDir, ["checkout", "-b", "feature/status-no-gh"]);
447 const remoteDir = yield* createBareRemote();
448 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
449 yield* runGit(repoDir, ["push", "-u", "origin", "feature/status-no-gh"]);
450​
451 const { manager } = yield* makeManager({
452 ghScenario: {
453 failWith: new GitHubCliError({
454 operation: "execute",
455 detail: "GitHub CLI (`gh`) is required but not available on PATH.",
456 }),
457 },
458 });
459​
460 const status = yield* manager.status({ cwd: repoDir });
461 expect(status.branch).toBe("feature/status-no-gh");
462 expect(status.pr).toBeNull();
463 }),
464 );
465​
466 it.effect("creates a commit when working tree is dirty", () =>
467 Effect.gen(function* () {
468 const repoDir = yield* makeTempDir("t3code-git-manager-");
469 yield* initRepo(repoDir);
470 fs.writeFileSync(path.join(repoDir, "README.md"), "hello\nworld\n");
471​
472 const { manager } = yield* makeManager();
473 const result = yield* runStackedAction(manager, {
474 cwd: repoDir,
475 action: "commit",
476 });
477​
478 expect(result.commit.status).toBe("created");
479 expect(result.push.status).toBe("skipped_not_requested");
480 expect(result.pr.status).toBe("skipped_not_requested");
481 expect(
482 yield* runGit(repoDir, ["log", "-1", "--pretty=%s"]).pipe(
483 Effect.map((result) => result.stdout.trim()),
484 ),
485 ).toBe("Implement stacked git actions");
486 }),
487 );
488​
489 it.effect("uses custom commit message when provided", () =>
490 Effect.gen(function* () {
491 const repoDir = yield* makeTempDir("t3code-git-manager-");
492 yield* initRepo(repoDir);
493 fs.writeFileSync(path.join(repoDir, "README.md"), "hello\ncustom\n");
494 let generatedCount = 0;
495​
496 const { manager } = yield* makeManager({
497 textGeneration: {
498 generateCommitMessage: () =>
499 Effect.sync(() => {
500 generatedCount += 1;
501 return {
502 subject: "this should not be used",
503 body: "",
504 };
505 }),
506 },
507 });
508 const result = yield* runStackedAction(manager, {
509 cwd: repoDir,
510 action: "commit",
511 commitMessage: "feat: custom summary line\n\n- details from user",
512 });
513​
514 expect(result.commit.status).toBe("created");
515 expect(result.commit.subject).toBe("feat: custom summary line");
516 expect(generatedCount).toBe(0);
517 expect(
518 yield* runGit(repoDir, ["log", "-1", "--pretty=%s"]).pipe(
519 Effect.map((result) => result.stdout.trim()),
520 ),
521 ).toBe("feat: custom summary line");
522 expect(
523 yield* runGit(repoDir, ["log", "-1", "--pretty=%b"]).pipe(
524 Effect.map((result) => result.stdout.trim()),
525 ),
526 ).toContain("- details from user");
527 }),
528 );
529​
530 it.effect("skips commit when there are no uncommitted changes", () =>
531 Effect.gen(function* () {
532 const repoDir = yield* makeTempDir("t3code-git-manager-");
533 yield* initRepo(repoDir);
534​
535 const { manager } = yield* makeManager();
536 const result = yield* runStackedAction(manager, {
537 cwd: repoDir,
538 action: "commit",
539 });
540​
541 expect(result.commit.status).toBe("skipped_no_changes");
542 expect(result.push.status).toBe("skipped_not_requested");
543 expect(result.pr.status).toBe("skipped_not_requested");
544 }),
545 );
546​
547 it.effect("commits and pushes with upstream auto-setup when needed", () =>
548 Effect.gen(function* () {
549 const repoDir = yield* makeTempDir("t3code-git-manager-");
550 yield* initRepo(repoDir);
551 yield* runGit(repoDir, ["checkout", "-b", "feature/stacked-flow"]);
552 const remoteDir = yield* createBareRemote();
553 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
554 fs.writeFileSync(path.join(repoDir, "feature.txt"), "feature\n");
555​
556 const { manager } = yield* makeManager();
557 const result = yield* runStackedAction(manager, {
558 cwd: repoDir,
559 action: "commit_push",
560 });
561​
562 expect(result.commit.status).toBe("created");
563 expect(result.push.status).toBe("pushed");
564 expect(result.push.setUpstream).toBe(true);
565 expect(
566 yield* runGit(repoDir, ["rev-parse", "--abbrev-ref", "@{upstream}"]).pipe(
567 Effect.map((result) => result.stdout.trim()),
568 ),
569 ).toBe("origin/feature/stacked-flow");
570 }),
571 );
572​
573 it.effect("skips push when branch is already up to date", () =>
574 Effect.gen(function* () {
575 const repoDir = yield* makeTempDir("t3code-git-manager-");
576 yield* initRepo(repoDir);
577 yield* runGit(repoDir, ["checkout", "-b", "feature/up-to-date"]);
578 const remoteDir = yield* createBareRemote();
579 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
580 yield* runGit(repoDir, ["push", "-u", "origin", "feature/up-to-date"]);
581​
582 const { manager } = yield* makeManager();
583 const result = yield* runStackedAction(manager, {
584 cwd: repoDir,
585 action: "commit_push",
586 });
587​
588 expect(result.commit.status).toBe("skipped_no_changes");
589 expect(result.push.status).toBe("skipped_up_to_date");
590 }),
591 );
592​
593 it.effect("returns existing PR metadata for commit/push/pr action", () =>
594 Effect.gen(function* () {
595 const repoDir = yield* makeTempDir("t3code-git-manager-");
596 yield* initRepo(repoDir);
597 yield* runGit(repoDir, ["checkout", "-b", "feature/existing-pr"]);
598 const remoteDir = yield* createBareRemote();
599 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
600 yield* runGit(repoDir, ["push", "-u", "origin", "feature/existing-pr"]);
601​
602 const { manager, ghCalls } = yield* makeManager({
603 ghScenario: {
604 prListSequence: [
605 JSON.stringify([
606 {
607 number: 42,
608 title: "Existing PR",
609 url: "https://github.com/pingdotgg/codething-mvp/pull/42",
610 baseRefName: "main",
611 headRefName: "feature/existing-pr",
612 },
613 ]),
614 ],
615 },
616 });
617 const result = yield* runStackedAction(manager, {
618 cwd: repoDir,
619 action: "commit_push_pr",
620 });
621​
622 expect(result.pr.status).toBe("opened_existing");
623 expect(result.pr.number).toBe(42);
624 expect(ghCalls.some((call) => call.startsWith("pr view "))).toBe(false);
625 }),
626 );
627​
628 it.effect("creates PR when one does not already exist", () =>
629 Effect.gen(function* () {
630 const repoDir = yield* makeTempDir("t3code-git-manager-");
631 yield* initRepo(repoDir);
632 yield* runGit(repoDir, ["checkout", "-b", "feature-create-pr"]);
633 const remoteDir = yield* createBareRemote();
634 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
635 fs.writeFileSync(path.join(repoDir, "changes.txt"), "change\n");
636 yield* runGit(repoDir, ["add", "changes.txt"]);
637 yield* runGit(repoDir, ["commit", "-m", "Feature commit"]);
638 yield* runGit(repoDir, ["push", "-u", "origin", "feature-create-pr"]);
639 yield* runGit(repoDir, ["config", "branch.feature-create-pr.gh-merge-base", "main"]);
640​
641 const { manager, ghCalls } = yield* makeManager({
642 ghScenario: {
643 prListSequence: [
644 "[]",
645 JSON.stringify([
646 {
647 number: 88,
648 title: "Add stacked git actions",
649 url: "https://github.com/pingdotgg/codething-mvp/pull/88",
650 baseRefName: "main",
651 headRefName: "feature-create-pr",
652 },
653 ]),
654 ],
655 },
656 });
657 const result = yield* runStackedAction(manager, {
658 cwd: repoDir,
659 action: "commit_push_pr",
660 });
661​
662 expect(result.pr.status).toBe("created");
663 expect(result.pr.number).toBe(88);
664 expect(
665 ghCalls.some((call) => call.includes("pr create --base main --head feature-create-pr")),
666 ).toBe(true);
667 expect(ghCalls.some((call) => call.startsWith("pr view "))).toBe(false);
668 }),
669 );
670​
671 it.effect("rejects push/pr actions from detached HEAD", () =>
672 Effect.gen(function* () {
673 const repoDir = yield* makeTempDir("t3code-git-manager-");
674 yield* initRepo(repoDir);
675 yield* runGit(repoDir, ["checkout", "--detach", "HEAD"]);
676​
677 const { manager } = yield* makeManager();
678 const errorMessage = yield* runStackedAction(manager, {
679 cwd: repoDir,
680 action: "commit_push",
681 }).pipe(
682 Effect.flip,
683 Effect.map((error) => error.message),
684 );
685 expect(errorMessage).toContain("detached HEAD");
686 }),
687 );
688​
689 it.effect("surfaces missing gh binary errors", () =>
690 Effect.gen(function* () {
691 const repoDir = yield* makeTempDir("t3code-git-manager-");
692 yield* initRepo(repoDir);
693 yield* runGit(repoDir, ["checkout", "-b", "feature/gh-missing"]);
694 const remoteDir = yield* createBareRemote();
695 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
696 yield* runGit(repoDir, ["push", "-u", "origin", "feature/gh-missing"]);
697​
698 const { manager } = yield* makeManager({
699 ghScenario: {
700 failWith: new GitHubCliError({
701 operation: "execute",
702 detail: "GitHub CLI (`gh`) is required but not available on PATH.",
703 }),
704 },
705 });
706​
707 const errorMessage = yield* runStackedAction(manager, {
708 cwd: repoDir,
709 action: "commit_push_pr",
710 }).pipe(
711 Effect.flip,
712 Effect.map((error) => error.message),
713 );
714 expect(errorMessage).toContain("GitHub CLI (`gh`) is required");
715 }),
716 );
717​
718 it.effect("surfaces gh auth errors with guidance", () =>
719 Effect.gen(function* () {
720 const repoDir = yield* makeTempDir("t3code-git-manager-");
721 yield* initRepo(repoDir);
722 yield* runGit(repoDir, ["checkout", "-b", "feature/gh-auth"]);
723 const remoteDir = yield* createBareRemote();
724 yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
725 yield* runGit(repoDir, ["push", "-u", "origin", "feature/gh-auth"]);
726​
727 const { manager } = yield* makeManager({
728 ghScenario: {
729 failWith: new GitHubCliError({
730 operation: "execute",
731 detail: "GitHub CLI is not authenticated. Run `gh auth login` and retry.",
732 }),
733 },
734 });
735​
736 const errorMessage = yield* runStackedAction(manager, {
737 cwd: repoDir,
738 action: "commit_push_pr",
739 }).pipe(
740 Effect.flip,
741 Effect.map((error) => error.message),
742 );
743 expect(errorMessage).toContain("gh auth login");
744 }),
745 );
746});