22 test files moved from core, plus the two that were split out of files core keeps. 351 tests pass. One change runs through every moved test, and it is the boundary rather than a chore: core internals can no longer be stubbed by requiring them, because there are none to require. `../utils/db` and `../model/settings` do not exist here. What a test controls instead is the ctx core would have handed over, installed once by test/_setup.js -- which is a better seam anyway, since it is exactly the surface the contract promises and nothing wider. The ctx _setup installs is deliberately unfrozen. Core freezes what it hands a module and entry.test.js still asserts against a frozen one; but a test that needs settings.get to return a path has to be able to say so. Two tests changed SHAPE, and that is the boundary too. fromShardEvent used to assert through publish() into pushDevices and a captured fetch -- which endpoints were hit, how many requests went out. None of that is this module's any more: publish is ctx.push.publish, and the device registry and the relay are behind it. Reaching for them from here would be reaching past ctx. What remains is what the module owns and is the part worth guarding: a game account resolves to a website user, a personal target that resolves to nobody is dropped rather than published, and a sensitive kind never reaches publish at all. Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
3.3 KiB
JavaScript
72 lines
3.3 KiB
JavaScript
const { test, beforeEach } = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const shardIngest = require('../utils/shardIngest')
|
|
|
|
// Build a set of stub deps that record the champ/page/state calls the dispatcher
|
|
// makes, plus a spy shardEvents.append and broadcast. Only the methods the tested
|
|
// kinds touch need to be real; the rest are no-op async so ingest() never throws.
|
|
function makeDeps() {
|
|
const calls = { champUpsert: [], champRemove: [], pageUpsert: [], pageRemove: [], appended: [], broadcast: [] }
|
|
const noop = async () => {}
|
|
return {
|
|
calls,
|
|
shardEvents: { append: async (row) => { calls.appended.push(row); return true } },
|
|
shardState: {
|
|
upsertChamp: async (ev) => { calls.champUpsert.push(ev) },
|
|
removeChamp: async (serial) => { calls.champRemove.push(serial) },
|
|
upsertPage: async (ev) => { calls.pageUpsert.push(ev) },
|
|
removePage: async (id) => { calls.pageRemove.push(id) },
|
|
// Unused by these kinds but present so any stray routing is a no-op.
|
|
clearOnline: noop, upsertOnline: noop, setOffline: noop, upsertHouse: noop, addEconomySample: noop,
|
|
},
|
|
uoLinkConfig: { recordStatus: noop },
|
|
broadcast: (ev) => { calls.broadcast.push(ev) },
|
|
// No-op push fan-out so ingest() stays hermetic (no real relay/DB).
|
|
pushDispatch: async () => {},
|
|
log: { warn() {}, info() {}, error() {} },
|
|
}
|
|
}
|
|
|
|
beforeEach(() => shardIngest.reset())
|
|
|
|
test('champ.update routes to shardState.upsertChamp and is not written to the event log', async () => {
|
|
const deps = makeDeps()
|
|
const ev = { kind: 'champ.update', serial: '0x1', category: 'champion', name: 'Abyss', status: 'active', t: 1 }
|
|
const r = await shardIngest.ingest(ev, deps)
|
|
assert.equal(deps.calls.champUpsert.length, 1)
|
|
assert.equal(deps.calls.champUpsert[0].serial, '0x1')
|
|
assert.equal(r.logged, false) // champ.* is state-only, not appended to shard_events
|
|
assert.equal(deps.calls.appended.length, 0)
|
|
assert.equal(deps.calls.broadcast.length, 1) // still broadcast live
|
|
})
|
|
|
|
test('champ.remove routes to shardState.removeChamp', async () => {
|
|
const deps = makeDeps()
|
|
await shardIngest.ingest({ kind: 'champ.remove', serial: '0x2', t: 2 }, deps)
|
|
assert.deepEqual(deps.calls.champRemove, ['0x2'])
|
|
})
|
|
|
|
test('page.new and page.updated upsert the page; page.closed removes it', async () => {
|
|
const deps = makeDeps()
|
|
await shardIngest.ingest({ kind: 'page.new', pageId: '0x24C', type: 'Bug', sender: { name: 'Al' }, t: 3 }, deps)
|
|
await shardIngest.ingest({ kind: 'page.updated', pageId: '0x24C', handled: true, t: 4 }, deps)
|
|
await shardIngest.ingest({ kind: 'page.closed', pageId: '0x24C', t: 5 }, deps)
|
|
assert.equal(deps.calls.pageUpsert.length, 2)
|
|
assert.deepEqual(deps.calls.pageRemove, ['0x24C'])
|
|
})
|
|
|
|
test('admin.audit is appended to the event log (moderation history)', async () => {
|
|
const deps = makeDeps()
|
|
const r = await shardIngest.ingest({ kind: 'admin.audit', action: 'ban', actor: 'web:jane', target: 'griefer', t: 6 }, deps)
|
|
assert.equal(r.logged, true)
|
|
assert.equal(deps.calls.appended.length, 1)
|
|
assert.equal(deps.calls.appended[0].kind, 'admin.audit')
|
|
})
|
|
|
|
test('champ.remove without a serial is a harmless no-op', async () => {
|
|
const deps = makeDeps()
|
|
await shardIngest.ingest({ kind: 'champ.remove', t: 7 }, deps)
|
|
assert.deepEqual(deps.calls.champRemove, [undefined])
|
|
})
|