fix(config): resolve remote hierarchy in memory for every profile

This commit is contained in:
2026-09-05 21:21:24 +08:00
parent 62328b6fd6
commit 053302c5df
27 changed files with 286 additions and 143 deletions
@@ -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']],