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

Function cloneAndCaptureAskpassEnv

src/node/services/projectService.test.ts:747–794  ·  view source on GitHub ↗
(options: {
      testCaseId: string;
      repoUrl: string;
      failIfSshAskpassIsSet: boolean;
    })

Source from the content-addressed store, hash-verified

745 }
746
747 async function cloneAndCaptureAskpassEnv(options: {
748 testCaseId: string;
749 repoUrl: string;
750 failIfSshAskpassIsSet: boolean;
751 }): Promise<Record<string, string>> {
752 const cloneParentDir = path.join(tempDir, `${options.testCaseId}-clone-parent`);
753 const fakeBinDir = path.join(tempDir, `fake-bin-${options.testCaseId}`);
754 const fakeGitPath = path.join(fakeBinDir, "git");
755 const fakeGitEnvLogPath = path.join(tempDir, `fake-git-${options.testCaseId}-env.log`);
756
757 await fs.mkdir(fakeBinDir, { recursive: true });
758 await writeFakeGitCloneEnvLoggingShim(fakeGitPath, {
759 failIfSshAskpassIsSet: options.failIfSshAskpassIsSet,
760 });
761
762 const sshPromptService = new SshPromptService(5000);
763 const release = sshPromptService.registerInteractiveResponder();
764 const sshCloneService = new ProjectService(config, sshPromptService);
765 const onRequest = (request: SshPromptRequest) => {
766 sshPromptService.respond(request.requestId, "yes");
767 };
768 sshPromptService.on("request", onRequest);
769
770 try {
771 return await withEnv(
772 {
773 PATH: `${fakeBinDir}${path.delimiter}${process.env.PATH ?? ""}`,
774 HOME: tempDir,
775 SSH_AUTH_SOCK: path.join(tempDir, "fake-ssh-agent.sock"),
776 FAKE_GIT_ENV_LOG: fakeGitEnvLogPath,
777 },
778 async () => {
779 const events = await collectCloneEvents(
780 sshCloneService,
781 options.repoUrl,
782 cloneParentDir
783 );
784 const successEvent = events.find((event) => event.type === "success");
785 expect(successEvent?.type).toBe("success");
786
787 return await readLoggedEnv(fakeGitEnvLogPath);
788 }
789 );
790 } finally {
791 sshPromptService.off("request", onRequest);
792 release();
793 }
794 }
795
796 it("SSH clone invokes askpass for host-key prompt and succeeds when accepted", async () => {
797 if (process.platform === "win32") {

Callers 1

Calls 6

withEnvFunction · 0.85
collectCloneEventsFunction · 0.85
readLoggedEnvFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected