test(server): port core's UO suite onto the ctx harness
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>
This commit is contained in:
27
server/test/_setup.js
Normal file
27
server/test/_setup.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// Initialise `core` once, before any test file is required.
|
||||
//
|
||||
// Loaded via `node --test --require ./test/_setup.js`, the same arrangement
|
||||
// core's own suite uses. It exists because of the one structural difference
|
||||
// between testing this module and testing the code when it lived in core:
|
||||
// nothing here can be stubbed by monkey-patching a core module, because there
|
||||
// are no core modules to patch. `require('../utils/db')` does not exist. What a
|
||||
// test controls instead is the `ctx` core would have handed over — which is a
|
||||
// better seam anyway, since it is exactly the surface the contract promises and
|
||||
// nothing wider.
|
||||
//
|
||||
// The ctx installed here is deliberately NOT frozen. Core freezes what it hands
|
||||
// a module, and `entry.test.js` asserts the module behaves against a frozen one;
|
||||
// but a test that needs `settings.get` to return a particular value has to be
|
||||
// able to say so, and a frozen ctx would mean re-initialising core per test. The
|
||||
// mutable copy is a test seam, not a claim about what core does.
|
||||
|
||||
const core = require('../core')
|
||||
const { fakeCtx } = require('./_fakes')
|
||||
|
||||
const ctx = fakeCtx({ freeze: false })
|
||||
core.init(ctx)
|
||||
|
||||
// Exposed so a test can reach the same object it is running against, e.g.
|
||||
// `testCtx.settings.get = async () => '/srv/uo'`. There is one ctx per process,
|
||||
// as there is in core, so a test that changes a member should put it back.
|
||||
module.exports = { ctx }
|
||||
Reference in New Issue
Block a user