diff --git a/server/src/app-config/env.ts b/server/src/app-config/env.ts index 11e39c6cf..94e5b60ee 100644 --- a/server/src/app-config/env.ts +++ b/server/src/app-config/env.ts @@ -28,6 +28,7 @@ export const SECRET_ENV_KEYS: ReadonlySet = new Set([ 'ADMIN_PASSWORD', 'PLACES_API_KEY', 'TREK_SERVICES_KEY', + 'TREK_MANAGED_ASSISTANT_URL', 'TREK_MANAGED_ASSISTANT_TOKEN', 'AMAP_API_KEY', 'AMAP_API_SECRET', diff --git a/server/tests/unit/app-config/validate.test.ts b/server/tests/unit/app-config/validate.test.ts index 250bf79c0..9553526a7 100644 --- a/server/tests/unit/app-config/validate.test.ts +++ b/server/tests/unit/app-config/validate.test.ts @@ -59,6 +59,41 @@ describe('validateEnvAtBoot', () => { ).not.toThrow(); }); + const managedAssistant = { + TREK_MANAGED: '1', + ENCRYPTION_KEY: 'a'.repeat(64), + TREK_MANAGED_ASSISTANT_URL: 'https://gate.example.com/ai/v1', + TREK_MANAGED_ASSISTANT_MODEL: 'provider/model', + TREK_MANAGED_ASSISTANT_TOKEN: 'synthetic-assistant-credential', + }; + + it('accepts a managed assistant with a complete gateway configuration', () => { + expect(() => validateEnvAtBoot(managedAssistant)).not.toThrow(); + }); + + it.each([ + ['TREK_MANAGED_ASSISTANT_URL', ''], + ['TREK_MANAGED_ASSISTANT_MODEL', ' '], + ['TREK_MANAGED_ASSISTANT_TOKEN', ' '], + ])('refuses partial managed assistant configuration with %s missing', (key, value) => { + const report = bootReport({ ...managedAssistant, [key]: value }); + expect(report.printed).toContain('URL, model and token must be configured together'); + }); + + it.each([ + 'https://name:synthetic-url-password@invalid host/', + 'http://gate.example.com/ai/v1', + 'https://user@gate.example.com/ai/v1', + 'https://:synthetic-url-password@gate.example.com/ai/v1', + 'https://gate.example.com/ai/v1?query=1', + 'https://gate.example.com/ai/v1#section', + ])('refuses an unsafe managed assistant URL', (url) => { + const report = bootReport({ ...managedAssistant, TREK_MANAGED_ASSISTANT_URL: url }); + expect(report.printed).toContain('must be an HTTPS URL without credentials, a query or a fragment'); + expect(report.printed).not.toContain('synthetic-url-password'); + expect(report.printed).not.toContain(managedAssistant.TREK_MANAGED_ASSISTANT_TOKEN); + }); + it('refuses an LLM ceiling that would silently become a zero timeout', () => { // Both shapes pass a plain "positive number" check and then degrade into an // immediate abort: a fractional value floors to 0, and anything past the