Skip to content

The agent that grows with you

fix(install-e2e): writeEnvFile must not delete a provider endpoint it isn't replacing

ethernet690b8d5b34a4
diff --git a/tests-js/scripts/desktop-smoke.test.ts b/tests-js/scripts/desktop-smoke.test.ts
index 12fd9d97005..dd4a5e6cc1e 100644
--- a/tests-js/scripts/desktop-smoke.test.ts
+++ b/tests-js/scripts/desktop-smoke.test.ts
@@ -269,3 +269,23 @@ test('a bundle-env HERMES_HOME clear cannot strand the mock config outside the r
}
} finally { fs.rmSync(root, { recursive: true, force: true }) }
})
+
+test('writeEnvFile without a URL keeps the journey provider endpoint', (): void => {
+ // The install e2e configures the mock provider through the CLI, which writes
+ // OPENAI_BASE_URL/OPENAI_API_KEY. The desktop smoke then calls writeEnvFile with
+ // no URL, and stripping the pair there deleted the endpoint the snapshot was
+ // meant to record -- the upgrade's own .env sync later put it back, and the leg
+ // failed as "the upgrade changed the user's own state".
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'smoke-env-'))
+ try {
+ writeEnvFile(home, 'e2e-mock-key', 'http://127.0.0.1:9000')
+ expect(fs.readFileSync(path.join(home, '.env'), 'utf8')).toContain('OPENAI_BASE_URL=http://127.0.0.1:9000/v1')
+
+ writeEnvFile(home)
+
+ const after = fs.readFileSync(path.join(home, '.env'), 'utf8')
+ expect(after).toContain('OPENAI_BASE_URL=http://127.0.0.1:9000/v1')
+ expect(after).toContain('OPENAI_API_KEY=e2e-mock-key')
+ expect(after).toContain('MOCK_API_KEY=e2e-mock-key')
+ } finally { fs.rmSync(home, { recursive: true, force: true }) }
+})
diff --git a/tests-js/scripts/mock-provider-config.ts b/tests-js/scripts/mock-provider-config.ts
index ad95cfa5a0e..6dabf7d8c5f 100644
--- a/tests-js/scripts/mock-provider-config.ts
+++ b/tests-js/scripts/mock-provider-config.ts
@@ -79,7 +79,15 @@ export function writeEnvFile(hermesHome: string, apiKey = 'e2e-mock-key', mockUr
}
const envPath = path.join(hermesHome, '.env')
const prior = fs.existsSync(envPath) ? fs.readFileSync(envPath, 'utf8') : ''
- const lines = prior.split(/\r?\n/).filter((line: string): boolean => !/^\s*(?:export\s+)?(?:MOCK_API_KEY|OPENAI_BASE_URL|OPENAI_API_KEY)\s*=/.test(line))
+ // Only drop keys this call actually REPLACES. With no mockUrl it writes
+ // MOCK_API_KEY alone, and stripping the portable pair then would delete a
+ // journey's provider endpoint: the install e2e's snapshot missed OPENAI_BASE_URL
+ // after this smoke ran, and the upgrade's own .env sync put it back -- reported
+ // as "the upgrade changed the user's own state".
+ const replaced = mockUrl
+ ? /^\s*(?:export\s+)?(?:MOCK_API_KEY|OPENAI_BASE_URL|OPENAI_API_KEY)\s*=/
+ : /^\s*(?:export\s+)?MOCK_API_KEY\s*=/
+ const lines = prior.split(/\r?\n/).filter((line: string): boolean => !replaced.test(line))
// OPENAI_BASE_URL + OPENAI_API_KEY is how EVERY vintage reaches an external
// OpenAI-compatible endpoint ("custom"); a bare MOCK_API_KEY only means
// something to a tree that knows a provider named `mock`, which older refs