#!/usr/bin/env node // 公众脊椎包自检:G4 失败关闭——缺一条即 FAIL,不猜跑 import fs from "node:fs"; import path from "node:path"; import crypto from "node:crypto"; const pkg = process.argv[2] ?? path.dirname(new URL(import.meta.url).pathname); const spine = JSON.parse(fs.readFileSync(path.join(pkg, "spine.json"), "utf8")); const tcs = fs.readFileSync(path.join(pkg, "ZHUYUAN-PUBLIC-SPINE-0001.tcs"), "utf8"); const missing = spine.entries.filter((e) => !tcs.includes(`"${e.rule}"`)); const recompute = crypto.createHash("sha256").update(JSON.stringify(spine.entries.map((e) => [e.id, e.rule]))).digest("hex"); const ok = missing.length === 0 && recompute === spine.spine_sha256 && spine.count === 24; console.log(JSON.stringify({ outcome: ok ? "PASS" : "FAIL", count: spine.count, missing: missing.map((m) => m.id), spine_sha256: spine.spine_sha256 })); process.exit(ok ? 0 : 1);