二七王:前端单测框架与 shared 同步守卫
测试侧用 vm.runInThisContext 加载浏览器全局脚本,正式代码不为测试加任何导出。 test_shared_sync 断言前后端 shared 逐字节一致,已做反向验证(改一个空格即红)。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// shared 同步守卫:服务端权威源与前端只读副本必须逐字节一致。
|
||||
// 忘了跑 sync_shared.cmd、或有人手改了前端副本,这条立刻红。
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { ROOT } = require('./_load');
|
||||
const t = require('./_assert')();
|
||||
|
||||
const srcDir = path.join(ROOT, 'server', 'games', 'erqiwang', 'shared');
|
||||
const dstDir = path.join(ROOT, 'client', 'js', '01_SubGame', 'codes', 'shared');
|
||||
|
||||
const srcFiles = fs.readdirSync(srcDir).filter(f => f.endsWith('.js')).sort();
|
||||
const dstFiles = fs.readdirSync(dstDir).filter(f => f.endsWith('.js')).sort();
|
||||
|
||||
t.eq('文件清单一致', dstFiles, srcFiles);
|
||||
t.eq('源目录非空', srcFiles.length > 0, true);
|
||||
|
||||
srcFiles.forEach(f => {
|
||||
const a = fs.readFileSync(path.join(srcDir, f));
|
||||
const b = fs.existsSync(path.join(dstDir, f)) ? fs.readFileSync(path.join(dstDir, f)) : Buffer.alloc(0);
|
||||
t.eq('字节一致: ' + f, a.equals(b), true);
|
||||
});
|
||||
|
||||
process.exit(t.done('shared_sync') ? 0 : 1);
|
||||
Reference in New Issue
Block a user