import assert from 'node:assert/strict' import test from 'node:test' import { normalizeRemoteConfig, parseCachedRemoteConfig, parseRemoteConfigCache, serializeRemoteConfigCache, } from '../src/remoteConfig' test('platform update feature is authoritative over the flat compatibility field', () => { assert.equal( normalizeRemoteConfig({ features: { update: false }, updateEnabled: true }).updateEnabled, false, ) assert.equal(normalizeRemoteConfig({ updateEnabled: true }).updateEnabled, true) }) test('missing update feature stays absent so XuqmConfig can safely default it off', () => { assert.equal(normalizeRemoteConfig({}).updateEnabled, undefined) assert.deepEqual(parseCachedRemoteConfig({ apiUrl: 'https://api.example.test' }), { apiUrl: 'https://api.example.test', }) }) test('cached update availability is preserved exactly', () => { assert.equal(parseCachedRemoteConfig({ updateEnabled: true })?.updateEnabled, true) assert.equal(parseCachedRemoteConfig({ updateEnabled: false })?.updateEnabled, false) }) test('non-sensitive LKG cache is strict, versioned and does not expire by age', () => { const raw = serializeRemoteConfigCache( { bugCollectApiUrl: 'https://errors.example.test', bugCollectEnabled: true, updateEnabled: false, }, 1, ) assert.deepEqual(parseRemoteConfigCache(raw), { cachedAt: 1, remote: { bugCollectApiUrl: 'https://errors.example.test', bugCollectEnabled: true, updateEnabled: false, }, }) assert.equal(raw.includes('signingKey'), false) assert.equal( parseRemoteConfigCache( JSON.stringify({ ...JSON.parse(raw), injectedSecret: 'must-be-rejected', }), ), null, ) }) test('cached remote config rejects unknown fields and unsafe endpoint schemes', () => { assert.equal(parseCachedRemoteConfig({ updateEnabled: true, unknown: true }), null) assert.equal(parseCachedRemoteConfig({ apiUrl: 'javascript:alert(1)' }), null) })