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:
Maurice
2026-12-01 00:52:42 +01:00
parent 311321dc15
commit e605d0bcab
2 changed files with 36 additions and 0 deletions
@@ -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