fix(config): resolve remote hierarchy in memory for every profile
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../../fixtures/remote-config.ts';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { BUILD_IDENTITY } from '../../../YouleNexus/assets/framework/config/sources/defaults.ts';
|
||||
@@ -7,7 +8,7 @@ import { LOCAL_MACHINE_KEY, localAccountKey, type LocalStoragePort } from '../..
|
||||
import { createLocalLoginSources, type LocalHostSnapshot } from '../../../YouleNexus/assets/framework/adapters/local/login-sources.ts';
|
||||
|
||||
const context: LocalStartupContext = { hostKind: 'h5', profile: 'local', config: {
|
||||
mode: 'debug', isDebugger: true, source: 'direct', gameserver: null, rawConfig: null,
|
||||
mode: 'debug', isDebugger: true, source: 'remote', gameserver: PROFILES.local!.gameserver, ...remoteFixture(),
|
||||
servers: PROFILES.local!.servers!, identity: BUILD_IDENTITY,
|
||||
} };
|
||||
class MapStorage implements LocalStoragePort {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../../fixtures/remote-config.ts';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { BUILD_IDENTITY } from '../../../YouleNexus/assets/framework/config/sources/defaults.ts';
|
||||
@@ -15,7 +16,7 @@ class MapStorage implements LocalStoragePort {
|
||||
|
||||
function context(overrides: Partial<typeof BUILD_IDENTITY> = {}): LocalStartupContext {
|
||||
return { hostKind: 'h5', profile: 'local', config: {
|
||||
mode: 'debug', isDebugger: true, source: 'direct', gameserver: null, rawConfig: null,
|
||||
mode: 'debug', isDebugger: true, source: 'remote', gameserver: PROFILES.local!.gameserver, ...remoteFixture(),
|
||||
servers: PROFILES.local!.servers!, identity: { ...BUILD_IDENTITY, ...overrides },
|
||||
} };
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import type { ConfigFetcher } from '../../YouleNexus/assets/framework/config/rem
|
||||
|
||||
test('resolveBootstrap:显式 hostKind 透传严格 RuntimeConfig,并保留 profile 元数据', async () => {
|
||||
const fetcher: ConfigFetcher = {
|
||||
async fetch() { return { data: { urlserver: '5.5.5.5:5000' } }; },
|
||||
async fetch() { return { player_server_tcp: '5.5.5.5:5000' }; },
|
||||
};
|
||||
const result = await resolveBootstrap({
|
||||
mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local', fetcher,
|
||||
});
|
||||
assert.equal(result.source, 'direct');
|
||||
assert.equal(result.source, 'remote');
|
||||
assert.equal(result.profile.name, 'local');
|
||||
assert.deepEqual(result.servers, ['ws://127.0.0.1:3088']);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
@@ -16,15 +17,15 @@ function options(search = '?profile=local'): ResolveRuntimeConfigOptions & {
|
||||
} {
|
||||
const fetcher = {
|
||||
calls: 0,
|
||||
async fetch(): Promise<never> {
|
||||
async fetch() {
|
||||
this.calls += 1;
|
||||
throw new Error('forbidden fetch');
|
||||
return { player_server_tcp: 'remote.example:3088' };
|
||||
},
|
||||
};
|
||||
return { mode: 'debug', hostKind: 'h5', win: {}, search, fetcher };
|
||||
}
|
||||
|
||||
test('local debug resolves the authoritative direct config without fetching', async () => {
|
||||
test('local debug fetches remote config before choosing authoritative local servers', async () => {
|
||||
const input = options();
|
||||
const context = await resolveLocalStartup(input);
|
||||
|
||||
@@ -32,7 +33,8 @@ test('local debug resolves the authoritative direct config without fetching', as
|
||||
assert.equal(context.profile, 'local');
|
||||
assert.equal(context.config.identity.gameid, BUILD_IDENTITY.gameid);
|
||||
assert.deepEqual(context.config.servers, PROFILES.local!.servers);
|
||||
assert.equal(input.fetcher.calls, 0);
|
||||
assert.equal(input.fetcher.calls, 1);
|
||||
assert.equal(context.config.source, 'remote');
|
||||
assert.equal(Object.isFrozen(context), true);
|
||||
});
|
||||
|
||||
@@ -107,9 +109,9 @@ function validContext(): LocalStartupContext {
|
||||
isDebugger: true,
|
||||
identity: BUILD_IDENTITY,
|
||||
servers: PROFILES.local!.servers!,
|
||||
source: 'direct',
|
||||
gameserver: null,
|
||||
rawConfig: null,
|
||||
source: 'remote',
|
||||
gameserver: PROFILES.local!.gameserver,
|
||||
...remoteFixture(BUILD_IDENTITY),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -119,7 +121,7 @@ test('context validator rejects forged config fields and malformed identity', ()
|
||||
const configCases: Array<[keyof RuntimeConfig, unknown]> = [
|
||||
['mode', 'release'],
|
||||
['isDebugger', false],
|
||||
['source', 'remote'],
|
||||
['source', 'direct'],
|
||||
['gameserver', 'https://example.com/config.txt'],
|
||||
['rawConfig', {}],
|
||||
['servers', ['ws://127.0.0.1:9999']],
|
||||
|
||||
@@ -23,10 +23,11 @@ test('resolveGameServer:空 gameconfig 使用配置源,非空值使用解码
|
||||
);
|
||||
});
|
||||
|
||||
test('默认 profile 是 ACTIVE_PROFILE,local 是显式 direct 源', () => {
|
||||
test('默认 profile 是 ACTIVE_PROFILE,local 保持 remote 源与独立连接目标', () => {
|
||||
assert.equal(resolveActiveProfile('').name, ACTIVE_PROFILE);
|
||||
const local = resolveActiveProfile('?profile=local');
|
||||
assert.equal(local.source, 'direct');
|
||||
assert.equal(local.source, 'remote');
|
||||
assert.ok(local.gameserver);
|
||||
assert.deepEqual(local.servers, ['ws://127.0.0.1:3088']);
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ test('HttpConfigFetcher:POST 空 body,并无条件以 ? 拼接 cache bust',
|
||||
const calls: Array<{ input: string; init?: RequestInit }> = [];
|
||||
const fetcher = new HttpConfigFetcher(async (input, init) => {
|
||||
calls.push({ input: String(input), init });
|
||||
return new Response('{"data":{"urlserver":"10.0.0.1:3088"}}');
|
||||
return new Response('{"player_server_tcp":"10.0.0.1:3088"}');
|
||||
});
|
||||
|
||||
await fetcher.fetch('https://config.example/file.txt?existing=1', () => '123');
|
||||
@@ -22,7 +22,7 @@ test('resolveRuntimeConfig:把 cacheBust 注入唯一的 HTTP 请求构造点'
|
||||
const calls: Array<{ input: string; init?: RequestInit }> = [];
|
||||
const fetcher = new HttpConfigFetcher(async (input, init) => {
|
||||
calls.push({ input: String(input), init });
|
||||
return new Response('{"data":{"urlserver":"10.0.0.1:3088"}}');
|
||||
return new Response('{"player_server_tcp":"10.0.0.1:3088"}');
|
||||
});
|
||||
|
||||
await resolveRuntimeConfig({
|
||||
@@ -49,7 +49,7 @@ test('HttpConfigFetcher:非法 JSON 显式抛 ConfigParseError', async () => {
|
||||
|
||||
test('HttpConfigFetcher:非 200 响应即使 body 是合法 JSON 也拒绝', async () => {
|
||||
const fetcher = new HttpConfigFetcher(async () => new Response(
|
||||
'{"data":{"urlserver":"10.0.0.1:3088"}}',
|
||||
'{"player_server_tcp":"10.0.0.1:3088"}',
|
||||
{ status: 503 },
|
||||
));
|
||||
await assert.rejects(
|
||||
|
||||
@@ -1,54 +1,68 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { parseUrlServers } from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
|
||||
const single = JSON.parse(readFileSync(
|
||||
new URL('../fixtures/contracts/remote-config-single.json', import.meta.url),
|
||||
'utf8',
|
||||
)) as unknown;
|
||||
const array = JSON.parse(readFileSync(
|
||||
new URL('../fixtures/contracts/remote-config-array.json', import.meta.url),
|
||||
'utf8',
|
||||
)) as unknown;
|
||||
|
||||
test('parseUrlServers:读取 data.urlserver 字符串并补 ws://', () => {
|
||||
assert.deepEqual(parseUrlServers(single), ['ws://10.0.0.1:3088']);
|
||||
import * as api from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
const identity = { agentid: '11', gameid: '22', channelid: '33', marketid: 44, version: 1 };
|
||||
const source = readFileSync(new URL('../../../projects/Game_Surface_3/js/00_Surface/12_Logic.js', import.meta.url), 'utf8');
|
||||
const start = source.indexOf('function get_paravalue(o_config, paraname){');
|
||||
const legacySource = source.slice(start, source.indexOf('function getConfig_Succ', start));
|
||||
function view(raw: unknown, selected = identity) {
|
||||
assert.equal(typeof api.createRemoteConfig, 'function', 'remote memory view must be exported');
|
||||
return api.createRemoteConfig(raw, selected);
|
||||
}
|
||||
function legacy(raw: unknown, name: string, selected = identity) {
|
||||
return runInNewContext(`${legacySource}; get_paravalue(wrapper, name)`, {
|
||||
wrapper: { data: raw }, name,
|
||||
GameData: { AgentId: selected.agentid, GameId: selected.gameid, ChannelId: selected.channelid, marketID: selected.marketid },
|
||||
});
|
||||
}
|
||||
test('memory view agrees with actual legacy function across all five scopes and preserves raw objects', () => {
|
||||
const scopes: Record<string, unknown>[] = [
|
||||
{ hall_config: { root: true }, rootOnly: 'root', falsy: 'inherited' },
|
||||
{ agentid: 11, hall_config: { agent: true }, agentOnly: 'agent', falsy: 0 },
|
||||
{ gameid: 22, hall_config: { game: true }, gameOnly: 'game', falsy: false },
|
||||
{ channelid: 33, hall_config: { channel: true }, channelOnly: 'channel', falsy: '' },
|
||||
{ marketid: '44', hall_config: ['market'], marketOnly: 'market', falsy: null },
|
||||
];
|
||||
const lists = ['agentlist', 'gamelist', 'channellist', 'marketlist'];
|
||||
for (let depth = 0; depth < scopes.length; depth++) {
|
||||
if (depth > 0) scopes[depth - 1][lists[depth - 1]] = [scopes[depth], { ...scopes[depth], hall_config: 'duplicate must lose' }];
|
||||
const result = view(scopes[0]);
|
||||
assert.strictEqual(result.raw, scopes[0]);
|
||||
for (const name of ['hall_config', 'rootOnly', 'agentOnly', 'gameOnly', 'channelOnly', 'marketOnly', 'falsy', 'missing']) {
|
||||
assert.deepEqual(result.getValue(name), legacy(scopes[0], name));
|
||||
}
|
||||
assert.strictEqual(result.getValue('hall_config'), scopes[depth].hall_config);
|
||||
assert.equal(result.getValue('falsy'), 'inherited');
|
||||
}
|
||||
assert.equal(view(scopes[0], { ...identity, marketid: 0 }).getValue('marketOnly'), null);
|
||||
assert.deepEqual(view(scopes[0], { ...identity, agentid: 'missing' }).getValue('hall_config'), { root: true });
|
||||
});
|
||||
|
||||
test('parseUrlServers:读取 data.urlserver 数组并保留已有 wss://', () => {
|
||||
assert.deepEqual(parseUrlServers(array), ['ws://10.0.0.1:3088', 'wss://backup.example/ws']);
|
||||
test('falsy root values remain null and missing identity levels stop inheritance', () => {
|
||||
for (const value of [0, false, '', null]) assert.equal(view({ x: value }).getValue('x'), null);
|
||||
assert.equal(view({ x: 'root', agentlist: [{ agentid: 'other', x: 'wrong' }] }).getValue('x'), 'root');
|
||||
});
|
||||
|
||||
test('parseUrlServers:拒绝旧的 *_server_tcp 字段', () => {
|
||||
assert.throws(
|
||||
() => parseUrlServers({ data: { player_server_tcp: 'wrong:1' } }),
|
||||
/data\.urlserver/,
|
||||
);
|
||||
test('invalid root and present hierarchy fail explicitly', () => {
|
||||
for (const raw of [null, [], 'json', { agentlist: {} }, { agentlist: [null] },
|
||||
{ agentlist: [{ agentid: 11, gamelist: {} }] }, { agentlist: [{ agentid: 11, gamelist: [{ gameid: 22, channellist: [false] }] }] }]) {
|
||||
assert.throws(() => view(raw), api.ConfigParseError);
|
||||
}
|
||||
});
|
||||
|
||||
test('parseUrlServers:保留原顺序和重复项,并冻结结果', () => {
|
||||
const servers = parseUrlServers({ data: { urlserver: ['same:1', 'same:1', 'ws://last:2'] } });
|
||||
assert.deepEqual(servers, ['ws://same:1', 'ws://same:1', 'ws://last:2']);
|
||||
assert.equal(Object.isFrozen(servers), true);
|
||||
test('server selection prefers scoped game then player and preserves order and duplicates', () => {
|
||||
for (const [raw, expected] of [
|
||||
[{ player_server_tcp: 'remote.example:3088' }, ['ws://remote.example:3088']],
|
||||
[{ player_server_tcp: 'unused', game_server_tcp: ['same:1', 'same:1', 'wss://last/ws'] }, ['ws://same:1', 'ws://same:1', 'wss://last/ws']],
|
||||
[{ game_server_tcp: '', player_server_tcp: 'player:1' }, ['ws://player:1']],
|
||||
[{ game_server_tcp: 'global:1', agentlist: [{ agentid: 11, game_server_tcp: 'agent:2' }] }, ['ws://agent:2']],
|
||||
] as const) {
|
||||
const servers = api.parseUrlServers(view(raw));
|
||||
assert.deepEqual(servers, expected); assert.ok(Object.isFrozen(servers));
|
||||
}
|
||||
});
|
||||
|
||||
test('parseUrlServers:拒绝空字符串、空数组和非字符串数组项', () => {
|
||||
assert.throws(() => parseUrlServers({ data: { urlserver: '' } }), /data\.urlserver/);
|
||||
assert.throws(() => parseUrlServers({ data: { urlserver: [] } }), /data\.urlserver/);
|
||||
assert.throws(() => parseUrlServers({ data: { urlserver: ['ok:1', ''] } }), /data\.urlserver/);
|
||||
assert.throws(() => parseUrlServers({ data: { urlserver: ['ok:1', 2] } }), /data\.urlserver/);
|
||||
});
|
||||
|
||||
test('parseUrlServers:显式拒绝已有的非 WebSocket scheme', () => {
|
||||
for (const value of [
|
||||
'http://config.example/ws',
|
||||
'https://config.example/ws',
|
||||
'ftp://config.example/ws',
|
||||
]) {
|
||||
assert.throws(
|
||||
() => parseUrlServers({ data: { urlserver: value } }),
|
||||
/不支持.*scheme/i,
|
||||
);
|
||||
test('missing or invalid chosen servers never fall back to obsolete envelope or player candidates', () => {
|
||||
for (const raw of [{ data: { urlserver: 'old:1' } }, {},
|
||||
...[[], ['ok:1', ''], ['ok:1', 2], true, ' ', 'http://wrong/ws', 'ws://', 'ws://user:pass@host:1', 'host:bad'].map(game_server_tcp => ({ game_server_tcp, player_server_tcp: 'valid:1' }))]) {
|
||||
assert.throws(() => api.parseUrlServers(view(raw)), api.ConfigParseError);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ function returning(value: unknown): ConfigFetcher & { calls: string[] } {
|
||||
};
|
||||
}
|
||||
|
||||
const REMOTE = { data: { urlserver: ['5.5.5.5:5000', '5.5.5.5:5000'] } };
|
||||
const REMOTE = { player_server_tcp: ['5.5.5.5:5000', '5.5.5.5:5000'] };
|
||||
|
||||
test('h5:只读 query 身份,不访问原生宿主,并生成严格 remote 配置', async () => {
|
||||
const fetcher = returning(REMOTE);
|
||||
@@ -133,16 +133,17 @@ test('uAgent_3:拒绝宿主提供的非法身份字段类型', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('显式 local debug:direct 字段不靠 null 推断,完整服务器来自 profile', async () => {
|
||||
test('显式 local debug:远程配置保留内存,连接服务器来自 profile', async () => {
|
||||
const fetcher = returning(REMOTE);
|
||||
const result = await resolveRuntimeConfig({
|
||||
mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local', fetcher,
|
||||
});
|
||||
assert.equal(result.source, 'direct');
|
||||
assert.equal(result.gameserver, null);
|
||||
assert.equal(result.rawConfig, null);
|
||||
assert.equal(result.source, 'remote');
|
||||
assert.ok(result.gameserver);
|
||||
assert.equal(result.rawConfig, REMOTE);
|
||||
assert.strictEqual(result.remoteConfig.raw, result.rawConfig);
|
||||
assert.deepEqual(result.servers, ['ws://127.0.0.1:3088']);
|
||||
assert.deepEqual(fetcher.calls, []);
|
||||
assert.equal(fetcher.calls.length, 1);
|
||||
});
|
||||
|
||||
test('远程抓取失败显式报错,不降级 direct', async () => {
|
||||
@@ -152,3 +153,39 @@ test('远程抓取失败显式报错,不降级 direct', async () => {
|
||||
/远程配置抓取失败/,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
test('release ignores local profile but still fetches and selects remote servers', async () => {
|
||||
const fetcher = returning(REMOTE);
|
||||
const result = await resolveRuntimeConfig({ mode: 'release', hostKind: 'h5', win: {}, search: '?profile=local', fetcher });
|
||||
assert.equal(fetcher.calls.length, 1);
|
||||
assert.deepEqual(result.servers, ['ws://5.5.5.5:5000', 'ws://5.5.5.5:5000']);
|
||||
assert.equal(result.isDebugger, false);
|
||||
});
|
||||
|
||||
|
||||
test('JSON parse errors retain their classification through the runtime boundary', async () => {
|
||||
const { ConfigParseError } = await import('../../YouleNexus/assets/framework/config/remote-config.ts');
|
||||
const error = new ConfigParseError('invalid JSON');
|
||||
const fetcher = { async fetch() { throw error; } };
|
||||
await assert.rejects(resolveRuntimeConfig({ mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local', fetcher }),
|
||||
actual => actual === error);
|
||||
});
|
||||
|
||||
test('local consumes explicit loopback targets after valid remote JSON even when remote candidates are absent', async () => {
|
||||
const raw = { visitor_server_tcp: 'unused.example:1234', notice: 'kept' };
|
||||
const fetcher = returning(raw);
|
||||
const result = await resolveRuntimeConfig({ mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local', fetcher });
|
||||
assert.equal(fetcher.calls.length, 1);
|
||||
assert.deepEqual(result.servers, ['ws://127.0.0.1:3088']);
|
||||
assert.strictEqual(result.rawConfig, raw);
|
||||
assert.equal(result.remoteConfig.getValue('notice'), 'kept');
|
||||
});
|
||||
|
||||
test('remote profiles reject missing game/player addresses without selecting visitor', async () => {
|
||||
for (const mode of ['debug', 'release'] as const) {
|
||||
const fetcher = returning({ visitor_server_tcp: 'unused.example:1234' });
|
||||
await assert.rejects(resolveRuntimeConfig({ mode, hostKind: 'h5', win: {}, search: '', fetcher }), /game_server_tcp\/player_server_tcp/);
|
||||
assert.equal(fetcher.calls.length, 1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"data":{"urlserver":["10.0.0.1:3088","wss://backup.example/ws"]}}
|
||||
{"player_server_tcp":["10.0.0.1:3088","wss://backup.example/ws"]}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"data":{"urlserver":"10.0.0.1:3088"}}
|
||||
{"player_server_tcp":"10.0.0.1:3088"}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { BUILD_IDENTITY } from '../../YouleNexus/assets/framework/config/sources/defaults.ts';
|
||||
import { createRemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
import type { ChannelIdentity } from '../../YouleNexus/assets/framework/config/identity.ts';
|
||||
|
||||
/** Test-only memory configuration shared by typed RuntimeConfig fixtures. */
|
||||
export function remoteFixture(identity: Readonly<ChannelIdentity> = BUILD_IDENTITY) {
|
||||
const remoteConfig = createRemoteConfig({ player_server_tcp: 'fixture.example:3088' }, identity);
|
||||
return { remoteConfig, rawConfig: remoteConfig.raw };
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class MapStorage implements LocalStoragePort {
|
||||
|
||||
function resolve(search = '?profile=local') {
|
||||
return resolveLocalStartup({ mode: 'debug', hostKind: 'h5', win: {}, search,
|
||||
fetcher: { async fetch(): Promise<never> { throw new Error('forbidden fetch'); } } });
|
||||
fetcher: { async fetch() { return { player_server_tcp: 'remote.example:3088' }; } } });
|
||||
}
|
||||
|
||||
function sourcesFor(context: Awaited<ReturnType<typeof resolve>>, storage: LocalStoragePort,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
@@ -13,7 +14,7 @@ import { FakeTransport } from '../helpers/fake-transport.ts';
|
||||
const CONFIG: RuntimeConfig = {
|
||||
mode: 'debug', isDebugger: true,
|
||||
identity: { agentid: 'A', channelid: 'C', gameid: '41', version: 1, marketid: 4 },
|
||||
source: 'direct', servers: ['ws://agent'], gameserver: null, rawConfig: null,
|
||||
source: 'remote', servers: ['ws://agent'], gameserver: 'https://fixture/config', ...remoteFixture(),
|
||||
};
|
||||
const ACCOUNT = { openid: 'o', nickname: 'n', avatar: 'a', sex: 0, province: '', city: '', unionid: 'u' };
|
||||
const LOGIN = {
|
||||
|
||||
@@ -137,7 +137,7 @@ test('real modern vertical replay preserves wire contracts, room ordering and te
|
||||
configRequests.push({ url: String(url), init });
|
||||
return new Response(JSON.stringify({
|
||||
urlserver: 'wrong-root.example:1',
|
||||
data: { urlserver: ['agent.example:3088', 'backup.example:3088'] },
|
||||
player_server_tcp: ['agent.example:3088', 'backup.example:3088'],
|
||||
}), { status: 200 });
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -40,7 +40,7 @@ async function setup(overrides: { config?: Partial<ResolveRuntimeConfigOptions>;
|
||||
let fetches = 0;
|
||||
const host = api.createLocalLoginHost({
|
||||
configOptions: { mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local&version=731',
|
||||
fetcher: { async fetch(): Promise<never> { fetches++; throw new Error('unexpected fetch'); } }, ...overrides.config },
|
||||
fetcher: { async fetch() { fetches++; return { player_server_tcp: 'remote.example:3088' }; } }, ...overrides.config },
|
||||
storage: { getItem: key => values.get(key) ?? null, setItem: (key, value) => { values.set(key, value); } },
|
||||
random: () => .5, now: () => 123456, sampleHost: () => ({ location: null }),
|
||||
view: { render: model => { overrides.render?.(model); pages.push(model); },
|
||||
@@ -70,7 +70,7 @@ for (const missing of ['resources', 'minimum', 'socket'] as const) test(`login w
|
||||
assert.equal(h.values.size, 0); assert.deepEqual(h.sockets[0]!.sent, []);
|
||||
h.resources.resolve(); h.minimum.resolve(); if (missing === 'socket') h.sockets[0]!.open();
|
||||
await starting;
|
||||
assert.equal(h.host.getSnapshot().ready, true); assert.equal(h.fetches(), 0);
|
||||
assert.equal(h.host.getSnapshot().ready, true); assert.equal(h.fetches(), 1);
|
||||
assert.equal(h.sockets.length, 1);
|
||||
assert.equal(h.evidence.filter(event => event.kind === 'startup-config').length, 1);
|
||||
await h.host.login();
|
||||
@@ -210,3 +210,35 @@ test('fatal overlay observer failure retains the original Runtime error object',
|
||||
assert.strictEqual(fault.errors[0], primary); assert.strictEqual(fault.errors[1], observer);
|
||||
assert.equal(h.host.getSnapshot().ready, false); assert.equal(h.sockets[0]!.closes, 1);
|
||||
});
|
||||
|
||||
test('remote fetch and parse failures leave local sockets and account storage untouched', async () => {
|
||||
for (const fetch of [async () => { throw new Error('network down'); }, async () => ({ agentlist: {} }), async () => null]) {
|
||||
const h = await setup({ config: { fetcher: { fetch } } });
|
||||
const result = h.host.start().catch(error => error);
|
||||
await flush();
|
||||
assert.equal(h.sockets.length, 0);
|
||||
assert.equal(h.values.size, 0);
|
||||
assert.ok(await result instanceof Error);
|
||||
assert.equal(h.failures.length, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('stop while remote fetch is pending prevents late socket creation', async () => {
|
||||
const pending = deferred();
|
||||
let fetched = false;
|
||||
const h = await setup({ config: { fetcher: { async fetch() {
|
||||
fetched = true; await pending.promise; return { player_server_tcp: 'remote.example:3088' };
|
||||
} } } });
|
||||
const result = h.host.start().catch(error => error);
|
||||
await flush(); assert.equal(fetched, true); assert.equal(h.sockets.length, 0);
|
||||
h.host.stop(); pending.resolve(); await result;
|
||||
assert.equal(h.sockets.length, 0); assert.equal(h.values.size, 0);
|
||||
});
|
||||
|
||||
test('startup diagnostics exclude raw remote fields', async t => {
|
||||
const h = await setup({ config: { fetcher: { async fetch() {
|
||||
return { player_server_tcp: 'remote.example:3088', privateConfig: 'DO_NOT_RECORD_REMOTE_SECRET' };
|
||||
} } } });
|
||||
t.after(() => h.host.stop()); await h.ready();
|
||||
assert.equal(JSON.stringify(h.evidence).includes('DO_NOT_RECORD_REMOTE_SECRET'), false);
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ async function setup(overrides: {
|
||||
.catch((error: unknown) => assert.fail(`LocalLoginTransport implementation must exist: ${String(error)}`));
|
||||
const context = await resolveLocalStartup({
|
||||
mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local',
|
||||
fetcher: { async fetch(): Promise<never> { throw new Error('unexpected fetch'); } },
|
||||
fetcher: { async fetch() { return { player_server_tcp: 'remote.example:3088' }; } },
|
||||
});
|
||||
const sockets: FakeSocket[] = [];
|
||||
const urls: string[] = [];
|
||||
|
||||
@@ -15,7 +15,7 @@ async function setup(recordHook?: (event: { kind: string; data: unknown }) => vo
|
||||
const api = await import('../../YouleNexus/assets/scripts/local-platform-login/local-login-wire.ts')
|
||||
.catch(error => assert.fail(`Local login Wire implementation must exist: ${String(error)}`));
|
||||
const context = await resolveLocalStartup({ mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local',
|
||||
fetcher: { async fetch(): Promise<never> { throw new Error('unexpected fetch'); } } });
|
||||
fetcher: { async fetch() { return { player_server_tcp: 'remote.example:3088' }; } } });
|
||||
const transports: FakeTransport[] = [];
|
||||
const events: WireEvent[] = [];
|
||||
const evidence: { kind: string; data: unknown }[] = [];
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
@@ -22,7 +23,7 @@ const RUNTIME_CONFIG: RuntimeConfig = Object.freeze({
|
||||
servers: Object.freeze(['ws://fixture']),
|
||||
source: 'remote',
|
||||
gameserver: 'https://fixture/config',
|
||||
rawConfig: Object.freeze({ data: Object.freeze({ urlserver: 'fixture' }) }),
|
||||
...remoteFixture(),
|
||||
});
|
||||
|
||||
function fixture(name: string): { data: Record<string, unknown> } {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
@@ -41,7 +42,7 @@ const RUNTIME_CONFIG: RuntimeConfig = Object.freeze({
|
||||
servers: Object.freeze(['ws://fixture']),
|
||||
source: 'remote',
|
||||
gameserver: 'https://fixture/config',
|
||||
rawConfig: Object.freeze({ data: Object.freeze({ urlserver: 'fixture' }) }),
|
||||
...remoteFixture(),
|
||||
});
|
||||
|
||||
function fixture(name: string): { data: Record<string, unknown> } {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
@@ -57,9 +58,9 @@ function runtimeConfig(gameid: string | number = '41'): RuntimeConfig {
|
||||
version: 10000,
|
||||
}),
|
||||
servers: Object.freeze(['ws://agent']),
|
||||
source: 'direct',
|
||||
gameserver: null,
|
||||
rawConfig: null,
|
||||
source: 'remote',
|
||||
gameserver: 'https://fixture/config',
|
||||
...remoteFixture(),
|
||||
}) as RuntimeConfig;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { StartupOrchestrator } from '../../YouleNexus/assets/framework/platform/startup.ts';
|
||||
@@ -13,7 +14,7 @@ function bootstrapOf(): BootstrapResult {
|
||||
mode: 'debug', isDebugger: true,
|
||||
identity: IDENTITY,
|
||||
servers: ['ws://test'],
|
||||
rawConfig: null,
|
||||
...remoteFixture(),
|
||||
profile: { name: 'debug' },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteFixture } from '../fixtures/remote-config.ts';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
@@ -83,7 +84,7 @@ const RUNTIME_CONFIG: RuntimeConfig = Object.freeze({
|
||||
servers: Object.freeze(['ws://fixture']),
|
||||
source: 'remote',
|
||||
gameserver: 'https://fixture/config',
|
||||
rawConfig: Object.freeze({ data: Object.freeze({ urlserver: 'fixture' }) }),
|
||||
...remoteFixture(),
|
||||
});
|
||||
|
||||
function makeModule(id: number, onRestore: (deskinfo: unknown) => void): GameModule {
|
||||
|
||||
Reference in New Issue
Block a user