51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { loadConfig } from '../src/config.js';
|
|
|
|
const validEnv = {
|
|
GITEA_URL: 'https://git.example.com/',
|
|
GITEA_TOKEN: 'tok',
|
|
CLAUDE_CODE_OAUTH_TOKEN: 'oauth',
|
|
OWNER_LOGIN: 'selimaj-dev',
|
|
};
|
|
|
|
test('loads valid config and strips trailing slash from url', () => {
|
|
const cfg = loadConfig(validEnv);
|
|
assert.equal(cfg.giteaUrl, 'https://git.example.com');
|
|
assert.equal(cfg.port, 3000);
|
|
assert.equal(cfg.model, 'sonnet');
|
|
assert.equal(cfg.maxTurns, 25);
|
|
assert.equal(cfg.webhookSecret, null);
|
|
});
|
|
|
|
test('throws listing all missing required vars', () => {
|
|
assert.throws(() => loadConfig({}), /GITEA_URL.*GITEA_TOKEN.*CLAUDE_CODE_OAUTH_TOKEN.*OWNER_LOGIN/s);
|
|
});
|
|
|
|
test('throws on invalid GITEA_URL', () => {
|
|
assert.throws(() => loadConfig({ ...validEnv, GITEA_URL: 'not a url' }), /not a valid URL/);
|
|
});
|
|
|
|
test('throws on non-http(s) protocol', () => {
|
|
assert.throws(() => loadConfig({ ...validEnv, GITEA_URL: 'ftp://example.com' }), /http or https/);
|
|
});
|
|
|
|
test('throws on invalid PORT', () => {
|
|
assert.throws(() => loadConfig({ ...validEnv, PORT: 'abc' }), /valid port number/);
|
|
assert.throws(() => loadConfig({ ...validEnv, PORT: '0' }), /valid port number/);
|
|
assert.throws(() => loadConfig({ ...validEnv, PORT: '99999' }), /valid port number/);
|
|
});
|
|
|
|
test('applies numeric overrides', () => {
|
|
const cfg = loadConfig({ ...validEnv, PORT: '8080', JOB_TIMEOUT_MS: '5000', CLAUDE_MAX_TURNS: '10' });
|
|
assert.equal(cfg.port, 8080);
|
|
assert.equal(cfg.jobTimeoutMs, 5000);
|
|
assert.equal(cfg.maxTurns, 10);
|
|
});
|
|
|
|
test('passes through webhook secret and trigger phrase', () => {
|
|
const cfg = loadConfig({ ...validEnv, WEBHOOK_SECRET: 's3cret', TRIGGER_PHRASE: '@bot' });
|
|
assert.equal(cfg.webhookSecret, 's3cret');
|
|
assert.equal(cfg.triggerPhrase, '@bot');
|
|
});
|