fix(qa): 禁止后台验收启动系统 Google Chrome
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Static check only: never start a browser, even when a legacy launcher fails this test."""
|
||||
import ast
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
def inspect_launchers(admin):
|
||||
problems, launches = [], 0
|
||||
for folder in ("live-native", "live-readonly", "local-preview"):
|
||||
for path in sorted((admin / folder).glob("*.py")):
|
||||
source = path.read_text()
|
||||
for node in ast.walk(ast.parse(source, filename=str(path))):
|
||||
if not isinstance(node, ast.Call) or not isinstance(node.func, ast.Attribute):
|
||||
continue
|
||||
if node.func.attr not in {"launch", "launch_persistent_context"}:
|
||||
continue
|
||||
launches += 1
|
||||
kwargs = {kw.arg: kw.value for kw in node.keywords}
|
||||
# The unbranded, default headless engine is the Playwright test shell.
|
||||
# Do not permit channel, executable_path, or **options to override it.
|
||||
headless = kwargs.get("headless")
|
||||
if (node.func.attr != "launch" or "chromium" not in ast.unparse(node.func.value)
|
||||
or node.args or set(kwargs) - {"headless", "args"}
|
||||
or not isinstance(headless, ast.Constant) or headless.value is not True):
|
||||
problems.append(str(path.relative_to(admin)))
|
||||
return launches, problems
|
||||
|
||||
|
||||
def test_isolated_headless_only():
|
||||
count, problems = inspect_launchers(Path(__file__).resolve().parents[1])
|
||||
assert count > 0 and not problems, problems
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
directory = Path(sys.argv[1]) if sys.argv[1:] else Path(__file__).resolve().parents[1]
|
||||
count, failures = inspect_launchers(directory)
|
||||
print(f"launchers_checked={count} noncompliant={len(failures)} browsers_started=0")
|
||||
sys.exit(1 if failures or not count else 0)
|
||||
Reference in New Issue
Block a user