feat(framework): config 原生同步身份来源(window.settings/app_* 逐字对齐)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-28 16:36:13 +08:00
co-authored by Claude Opus 4.8
parent 510c074627
commit 119a457c59
2 changed files with 69 additions and 0 deletions
@@ -0,0 +1,29 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { nativeSettingsSource } from '../../../YouleNexus/assets/framework/config/sources/native-settings.ts';
test('优先从 window.settings 读取 agentid/channelid/marketid', () => {
const win = {
settings: {
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({})(), {});
});