import assert from 'node:assert/strict'; import { afterEach, describe, it } from 'node:test'; import { loadConfig } from '../src/config.ts'; const SAVED = { ...process.env }; afterEach(() => { process.env = { ...SAVED }; }); describe('loadConfig', () => { it('requires the instance URL and token', () => { delete process.env.TSC_URL; process.env.TSC_JWT_COOKIE = 'x'; assert.throws(() => loadConfig(), /TSC_URL/); }); it('strips trailing slashes so paths concatenate cleanly', () => { process.env.TSC_URL = 'https://example.org///'; process.env.TSC_JWT_COOKIE = 'x'; assert.equal(loadConfig().baseUrl, 'https://example.org'); }); it('rejects a non-numeric port rather than silently defaulting', () => { process.env.TSC_URL = 'https://example.org'; process.env.TSC_JWT_COOKIE = 'x'; process.env.PORT = 'not-a-number'; assert.throws(() => loadConfig(), /PORT/); }); it('treats a blank auth token as absent', () => { process.env.TSC_URL = 'https://example.org'; process.env.TSC_JWT_COOKIE = 'x'; process.env.MCP_AUTH_TOKEN = ' '; assert.equal(loadConfig().authToken, undefined); }); }); describe('loadConfig: state directory', () => { it('resolves the state directory to an absolute path', () => { process.env.TSC_URL = 'https://example.org'; process.env.TSC_JWT_COOKIE = 'x'; process.env.STATE_DIR = 'tmp/state'; assert.match(loadConfig().stateDir ?? '', /^\/.*\/tmp\/state$/); }); });