fix(qa): 禁止后台验收启动系统 Google Chrome

This commit is contained in:
2026-12-01 20:20:59 +08:00
parent 4101b11aaf
commit e4712895f3
17 changed files with 73 additions and 32 deletions
+3 -1
View File
@@ -16,6 +16,8 @@ node live-native/build.mjs && node live-native/server.mjs
构建输出仅在本工作树 `admin/node_modules/.zyt-live-native/dist`。本机会话任务为 `local.zyt.live-native.bfc2`,可用 `launchctl remove local.zyt.live-native.bfc2` 停止,不设开机启动项。可选 `server.mjs --qa` 使用 5181 供隔离验收。
黑盒检查:`python3 live-native/browser_contract.py --host 127.0.0.1:5179 --chrome <Chromium路径> --out <本地截图目录>`。测试拦截所有非本机请求,仅用虚构登录/统计数据检查真实组件;不验证真实用户凭据或线上写入。
黑盒检查:`python3 live-native/browser_contract.py --host 127.0.0.1:5179 --out <本地截图目录>`。测试拦截所有非本机请求,仅用虚构登录/统计数据检查真实组件;不验证真实用户凭据或线上写入。
分批 UI 验收:`node live-native/build.mjs v1-example` 只写入本机候选目录;`node live-native/server.mjs --qa v1-example` 在本机 5181 查看它。验收通过后运行 `node live-native/promote-local.mjs apply v1-example`;如需切回上版且当前仍是此构建,运行 `node live-native/promote-local.mjs restore v1-example`。每次应用使用唯一候选名。5179 的旧哈希资源继续可用,不涉及正式发布目录。
浏览器验收仅使用 Playwright 配套的 Chromium Headless Shell,不调用系统 Google Chrome。未安装专用引擎时,跳过浏览器验收;不要指定系统浏览器补跑。
+2 -2
View File
@@ -222,12 +222,12 @@ def scenario(browser, args, wx, iam):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", type=loopback, default="127.0.0.1:5179")
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path, help="Optional directory for offline screenshots")
args = parser.parse_args()
if args.out:
args.out.mkdir(parents=True, exist_ok=True)
with sync_playwright() as pw, pw.chromium.launch(executable_path=args.chrome, args=[
with sync_playwright() as pw, pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1",
]) as browser:
+2 -2
View File
@@ -251,13 +251,13 @@ def reader_checks(page, ui, fx, out, report):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", type=loopback, default="127.0.0.1:5181")
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path)
args = parser.parse_args()
if args.out:
args.out.mkdir(parents=True, exist_ok=True)
report = {"checks": [], "errors": [], "business_writes": [], "fixtures": {}}
with sync_playwright() as pw, pw.chromium.launch(headless=True, executable_path=args.chrome, args=[
with sync_playwright() as pw, pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1"]) as browser:
for role in ("reader", "edit", "delete", "operator"):
+2 -2
View File
@@ -186,10 +186,10 @@ def protected_startup(browser,host):
if __name__=="__main__":
ap=argparse.ArgumentParser(description=__doc__);ap.add_argument("--host",type=loopback,default="127.0.0.1:5179")
ap.add_argument("--chrome",required=True);ap.add_argument("--out",type=Path)
ap.add_argument("--out",type=Path)
a=ap.parse_args()
if a.out: a.out.mkdir(parents=True,exist_ok=True)
with sync_playwright() as pw,pw.chromium.launch(executable_path=a.chrome,headless=True,args=CHROME_ARGS) as browser:
with sync_playwright() as pw,pw.chromium.launch(headless=True, args=CHROME_ARGS) as browser:
report={"light":boot(browser,a.host,a.out,False),"dark_reduced":boot(browser,a.host,a.out,True,True),
"journey":journey(browser,a.host,a.out),"asset_failure":failed_page(browser,a.host,a.out),"startup_guards":protected_startup(browser,a.host),"real_api_calls":0,"status":"PASS"}
print(json.dumps(report,ensure_ascii=False))
+1 -4
View File
@@ -1,7 +1,6 @@
"""Offline component test: real shared pagination SFC + installed Element Plus, no server or API."""
import argparse
import json
import os
import re
import subprocess
import tempfile
@@ -125,9 +124,7 @@ def main():
subprocess.run(['node','build.mjs'],cwd=root,check=True,stdout=subprocess.DEVNULL)
dist=root/'dist'
with sync_playwright() as pw:
exe=os.environ.get('CHROME_BIN')
mac='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
browser=pw.chromium.launch(executable_path=exe or (mac if Path(mac).exists() else None),
browser=pw.chromium.launch(headless=True,
args=['--disable-background-networking'])
page=browser.new_page()
errors,requests=[],[]
+2 -2
View File
@@ -399,14 +399,14 @@ def check(page, fixture, out):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", type=loopback, default="127.0.0.1:5179")
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path, help="Optional local screenshots directory")
args = parser.parse_args()
if args.out:
args.out.mkdir(parents=True, exist_ok=True)
fixture = Fixture(args.host, False, False)
setup_menu(fixture)
with sync_playwright() as pw, pw.chromium.launch(executable_path=args.chrome, args=[
with sync_playwright() as pw, pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1"]) as browser:
with browser.new_context(service_workers="block", viewport={"width": 1440, "height": 960},
+2 -2
View File
@@ -310,13 +310,13 @@ def reader_checks(page, stats, fx, report, out):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", type=loopback, default="127.0.0.1:5179")
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path, help="Write JSON and local screenshots to this directory")
args = parser.parse_args()
if args.out:
args.out.mkdir(parents=True, exist_ok=True)
report = {"checks": {}, "infrastructure_errors": []}
with sync_playwright() as pw, pw.chromium.launch(executable_path=args.chrome, args=[
with sync_playwright() as pw, pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1"]) as browser:
for role in ("reader", "edit", "delete"):
+2 -2
View File
@@ -147,14 +147,14 @@ def exercise(page, fixture, out):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", type=loopback, default="127.0.0.1:5179")
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path, help="Optional directory for local screenshots")
args = parser.parse_args()
if args.out:
args.out.mkdir(parents=True, exist_ok=True)
fixture = Fixture(args.host, False, False)
register_menu(fixture)
with sync_playwright() as pw, pw.chromium.launch(executable_path=args.chrome, args=[
with sync_playwright() as pw, pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1"]) as browser:
with browser.new_context(service_workers="block", viewport={"width": 1440, "height": 960},
@@ -164,12 +164,12 @@ def run(browser, args, mobile):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", type=loopback, default="127.0.0.1:5179")
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path)
args = parser.parse_args()
if args.out:
args.out.mkdir(parents=True, exist_ok=True)
with sync_playwright() as pw, pw.chromium.launch(executable_path=args.chrome, args=[
with sync_playwright() as pw, pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1"]) as browser:
cases = [run(browser, args, mobile) for mobile in (False, True)]
+3 -1
View File
@@ -14,10 +14,12 @@
node live-readonly/build.mjs && node live-readonly/server.mjs
```
验证(不使用真实账号):`node --test live-readonly/resources.test.mjs live-readonly/transport.test.mjs`;`browser_contract.py --chrome <Chromium路径> --out <截图目录>` 使用全新的浏览器,拦截整个正式域名并只返回测试响应。只有正式账号本人登录后,才能确认该账号实际可见的实时数据。
验证(不使用真实账号):`node --test live-readonly/resources.test.mjs live-readonly/transport.test.mjs`;`browser_contract.py --out <截图目录>` 使用全新的浏览器,拦截整个正式域名并只返回测试响应。只有正式账号本人登录后,才能确认该账号实际可见的实时数据。
本机运行任务:`launchctl print gui/$(id -u)/local.zyt.live-readonly.bfc2`。退出服务:`launchctl remove local.zyt.live-readonly.bfc2`。未安装开机启动项。
## 左栏的数据来源
登录和「刷新线上菜单」均读取本次账号 `/auth.admin/mySelf` 返回的 `data.menu`。可见目录、层级、同名项、显示名称、图标与顺序由正式服务器决定;隐藏、禁用和按钮权限项不挤进侧栏。已审过的页面使用本地新版只读组件;其余真实菜单保留,点击会说明可否进入正式页面。仅用户再次明确选择才新开正式站或菜单指定的外部站点,不向目标传递本地令牌。正式站沿用其原有登录与操作权限。无返回菜单时不补演示菜单。可运行 `browser_menu_contract.py --help` 查看多层级、同名项及权限变更的离线验收。
浏览器验收仅使用 Playwright 配套的 Chromium Headless Shell,不调用系统 Google Chrome。未安装专用引擎时,跳过浏览器验收;不要指定系统浏览器补跑。
+2 -2
View File
@@ -4,10 +4,10 @@ from pathlib import Path
from urllib.parse import urlsplit
from playwright.sync_api import expect,sync_playwright
import json
p=ArgumentParser();p.add_argument('--chrome',required=True);p.add_argument('--out',type=Path,required=True);arg=p.parse_args();arg.out.mkdir(parents=True,exist_ok=True)
p=ArgumentParser();p.add_argument('--out',type=Path,required=True);arg=p.parse_args();arg.out.mkdir(parents=True,exist_ok=True)
base='http://127.0.0.1:5179'; official='https://admin.zhenyangtang.com.cn'; calls=[]; unexpected=[]; errors=[]
with sync_playwright() as pw:
b=pw.chromium.launch(executable_path=arg.chrome,args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
b=pw.chromium.launch(headless=True, args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
c=b.new_context(service_workers='block',viewport={'width':1320,'height':850});page=c.new_page();page.on('pageerror',lambda e:errors.append(str(e)))
def route(r):
u=urlsplit(r.request.url); path=u.path.removeprefix('/adminapi');m=r.request.method
+2 -2
View File
@@ -132,7 +132,7 @@ def visit(page, parent, name, base, id_):
def check(pw, args):
base = f"http://127.0.0.1:{args.port}"
mock, errors = Offline(base), []
with pw.chromium.launch(executable_path=args.chrome, args=[
with pw.chromium.launch(headless=True, args=[
"--disable-background-networking", "--disable-quic", "--no-proxy-server",
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1",
]) as browser:
@@ -221,7 +221,7 @@ def check(pw, args):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--chrome", required=True)
parser.add_argument("--out", type=Path, required=True)
parser.add_argument("--port", type=int, default=5179)
args = parser.parse_args()
+4 -2
View File
@@ -20,7 +20,7 @@ node local-preview/build.mjs && node local-preview/server.mjs 5180
验证:`node --test local-preview/server.test.mjs local-preview/fixtures.test.mjs local-preview/modules/*.test.mjs` 离线检查入口分流和模拟数据;5180 演示服务运行后 `node local-preview/verify-http.mjs` 复核写入、代理、跨域等均被拒绝。可选的 `browser_smoke.py` 使用 Python Playwright 和本地 Chromium,只允许本机请求。
`verify-art-parameters.py --chrome <Chromium可执行文件> --out <截图目录>` 对照固定的 Art Design Pro 默认参数,测量实际渲染的亮色、暗色和经典外观,并保存对应截图和 computed.json。该验收同样只访问回环地址。
`verify-art-parameters.py --out <截图目录>` 对照固定的 Art Design Pro 默认参数,测量实际渲染的亮色、暗色和经典外观,并保存对应截图和 computed.json。该验收同样只访问回环地址。
## 本地演示数据如何关联
@@ -32,4 +32,6 @@ node local-preview/build.mjs && node local-preview/server.mjs 5180
| `/admin/dept-stats` | 以挂号医助所属部门、接诊日期统计。同部门/日期的「查看明细」带入相同筛选条件。 |
| `/admin/workbench` 和 `/admin/order` | 保留原工作台/订单。订单支持虚构支付状态、未关联患者和操作记录;真实支付、排班变更、调账、导出文件等不开放。 |
日期从本机日历生成,每天第一次读取时建立同一份快照。`browser_modules.py --chrome <Chromium路径> --out <目录>` 在独立浏览器中验证统计下钻、用户/排班/订单跳转、筛选、窄屏及零外部请求。
日期从本机日历生成,每天第一次读取时建立同一份快照。`browser_modules.py --out <目录>` 在独立浏览器中验证统计下钻、用户/排班/订单跳转、筛选、窄屏及零外部请求。
浏览器验收仅使用 Playwright 配套的 Chromium Headless Shell,不调用系统 Google Chrome。未安装专用引擎时,跳过浏览器验收;不要指定系统浏览器补跑。
+2 -2
View File
@@ -4,7 +4,7 @@ from pathlib import Path
from urllib.parse import urlsplit, parse_qs
from playwright.sync_api import expect, sync_playwright
p = argparse.ArgumentParser()
p.add_argument('--chrome', required=True)
p.add_argument('--out', required=True, type=Path)
args = p.parse_args()
args.out.mkdir(exist_ok=True, parents=True)
@@ -14,7 +14,7 @@ foreign = []
failed = []
passed = []
with sync_playwright() as pw:
browser = pw.chromium.launch(executable_path=args.chrome, args=['--disable-background-networking', '--no-proxy-server', '--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
browser = pw.chromium.launch(headless=True, args=['--disable-background-networking', '--no-proxy-server', '--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
ctx = browser.new_context(viewport={'width': 1440, 'height': 1000}, service_workers='block', color_scheme='light')
pg = ctx.new_page()
pg.set_default_timeout(7000)
+2 -2
View File
@@ -8,12 +8,12 @@ from playwright.sync_api import sync_playwright, expect
args = argparse.ArgumentParser()
args.add_argument('--screens', type=Path, required=True)
args.add_argument('--chrome', help='Path to an installed Chromium/Chrome executable')
a = args.parse_args(); a.screens.mkdir(exist_ok=True, parents=True)
origin = 'http://127.0.0.1:5180'
errors, external, failed = [], [], []
with sync_playwright() as p:
browser = p.chromium.launch(executable_path=a.chrome, args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
browser = p.chromium.launch(headless=True, args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
ctx = browser.new_context(viewport={'width':1440, 'height':960}, color_scheme='light', service_workers='block')
def only_local(route):
if route.request.url.startswith(origin+'/'):
+2 -2
View File
@@ -7,7 +7,7 @@ from playwright.sync_api import expect, sync_playwright
parser = argparse.ArgumentParser()
parser.add_argument('--out', type=Path, required=True)
parser.add_argument('--chrome', required=True)
parser.add_argument('--record-only', action='store_true', help='record the pre-correction build without asserting parity')
a = parser.parse_args()
a.out.mkdir(exist_ok=True, parents=True)
@@ -31,7 +31,7 @@ read_colors = """() => {
}"""
modes = {}; external=[]; palette=[]
with sync_playwright() as pw:
browser=pw.chromium.launch(executable_path=a.chrome,args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
browser=pw.chromium.launch(headless=True, args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'])
ctx=browser.new_context(viewport={'width':1440,'height':960},color_scheme='light',service_workers='block')
def local(route):
if route.request.url.startswith(origin): return route.continue_()
+38
View File
@@ -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)