fix(config): restore legacy gameserver and urlserver contract
This commit is contained in:
@@ -1,29 +1,59 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { nativeSettingsSource } from '../../../YouleNexus/assets/framework/config/sources/native-settings.ts';
|
||||
import {
|
||||
getchannelName,
|
||||
getmarketname,
|
||||
getothername,
|
||||
nativeIdentitySource,
|
||||
} from '../../../YouleNexus/assets/framework/config/sources/native-settings.ts';
|
||||
|
||||
test('优先从 window.settings 读取 agentid/channelid/marketid', () => {
|
||||
test('非 uAgent_3 getothername 调 settings,异常只在源边界转换为空串', () => {
|
||||
const names: string[] = [];
|
||||
const win = { settings: { getothername(name: string) { names.push(name); throw new Error('bridge'); } } };
|
||||
assert.equal(getothername(win, 'native-settings', 'gameconfig'), '');
|
||||
assert.deepEqual(names, ['gameconfig']);
|
||||
});
|
||||
|
||||
test('getchannelName 返回 truthy settings 结果,否则按宿主执行旧缺省语义', () => {
|
||||
assert.equal(getchannelName({ settings: { getchannelName: () => 'C1' } }, 'native-settings'), 'C1');
|
||||
assert.equal(getchannelName({ settings: { getchannelName: () => 0 } }, 'native-settings'), '');
|
||||
assert.equal(getchannelName({ settings: { getchannelName: () => { throw new Error('bridge'); } } }, 'native-settings'), '');
|
||||
assert.equal(getchannelName({
|
||||
settings: { getchannelName: () => { throw new Error('bridge'); } },
|
||||
app_channel: 'APP-C',
|
||||
}, 'uAgent_3'), 'APP-C');
|
||||
});
|
||||
|
||||
test('getmarketname 返回 settings 结果;异常按宿主执行旧缺省语义', () => {
|
||||
assert.equal(getmarketname({ settings: { getmarketname: () => 0 } }, 'native-settings'), 0);
|
||||
assert.equal(getmarketname({ settings: { getmarketname: () => { throw new Error('bridge'); } } }, 'native-settings'), '4');
|
||||
assert.equal(getmarketname({
|
||||
settings: { getmarketname: () => { throw new Error('bridge'); } },
|
||||
app_market: 8,
|
||||
}, 'uAgent_3'), 8);
|
||||
});
|
||||
|
||||
test('uAgent_3 getothername 只读 app_<name>,不调用 settings', () => {
|
||||
let settingsCalls = 0;
|
||||
const win = {
|
||||
settings: { getothername: () => { settingsCalls += 1; return 'WRONG'; } },
|
||||
app_agent: 'APP-A',
|
||||
app_gameconfig: 'host-path#80-a',
|
||||
};
|
||||
assert.equal(getothername(win, 'uAgent_3', 'agent'), 'APP-A');
|
||||
assert.equal(getothername(win, 'uAgent_3', 'gameconfig'), 'host-path#80-a');
|
||||
assert.equal(settingsCalls, 0);
|
||||
});
|
||||
|
||||
test('nativeIdentitySource 仅返回所选宿主提供的原生身份字段', () => {
|
||||
const win = {
|
||||
settings: {
|
||||
getothername: (name: string) => (name === 'agent' ? 'NA' : ''),
|
||||
getothername: (name: string) => name === 'agent' ? 'NA' : '',
|
||||
getchannelName: () => 'NC',
|
||||
getmarketname: () => 7,
|
||||
},
|
||||
};
|
||||
assert.deepEqual(nativeSettingsSource(win)(), { agentid: 'NA', channelid: 'NC', marketid: 7 });
|
||||
});
|
||||
|
||||
test('settings 抛错时回退到全局 app_agent / app_market', () => {
|
||||
const win: any = {
|
||||
settings: { getothername: () => { throw new Error('no bridge'); },
|
||||
getchannelName: () => { throw new Error('no bridge'); },
|
||||
getmarketname: () => { throw new Error('no bridge'); } },
|
||||
app_agent: 'GA',
|
||||
app_market: 5,
|
||||
};
|
||||
assert.deepEqual(nativeSettingsSource(win)(), { agentid: 'GA', marketid: 5 });
|
||||
});
|
||||
|
||||
test('完全无原生注入 → 空对象', () => {
|
||||
assert.deepEqual(nativeSettingsSource({})(), {});
|
||||
assert.deepEqual(nativeIdentitySource(win, 'native-settings')(), {
|
||||
agentid: 'NA', channelid: 'NC', marketid: 7,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user