mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-20 07:38:34 +02:00
Removes operator-private material from the shipped tree, corrects documentation
that had drifted from the code, deletes dead code, and applies a consistent
prose style.
Private material moved out of the public tree (docs/private/, git-ignored):
- the wallet keyfile recovery runbook and its helper scripts, which together
published the mainnet wallet file path, the service account, backup snapshot
filenames, and the wallet RPC listener state. The helper duplicated the same
constants, so relocating the document alone would not have removed them.
- the stagenet parallel-candidate runbook and its fixtures.
- the dated production-state record, the internal remediation plan, and the
TODO list. None are reference documentation for an outside reader.
Redacted or genericised:
- operator home-directory paths in shipped scripts and units. The asset build
script now takes KENNEY_ASSETS_DIR instead of a hard-coded path.
- private LAN addresses in tests, env examples and deploy docs, replaced with
RFC 5737 documentation addresses.
- the default alert sender and the notification hub example.
- the Monero wallet unit now matches the Wownero one: a dedicated service
account and a config file, instead of the operator's login account with the
wallet password in argv where any local user can read it from /proc.
Ignore rules now cover every .env variant rather than the bare name, plus local
agent state. The deployment docs instruct operators to create .env.mainnet and
.env.stagenet, which the exact-name rule would have allowed to be committed.
Documentation corrected against the code: per-chain dungeon level counts, the
premium unlock rule, Tavern chat scope, backup retention, the chain-profile
fallback, the environment template location, and several sections describing
shipped work as pending.
Dead code removed: configPersistence, rpccalls, a duplicate vendored ROT.js
bundle, the unused tile-picker overlay, the unreachable legacy game-size path
and its vestigial parameter, spectator stubs that shadowed the real
SpectatorManager, and commented-out debugging. nip98 now imports the shared
nostr loader rather than duplicating it.
Prose style: em-dashes removed throughout in favour of colons, semicolons and
commas; comments restated as present-tense descriptions of the code rather than
narration of past changes.
127 suites / 1015 tests pass.
106 lines
4.5 KiB
JavaScript
106 lines
4.5 KiB
JavaScript
/**
|
|
* Admission is refused while no blockchain node is reachable.
|
|
*
|
|
* A run's lifetime is measured in blocks and its entry block comes from the last SUCCESSFUL poll.
|
|
* With every node down that value goes stale silently, so a game admitted during an outage was
|
|
* anchored to an already-past block and killed as a timeout on the first recovered poll: the
|
|
* player lost a run, and in paid mode an entry, to our infrastructure. Refuse up front instead.
|
|
*/
|
|
|
|
const SocketHandlers = require('../src/network/socketHandlers');
|
|
|
|
function handlers({ chainHealthy, shuttingDown = false }) {
|
|
const h = Object.create(SocketHandlers.prototype);
|
|
h._isShuttingDown = shuttingDown;
|
|
h._admissionsInFlight = new Set();
|
|
h.debugManager = { CONSOLE_LOGGING: false, isChainHealthy: () => chainHealthy };
|
|
h.broadcastManager = { sendStatusUpdate: jest.fn() };
|
|
return h;
|
|
}
|
|
|
|
function socket() {
|
|
const emitted = [];
|
|
return { id: 's1', emitted, emit: (event, payload) => emitted.push({ event, payload }) };
|
|
}
|
|
|
|
describe('admission while no node is reachable', () => {
|
|
test('refuses the admission and never runs the task', async () => {
|
|
const h = handlers({ chainHealthy: false });
|
|
const s = socket();
|
|
const task = jest.fn();
|
|
|
|
await h._runAdmission(s, 'auto_start', task);
|
|
|
|
expect(task).not.toHaveBeenCalled();
|
|
const refusal = s.emitted.find(e => e.event === 'chain_unavailable');
|
|
expect(refusal).toBeDefined();
|
|
expect(refusal.payload).toMatchObject({ code: 'NODE_UNREACHABLE', kind: 'auto_start' });
|
|
// The player must be told nothing was taken from them.
|
|
expect(refusal.payload.message).toMatch(/nothing was charged/i);
|
|
expect(h.broadcastManager.sendStatusUpdate).toHaveBeenCalled();
|
|
});
|
|
|
|
test('runs the admission normally when a node is reachable', async () => {
|
|
const h = handlers({ chainHealthy: true });
|
|
const s = socket();
|
|
const task = jest.fn().mockResolvedValue('started');
|
|
|
|
await expect(h._runAdmission(s, 'join_queue', task)).resolves.toBe('started');
|
|
expect(task).toHaveBeenCalledTimes(1);
|
|
expect(s.emitted).toHaveLength(0);
|
|
});
|
|
|
|
test('gates every admission kind, including paid intake', async () => {
|
|
for (const kind of ['auto_start', 'play_free', 'join_queue', 'early_entry',
|
|
'request_payment', 'match_queue']) {
|
|
const h = handlers({ chainHealthy: false });
|
|
const s = socket();
|
|
const task = jest.fn();
|
|
await h._runAdmission(s, kind, task);
|
|
expect(task).not.toHaveBeenCalled();
|
|
expect(s.emitted.some(e => e.event === 'chain_unavailable')).toBe(true);
|
|
}
|
|
});
|
|
|
|
test('shutdown still takes precedence over the node check', async () => {
|
|
const h = handlers({ chainHealthy: false, shuttingDown: true });
|
|
h._emitShutdownAdmissionRefusal = jest.fn();
|
|
const s = socket();
|
|
|
|
await h._runAdmission(s, 'auto_start', jest.fn());
|
|
|
|
expect(h._emitShutdownAdmissionRefusal).toHaveBeenCalled();
|
|
expect(s.emitted.some(e => e.event === 'chain_unavailable')).toBe(false);
|
|
});
|
|
|
|
test('paid intake is refused when the WALLET is unreachable, but credits/free are not', async () => {
|
|
// Not a failover: two wallet-rpc processes over one wallet file can spend the same outputs.
|
|
// The safe response to a wallet outage is a clean refusal of intake only.
|
|
const h = handlers({ chainHealthy: true });
|
|
h.walletService = { isHealthy: false };
|
|
|
|
const paid = socket();
|
|
await h._runAdmission(paid, 'request_payment', jest.fn());
|
|
const refusal = paid.emitted.find(e => e.event === 'payment_unavailable');
|
|
expect(refusal).toBeDefined();
|
|
expect(refusal.payload).toMatchObject({ code: 'WALLET_UNREACHABLE' });
|
|
|
|
for (const kind of ['auto_start', 'play_free', 'join_queue']) {
|
|
const s = socket();
|
|
const task = jest.fn().mockResolvedValue('ok');
|
|
await expect(h._runAdmission(s, kind, task)).resolves.toBe('ok');
|
|
expect(task).toHaveBeenCalled();
|
|
}
|
|
});
|
|
|
|
test('a runtime without the health probe is left alone (fires only on an explicit false)', async () => {
|
|
const h = handlers({ chainHealthy: true });
|
|
h.debugManager = { CONSOLE_LOGGING: false }; // no isChainHealthy at all
|
|
const s = socket();
|
|
const task = jest.fn().mockResolvedValue('ok');
|
|
|
|
await expect(h._runAdmission(s, 'auto_start', task)).resolves.toBe('ok');
|
|
expect(task).toHaveBeenCalled();
|
|
});
|
|
});
|