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
@@ -38,7 +38,9 @@ SDK runtime 也不导入框架实现层,平台适配由 `platform/game-host-ad
`GameEntry.resolveSeatCount` 只接收真实房间的 `roomtype`,预检只检查该方法存在;
GameHost 在进房边界验证返回值是正整数并与服务器座位数组长度相同。
`assertGameContract(entry, samples)` 的每个样本由游戏提供 `roomtype`、`expectedSeatCount`
`assertGameContract(entry, samples, assert)` 的 `assert` 由测试调用方从 `node:assert/strict`
显式导入并传入;harness 仅引用断言类型,避免 Creator 加载脚本时解析 Node 内置模块。
每个样本由游戏提供 `roomtype`、`expectedSeatCount`
和对应的 `makeHost` 工厂,不要求游戏支持框架虚构的房间配置。
远程地址唯一取自 `data.urlserver`。配置请求使用空 body 的 POST,沿用无条件 `?` 缓存参数拼接。
@@ -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();