fix(sdk): inject assertions into Creator-loaded contract harness

This commit is contained in:
2026-09-05 18:58:44 +08:00
parent 690fdef78a
commit 266be19e76
3 changed files with 40 additions and 6 deletions
@@ -1,4 +1,4 @@
import { strict as assert } from 'node:assert';
import type { strict } from 'node:assert';
import type {
GameEntry,
GameHost,
@@ -21,8 +21,12 @@ export interface GameContractSample {
readonly makeHost: GameContractHostFactory;
}
/** Runs the shared lifecycle checks required of the app's sole GameEntry. */
export function assertGameContract(entry: GameEntry, samples: readonly GameContractSample[]): void {
/** Runs lifecycle checks with assertions explicitly supplied by the test caller. */
export function assertGameContract(
entry: GameEntry,
samples: readonly GameContractSample[],
assert: typeof strict,
): void {
assert.ok(samples.length > 0, 'conformance requires game-owned roomtype samples');
assertGameEntry(entry);
for (const route of ['platform', 'agent', 'room']) {
@@ -48,8 +52,8 @@ export function assertGameContract(entry: GameEntry, samples: readonly GameContr
const sessions = new GameSessionHost(entry);
for (const sample of samples) {
runCycle(sessions, sample, entry, 1);
runCycle(sessions, sample, entry, 2);
runCycle(sessions, sample, entry, 1, assert);
runCycle(sessions, sample, entry, 2, assert);
}
assert.equal(sessions.state, 'idle');
}
@@ -59,6 +63,7 @@ function runCycle(
sample: GameContractSample,
entry: GameEntry,
cycle: number,
assert: typeof strict,
): void {
const contractHost = sample.makeHost();
const snapshot = contractHost.host.getSnapshot();