| 977 | } |
| 978 | |
| 979 | function buildEnvTrie(env: Record<string, string | undefined>): EnvTrieNode { |
| 980 | const trie: EnvTrieNode = {} |
| 981 | |
| 982 | for (const [name, value] of Object.entries(env)) { |
| 983 | if (value === undefined) continue |
| 984 | |
| 985 | // Split on "_" and keep empty segments (no special handling for "__") |
| 986 | const segments = name.split("_") |
| 987 | |
| 988 | let node = trie |
| 989 | for (const seg of segments) { |
| 990 | const children = node.children ??= Object.create(null) |
| 991 | node = children[seg] ??= {} |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | return trie |
| 996 | } |
| 997 | |
| 998 | function nodeAtEnv( |
| 999 | trie: EnvTrieNode, |