mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
test(config): cover managed assistant boot validation
Cover the gateway tuple, HTTPS restrictions, and credential redaction. Mask the configured URL on schema failures because malformed URLs can contain credentials.
This commit is contained in:
@@ -28,6 +28,7 @@ export const SECRET_ENV_KEYS: ReadonlySet<string> = new Set([
|
||||
'ADMIN_PASSWORD',
|
||||
'PLACES_API_KEY',
|
||||
'TREK_SERVICES_KEY',
|
||||
'TREK_MANAGED_ASSISTANT_URL',
|
||||
'TREK_MANAGED_ASSISTANT_TOKEN',
|
||||
'AMAP_API_KEY',
|
||||
'AMAP_API_SECRET',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user