MCPcopy
hub / github.com/coder/mux / cloneWithFakeGit

Function cloneWithFakeGit

src/node/services/projectService.test.ts:72–101  ·  view source on GitHub ↗
(
  tempDir: string,
  service: ProjectService,
  input: { testCaseId: string; repoUrl: string; cloneParentDir: string; sshAuthSock?: string }
)

Source from the content-addressed store, hash-verified

70}
71
72async function cloneWithFakeGit(
73 tempDir: string,
74 service: ProjectService,
75 input: { testCaseId: string; repoUrl: string; cloneParentDir: string; sshAuthSock?: string }
76) {
77 if (process.platform === "win32") {
78 // These tests rely on a POSIX shell shim named "git" in PATH.
79 return null;
80 }
81
82 const fakeBinDir = path.join(tempDir, `fake-bin-${input.testCaseId}`);
83 const fakeGitArgsLogPath = path.join(tempDir, `fake-git-${input.testCaseId}-args.log`);
84 await fs.mkdir(fakeBinDir, { recursive: true });
85 await writeFakeGitCloneShim(path.join(fakeBinDir, "git"));
86
87 const result = await withEnv(
88 {
89 PATH: `${fakeBinDir}${path.delimiter}${process.env.PATH ?? ""}`,
90 FAKE_GIT_ARGS_LOG: fakeGitArgsLogPath,
91 HOME: tempDir,
92 SSH_AUTH_SOCK: input.sshAuthSock,
93 },
94 () => service.clone({ repoUrl: input.repoUrl, cloneParentDir: input.cloneParentDir })
95 );
96
97 expect(result.success).toBe(true);
98 if (!result.success) throw new Error("Expected success");
99 const loggedArgs = (await fs.readFile(fakeGitArgsLogPath, "utf-8")).trim().split("\n");
100 return { result, loggedArgs, cloneWorkPath: loggedArgs[4] ?? "" };
101}
102
103describe("ProjectService", () => {
104 let tempDir: string;

Callers 1

Calls 4

writeFakeGitCloneShimFunction · 0.85
withEnvFunction · 0.85
cloneMethod · 0.80
readFileMethod · 0.65

Tested by

no test coverage detected