fix(test): 修复 build-game 测试中的关键断言缺陷

两处修复:

1. 修复夹具差异不足导致的无效断言
   - DEFAULT_BTN 与 SKINNED 之前使用完全相同参数,生成字节一致的 PNG
   - 导致 composeSkin 的核心验证断言(.equals)无论合成是否发生都绿灯通过
   - 现改为 makePng(64, 64, [1, 2, 3]) 与 makePng(64, 64, [9, 9, 9])
   - 验证: DEFAULT_BTN 176 bytes, SKINNED 151 bytes, .equals() = false

2. 补入框架真源只读验证
   - 测试 1 中新增断言: buildGame 后框架源文件仍为原值
   - 覆盖红线 #1「框架真源全程只读」的唯一缺口
   - 若 composeSkin 误传 gameDir, 新断言会直接捕获真源污染

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-27 22:16:20 +08:00
co-authored by Claude Opus 5
parent 134f4c877c
commit e224d1fa3e
@@ -38,7 +38,7 @@ function makePng(w, h, rgb = [0, 0, 0]) {
} }
const DEFAULT_BTN = makePng(64, 64, [1, 2, 3]); const DEFAULT_BTN = makePng(64, 64, [1, 2, 3]);
const SKINNED = makePng(64, 64, [1, 2, 3]); const SKINNED = makePng(64, 64, [9, 9, 9]);
function put(dir, rel, content) { function put(dir, rel, content) {
const p = join(dir, ...rel.split('/')); const p = join(dir, ...rel.split('/'));
@@ -82,6 +82,7 @@ test('buildGame 走通全流程:实体化 → 合成 → 调构建 → 写 bui
const r = buildGame('demo', baseOpts(s, { runBuild: (dir, p) => calls.push([dir, p]) })); const r = buildGame('demo', baseOpts(s, { runBuild: (dir, p) => calls.push([dir, p]) }));
assert.ok(readFileSync(join(r.workspaceDir, 'assets', 'framework', 'ui', 'atlas-hall', 'btn.png')).equals(SKINNED)); assert.ok(readFileSync(join(r.workspaceDir, 'assets', 'framework', 'ui', 'atlas-hall', 'btn.png')).equals(SKINNED));
assert.ok(readFileSync(join(s.frameworkSrc, 'ui', 'atlas-hall', 'btn.png')).equals(DEFAULT_BTN), '框架真源必须只读:合成只能发生在临时工作区');
assert.equal(calls.length, 1); assert.equal(calls.length, 1);
assert.equal(calls[0][0], r.workspaceDir); assert.equal(calls[0][0], r.workspaceDir);
assert.equal(calls[0][1], 'web-mobile'); assert.equal(calls[0][1], 'web-mobile');