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

SourceControlRepositoryService.test.ts

698 lines25.0 KB

1import * as NodePath from "@effect/platform-node/NodePath";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import * as Effect from "effect/Effect";
5import * as FileSystem from "effect/FileSystem";
6import * as Path from "effect/Path";
7import * as Layer from "effect/Layer";
8import * as PlatformError from "effect/PlatformError";
9import * as Schema from "effect/Schema";
10import { ChildProcessSpawner } from "effect/process";
11​
12import { GitCommandError, SourceControlProviderError } from "@t3tools/contracts";
13​
14import * as ServerConfig from "../config.ts";
15import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
16import * as BitbucketApi from "./BitbucketApi.ts";
17import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
18import type * as SourceControlProvider from "./SourceControlProvider.ts";
19import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
20import * as SourceControlRepositoryService from "./SourceControlRepositoryService.ts";
21​
22const isSourceControlProviderError = Schema.is(SourceControlProviderError);
23​
24const CLONE_URLS = {
25 nameWithOwner: "octocat/t3code",
26 url: "https://github.com/octocat/t3code",
27 sshUrl: "git@github.com:octocat/t3code.git",
28};
29​
30function makeProvider(
31 overrides: Partial<SourceControlProvider.SourceControlProvider["Service"]> = {},
32): SourceControlProvider.SourceControlProvider["Service"] {
33 const unsupported = (operation: string) =>
34 Effect.die(`unexpected provider operation ${operation}`) as Effect.Effect<
35 never,
36 SourceControlProviderError
37 >;
38​
39 return {
40 kind: "github",
41 listChangeRequests: () => unsupported("listChangeRequests"),
42 getChangeRequest: () => unsupported("getChangeRequest"),
43 createChangeRequest: () => unsupported("createChangeRequest"),
44 getRepositoryCloneUrls: () => Effect.succeed(CLONE_URLS),
45 createRepository: () => Effect.succeed(CLONE_URLS),
46 getDefaultBranch: () => Effect.succeed(null),
47 checkoutChangeRequest: () => unsupported("checkoutChangeRequest"),
48 ...overrides,
49 };
51​
52function processOutput(): GitVcsDriver.ExecuteGitResult {
53 return {
54 exitCode: ChildProcessSpawner.ExitCode(0),
55 stdout: "",
56 stderr: "",
57 stdoutTruncated: false,
58 stderrTruncated: false,
59 };
61​
62function layer(input: {
63 readonly provider?: SourceControlProvider.SourceControlProvider["Service"];
64 readonly git?: Partial<GitVcsDriver.GitVcsDriver["Service"]>;
65 readonly fileSystem?: FileSystem.FileSystem;
66}) {
67 const layerService = SourceControlRepositoryService.layer.pipe(
68 Layer.provide(
69 Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
70 resolveLink: () => undefined,
71 get: () => Effect.succeed(input.provider ?? makeProvider()),
72 }),
73 ),
74 Layer.provide(
75 Layer.mock(GitVcsDriver.GitVcsDriver)({
76 execute: () => Effect.succeed(processOutput()),
77 ensureRemote: () => Effect.succeed("origin"),
78 pushCurrentBranch: () =>
79 Effect.succeed({
80 status: "pushed" as const,
81 branch: "feature/remote-v1",
82 upstreamBranch: "origin/feature/remote-v1",
83 setUpstream: true,
84 }),
85 ...input.git,
86 }),
87 ),
88 Layer.provide(
89 ServerConfig.layerTest(
90 process.cwd(),
91 input.fileSystem ? "/tmp/t3-source-control-repos" : { prefix: "t3-source-control-repos-" },
92 ),
93 ),
94 );
95​
96 return input.fileSystem
97 ? layerService.pipe(
98 Layer.provide(Layer.succeed(FileSystem.FileSystem, input.fileSystem)),
99 Layer.provideMerge(NodePath.layer),
100 )
101 : layerService.pipe(Layer.provideMerge(NodeServices.layer));
103​
104it.effect("looks up repositories through the requested provider without search", () => {
105 const calls: Array<{ cwd: string; repository: string }> = [];
106 const provider = makeProvider({
107 getRepositoryCloneUrls: (input) =>
108 Effect.sync(() => {
109 calls.push({ cwd: input.cwd, repository: input.repository });
110 return CLONE_URLS;
111 }),
112 });
113​
114 return Effect.gen(function* () {
115 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
116 const result = yield* service.lookupRepository({
117 provider: "github",
118 repository: "octocat/t3code",
119 cwd: "/workspace",
120 });
121​
122 assert.deepStrictEqual(result, { provider: "github", ...CLONE_URLS });
123 assert.deepStrictEqual(calls, [{ cwd: "/workspace", repository: "octocat/t3code" }]);
124 }).pipe(Effect.provide(layer({ provider })));
125});
126​
127it.effect("preserves provider failures without deriving the repository message from them", () => {
128 const providerCause = new SourceControlProviderError({
129 provider: "github",
130 operation: "getRepositoryCloneUrls",
131 cwd: "/workspace",
132 repository: "octocat/t3code",
133 detail: "credential token abc123 was rejected",
134 });
135 const provider = makeProvider({
136 getRepositoryCloneUrls: () => Effect.fail(providerCause),
137 });
138​
139 return Effect.gen(function* () {
140 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
141 const error = yield* Effect.flip(
142 service.lookupRepository({
143 provider: "github",
144 repository: "octocat/t3code",
145 cwd: "/workspace",
146 }),
147 );
148​
149 assert.strictEqual(error.provider, "github");
150 assert.strictEqual(error.operation, "lookupRepository");
151 assert.strictEqual(error.detail, "The source control operation could not be completed.");
152 assert.strictEqual(
153 error.message,
154 "Source control repository operation lookupRepository failed for github: The source control operation could not be completed.",
155 );
156 assert.strictEqual(error.cause, providerCause);
157 }).pipe(Effect.provide(layer({ provider })));
158});
159​
160it.effect(
161 "reports the safe Bitbucket locator detail through repository lookup and publishing",
162 () =>
163 Effect.gen(function* () {
164 const locatorCause = new BitbucketApi.BitbucketRepositoryLocatorError({
165 repository: "credential-token-abc123",
166 });
167 const provider = yield* BitbucketSourceControlProvider.make.pipe(
168 Effect.provide(
169 Layer.mock(BitbucketApi.BitbucketApi)({
170 getRepositoryCloneUrls: () => Effect.fail(locatorCause),
171 createRepository: () => Effect.fail(locatorCause),
172 }),
173 ),
174 );
175​
176 yield* Effect.gen(function* () {
177 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
178 const input = {
179 provider: "bitbucket" as const,
180 repository: locatorCause.repository,
181 cwd: "/workspace",
182 };
183 for (const operation of [
184 service.lookupRepository(input).pipe(Effect.asVoid),
185 service.publishRepository({ ...input, visibility: "private" }).pipe(Effect.asVoid),
186 ]) {
187 const error = yield* Effect.flip(operation);
188​
189 assert.strictEqual(error.provider, "bitbucket");
190 assert.strictEqual(
191 error.detail,
192 "Bitbucket repositories must be specified as workspace/repository.",
193 );
194 assert.notInclude(error.message, locatorCause.repository);
195 assert.instanceOf(error.cause, SourceControlProviderError);
196 assert.strictEqual(
197 isSourceControlProviderError(error.cause) ? error.cause.cause : null,
198 locatorCause,
199 );
200 }
201 }).pipe(Effect.provide(layer({ provider })));
202 }),
203);
204​
205it.effect("keeps a plain Bitbucket locator lookalike out of the repository message", () => {
206 const provider = makeProvider({
207 kind: "bitbucket",
208 getRepositoryCloneUrls: () =>
209 Effect.fail(
210 new SourceControlProviderError({
211 provider: "bitbucket",
212 operation: "getRepositoryCloneUrls",
213 cwd: "/workspace",
214 detail: "credential token abc123 was rejected",
215 cause: {
216 _tag: "BitbucketRepositoryLocatorError",
217 repository: "t3code",
218 detail: "credential token abc123 was rejected",
219 },
220 }),
221 ),
222 });
223​
224 return Effect.gen(function* () {
225 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
226 const error = yield* Effect.flip(
227 service.lookupRepository({ provider: "bitbucket", repository: "t3code" }),
228 );
229​
230 assert.strictEqual(error.detail, "The source control operation could not be completed.");
231 assert.notInclude(error.message, "abc123");
232 }).pipe(Effect.provide(layer({ provider })));
233});
234​
235it.effect("keeps arbitrary Bitbucket request failures out of the repository message", () =>
236 Effect.gen(function* () {
237 const cause = new BitbucketApi.BitbucketRequestError({
238 operation: "getRepository",
239 cause: new Error("credential token abc123 was rejected"),
240 });
241 const provider = yield* BitbucketSourceControlProvider.make.pipe(
242 Effect.provide(
243 Layer.mock(BitbucketApi.BitbucketApi)({
244 getRepositoryCloneUrls: () => Effect.fail(cause),
245 }),
246 ),
247 );
248​
249 yield* Effect.gen(function* () {
250 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
251 const error = yield* Effect.flip(
252 service.lookupRepository({
253 provider: "bitbucket",
254 repository: "pingdotgg/t3code",
255 cwd: "/workspace",
256 }),
257 );
258​
259 assert.strictEqual(error.detail, "The source control operation could not be completed.");
260 assert.notInclude(error.message, "abc123");
261 assert.notInclude(error.message, cause.detail);
262 }).pipe(Effect.provide(layer({ provider })));
263 }),
264);
265​
266it.effect("clones a looked-up repository into the requested destination", () =>
267 Effect.gen(function* () {
268 const fs = yield* FileSystem.FileSystem;
269 const path = yield* Path.Path;
270 const parent = yield* fs.makeTempDirectoryScoped({
271 prefix: "t3-source-control-clone-parent-",
272 });
273 const destinationPath = path.join(parent, "t3code");
274 const cloneCalls: Array<{ cwd: string; args: ReadonlyArray<string> }> = [];
275​
276 yield* Effect.gen(function* () {
277 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
278 const result = yield* service.cloneRepository({
279 provider: "github",
280 repository: "octocat/t3code",
281 destinationPath,
282 protocol: "https",
283 });
284​
285 assert.deepStrictEqual(result, {
286 cwd: destinationPath,
287 remoteUrl: CLONE_URLS.url,
288 repository: { provider: "github", ...CLONE_URLS },
289 });
290 assert.deepStrictEqual(cloneCalls, [
291 {
292 cwd: parent,
293 args: ["clone", "--progress", "--", CLONE_URLS.url, "t3code"],
294 },
295 ]);
296 }).pipe(
297 Effect.provide(
298 layer({
299 git: {
300 execute: (input) =>
301 Effect.sync(() => {
302 cloneCalls.push({ cwd: input.cwd, args: input.args });
303 return processOutput();
304 }),
305 },
306 }),
307 ),
308 );
309 }).pipe(Effect.provide(NodeServices.layer)),
310);
311​
312it.effect.each(["--bare", "source.git"])(
313 "clones a local repository named %s as a working tree",
314 (repositoryName) =>
315 Effect.gen(function* () {
316 const fs = yield* FileSystem.FileSystem;
317 const path = yield* Path.Path;
318 const git = yield* GitVcsDriver.GitVcsDriver;
319 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-clone-options-" });
320 yield* git.execute({
321 operation: "test.init",
322 cwd: parent,
323 args: ["init", "--bare", path.join(parent, repositoryName)],
324 });
325 const destinationPath = path.join(parent, "checkout");
326 yield* Effect.gen(function* () {
327 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
328 const result = yield* service.cloneRepository({
329 remoteUrl: repositoryName,
330 destinationPath,
331 });
332 assert.strictEqual(result.cwd, destinationPath);
333 assert.isTrue(yield* fs.exists(path.join(destinationPath, ".git")));
334 }).pipe(Effect.provide(layer({ git: { execute: git.execute } })));
335 }).pipe(
336 Effect.provide(
337 GitVcsDriver.layer.pipe(
338 Layer.provide(
339 ServerConfig.layerTest(process.cwd(), {
340 prefix: "t3-clone-options-config-",
341 }),
342 ),
343 Layer.provideMerge(NodeServices.layer),
344 ),
345 ),
346 ),
347);
348​
349it.effect("reports clone progress from git's stderr and keeps its error text on failure", () =>
350 Effect.gen(function* () {
351 const fs = yield* FileSystem.FileSystem;
352 const path = yield* Path.Path;
353 const parent = yield* fs.makeTempDirectoryScoped({
354 prefix: "t3-source-control-clone-progress-",
355 });
356 const destinationPath = path.join(parent, "t3code");
357 const progress: Array<{ stage: string; percent: number | null; detail: string | null }> = [];
358​
359 const stderrLines = [
360 "Cloning into 't3code'...",
361 "remote: Enumerating objects: 10, done.",
362 "Receiving objects: 40% (4/10), 1.00 MiB | 2.00 MiB/s",
363 "Receiving objects: 100% (10/10), 2.50 MiB | 2.00 MiB/s, done.",
364 "fatal: early EOF",
365 "fatal: unable to access 'https://user:s3c@ret@github.com/octocat/t3code.git/': could not resolve host",
366 ];
367 const error = yield* Effect.gen(function* () {
368 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
369 return yield* Effect.flip(
370 service.cloneRepository(
371 { remoteUrl: CLONE_URLS.sshUrl, destinationPath },
372 { onProgress: (line) => Effect.sync(() => void progress.push(line)) },
373 ),
374 );
375 }).pipe(
376 Effect.provide(
377 layer({
378 git: {
379 execute: (input) =>
380 Effect.gen(function* () {
381 for (const line of stderrLines) {
382 yield* input.progress?.onStderrLine?.(line) ?? Effect.void;
383 }
384 return yield* new GitCommandError({
385 operation: input.operation,
386 command: "git",
387 cwd: input.cwd,
388 detail: "Git command exited with a non-zero status.",
389 exitCode: 128,
390 });
391 }),
392 },
393 }),
394 ),
395 );
396​
397 assert.deepStrictEqual(progress, [
398 { stage: "counting", percent: null, detail: null },
399 { stage: "receiving", percent: 40, detail: "1.00 MiB | 2.00 MiB/s" },
400 { stage: "receiving", percent: 100, detail: "2.50 MiB | 2.00 MiB/s" },
401 ]);
402 // Git echoes the remote in some failures; the credentials must not follow.
403 assert.strictEqual(
404 error.detail,
405 "fatal: early EOF fatal: unable to access 'https://github.com/octocat/t3code.git/': could not resolve host",
406 );
407 }).pipe(Effect.provide(NodeServices.layer)),
408);
409​
410it.effect("strips embedded credentials from the remote URL it reports", () =>
411 Effect.gen(function* () {
412 const fs = yield* FileSystem.FileSystem;
413 const path = yield* Path.Path;
414 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-redact-" });
415 const destinationPath = path.join(parent, "t3code");
416 const cloneArgs: Array<ReadonlyArray<string>> = [];
417 const result = yield* Effect.gen(function* () {
418 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
419 return yield* service.prepareClone({
420 remoteUrl: "https://user:s3cret@github.com/octocat/t3code.git",
421 destinationPath,
422 });
423 }).pipe(
424 Effect.provide(
425 layer({
426 git: {
427 execute: (input) =>
428 Effect.sync(() => {
429 cloneArgs.push(input.args);
430 return processOutput();
431 }),
432 },
433 }),
434 ),
435 );
436 assert.equal(result.remoteUrl, "https://github.com/octocat/t3code.git");
437 // Git itself still receives the credentials.
438 assert.equal(result.cloneUrl, "https://user:s3cret@github.com/octocat/t3code.git");
439 }).pipe(Effect.provide(NodeServices.layer)),
440);
441​
442it.effect("discards only a directory git wrote to", () =>
443 Effect.gen(function* () {
444 const fs = yield* FileSystem.FileSystem;
445 const path = yield* Path.Path;
446 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-discard-" });
447 const partial = path.join(parent, "partial");
448 yield* fs.makeDirectory(path.join(partial, ".git"), { recursive: true });
449 yield* fs.writeFileString(path.join(partial, "README.md"), "half");
450 const foreign = path.join(parent, "foreign");
451 yield* fs.makeDirectory(foreign);
452 yield* fs.writeFileString(path.join(foreign, "notes.txt"), "mine");
453​
454 // A file where the directory should be must not be removed either.
455 const replaced = path.join(parent, "replaced");
456 yield* fs.writeFileString(replaced, "not a directory");
457​
458 yield* Effect.gen(function* () {
459 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
460 yield* service.discardClone(partial);
461 const error = yield* Effect.flip(service.discardClone(foreign));
462 assert.include(error.detail, "not from the clone");
463 const replacedError = yield* Effect.flip(service.discardClone(replaced));
464 assert.include(replacedError.detail, "could not be inspected");
465 // A destination that never got created is nothing to discard.
466 yield* service.discardClone(path.join(parent, "missing"));
467 }).pipe(Effect.provide(layer({})));
468​
469 // The partial clone is emptied but its directory (the workspace root) stays.
470 assert.deepStrictEqual(yield* fs.readDirectory(partial), []);
471 assert.deepStrictEqual(yield* fs.readDirectory(foreign), ["notes.txt"]);
472 assert.strictEqual(yield* fs.readFileString(replaced), "not a directory");
473 }).pipe(Effect.provide(NodeServices.layer)),
474);
475​
476it.effect("redacts query tokens and userinfo containing '@' from reported URLs", () =>
477 Effect.gen(function* () {
478 const fs = yield* FileSystem.FileSystem;
479 const path = yield* Path.Path;
480 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-redact2-" });
481 yield* Effect.gen(function* () {
482 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
483 const query = yield* service.prepareClone({
484 remoteUrl: "https://github.com/octocat/t3code.git?access_token=s3cret",
485 destinationPath: path.join(parent, "a"),
486 });
487 assert.equal(query.remoteUrl, "https://github.com/octocat/t3code.git");
488 const nested = yield* service.prepareClone({
489 remoteUrl: "https://user:pa@rt@github.com/octocat/t3code.git",
490 destinationPath: path.join(parent, "b"),
491 });
492 assert.equal(nested.remoteUrl, "https://github.com/octocat/t3code.git");
493 }).pipe(Effect.provide(layer({})));
494 }).pipe(Effect.provide(NodeServices.layer)),
495);
496​
497it.effect("preserves destination probe failures instead of treating them as missing paths", () => {
498 const fileSystemCause = PlatformError.systemError({
499 _tag: "PermissionDenied",
500 module: "FileSystem",
501 method: "exists",
502 pathOrDescriptor: "/restricted/t3code",
503 });
504​
505 return Effect.gen(function* () {
506 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
507 const error = yield* Effect.flip(
508 service.cloneRepository({
509 remoteUrl: CLONE_URLS.sshUrl,
510 destinationPath: "/restricted/t3code",
511 }),
512 );
513​
514 assert.strictEqual(error.provider, "unknown");
515 assert.strictEqual(error.operation, "cloneRepository");
516 assert.strictEqual(error.cause, fileSystemCause);
517 }).pipe(
518 Effect.provide(
519 layer({
520 fileSystem: FileSystem.makeNoop({
521 exists: () => Effect.fail(fileSystemCause),
522 makeDirectory: () => Effect.void,
523 }),
524 }),
525 ),
526 );
527});
528​
529it.effect("publishes by creating the repository, adding a remote, and pushing upstream", () => {
530 const createCalls: Array<{ cwd: string; repository: string; visibility: string }> = [];
531 const remoteCalls: Array<{ cwd: string; preferredName: string; url: string }> = [];
532 const pushCalls: Array<{ cwd: string; remoteName: string | null | undefined }> = [];
533 const provider = makeProvider({
534 createRepository: (input) =>
535 Effect.sync(() => {
536 createCalls.push({
537 cwd: input.cwd,
538 repository: input.repository,
539 visibility: input.visibility,
540 });
541 return CLONE_URLS;
542 }),
543 });
544​
545 return Effect.gen(function* () {
546 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
547 const result = yield* service.publishRepository({
548 cwd: "/workspace",
549 provider: "github",
550 repository: "octocat/t3code",
551 visibility: "private",
552 remoteName: "origin",
553 protocol: "ssh",
554 });
555​
556 assert.deepStrictEqual(result, {
557 repository: { provider: "github", ...CLONE_URLS },
558 remoteName: "origin",
559 remoteUrl: CLONE_URLS.sshUrl,
560 branch: "feature/remote-v1",
561 upstreamBranch: "origin/feature/remote-v1",
562 status: "pushed",
563 });
564 assert.deepStrictEqual(createCalls, [
565 { cwd: "/workspace", repository: "octocat/t3code", visibility: "private" },
566 ]);
567 assert.deepStrictEqual(remoteCalls, [
568 { cwd: "/workspace", preferredName: "origin", url: CLONE_URLS.sshUrl },
569 ]);
570 assert.deepStrictEqual(pushCalls, [{ cwd: "/workspace", remoteName: "origin" }]);
571 }).pipe(
572 Effect.provide(
573 layer({
574 provider,
575 git: {
576 ensureRemote: (input) =>
577 Effect.sync(() => {
578 remoteCalls.push(input);
579 return "origin";
580 }),
581 pushCurrentBranch: (cwd, _fallbackBranch, options) =>
582 Effect.sync(() => {
583 pushCalls.push({ cwd, remoteName: options?.remoteName });
584 return {
585 status: "pushed" as const,
586 branch: "feature/remote-v1",
587 upstreamBranch: "origin/feature/remote-v1",
588 setUpstream: true,
589 };
590 }),
591 },
592 }),
593 ),
594 );
595});
596​
597it.effect("publishes to the remote name returned by ensureRemote", () => {
598 const pushCalls: Array<{ cwd: string; remoteName: string | null | undefined }> = [];
599​
600 return Effect.gen(function* () {
601 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
602 const result = yield* service.publishRepository({
603 cwd: "/workspace",
604 provider: "github",
605 repository: "octocat/t3code",
606 visibility: "private",
607 remoteName: "origin",
608 protocol: "ssh",
609 });
610​
611 assert.equal(result.remoteName, "origin-1");
612 assert.deepStrictEqual(pushCalls, [{ cwd: "/workspace", remoteName: "origin-1" }]);
613 }).pipe(
614 Effect.provide(
615 layer({
616 git: {
617 ensureRemote: () => Effect.succeed("origin-1"),
618 pushCurrentBranch: (cwd, _fallbackBranch, options) =>
619 Effect.sync(() => {
620 pushCalls.push({ cwd, remoteName: options?.remoteName });
621 return {
622 status: "pushed" as const,
623 branch: "feature/remote-v1",
624 upstreamBranch: `${options?.remoteName ?? "missing"}/feature/remote-v1`,
625 setUpstream: true,
626 };
627 }),
628 },
629 }),
630 ),
631 );
632});
633​
634it.effect("publish succeeds with status remote_added when the local repo has no commits", () => {
635 let pushCalls = 0;
636 return Effect.gen(function* () {
637 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
638 const result = yield* service.publishRepository({
639 cwd: "/workspace",
640 provider: "github",
641 repository: "octocat/t3code",
642 visibility: "private",
643 remoteName: "origin",
644 protocol: "ssh",
645 });
646​
647 assert.deepStrictEqual(result, {
648 repository: { provider: "github", ...CLONE_URLS },
649 remoteName: "origin",
650 remoteUrl: CLONE_URLS.sshUrl,
651 branch: "main",
652 status: "remote_added",
653 });
654 assert.strictEqual(pushCalls, 0);
655 }).pipe(
656 Effect.provide(
657 layer({
658 git: {
659 execute: (input) =>
660 input.args[0] === "rev-parse"
661 ? Effect.fail(
662 new GitCommandError({
663 operation: input.operation,
664 command: "git rev-parse --verify HEAD",
665 cwd: input.cwd,
666 detail: "fatal: Needed a single revision",
667 }),
668 )
669 : Effect.succeed(processOutput()),
670 statusDetails: () =>
671 Effect.succeed({
672 isRepo: true,
673 hasOriginRemote: true,
674 isDefaultBranch: true,
675 branch: "main",
676 upstreamRef: null,
677 hasWorkingTreeChanges: false,
678 workingTree: { files: [], insertions: 0, deletions: 0 },
679 hasUpstream: false,
680 aheadCount: 0,
681 behindCount: 0,
682 aheadOfDefaultCount: 0,
683 }),
684 pushCurrentBranch: () =>
685 Effect.sync(() => {
686 pushCalls += 1;
687 return {
688 status: "pushed" as const,
689 branch: "main",
690 upstreamBranch: "origin/main",
691 setUpstream: true,
692 };
693 }),
694 },
695 }),
696 ),
697 );
698});