MCPcopy Create free account
hub / github.com/coder/mux / withEnv

Function withEnv

src/node/services/projectService.test.ts:31–54  ·  view source on GitHub ↗
(
  updates: Record<string, string | undefined>,
  run: () => Promise<T>
)

Source from the content-addressed store, hash-verified

29const ARCHIVED_AT = "2026-01-01T00:00:00.000Z";
30
31async function withEnv<T>(
32 updates: Record<string, string | undefined>,
33 run: () => Promise<T>
34): Promise<T> {
35 const originals = Object.fromEntries(Object.keys(updates).map((key) => [key, process.env[key]]));
36 for (const [key, value] of Object.entries(updates)) {
37 if (value === undefined) {
38 delete process.env[key];
39 } else {
40 process.env[key] = value;
41 }
42 }
43 try {
44 return await run();
45 } finally {
46 for (const [key, value] of Object.entries(originals)) {
47 if (value === undefined) {
48 delete process.env[key];
49 } else {
50 process.env[key] = value;
51 }
52 }
53 }
54}
55
56async function writeFakeGitCloneShim(fakeGitPath: string): Promise<void> {
57 await fs.writeFile(

Callers 2

cloneWithFakeGitFunction · 0.85

Calls 1

runFunction · 0.70

Tested by

no test coverage detected