mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 03:13:46 +00:00
compose.yml now holds each default as ${VAR:-default}, and the code keeps
no fallback values. The bot stops at startup on a missing or invalid
PORT or LOG_LEVEL, /addsticker refuses without STICKER_PACK_NAME, and the
renderer refuses to start until every RENDERER_* setting is a valid
value, listing each problem. Settings whose empty value means none or
all (MODULES, OWNER_ID, ADMIN_IDS, the API tokens) use ${VAR:-}.
The renderer's npm start and dev load .env when present, so a local run
works from a copy of .env.example.
BREAKING CHANGE: running outside compose now requires LOG_LEVEL and PORT
for the bot, STICKER_PACK_NAME for /addsticker, and every RENDERER_*
variable for the renderer.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import {describe, expect, test} from 'vitest';
|
|
import {loadConfig, minRenderTimeoutMs} from '../src/config.js';
|
|
|
|
const validEnv = {
|
|
RENDERER_HOST: '0.0.0.0',
|
|
RENDERER_PORT: '3000',
|
|
RENDERER_MAX_CONCURRENT_RENDERS: '1',
|
|
RENDERER_RENDER_TIMEOUT_MS: '15000',
|
|
RENDERER_MAX_OPTIONS: '32',
|
|
RENDERER_MAX_OPTION_CHARS: '40',
|
|
};
|
|
|
|
describe('loadConfig', () => {
|
|
test('reads every RENDERER_* setting', () => {
|
|
expect(loadConfig(validEnv)).toEqual({
|
|
host: '0.0.0.0',
|
|
port: 3000,
|
|
maxConcurrentRenders: 1,
|
|
renderTimeoutMs: 15000,
|
|
maxOptions: 32,
|
|
maxOptionChars: 40,
|
|
});
|
|
});
|
|
|
|
test('keeps render timeout compatible with Remotion browser timeout limits', () => {
|
|
const config = loadConfig({...validEnv, RENDERER_RENDER_TIMEOUT_MS: '500'});
|
|
|
|
expect(config.renderTimeoutMs).toBe(minRenderTimeoutMs);
|
|
});
|
|
|
|
test('has no fallback: missing settings are all reported', () => {
|
|
expect(() => loadConfig({})).toThrow(
|
|
/RENDERER_HOST is required.*RENDERER_PORT is required.*RENDERER_MAX_OPTION_CHARS is required/,
|
|
);
|
|
});
|
|
|
|
test('treats an empty value as missing', () => {
|
|
expect(() => loadConfig({...validEnv, RENDERER_MAX_OPTIONS: ''})).toThrow(
|
|
/RENDERER_MAX_OPTIONS is required/,
|
|
);
|
|
});
|
|
|
|
test.each(['0', '-1', '1.5', 'abc'])('rejects non-positive-integer %s', (value) => {
|
|
expect(() => loadConfig({...validEnv, RENDERER_MAX_OPTIONS: value})).toThrow(
|
|
/RENDERER_MAX_OPTIONS must be a positive integer/,
|
|
);
|
|
});
|
|
});
|