feat: migrate platform login scenes and native login flows
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { STARTUP_CONFIG } from '../../YouleNexus/assets/framework/config/profiles.ts';
|
||||
import { STARTUP_CONFIG as EDITABLE_STARTUP_CONFIG } from '../../YouleNexus/assets/framework/config/profiles.ts';
|
||||
// 固定测试来源,允许开发者独立切换项目的 local/remote 开关。
|
||||
const STARTUP_CONFIG = Object.freeze({...EDITABLE_STARTUP_CONFIG, configSource:'remote' as const});
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { BUILD_IDENTITY } from '../../YouleNexus/assets/framework/config/sources/defaults.ts';
|
||||
@@ -30,9 +32,9 @@ test('h5:只读 query 身份,不访问原生宿主,并生成严格 remote
|
||||
assert.deepEqual(result.identity, { ...BUILD_IDENTITY, agentid: 'HA', channelid: 'HC' });
|
||||
assert.deepEqual(result.servers, ['ws://5.5.5.5:5000', 'ws://5.5.5.5:5000']);
|
||||
assert.equal(result.source, 'remote');
|
||||
assert.equal(result.gameserver, 'https://tsgames.daoqi88.cn/config/update_jsonv2.txt');
|
||||
assert.equal(result.gameserver, STARTUP_CONFIG.gameserver);
|
||||
assert.equal(result.rawConfig, REMOTE);
|
||||
assert.deepEqual(fetcher.calls, ['https://tsgames.daoqi88.cn/config/update_jsonv2.txt']);
|
||||
assert.deepEqual(fetcher.calls, [STARTUP_CONFIG.gameserver]);
|
||||
assert.equal(Object.isFrozen(result), true);
|
||||
assert.equal(Object.isFrozen(result.identity), true);
|
||||
assert.equal(Object.isFrozen(result.servers), true);
|
||||
@@ -201,7 +203,7 @@ for (const mode of ['debug','release'] as const) for (const useLocalServer of [t
|
||||
source.localServers=['ws://localhost:9999']; assert.deepEqual(result.startupConfig.localServers,STARTUP_CONFIG.localServers);
|
||||
});
|
||||
test('default runtime starts without query configuration', async () => {
|
||||
const result=await resolveRuntimeConfig({hostKind:'h5',win:{},search:'',fetcher:returning({notice:'kept'})});
|
||||
const result=await resolveRuntimeConfig({startupConfig:STARTUP_CONFIG,hostKind:'h5',win:{},search:'',fetcher:returning({notice:'kept'})});
|
||||
assert.deepEqual(result.startupConfig,STARTUP_CONFIG); assert.deepEqual(result.servers,STARTUP_CONFIG.localServers);
|
||||
});
|
||||
|
||||
@@ -216,3 +218,38 @@ for (const mode of ['debug','release'] as const) for (const useLocalServer of [t
|
||||
const fetcher={async fetch(){throw new Error('remote unavailable');}};
|
||||
await assert.rejects(resolveRuntimeConfig({startupConfig:{...STARTUP_CONFIG,mode,useLocalServer},hostKind:'h5',win:{},search:'',fetcher}),/远程配置抓取失败/);
|
||||
});
|
||||
|
||||
// 本地来源必须在运行时边界隔离网络读取,并复用正式配置的层级取值规则。
|
||||
test('local txt selects one source, ignores gameconfig and preserves scoped values', async () => {
|
||||
const remote = returning(REMOTE);
|
||||
const local = returning({showVisitor: 1, agentlist: [{agentid: BUILD_IDENTITY.agentid, deviceLogin: true}]});
|
||||
const result = await resolveRuntimeConfig({startupConfig:{...STARTUP_CONFIG, configSource:'local'},
|
||||
hostKind:'h5',win:{},search:'?gameconfig=unwanted-host',fetcher:remote,localFetcher:local});
|
||||
assert.equal(result.source,'local');
|
||||
assert.deepEqual(remote.calls,[]);
|
||||
assert.deepEqual(local.calls,[STARTUP_CONFIG.localConfigResource]);
|
||||
assert.equal(result.remoteConfig.getValue('showVisitor'),1);
|
||||
assert.equal(result.remoteConfig.getValue('deviceLogin'),true);
|
||||
assert.deepEqual(result.servers,STARTUP_CONFIG.localServers);
|
||||
});
|
||||
|
||||
test('local txt errors never fall back to remote, release rejects before I/O', async () => {
|
||||
const remote=returning(REMOTE); let localCalls=0;
|
||||
const localFetcher={async fetch(){localCalls++;throw Error('missing txt');}};
|
||||
const options={startupConfig:{...STARTUP_CONFIG,configSource:'local' as const},hostKind:'h5' as const,win:{},search:'',fetcher:remote,localFetcher};
|
||||
await assert.rejects(resolveRuntimeConfig(options),/本地配置读取失败/);
|
||||
assert.equal(localCalls,1);assert.equal(remote.calls.length,0);
|
||||
await assert.rejects(resolveRuntimeConfig({...options,startupConfig:{...options.startupConfig,mode:'release'}}),/configSource/);
|
||||
assert.equal(localCalls,1);
|
||||
await assert.rejects(resolveRuntimeConfig({...options,localFetcher:undefined}),/localFetcher/);
|
||||
});
|
||||
|
||||
test('local txt and socket target are independent; remote mode never touches local loader', async () => {
|
||||
const remote=returning(REMOTE),local=returning(REMOTE);
|
||||
const options={hostKind:'h5' as const,win:{},search:'',fetcher:remote,localFetcher:local};
|
||||
const result=await resolveRuntimeConfig({...options,startupConfig:{...STARTUP_CONFIG,configSource:'local',useLocalServer:false}});
|
||||
assert.deepEqual(result.servers,['ws://5.5.5.5:5000','ws://5.5.5.5:5000']);
|
||||
assert.equal(remote.calls.length,0);assert.equal(local.calls.length,1);
|
||||
await resolveRuntimeConfig({...options,startupConfig:{...STARTUP_CONFIG,configSource:'remote'}});
|
||||
assert.equal(remote.calls.length,1);assert.equal(local.calls.length,1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user