feat(config): unify startup mode and server selection

This commit is contained in:
2026-09-05 22:52:14 +08:00
parent 239af0aa39
commit facceeae9b
26 changed files with 204 additions and 240 deletions
@@ -1,10 +1,9 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
ACTIVE_PROFILE,
PROFILES,
STARTUP_CONFIG,
validateStartupConfig,
decodeGameConfig,
resolveActiveProfile,
resolveGameServer,
} from '../../YouleNexus/assets/framework/config/profiles.ts';
@@ -23,19 +22,13 @@ test('resolveGameServer:空 gameconfig 使用配置源,非空值使用解码
);
});
test('默认 profile 是 ACTIVE_PROFILE,local 保持 remote 源与独立连接目标', () => {
assert.equal(resolveActiveProfile('').name, ACTIVE_PROFILE);
const local = resolveActiveProfile('?profile=local');
assert.equal(local.source, 'remote');
assert.ok(local.gameserver);
assert.deepEqual(local.servers, ['ws://127.0.0.1:3088']);
test('one frozen source defines the complete default startup configuration', () => {
assert.deepEqual(STARTUP_CONFIG, { mode: 'debug', gameserver: 'https://tsgames.daoqi88.cn/config/update_jsonv2.txt', useLocalServer: true, localServers: ['ws://127.0.0.1:3088'] });
assert.ok(Object.isFrozen(STARTUP_CONFIG)); assert.ok(Object.isFrozen(STARTUP_CONFIG.localServers));
});
test('未知 profile 显式报错,不回退到 ACTIVE_PROFILE', () => {
assert.throws(() => resolveActiveProfile('?profile=nope'), /未知 profile/);
});
test('正常 build 可达 profile 不含占位调试账号', () => {
assert.equal(JSON.stringify(PROFILES).includes('REPLACE_ME'), false);
assert.equal(PROFILES.staging.account, undefined);
test('source validation rejects malformed configuration without defaults', () => {
for (const patch of [{mode:'other'}, {useLocalServer:undefined}, {gameserver:'ws://host'}, {gameserver:''}, {localServers:[]}, {localServers:['ws://example.com:3088']}, {localServers:['ws://user:pass@localhost']}, {localServers:['ws://localhost/#fragment']}, {localServers:['ws://127.999.0.1']}, {localServers:['not-a-url']}]) {
assert.throws(() => validateStartupConfig({...STARTUP_CONFIG,...patch} as any), /startup config/i);
}
for (const url of ['ws://127.4.3.2:3088','wss://localhost:3088','ws://[::1]:3088']) assert.deepEqual(validateStartupConfig({...STARTUP_CONFIG,localServers:[url]}).localServers,[url]);
});