From b6086c4c227225ecfc0f6207f25105d664b8ad7a Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Sat, 29 Aug 2026 14:05:36 -0700 Subject: [PATCH 1/2] Add tests for memory-mount process env restore afterEach currently deletes DATABASE_URL when a test never called stashEnv. Snapshot KEYS at module load and assert they survive a non-stash resolveMemoryEmbed test so later drizzle suites in the same process still see the original env. --- apps/hub/src/memory-mount.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/hub/src/memory-mount.test.ts b/apps/hub/src/memory-mount.test.ts index c849f3b38..a8da59c1a 100644 --- a/apps/hub/src/memory-mount.test.ts +++ b/apps/hub/src/memory-mount.test.ts @@ -21,6 +21,17 @@ const KEYS = [ type EnvKey = (typeof KEYS)[number]; +const originals: Record = { + DATABASE_URL: process.env["DATABASE_URL"], + EMBED_BASE_URL: process.env["EMBED_BASE_URL"], + EMBED_MODEL: process.env["EMBED_MODEL"], + EMBED_API_STYLE: process.env["EMBED_API_STYLE"], + EMBED_API_KEY: process.env["EMBED_API_KEY"], + RERANK_BASE_URL: process.env["RERANK_BASE_URL"], + RERANK_MODEL: process.env["RERANK_MODEL"], + OLLAMA_BASE_URL: process.env["OLLAMA_BASE_URL"], +}; + const saved: Partial> = {}; function clearEnvKey(key: EnvKey): void { @@ -99,6 +110,12 @@ describe("resolveMemoryEmbed", () => { source: "OLLAMA_BASE_URL", }); }); + + test("afterEach restores KEYS after a non-stash resolveMemoryEmbed test", () => { + for (const key of KEYS) { + expect(process.env[key]).toBe(originals[key]); + } + }); }); describe("applyResolvedEmbedToProcessEnv", () => { From 1052f150934a714407211893f3c60d8e3bbedd3f Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Sat, 29 Aug 2026 14:06:45 -0700 Subject: [PATCH 2/2] Restore process env after memory-mount tests Snapshot KEYS at module load and restore them in afterEach. stashEnv only clears for the current test. Non-stash resolveMemoryEmbed tests no longer delete DATABASE_URL, so later drizzle suites in the same Bun process still see the original env. --- apps/hub/src/memory-mount.test.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/hub/src/memory-mount.test.ts b/apps/hub/src/memory-mount.test.ts index a8da59c1a..cd4bb4340 100644 --- a/apps/hub/src/memory-mount.test.ts +++ b/apps/hub/src/memory-mount.test.ts @@ -32,8 +32,6 @@ const originals: Record = { OLLAMA_BASE_URL: process.env["OLLAMA_BASE_URL"], }; -const saved: Partial> = {}; - function clearEnvKey(key: EnvKey): void { // Must actually remove the key: `process.env[key] = undefined` stores the // *string* "undefined" (Bun >= 1.4 matches Node here), which reads as a @@ -43,18 +41,18 @@ function clearEnvKey(key: EnvKey): void { Reflect.deleteProperty(process.env, key); } -afterEach(() => { +function restoreOriginalEnv(): void { for (const key of KEYS) { - const value = saved[key]; + const value = originals[key]; if (value === undefined) clearEnvKey(key); else process.env[key] = value; - saved[key] = undefined; } -}); +} + +afterEach(restoreOriginalEnv); function stashEnv(): void { for (const key of KEYS) { - saved[key] = process.env[key]; clearEnvKey(key); } }