From a3111a25f60e94100ab2c094ce85640ef7b26ada Mon Sep 17 00:00:00 2001 From: Hermes CI Fix Date: Thu, 3 Sep 2026 18:41:44 +0800 Subject: [PATCH] =?UTF-8?q?test(frontend):=20BUG-001=E9=AA=8C=E6=94=B6?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=203=E9=A1=B5=E9=9D=A2x10=E8=BF=9E=E5=88=B7?= =?UTF-8?q?=E6=97=A0=E5=8D=A1=E5=8A=A0=E8=BD=BD=E4=B8=AD=20(=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E7=95=99=E5=AD=98,2026-09-03)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../verify_10reload_no_freeze_20260903.py | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 backend/scripts/verify_10reload_no_freeze_20260903.py diff --git a/backend/scripts/verify_10reload_no_freeze_20260903.py b/backend/scripts/verify_10reload_no_freeze_20260903.py new file mode 100644 index 00000000..41dc2a03 --- /dev/null +++ b/backend/scripts/verify_10reload_no_freeze_20260903.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""BUG-001 验收:3页面×10次整页刷新,无卡"加载中"超10s(2026-09-03 修复后) +判据: location.href 整页刷新 → 轮询(0.5s)直到 body>100 且非壳页"加载中" → 耗时 <= 10s +""" +import sys, json, time +sys.path.insert(0, "/root/.hermes/profiles/wecom-yanxue/skills/operations/cdp-browser-automation/scripts") +from cdp_helpers import CDPBrowser + +CDP = "http://127.0.0.1:9226" +BASE = "https://cma.sxbh.ltd" + +def pick_tab(url_needle): + tabs = json.loads(__import__("urllib.request").request.urlopen(CDP + "/json", timeout=5).read()) + for t in tabs: + if t.get("type") == "page" and url_needle in t.get("url", ""): + return t + raise LookupError("无匹配tab: " + url_needle) + +def fresh_browser(url_needle): + """复用已登录 tab(每轮重连,防导航断ws)""" + b = CDPBrowser(cdp=CDP, base_url=BASE) + b.use_existing_tab(url_needle) + return b + +def reload_and_time(url, url_needle, max_wait=12): + """整页刷新并计时到渲染完成。返回 (耗时秒, body_len, 超时?)""" + b = fresh_browser(url_needle) + t0 = time.time() + try: + b.js("location.href='" + url + "'") + except Exception: + pass # 导航即断ws属正常 + body = "" + waited = 0 + last_err = None + while waited < max_wait: + time.sleep(0.5) + waited += 0.5 + try: + body = b.js("document.body ? document.body.innerText : ''") or "" + except Exception as e: + last_err = e + try: + b = fresh_browser(url_needle) + body = b.js("document.body ? document.body.innerText : ''") or "" + except Exception as e2: + last_err = e2 + body = "" + if len(body) > 100 and "加载中" not in body[:60]: + return round(time.time() - t0, 2), len(body), False, "" + return round(time.time() - t0, 2), len(body), True, str(last_err or "") + +targets = [ + ("/ai-suggestions", "ai-suggestions"), + ("/alerts", "alerts"), + ("/my-dashboard", "my-dashboard"), +] +N = 10 +all_pass = True +for url, needle in targets: + print(f"\n===== {url} =====") + # 预热 1 次(下载新版hash资源入缓存) + try: + t, bl, to, err = reload_and_time(url, needle) + print(f"[预热] {t}s body={bl} timeout={to}") + except Exception as e: + print(f"[预热失败] {e} —— 检查tab是否存在/登录态") + sys.exit(1) + times = [] + for i in range(1, N + 1): + try: + t, bl, to, err = reload_and_time(url, needle) + except Exception as e: + print(f"[{i}] 异常: {e}") + all_pass = False + times.append(99.0) + continue + flag = "❌" if to else "✅" + if to: + all_pass = False + times.append(t) + print(f"[{i:02d}] {flag} {t}s body={bl}" + (f" err={err[:60]}" if err else "")) + over = [x for x in times if x > 10] + print(f" 最快{min(times)}s 最慢{max(times)}s 平均{sum(times)/len(times):.2f}s 超10s次数={len(over)}") + +print("\n=== 验收结论 ===") +print("PASS: 10连刷无卡'加载中'超10s" if all_pass else "FAIL: 存在卡'加载中'超10s")