7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
test(proxy): scrub the OS-wide proxy fallback so the proxy suites stay hermetic (#1211)
paul.zhang0e1cbfb2924f
diff --git a/server/src/__tests__/lib/proxy-restore.test.ts b/server/src/__tests__/lib/proxy-restore.test.tsindex a1508dd0..583c970d 100644--- a/server/src/__tests__/lib/proxy-restore.test.ts+++ b/server/src/__tests__/lib/proxy-restore.test.ts@@ -1,4 +1,4 @@-import { describe, it, expect, beforeEach, afterAll } from 'vitest';+import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';import { initDb, getDb, setSetting } from '../../db/index.js';import {restoreProxySettings,@@ -16,6 +16,18 @@ import {encodeFetchRelayToken,} from '../../lib/proxy.js';+// #838 reads the OS-wide proxy (scutil/reg/gsettings) as a last-resort+// fallback when neither the env nor the DB configures one. A developer+// machine can genuinely have that set (macOS System Settings → Proxies),+// which fails every "no proxy configured" case below for the same reason+// clearProxyEnv() exists — the ambient system, not the code under test.+// '' parses as "no proxy" in every platform branch, so the suite sees a+// clean machine regardless of the host's system settings.+vi.mock('node:child_process', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ execFileSync: () => '',+}));+// #949: the desktop embedder builds the app without server/src/index.ts, so// the proxy state it starts with is whatever the module defaults are — an// empty URL. The URL the user saved through PUT /api/settings/proxy sits indiff --git a/server/src/__tests__/lib/proxy.test.ts b/server/src/__tests__/lib/proxy.test.tsindex d07e826c..d9630751 100644--- a/server/src/__tests__/lib/proxy.test.ts+++ b/server/src/__tests__/lib/proxy.test.ts@@ -26,6 +26,18 @@ import {parseRegProxy,} from '../../lib/proxy.js';+// #838 reads the OS-wide proxy (scutil/reg/gsettings) as a last-resort+// fallback when neither the env nor the DB configures one. A developer+// machine can genuinely have that set (macOS System Settings → Proxies),+// which fails every "no proxy configured" case below for the same reason+// clearProxyEnv() exists — the ambient system, not the code under test.+// '' parses as "no proxy" in every platform branch, so the suite sees a+// clean machine regardless of the host's system settings.+vi.mock('node:child_process', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ execFileSync: () => '',+}));+// Every env var the proxy config reads, in both the upper- and lower-case// spellings the convention allows. Cleared around each test so a developer// machine that genuinely sits behind a corporate proxy doesn't fail the suite.diff --git a/server/src/__tests__/routes/settings-proxy.test.ts b/server/src/__tests__/routes/settings-proxy.test.tsindex 9cfc2dab..e6555791 100644--- a/server/src/__tests__/routes/settings-proxy.test.ts+++ b/server/src/__tests__/routes/settings-proxy.test.ts@@ -1,10 +1,19 @@-import { describe, it, expect, beforeAll, afterAll } from 'vitest';+import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';import type { Express } from 'express';import { createApp } from '../../app.js';import { getSetting, initDb } from '../../db/index.js';import { mintDashboardToken } from '../helpers/auth.js';import { applyFetchRelayToken, applyProxyMode, applyProxyUrl } from '../../lib/proxy.js';+// #838 falls back to the OS-wide proxy (scutil/reg/gsettings) when nothing is+// configured in the DB or the env, so on a machine whose system proxy is set+// the "clears the proxy on an empty string" case would read the ambient proxy+// back. '' parses as "no proxy" in every platform branch.+vi.mock('node:child_process', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ execFileSync: () => '',+}));+async function request(app: Express, method: string, path: string, body: any, token: string) {const server = app.listen(0, '127.0.0.1');if (!server.listening) await new Promise<void>(resolve => server.once('listening', () => resolve()));