52 lines
2.5 KiB
TypeScript
52 lines
2.5 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { GameSessionHost } from '../../YouleNexus/assets/framework/sdk/runtime/game-session-host.ts';
|
|
import type { GameHost, PlatformToGameEvent, GameServerMessage } from '../../YouleNexus/assets/framework/sdk/contracts/index.ts';
|
|
|
|
async function setup() {
|
|
const api = await import('../../YouleNexus/assets/scripts/local-platform-login/local-login-game-entry.ts')
|
|
.catch(error => assert.fail(`Diagnostic GameEntry implementation must exist: ${String(error)}`));
|
|
const evidence: { kind: string; data: unknown }[] = [];
|
|
return { entry: api.createDiagnosticGameEntry(101, event => evidence.push(event)), evidence };
|
|
}
|
|
|
|
test('real GameSessionHost validates and releases one diagnostic instance without entering a game', async () => {
|
|
const { entry, evidence } = await setup();
|
|
const host = new GameSessionHost(entry);
|
|
assert.equal(host.state, 'idle');
|
|
assert.equal(entry.key, 'local-platform-login');
|
|
assert.equal(entry.route, 'local-platform-login');
|
|
assert.equal(entry.gameId, 101);
|
|
assert.deepEqual(evidence, [
|
|
{ kind: 'diagnostic-module', data: { instanceId: 1, state: 'created' } },
|
|
{ kind: 'diagnostic-module', data: { instanceId: 1, state: 'disposed' } },
|
|
]);
|
|
host.dispose();
|
|
host.dispose();
|
|
assert.equal(evidence.length, 2);
|
|
});
|
|
|
|
test('every game behavior records its operation and throws; dispose is idempotent', async () => {
|
|
const { entry, evidence } = await setup();
|
|
assert.throws(() => entry.resolveSeatCount([]), /resolveSeatCount/);
|
|
const module = entry.createModule();
|
|
for (const [operation, invoke] of [
|
|
['attach', () => module.attach({} as GameHost)],
|
|
['restore', () => module.restore({})],
|
|
['handlePlatformEvent', () => module.handlePlatformEvent({} as PlatformToGameEvent)],
|
|
['handleGameMessage', () => module.handleGameMessage({} as GameServerMessage)],
|
|
] as const) {
|
|
assert.throws(invoke, new RegExp(operation));
|
|
assert.equal(evidence[evidence.length - 1]?.kind, 'scope-violation');
|
|
assert.equal((evidence[evidence.length - 1]?.data as { operation: string }).operation, operation);
|
|
}
|
|
module.dispose();
|
|
module.dispose();
|
|
entry.createModule().dispose();
|
|
const lifecycle = evidence.filter(event => event.kind === 'diagnostic-module');
|
|
assert.deepEqual(lifecycle.map(event => event.data), [
|
|
{ instanceId: 1, state: 'created' }, { instanceId: 1, state: 'disposed' },
|
|
{ instanceId: 2, state: 'created' }, { instanceId: 2, state: 'disposed' },
|
|
]);
|
|
});
|