@@ -3,35 +3,12 @@ import { describe, test, expect, beforeEach, afterEach } from "bun:test"
33import { mkdtemp , rm , mkdir , writeFile } from "fs/promises"
44import { tmpdir } from "os"
55import path from "path"
6+ import { resolveEnvVars } from "../../src/mcp"
67
78// -------------------------------------------------------------------------
89// resolveEnvVars — safety-net resolver at MCP launch site
910// -------------------------------------------------------------------------
1011
11- // Import the module to access resolveEnvVars indirectly via the env spread.
12- // Since resolveEnvVars is a module-level function (not inside the MCP namespace),
13- // we test it directly by importing the file and extracting the function.
14- // For now, inline the same logic here for unit testing.
15-
16- const ENV_VAR_PATTERN =
17- / \$ \$ ( \{ [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ ] * (?: : - [ ^ } ] * ) ? \} ) | (?< ! \$ ) \$ \{ ( [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ ] * ) (?: : - ( [ ^ } ] * ) ) ? \} | \{ e n v : ( [ ^ } ] + ) \} / g
18-
19- function resolveEnvVars ( environment : Record < string , string > ) : Record < string , string > {
20- const resolved : Record < string , string > = { }
21- for ( const [ key , value ] of Object . entries ( environment ) ) {
22- resolved [ key ] = value . replace ( ENV_VAR_PATTERN , ( match , escaped , dollarVar , dollarDefault , braceVar ) => {
23- if ( escaped !== undefined ) return "$" + escaped
24- if ( dollarVar !== undefined ) {
25- const envValue = process . env [ dollarVar ]
26- return envValue !== undefined && envValue !== "" ? envValue : ( dollarDefault ?? "" )
27- }
28- if ( braceVar !== undefined ) return process . env [ braceVar ] || ""
29- return match
30- } )
31- }
32- return resolved
33- }
34-
3512describe ( "resolveEnvVars" , ( ) => {
3613 const ORIGINAL_ENV = { ...process . env }
3714
0 commit comments