The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): system proxy env honours mixed-case proxy variables
Teknium87628aa789d2
diff --git a/apps/desktop/electron/updater/system-proxy-env.test.ts b/apps/desktop/electron/updater/system-proxy-env.test.tsindex 86d552eeab6..c82a8bbf2a6 100644--- a/apps/desktop/electron/updater/system-proxy-env.test.ts+++ b/apps/desktop/electron/updater/system-proxy-env.test.ts@@ -84,4 +84,21 @@ describe('update child proxy env from the system proxy (#123387)', () => {expect(next.HTTPS_PROXY).toBe('http://10.0.0.42:8080')})++ it('reads proxy settings in any letter case, as urllib and Windows do', async () => {+ const github = pac({ 'github.com': 'PROXY 10.0.0.7:7890' })++ expect(await systemProxyEnv({ Https_Proxy: 'http://explicit.corp:3128' }, github, ['github.com'])).toEqual({})++ // Windows hands the child one variable per case-insensitive name: the user's No_Proxy entries+ // must survive in the value the update sets, and come back alone after the relaunch restore.+ const user = { No_Proxy: 'corp.internal' }+ const env = await systemProxyEnv(user, github, ['github.com'], () => {}, true)+ const restored = restoreUserProxyEnv({ ...user, ...env })++ expect(env.NO_PROXY?.split(',')).toContain('corp.internal')+ expect(env.HERMES_UPDATE_SYSTEM_PROXY?.split(',')).not.toContain('NO_PROXY')+ expect(new Set(Object.entries(restored).filter(([key]) => key.toLowerCase() === 'no_proxy').map(([, v]) => v)))+ .toEqual(new Set(['corp.internal']))+ })})diff --git a/apps/desktop/electron/updater/system-proxy-env.ts b/apps/desktop/electron/updater/system-proxy-env.tsindex 3c9c45a2ba6..d713eb0741f 100644--- a/apps/desktop/electron/updater/system-proxy-env.ts+++ b/apps/desktop/electron/updater/system-proxy-env.ts@@ -98,21 +98,39 @@ export function restoreUserProxyEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {return env}+/**+ * Every value set under ``name`` in any letter case. Python's urllib lowercases env names on+ * every OS, and Windows env names are case-insensitive, so `Https_Proxy` / `No_Proxy` are real+ * settings even though a copied `process.env` is an ordinary, case-sensitive object.+ */+function valuesAnyCase(env: NodeJS.ProcessEnv, name: string): string[] {+ return Object.keys(env)+ .filter((key: string): boolean => key.toLowerCase() === name)+ .map((key: string): string => env[key] ?? '')+}+/** The user's own NO_PROXY entries, extended (never replaced) by the local bypass and DIRECT update hosts. */-function noProxyEnv(userEnv: NodeJS.ProcessEnv, direct: string[]): { env: NodeJS.ProcessEnv; added: string[] } {- const user = `${userEnv.no_proxy ?? ''},${userEnv.NO_PROXY ?? ''}`- const entries = user.split(',').map((entry: string): string => entry.trim())+function noProxyEnv(+ userEnv: NodeJS.ProcessEnv,+ direct: string[],+ isWindows: boolean+): { env: NodeJS.ProcessEnv; added: string[] } {+ const userValues = valuesAnyCase(userEnv, 'no_proxy')+ const entries = userValues.join(',').split(',').map((entry: string): string => entry.trim())const value = [...new Set([...entries.filter(Boolean), ...LOCAL_BYPASS, ...direct])].join(',')const env: NodeJS.ProcessEnv = {}const added: string[] = []for (const key of NO_PROXY_KEYS) {env[key] = value+ // On Windows a `No_Proxy` IS `NO_PROXY` to the child and to the relaunched app's restore, so+ // it is saved like an exact match; marked as added, the restore would delete the user's value.+ const own = userEnv[key] ?? (isWindows ? valuesAnyCase(userEnv, 'no_proxy')[0] : undefined)- if (userEnv[key] === undefined) {+ if (own === undefined) {added.push(key)} else {- env[`${SAVED_PREFIX}${key}`] = userEnv[key]+ env[`${SAVED_PREFIX}${key}`] = own}}@@ -123,12 +141,14 @@ export async function systemProxyEnv(env: NodeJS.ProcessEnv,resolveProxy: (url: string) => Promise<string>,hosts: string[] = UPDATE_HOSTS,- note: (message: string) => void = () => {}+ note: (message: string) => void = () => {},+ isWindows: boolean = process.platform === 'win32'): Promise<NodeJS.ProcessEnv> {// A value an earlier update marked as the Desktop's is never the user's own.const userEnv = restoreUserProxyEnv({ ...env })+ const explicitNames = new Set(PROXY_ENV_KEYS.map((key: string): string => key.toLowerCase()))- if (PROXY_ENV_KEYS.some((key: string): boolean => Boolean(userEnv[key]?.trim()))) {+ if ([...explicitNames].some((name: string): boolean => valuesAnyCase(userEnv, name).some(value => value.trim()))) {return {}}@@ -161,7 +181,7 @@ export async function systemProxyEnv(const proxy = routed[0].proxy as stringconst direct = answers.filter(answer => answer.kind === 'DIRECT').map(answer => answer.host)- const noProxy = noProxyEnv(userEnv, direct)+ const noProxy = noProxyEnv(userEnv, direct, isWindows)return {...Object.fromEntries(PROXY_SET_KEYS.map((key: string) => [key, proxy])),