zhuyuan-ice-gl-zy001/ZCODE-DEV-20260826/public-spine/v0.1/self-check.mjs

13 lines
906 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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);