• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gregreindel / llm-exe / 18725083385

22 Oct 2025 05:49PM UTC coverage: 99.681%. First build
18725083385

Pull #125

github

web-flow
Merge a1bbf16cc into f4b25ce06
Pull Request #125: Draft PR for release version v2.3.2

1053 of 1060 branches covered (99.34%)

Branch coverage included in aggregate %.

80 of 83 new or added lines in 6 files covered. (96.39%)

2385 of 2389 relevant lines covered (99.83%)

50.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.7
/src/utils/modules/runWithTemporaryEnv.ts
1
export async function runWithTemporaryEnv<R>(
11✔
2
  env: () => void,
3
  handler: () => Promise<R>
4
): Promise<R> {
5
  // Store original values for all env vars that will be modified
6
  const modifiedKeys: string[] = [];
9✔
7
  const originalValues: Record<string, string | undefined> = {};
9✔
8
  
9
  // Capture the current state before any modifications
10
  const envBefore = { ...process.env };
9✔
11
  
12
  try {
9✔
13
    // Run the environment setup
14
    try {
9✔
15
      env();
9✔
16
    } catch (envError) {
17
      // Track environment changes even if setup throws
18
      // This ensures cleanup happens regardless of errors
19
      const envAfter = process.env;
1✔
20
      for (const key in envAfter) {
1✔
21
        if (envBefore[key] !== envAfter[key]) {
136✔
22
          modifiedKeys.push(key);
1✔
23
          originalValues[key] = envBefore[key];
1✔
24
        }
25
      }
26
      
27
      // Also track keys that were deleted during setup
28
      for (const key in envBefore) {
1✔
29
        if (!(key in envAfter) && !modifiedKeys.includes(key)) {
135!
NEW
30
          modifiedKeys.push(key);
×
NEW
31
          originalValues[key] = envBefore[key];
×
32
        }
33
      }
34
      
35
      // Re-throw the error after tracking changes
36
      throw envError;
1✔
37
    }
38
    
39
    // Determine which keys were modified by comparing before and after
40
    const envAfter = process.env;
8✔
41
    for (const key in envAfter) {
8✔
42
      if (envBefore[key] !== envAfter[key]) {
1,089✔
43
        modifiedKeys.push(key);
9✔
44
        originalValues[key] = envBefore[key];
9✔
45
      }
46
    }
47
    
48
    // Also check for keys that existed before but were deleted
49
    for (const key in envBefore) {
8✔
50
      if (!(key in envAfter) && !modifiedKeys.includes(key)) {
1,082✔
51
        modifiedKeys.push(key);
1✔
52
        originalValues[key] = envBefore[key];
1✔
53
      }
54
    }
55
    
56
    // Execute the handler
57
    const value = await handler();
8✔
58
    return value;
6✔
59
  } finally {
60
    // Restore only the modified values
61
    for (const key of modifiedKeys) {
9✔
62
      const originalValue = originalValues[key];
11✔
63
      if (originalValue === undefined) {
11✔
64
        delete process.env[key];
9✔
65
      } else {
66
        process.env[key] = originalValue;
2✔
67
      }
68
    }
69
  }
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc