112 lines
3.7 KiB
TypeScript
112 lines
3.7 KiB
TypeScript
|
|
import { assertEquals } from 'jsr:@std/assert@^1.0.0';
|
||
|
|
import { ConfigHandler } from '../ts/cli/config-handler.ts';
|
||
|
|
import { PATHS } from '../ts/constants.ts';
|
||
|
|
import { logger } from '../ts/logger.ts';
|
||
|
|
|
||
|
|
Deno.test('ConfigHandler init writes the current default config shape', async () => {
|
||
|
|
const tempDir = await Deno.makeTempDir();
|
||
|
|
const originalConfigDir = PATHS.CONFIG_DIR;
|
||
|
|
const originalConfigFile = PATHS.CONFIG_FILE;
|
||
|
|
(PATHS as { CONFIG_DIR: string }).CONFIG_DIR = tempDir;
|
||
|
|
(PATHS as { CONFIG_FILE: string }).CONFIG_FILE = `${tempDir}/config.json`;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const handler = new ConfigHandler();
|
||
|
|
await handler.init();
|
||
|
|
|
||
|
|
const config = JSON.parse(await Deno.readTextFile(`${tempDir}/config.json`));
|
||
|
|
assertEquals(config.ui.enabled, true);
|
||
|
|
assertEquals(config.ui.assetSource, 'bundle');
|
||
|
|
assertEquals(config.cluster.role, 'standalone');
|
||
|
|
assertEquals(config.models.registryUrl, 'https://list.modelgrid.com/catalog/models.json');
|
||
|
|
assertEquals(config.models.autoDeploy, true);
|
||
|
|
assertEquals(config.models.defaultEngine, 'vllm');
|
||
|
|
} finally {
|
||
|
|
(PATHS as { CONFIG_DIR: string }).CONFIG_DIR = originalConfigDir;
|
||
|
|
(PATHS as { CONFIG_FILE: string }).CONFIG_FILE = originalConfigFile;
|
||
|
|
await Deno.remove(tempDir, { recursive: true });
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
Deno.test('ConfigHandler show renders canonical model and ui settings', async () => {
|
||
|
|
const tempDir = await Deno.makeTempDir();
|
||
|
|
const originalConfigFile = PATHS.CONFIG_FILE;
|
||
|
|
const boxes: Array<{ title: string; lines: string[] }> = [];
|
||
|
|
const originalLog = logger.log;
|
||
|
|
const originalLogBox = logger.logBox;
|
||
|
|
|
||
|
|
(PATHS as { CONFIG_FILE: string }).CONFIG_FILE = `${tempDir}/config.json`;
|
||
|
|
|
||
|
|
logger.log = (_message: string) => {};
|
||
|
|
logger.logBox = (
|
||
|
|
title: string,
|
||
|
|
lines: string[],
|
||
|
|
) => {
|
||
|
|
boxes.push({ title, lines });
|
||
|
|
};
|
||
|
|
|
||
|
|
try {
|
||
|
|
await Deno.writeTextFile(
|
||
|
|
`${tempDir}/config.json`,
|
||
|
|
JSON.stringify({
|
||
|
|
version: '1.0.0',
|
||
|
|
api: {
|
||
|
|
port: 8080,
|
||
|
|
host: '0.0.0.0',
|
||
|
|
apiKeys: ['sk-test'],
|
||
|
|
rateLimit: 60,
|
||
|
|
cors: true,
|
||
|
|
corsOrigins: ['*'],
|
||
|
|
},
|
||
|
|
ui: {
|
||
|
|
enabled: true,
|
||
|
|
port: 8081,
|
||
|
|
host: '0.0.0.0',
|
||
|
|
assetSource: 'bundle',
|
||
|
|
},
|
||
|
|
docker: {
|
||
|
|
networkName: 'modelgrid',
|
||
|
|
runtime: 'docker',
|
||
|
|
},
|
||
|
|
gpus: {
|
||
|
|
autoDetect: true,
|
||
|
|
assignments: {},
|
||
|
|
},
|
||
|
|
containers: [],
|
||
|
|
models: {
|
||
|
|
registryUrl: 'https://example.com/catalog.json',
|
||
|
|
autoDeploy: false,
|
||
|
|
defaultEngine: 'vllm',
|
||
|
|
autoLoad: ['meta-llama/Llama-3.1-8B-Instruct'],
|
||
|
|
},
|
||
|
|
cluster: {
|
||
|
|
enabled: false,
|
||
|
|
nodeName: 'modelgrid-local',
|
||
|
|
role: 'standalone',
|
||
|
|
bindHost: '0.0.0.0',
|
||
|
|
gossipPort: 7946,
|
||
|
|
heartbeatIntervalMs: 5000,
|
||
|
|
seedNodes: [],
|
||
|
|
},
|
||
|
|
checkInterval: 30000,
|
||
|
|
}),
|
||
|
|
);
|
||
|
|
|
||
|
|
const handler = new ConfigHandler();
|
||
|
|
await handler.show();
|
||
|
|
|
||
|
|
const modelsBox = boxes.find((box) => box.title === 'Models');
|
||
|
|
assertEquals(modelsBox?.lines.some((line) => line.includes('Auto Deploy:')), true);
|
||
|
|
assertEquals(modelsBox?.lines.some((line) => line.includes('Default Engine: vllm')), true);
|
||
|
|
assertEquals(modelsBox?.lines.some((line) => line.includes('https://example.com/catalog.json')), true);
|
||
|
|
|
||
|
|
const apiBox = boxes.find((box) => box.title === 'API Server');
|
||
|
|
assertEquals(apiBox?.lines.some((line) => line.includes('Rate Limit: 60 req/min')), true);
|
||
|
|
} finally {
|
||
|
|
logger.log = originalLog;
|
||
|
|
logger.logBox = originalLogBox;
|
||
|
|
(PATHS as { CONFIG_FILE: string }).CONFIG_FILE = originalConfigFile;
|
||
|
|
await Deno.remove(tempDir, { recursive: true });
|
||
|
|
}
|
||
|
|
});
|