"""后台页面内联 JS 语法校验:把 admin_html 里的 ", html, re.S)
print(f"[info] script blocks = {len(scripts)}")
if not node:
print(" [SKIP] 没装 node,跳过 JS 语法检查")
else:
for i, js in enumerate(scripts):
if not js.strip():
continue
with tempfile.NamedTemporaryFile("w", suffix=f".chk{i}.js",
delete=False, encoding="utf-8") as f:
f.write(js)
path = f.name
r = subprocess.run([node, "--check", path], capture_output=True, text=True)
check(f"script#{i} 语法({len(js)} chars)", r.returncode == 0, r.stderr[:2000])
os.unlink(path)
# 关键函数必须在:改界面时被误删就会在这里报出来
for name in (
"function authModeIds", "function onAuthModeChange",
"function applyDualKeyPreset", "function mergeDualHeader",
"function collectExtraHeaders", "function authModeBodyCheck",
"function pendingHeaderNames", "function authHeaderLabel",
"function extraHeadersToText", "function addProvider",
"function saveProviderEdit", "function editProvider",
"function probeNewProvider", "function loadProviders",
"function splitModelList",
):
check(name, name in html)
# 新版控件与版本号占位符(第二个请求头输入框必须在折叠块外面,不能藏在 里)
for token in ("pAuthMode", "epAuthMode", "pAuthModeHint", "epAuthModeHint",
"pDualRow", "epDualRow", "pDualHeaderName", "pDualHeaderValue",
"epDualHeaderName", "epDualHeaderValue",
"applyDualKeyPreset('p')", "applyDualKeyPreset('ep')",
'id="uiRevBadge"',
''):
check(f"页面含 {token}", token in html)
# 结构校验:第二个请求头那一行要在 之前(否则又会被折叠起来看不见)
i_keys = html.find('id="pKeys"')
i_row = html.find('id="pDualRow"')
i_det = html.find('', i_keys)
check("第二个请求头输入框在折叠块之前(可见)",
0 < i_keys < i_row < i_det, f"pKeys={i_keys} pDualRow={i_row} details={i_det}")
print("\n" + ("=" * 60))
if FAILS:
print(f"FAILED: {len(FAILS)} -> {FAILS}")
return 1
print("ALL PASS")
return 0
if __name__ == "__main__":
sys.exit(main())