// 验证 sim 门禁**真的会拦**:往骨架里注入一个真实外链标签,看 check:dist 是否报错。 // 一个从不失败的检查等于没有检查——上一版它对整页扫标签,四个分发全是假阳性; // 收紧之后必须确认它没有紧到"什么都查不到"。 import { readFileSync, writeFileSync, copyFileSync, unlinkSync } from "node:fs"; import { execFileSync } from "node:child_process"; const page = "dist/releases/single-hsr-kv37/sim/index.html"; const backup = `${page}.bak`; function runCheck() { try { return execFileSync("node", ["tools/check-dist.ts"], { encoding: "utf8" }); } catch (error) { const e = error as { stdout?: string; stderr?: string }; return (e.stdout || "") + (e.stderr || ""); } } function inject(html, tag) { const anchor = '
'; if (!html.includes(anchor)) throw new Error("锚点没找到,测试需要更新"); return html.replace(anchor, anchor + tag); } const cases = [ ["外链 script", ''], ["file:// 绝对路径", ''], ["根绝对路径", ''], ["type=module", ''], ]; const original = readFileSync(page, "utf8"); copyFileSync(page, backup); let failed = 0; try { console.log("=== 干净页面应当通过 ==="); const clean = runCheck(); const cleanOk = clean.includes("✓ 自包含"); console.log(` ${cleanOk ? "✓" : "✗"} 未注入时通过`); if (!cleanOk) failed++; for (const [label, tag] of cases) { writeFileSync(page, inject(original, tag)); const output = runCheck(); // 必须是**失败**,且失败原因里提到 sim/index.html const caught = !output.includes("✓ 自包含") && output.includes("sim/index.html"); console.log(` ${caught ? "✓" : "✗"} 拦住了「${label}」`); if (!caught) { failed++; console.log(` check 输出:${output.split("\n").slice(0, 3).join(" | ")}`); } } } finally { writeFileSync(page, original); unlinkSync(backup); } const restored = runCheck(); console.log(`\n还原后:${restored.includes("✓ 自包含") ? "✓ 通过" : "✗ 仍失败"}`); if (!restored.includes("✓ 自包含")) failed++; console.log(failed === 0 ? "\nsim 门禁:四种外部依赖都能拦住" : `\nsim 门禁:${failed} 处不符合预期`); process.exit(failed === 0 ? 0 : 1);