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,3 +1,4 @@
import { STARTUP_CONFIG } from '../../YouleNexus/assets/framework/config/profiles.ts';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
@@ -39,7 +40,7 @@ async function setup(overrides: { config?: Partial<ResolveRuntimeConfigOptions>;
const values = new Map<string, string>(), frames = new Set<() => void>();
let fetches = 0;
const host = api.createLocalLoginHost({
configOptions: { mode: 'debug', hostKind: 'h5', win: {}, search: '?profile=local&version=731',
configOptions: { hostKind: 'h5', win: {}, search: '?profile=local&version=731',
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 }),
@@ -138,7 +139,7 @@ for (const phase of ['config', 'resources', 'prepare'] as const) test(`stop duri
assert.deepEqual(h.failures, []);
});
for (const config of [{ search: '?profile=prod' }, { hostKind: 'native-settings' as const }]) test('invalid local input cannot create an account or connection', async () => {
for (const config of [{ startupConfig: {...STARTUP_CONFIG,mode:'release' as const} }, { startupConfig: {...STARTUP_CONFIG,useLocalServer:false} }, { hostKind: 'native-settings' as const }]) test('invalid local input cannot create an account or connection', async () => {
const h = await setup({ config });
await assert.rejects(h.host.start(), /local startup/);
assert.equal(h.values.size, 0); assert.equal(h.sockets.length, 0); assert.equal(h.failures.length, 1);
@@ -242,3 +243,10 @@ test('startup diagnostics exclude raw remote fields', async t => {
t.after(() => h.host.stop()); await h.ready();
assert.equal(JSON.stringify(h.evidence).includes('DO_NOT_RECORD_REMOTE_SECRET'), false);
});
test('default no-query host reaches login ready and ignores conflicting selectors', async t => {
for (const search of ['', '?mode=release&mode=other&profile=prod&profile=unknown']) {
const h=await setup({config:{search}}); t.after(()=>h.host.stop()); await h.ready();
assert.equal(h.fetches(),1); assert.equal(h.host.getSnapshot().ready,true); assert.ok(h.activations.includes('login')); assert.equal(h.failures.length,0);
}
});