// Phase B (roster): config plumbs the co-equal device roster + the control-surface writers
// allowlist from env/file. The roster is what makes the DEPLOYED daemon admit N co-equal writers
// (index.js passes cfg.members to bootSwarmDevice); absent → self-only (the pre-B behaviour).
import '../lib/bare-globals.js'
import test from 'brittle'
import { loadConfig } from '../lib/config.js'
const ISOLATE = () => { process.env.PEER_CONFIG = '/nonexistent-hpp/config.json' } // force file -> {}
test('config parses swarm roster + writers from env', (t) => {
ISOLATE()
process.env.PEER_SWARM = '1'
process.env.PEER_MEMBERS = 'aa11,BB22, cc33 '
process.env.PEER_WRITERS = 'dd44'
process.env.PEER_DEVICE_MNEMONIC = 'a b c'
const c = loadConfig()
t.is(c.swarm, true, 'swarm mode enabled')
t.alike(c.members, [{ key: 'aa11', role: 1 }, { key: 'bb22', role: 1 }, { key: 'cc33', role: 1 }], 'roster lowercased, trimmed, role-equal')
t.alike(c.writers, ['dd44'], 'writers allowlist parsed')
t.is(c.deviceMnemonic, 'a b c', 'device mnemonic')
// bare's process.env proxy has no deleteProperty; '' reads as unset (config pick: env !== '').
for (const k of ['PEER_SWARM', 'PEER_MEMBERS', 'PEER_WRITERS', 'PEER_DEVICE_MNEMONIC']) process.env[k] = ''
})
test('config defaults: no roster (self-only), read-only, not swarm', (t) => {
ISOLATE()
const c = loadConfig()
t.is(c.swarm, false, 'not swarm by default')
t.is(c.members, null, 'no roster by default (self-only)')
t.is(c.writers, null, 'read-only by default (no remote writers)')
})