MCPcopy Create free account
hub / github.com/cli/cli / prepareHome

Function prepareHome

evals/src/core/home.ts:33–62  ·  view source on GitHub ↗
(
  home: string, config: { gh: string; token: string; modelToken: string; observe?: boolean },
)

Source from the content-addressed store, hash-verified

31
32/** Prepares an isolated agent home: gh (observed by default), its token, and a git credential helper. */
33export async function prepareHome(
34 home: string, config: { gh: string; token: string; modelToken: string; observe?: boolean },
35): Promise<NodeJS.ProcessEnv> {
36 for (const dir of ["bin", "tmp", ".config/gh", ".copilot"]) await mkdir(join(home, dir), { recursive: true });
37 if (config.observe === false) {
38 await copyFile(config.gh, join(home, "bin/gh"));
39 await chmod(join(home, "bin/gh"), 0o700);
40 } else {
41 await copyFile(config.gh, join(home, "bin/gh-real"));
42 await chmod(join(home, "bin/gh-real"), 0o700);
43 await writeGhWrapper(join(home, "bin/gh"), join(home, "bin/gh-real"), join(home, ".commands.sock"));
44 }
45 const env = isolatedEnvironment(home, [
46 join(home, "bin"), dirname(process.execPath), "/usr/bin", "/bin", "/usr/sbin", "/sbin",
47 ].join(delimiter), config.modelToken);
48 await writeFile(join(home, ".config/gh/hosts.yml"),
49 `github.com:\n oauth_token: ${JSON.stringify(config.token)}\n git_protocol: https\n`, { mode: 0o600 });
50 const credentialHelper = join(home, "bin/git-credential-fixture");
51 await writeFile(credentialHelper, `#!${process.execPath}
52let input = "";
53for await (const chunk of process.stdin) input += chunk;
54if (process.argv[2] === "get" && /^host=github\\.com$/m.test(input) && /^protocol=https$/m.test(input)) {
55 process.stdout.write("username=x-access-token\\npassword=" + process.env.GH_EVAL_GIT_TOKEN + "\\n");
56}
57`, { mode: 0o700 });
58 await writeFile(join(home, ".gitconfig"),
59 `[user]\n\tname = Fixture author\n\temail = fixture@example.invalid\n[credential]\n\thelper =\n\thelper = ${JSON.stringify(`!${JSON.stringify(credentialHelper)}`)}\n`, { mode: 0o600 });
60 env.GH_EVAL_GIT_TOKEN = config.token;
61 return env;
62}

Callers 3

harness.test.tsFile · 0.85
mainFunction · 0.85
trialMethod · 0.85

Calls 3

writeGhWrapperFunction · 0.85
isolatedEnvironmentFunction · 0.85
writeFileFunction · 0.50

Tested by

no test coverage detected