fix(config): restore legacy gameserver and urlserver contract

This commit is contained in:
2026-09-05 01:25:50 +08:00
parent f25211c64e
commit d1ad63983b
16 changed files with 622 additions and 383 deletions
@@ -1,27 +1,40 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { resolveActiveProfile, PROFILES, ACTIVE_PROFILE } from '../../YouleNexus/assets/framework/config/profiles.ts';
import {
ACTIVE_PROFILE,
PROFILES,
decodeGameConfig,
resolveActiveProfile,
resolveGameServer,
} from '../../YouleNexus/assets/framework/config/profiles.ts';
test('默认返回 ACTIVE_PROFILE', () => {
const p = resolveActiveProfile('');
assert.equal(p.name, ACTIVE_PROFILE);
test('decodeGameConfig:按旧协议把 -/# 解码为远程 txt URL', () => {
assert.equal(decodeGameConfig('host-path#8080-config'), 'http://host/path:8080/config.txt');
});
test('prod profile 无调试覆盖、isDebugger=false', () => {
const prod = PROFILES['prod'];
assert.equal(prod.isDebugger, false);
assert.equal(prod.server, undefined);
assert.equal(prod.identity, undefined);
assert.ok(prod.gameserver && prod.gameserver.length > 0);
test('resolveGameServer:空 gameconfig 使用配置源,非空值使用解码后的注入源', () => {
assert.equal(
resolveGameServer({ configured: 'https://default/config.txt', injectedGameConfig: '' }),
'https://default/config.txt',
);
assert.equal(
resolveGameServer({ configured: 'https://default/config.txt', injectedGameConfig: 'host-path#80-a' }),
'http://host/path:80/a.txt',
);
});
test('?profile=local 切到 local,含调试服地址', () => {
const p = resolveActiveProfile('?profile=local');
assert.equal(p.name, 'local');
assert.ok(p.server && p.server.startsWith('ws://'));
test('默认 profile 是 ACTIVE_PROFILE,local 是显式 direct 源', () => {
assert.equal(resolveActiveProfile('').name, ACTIVE_PROFILE);
const local = resolveActiveProfile('?profile=local');
assert.equal(local.source, 'direct');
assert.deepEqual(local.servers, ['ws://127.0.0.1:3088']);
});
test('未知 profile 回退到 ACTIVE_PROFILE', () => {
const p = resolveActiveProfile('?profile=nope');
assert.equal(p.name, ACTIVE_PROFILE);
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);
});