44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Native-confirm gate (drill F-11; alert added v0.126.4) — native confirm()/prompt()/alert()
|
|
dialogs are OS-modals that block browser automation (CDP freezes) and are banned from the UI;
|
|
consequential actions use the inline felhomConfirm helper (layout.html) or the .confirm-overlay
|
|
dialog; error/info surfaces use showAlert (layout.html modal). alert() joined the ban after the
|
|
0.87.0 wizard leg: a decommission error path alert() froze the automation exactly like F-11
|
|
predicted (the operator had to click the OS-modal away).
|
|
|
|
Run from controller/: python scripts/native_confirm_gate.py
|
|
Exit 1 if any native confirm(/prompt(/alert( call remains in the templates.
|
|
"""
|
|
import io, os, re, sys
|
|
|
|
ROOTS = [
|
|
os.path.join("internal", "web", "templates"),
|
|
os.path.join("internal", "setup", "templates"),
|
|
]
|
|
|
|
# A bare confirm(/prompt(/alert( CALL with an argument: not preceded by an identifier character,
|
|
# so felhomConfirm(, showAlert( and onRestoreConfirmChange( never match. window.confirm( /
|
|
# window.alert( still match ('.' is not an identifier character).
|
|
NATIVE = re.compile(r"(?<![A-Za-z0-9_$])(?:confirm|prompt|alert)\(\s*[^)\s]")
|
|
|
|
|
|
def main():
|
|
total = 0
|
|
for root in ROOTS:
|
|
for fn in sorted(os.listdir(root)):
|
|
if not fn.endswith(".html"):
|
|
continue
|
|
path = os.path.join(root, fn)
|
|
for lineno, line in enumerate(io.open(path, encoding="utf-8"), 1):
|
|
if NATIVE.search(line):
|
|
total += 1
|
|
print("%s:%d %s" % (fn, lineno, line.strip()[:120].encode('ascii', 'backslashreplace').decode()))
|
|
if total:
|
|
print("NATIVE CONFIRM GATE FAILED: %d native confirm()/prompt()/alert() call(s) remain" % total)
|
|
sys.exit(1)
|
|
print("native-confirm gate OK — no native confirm()/prompt()/alert() in templates")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|