// Which atlas source runs, and what boot does with the answer // (docs/link/v8.md §10, §17.7; docs/website/SPAWN_ATLAS.md). // // The model is the only place that decides between a local ServUO tree and the // shard bridge, so these drive it with the shard, the database and the // filesystem all stubbed. Nothing here reaches a real sidecar or a real tree. // // The rule under test is the one the cliloc pipeline settled first and this // inherits: the bridge wins whenever uo-link is configured and enabled, a local // path is what a site with no shard link uses, and an explicit path is an // instruction that overrules both. const { test } = require('node:test') const assert = require('node:assert/strict') const atlas = require('../model/shardAtlas/shardAtlas.model') const db = require('../model/shardAtlas/shardAtlas.db') const source = require('../utils/spawnAtlasSource') const uoLinkConfig = require('../model/uoLinkConfig/uoLinkConfig.model') const { ctx } = require('./_setup') const saved = { getMeta: db.getMeta, getPending: db.getPending, getFacets: db.getFacets, hashFrom: source.hashFrom, buildFrom: source.buildFrom, getSafe: uoLinkConfig.getSafe, settingsGet: ctx.settings.get, } function restore() { db.getMeta = saved.getMeta db.getPending = saved.getPending db.getFacets = saved.getFacets source.hashFrom = saved.hashFrom source.buildFrom = saved.buildFrom uoLinkConfig.getSafe = saved.getSafe ctx.settings.get = saved.settingsGet } /** Whatever source the model chose, captured rather than read. */ function rig({ linked = true, treePath = '', meta = null } = {}) { const asked = { hash: [], build: [] } uoLinkConfig.getSafe = async () => ({ enabled: linked, baseUrl: linked ? 'http://127.0.0.1:8099' : null, }) ctx.settings.get = async () => treePath db.getMeta = async () => meta db.getPending = async () => null db.getFacets = async () => [] source.hashFrom = async (descriptor) => { asked.hash.push(descriptor) return { 'Data/Regions.xml': 'aa' } } source.buildFrom = async (descriptor) => { asked.build.push(descriptor) throw new Error('the test stops before a build') } return asked } test('a linked shard is the atlas source, and the configured path is not consulted', async () => { const asked = rig({ linked: true, treePath: '/srv/servuo' }) const status = await atlas.status() assert.equal(status.source, 'bridge') assert.equal(status.path, 'the shard bridge') assert.equal(status.configured, true) assert.deepEqual(asked.hash[0], { kind: 'bridge', root: '' }) restore() }) test('with no shard linked the configured tree is the source', async () => { const asked = rig({ linked: false, treePath: '/srv/servuo' }) const status = await atlas.status() assert.equal(status.source, 'fs') assert.equal(status.path, '/srv/servuo') assert.deepEqual(asked.hash[0], { kind: 'fs', root: '/srv/servuo' }) restore() }) test('an explicit path overrules the bridge — it is an instruction, not a default', async () => { const asked = rig({ linked: true, treePath: '/srv/servuo' }) await atlas.status({ path: '/tmp/other-tree' }) assert.deepEqual(asked.hash[0], { kind: 'fs', root: '/tmp/other-tree' }) restore() }) test('no shard and no path is "nothing configured", not an error', async () => { rig({ linked: false, treePath: '' }) const status = await atlas.status() assert.equal(status.configured, false) const result = await atlas.refresh() assert.equal(result.status, 'skipped') restore() }) test('boot does not call the shard; it says where the import lives instead', async () => { // §17.7's rule, and the reason it is not free: an install whose atlas comes // over the bridge has NO automatic refresh at all, so the skip has to be // deliberate and visible rather than a path that quietly does nothing. const asked = rig({ linked: true, treePath: '/srv/servuo' }) const result = await atlas.refreshOnBoot() assert.equal(result.status, 'skipped') assert.equal(result.source, 'bridge') assert.equal(asked.hash.length, 0, 'boot made no shard call at all') assert.equal(asked.build.length, 0) restore() }) test('boot still refreshes by itself from a local tree', async () => { const asked = rig({ linked: false, treePath: '/srv/servuo' }) await atlas.refreshOnBoot() assert.deepEqual(asked.hash[0], { kind: 'fs', root: '/srv/servuo' }) restore() }) test('a source that cannot be read is reported, with which end could not read it', async () => { rig({ linked: true, treePath: '' }) source.hashFrom = async () => { const { TreeBridgeError } = require('../utils/treeBridge') throw new TreeBridgeError('the shard is not serving its tree', 'DISABLED') } const result = await atlas.refresh() assert.equal(result.status, 'unavailable') assert.equal(result.source, 'bridge') assert.equal(result.code, 'DISABLED') restore() })