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 { resolveLoginPolicy, loginButtons } from '../../YouleNexus/assets/framework/presentation/login-policy.ts'; import { resolveRuntimeConfig } from '../../YouleNexus/assets/framework/config/runtime-config.ts'; const remote = (values: Record) => ({raw:values,getValue:(key:string)=>values[key] ?? null}); test('source defaults and channel overrides retain legacy button order', () => { const policy = resolveLoginPolicy(remote({})); assert.deepEqual(loginButtons(policy, 0, false), {wechat:true,visitor:false,phone:false,quick:false,qq:false,account:false}); assert.deepEqual(loginButtons(policy, 1, false), {wechat:true,visitor:true,phone:false,quick:false,qq:false,account:false}); const configured = resolveLoginPolicy(remote({deviceLogin:1,hall_config:{showVisitor:1,qqLogin:1}})); assert.deepEqual(loginButtons(configured, 0, false), {wechat:false,visitor:true,phone:true,quick:false,qq:true,account:false}); assert.deepEqual(loginButtons(configured, 0, true), {wechat:false,visitor:true,phone:false,quick:false,qq:true,account:true}); }); test('invalid upstream login options fail at the config source', () => { assert.throws(()=>resolveLoginPolicy(remote({deviceLogin:'yes'})), /deviceLogin/); assert.throws(()=>resolveLoginPolicy(remote({hall_config:{qqLogin:[]}})), /qqLogin/); }); test('build identity selects its own remote agent showVisitor through to login buttons', async () => { // Relevant hierarchy captured from config_test/update_jsonv2.txt on 2026-09-06. const config = {agentlist:[ {agentid:'veRa0qrBf0df2K1G4de2tgfmVxB2jxpv',gamelist:[{gameid:'G2hw0ubng0zcoI0r4mx3H2yr4GejidwO'}]}, {agentid:'1B2h0ccl205c390Y28m1Ajdplkuu4wgy',showVisitor:1,gamelist:[ {gameid:'J9r4022t80pxlb01zOK76DN1WD4QewFl',channellist:[ {channelid:'aouv0LotK0pYyQ0Pdrx0CsdcaezfzrcG',marketlist:[{marketid:4,deviceLogin:true}]}]}]}, ]}; const options={startupConfig:{...STARTUP_CONFIG,configSource:'remote' as const},hostKind:'h5' as const,win:{},search:'',fetcher:{fetch:async()=>config}}; const resolved=await resolveRuntimeConfig(options); assert.equal(resolved.remoteConfig.getValue('showVisitor'),1); assert.equal(resolved.identity.channelid,'aouv0LotK0pYyQ0Pdrx0CsdcaezfzrcG'); const buttons=loginButtons(resolveLoginPolicy(resolved.remoteConfig),0,false); assert.equal(buttons.visitor,true);assert.equal(buttons.wechat,false); assert.equal(buttons.phone,true,'market deviceLogin and agent showVisitor both take effect'); const other=await resolveRuntimeConfig({...options,search:'?agentid=veRa0qrBf0df2K1G4de2tgfmVxB2jxpv'}); assert.equal(resolveLoginPolicy(other.remoteConfig).showVisitor,false,'must not read another agent configuration'); });