2026-04-21 12:44:11 +00:00
|
|
|
import { assertEquals } from 'jsr:@std/assert@^1.0.0';
|
2026-04-21 12:45:16 +00:00
|
|
|
import { ConfigManager } from '../ts/config/config-manager.ts';
|
2026-04-21 12:44:11 +00:00
|
|
|
import type { IModelGridConfig } from '../ts/interfaces/config.ts';
|
2026-04-21 13:10:55 +00:00
|
|
|
import { logger } from '../ts/logger.ts';
|
2026-04-21 12:44:11 +00:00
|
|
|
|
2026-04-21 12:45:16 +00:00
|
|
|
Deno.test('ConfigManager normalizes current config defaults', () => {
|
|
|
|
|
const configManager = new ConfigManager();
|
2026-04-21 12:44:11 +00:00
|
|
|
|
2026-04-21 12:45:16 +00:00
|
|
|
const normalized = configManager.normalizeConfig({
|
2026-04-21 12:44:11 +00:00
|
|
|
version: '1.0.0',
|
|
|
|
|
api: {
|
|
|
|
|
port: 9000,
|
|
|
|
|
host: '127.0.0.1',
|
|
|
|
|
apiKeys: ['test-key'],
|
|
|
|
|
},
|
|
|
|
|
docker: {
|
|
|
|
|
networkName: 'modelgrid',
|
|
|
|
|
runtime: 'docker',
|
|
|
|
|
},
|
|
|
|
|
gpus: {
|
|
|
|
|
autoDetect: true,
|
|
|
|
|
assignments: {},
|
|
|
|
|
},
|
|
|
|
|
containers: [],
|
|
|
|
|
models: {
|
|
|
|
|
registryUrl: 'https://example.com/catalog.json',
|
|
|
|
|
autoDeploy: false,
|
|
|
|
|
defaultEngine: 'vllm',
|
|
|
|
|
autoLoad: ['Qwen/Qwen2.5-7B-Instruct'],
|
|
|
|
|
},
|
|
|
|
|
cluster: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
nodeName: 'modelgrid-local',
|
|
|
|
|
role: 'standalone',
|
|
|
|
|
bindHost: '0.0.0.0',
|
|
|
|
|
gossipPort: 7946,
|
|
|
|
|
heartbeatIntervalMs: 5000,
|
|
|
|
|
seedNodes: [],
|
|
|
|
|
},
|
|
|
|
|
checkInterval: 15000,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assertEquals(normalized.models.registryUrl, 'https://example.com/catalog.json');
|
|
|
|
|
assertEquals(normalized.models.autoDeploy, false);
|
|
|
|
|
assertEquals(normalized.models.defaultEngine, 'vllm');
|
|
|
|
|
assertEquals(normalized.ui.enabled, true);
|
|
|
|
|
assertEquals(normalized.ui.port, 8081);
|
|
|
|
|
assertEquals(normalized.ui.assetSource, 'bundle');
|
|
|
|
|
});
|
2026-04-21 13:10:55 +00:00
|
|
|
|
|
|
|
|
Deno.test('ConfigManager warns when config contains ignored keys', () => {
|
|
|
|
|
const configManager = new ConfigManager();
|
|
|
|
|
const warnings: string[] = [];
|
|
|
|
|
const originalWarn = logger.warn;
|
|
|
|
|
logger.warn = (message: string) => {
|
|
|
|
|
warnings.push(message);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
configManager.normalizeConfig({
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
api: {
|
|
|
|
|
port: 8080,
|
|
|
|
|
host: '127.0.0.1',
|
|
|
|
|
apiKeys: [],
|
|
|
|
|
},
|
|
|
|
|
docker: {
|
|
|
|
|
networkName: 'modelgrid',
|
|
|
|
|
runtime: 'docker',
|
|
|
|
|
},
|
|
|
|
|
gpus: {
|
|
|
|
|
autoDetect: true,
|
|
|
|
|
assignments: {},
|
|
|
|
|
},
|
|
|
|
|
containers: [
|
|
|
|
|
{ id: 'legacy', type: 'ollama' } as never,
|
|
|
|
|
],
|
|
|
|
|
models: {
|
|
|
|
|
registryUrl: 'https://example.com/catalog.json',
|
|
|
|
|
autoDeploy: true,
|
|
|
|
|
defaultEngine: 'vllm',
|
|
|
|
|
autoLoad: [],
|
|
|
|
|
greenlistUrl: 'https://legacy.example.com/catalog.json',
|
|
|
|
|
autoPull: true,
|
|
|
|
|
defaultContainer: 'legacy-container',
|
|
|
|
|
} as IModelGridConfig['models'] & {
|
|
|
|
|
greenlistUrl: string;
|
|
|
|
|
autoPull: boolean;
|
|
|
|
|
defaultContainer: string;
|
|
|
|
|
},
|
|
|
|
|
cluster: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
nodeName: 'modelgrid-local',
|
|
|
|
|
role: 'standalone',
|
|
|
|
|
bindHost: '0.0.0.0',
|
|
|
|
|
gossipPort: 7946,
|
|
|
|
|
heartbeatIntervalMs: 5000,
|
|
|
|
|
seedNodes: [],
|
|
|
|
|
},
|
|
|
|
|
checkInterval: 30000,
|
|
|
|
|
legacySection: true,
|
|
|
|
|
} as Partial<IModelGridConfig> & {
|
|
|
|
|
legacySection: boolean;
|
|
|
|
|
models: IModelGridConfig['models'] & {
|
|
|
|
|
greenlistUrl: string;
|
|
|
|
|
autoPull: boolean;
|
|
|
|
|
defaultContainer: string;
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
logger.warn = originalWarn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assertEquals(warnings.includes('Ignoring unknown config key: legacySection'), true);
|
|
|
|
|
assertEquals(warnings.includes('Ignoring removed config key: models.greenlistUrl'), true);
|
|
|
|
|
assertEquals(warnings.includes('Ignoring removed config key: models.autoPull'), true);
|
|
|
|
|
assertEquals(warnings.includes('Ignoring removed config key: models.defaultContainer'), true);
|
|
|
|
|
assertEquals(warnings.includes('Ignoring unsupported container type: ollama'), true);
|
|
|
|
|
});
|