206 lines
12 KiB
Python
206 lines
12 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
第 9 道常驻闸:反馈四级表面必须真的是「自绘的那一套」,不许退回默认组件(R19)。
|
||
|
||
症状(2026-11 第十三轮 · 用户原话「整体修改系统中所有提示窗、完成后的反馈 tips 等。
|
||
不要使用默认组件」):改动做完之后,源码层由 classaudit 的第 6 条静态禁止
|
||
`window.confirm` / `message.*` / `notification.*`,但**静态查不出两件事实**——
|
||
① 运行时是否还有某条老路径真的弹出过原生对话框(`dialog` 事件);
|
||
② 自绘吐司是否真的**显示出来了**:ToastHost 挂错位置、provider 没渲染、
|
||
store 被引成第二份实例,都会让 notify() 静默返回、页面一条提示都不出,
|
||
而静态审计照样是 0。
|
||
做法:一条浏览器路径逐项验(视口 1440×900,明暗两套主题各跑一遍)——
|
||
A 全站禁止原生对话框:任何一次 `dialog`(alert / confirm / prompt)都算失败;
|
||
B 真实路径的成功反馈:/users 整行点开编辑抽屉 → 抽屉底部「保存账号」→ 右下角出现 `.nex-toast`、
|
||
`.ant-message` 一个都不许有、吐司落在视口右下角的留白带里、倒计时条在跑;
|
||
C 悬停暂停:指针移到吐司上 → `.nex-toast-progress` 的 animation-play-state 必须是 paused,
|
||
移开恢复 running(条停了卡片却消失 = 半成品);
|
||
D 去重与堆叠上限:同一句话推两次只留一颗且标 ×2;连推 7 句只留 5 颗;
|
||
`notifyLoading` 那颗不自动消失且没有倒计时条;
|
||
E 关闭键是唯一的即时出口:点 `.nex-toast-close` 后吐司消失;
|
||
F 真实路径的确认框:/ 点某张卡的删除 → `.nex-confirm` 可见、
|
||
问话与后果分两行、footer 恰好一颗 primary 且是 dangerous;按 Esc 关掉后
|
||
项目数量不变(确认框不许替用户做决定)。
|
||
为什么探针要用**应用自己那份 store 模块**:Vite 加载的 URL 带 `?t=` 时间戳,
|
||
`import('/src/stores/notice.ts')` 会拿到第二份 zustand 实例——push 进了新队列,
|
||
界面上那颗永远不出现,探针于是变成假绿。所以先从 performance 资源表里
|
||
找回应用真正加载的那条 URL 再 import。
|
||
"""
|
||
import os
|
||
import sys
|
||
from playwright.sync_api import sync_playwright
|
||
|
||
BASE = os.environ.get("NEX_BASE", "http://localhost:5173")
|
||
SHOTS = "/tmp/nexw/feedbackshots"
|
||
os.makedirs(SHOTS, exist_ok=True)
|
||
TOL = 40 # 吐司离视口右/下边缘允许的留白区间(设计值 marginLG = 24)
|
||
|
||
# 应用加载的模块 URL 带着 HMR 时间戳,必须从 performance 资源表里捞回同一份实例
|
||
IMPORT_STORE = """
|
||
(name) => {
|
||
const hit = performance.getEntriesByType('resource').map(e => e.name)
|
||
.filter(n => n.includes('/src/stores/' + name + '.ts')).pop();
|
||
if (!hit) throw new Error('应用没有加载 stores/' + name + '.ts,探针无从触发');
|
||
return hit;
|
||
}
|
||
"""
|
||
|
||
fails = []
|
||
|
||
|
||
def check(cond, msg):
|
||
if not cond:
|
||
fails.append(msg)
|
||
return cond
|
||
|
||
|
||
def login(pg, theme):
|
||
pg.goto(BASE + "/login", wait_until="networkidle")
|
||
if pg.locator("#login-user").count():
|
||
pg.fill("#login-user", "admin")
|
||
pg.fill("#login-pass", "admin1234")
|
||
pg.click("button[type=submit]")
|
||
pg.wait_for_timeout(1200)
|
||
pg.evaluate("t => localStorage.setItem('nex-the', t)", theme)
|
||
|
||
|
||
def push(pg, tone, title, desc=None, duration=None):
|
||
"""用应用自己那份 notice 实例推一条吐司(等价于页面上任何一次 notify())"""
|
||
pg.evaluate(
|
||
"""async ([u, tone, title, desc, duration]) => {
|
||
const m = await import(u);
|
||
const fn = { ok: m.notify, bad: m.notifyBad, warn: m.notifyWarn, info: m.notifyInfo }[tone];
|
||
fn({ title, ...(desc ? { desc } : {}), ...(duration ? { duration } : {}) });
|
||
}""",
|
||
[pg.evaluate(IMPORT_STORE, "notice"), tone, title, desc, duration])
|
||
pg.wait_for_timeout(260)
|
||
|
||
|
||
def box(pg, sel):
|
||
return pg.locator(sel).last.bounding_box()
|
||
|
||
|
||
def run_theme(pw, theme):
|
||
b = pw.chromium.launch()
|
||
pg = b.new_page(viewport={"width": 1440, "height": 900})
|
||
dialogs = []
|
||
pg.on("dialog", lambda d: (dialogs.append(d.type), d.dismiss()))
|
||
login(pg, theme)
|
||
|
||
# ── B/C/D/E:吐司 ────────────────────────────────────────────────────────
|
||
pg.goto(BASE + "/users", wait_until="networkidle")
|
||
pg.wait_for_timeout(1600)
|
||
# 管理类模块统一走「整行点开抽屉」(UI规范 §13.5),保存那颗按钮在抽屉底部:
|
||
# PATCH 的还是原值,不改数据,只验反馈 surface 是真的。
|
||
pg.locator('main button[aria-label="编辑账号"]').first.click()
|
||
pg.wait_for_timeout(900)
|
||
pg.locator(".ant-drawer-footer button:has-text('保存账号')").click()
|
||
# 指针必须挪开:抽屉底部那颗主按钮就在右下角,正对着吐司的落位带,
|
||
# 手留在那儿 = 一直 hover 着吐司,C 读到的倒计时条永远是 paused(探针自己造的假红)。
|
||
pg.mouse.move(24, 320)
|
||
pg.wait_for_timeout(900)
|
||
toasts = pg.locator(".nex-toast")
|
||
if not check(toasts.count() >= 1, f"[{theme}] B 抽屉「保存账号」之后右下角没有出现自绘吐司"):
|
||
return pg, b
|
||
check(pg.locator(".ant-message").count() == 0, f"[{theme}] B 出现了 antd 默认 <message>(R19 禁)")
|
||
bx = box(pg, ".nex-toast")
|
||
gap_r = 1440 - (bx["x"] + bx["width"])
|
||
gap_b = 900 - (bx["y"] + bx["height"])
|
||
check(0 <= gap_r <= TOL, f"[{theme}] B 吐司没贴右下角留白带:距右缘 {gap_r:.0f}px(应 ≤{TOL})")
|
||
check(0 <= gap_b <= TOL, f"[{theme}] B 吐司没贴右下角留白带:距下缘 {gap_b:.0f}px(应 ≤{TOL})")
|
||
check(bx["x"] + bx["width"] / 2 > 720 and bx["y"] + bx["height"] / 2 > 450,
|
||
f"[{theme}] B 吐司不在右下象限:{bx['x']:.0f},{bx['y']:.0f}")
|
||
# 截图前先清干净,后面几项都从「屏上只有探针吐司」的状态出发
|
||
pg.evaluate("async (u) => (await import(u)).clearNotices()", pg.evaluate(IMPORT_STORE, "notice"))
|
||
pg.wait_for_timeout(400)
|
||
|
||
push(pg, "bad", "探针:失败反馈", "第二行放后果 / 明细,读不读得完由悬停决定")
|
||
state = pg.evaluate(
|
||
"""() => { const el = document.querySelector('.nex-toast .nex-toast-progress');
|
||
return el ? getComputedStyle(el).animationPlayState : 'none'; }""")
|
||
check(state == "running", f"[{theme}] C 倒计时条初始不是 running(读到 {state})")
|
||
pg.locator(".nex-toast").last.hover()
|
||
pg.wait_for_timeout(300)
|
||
state = pg.evaluate(
|
||
"""() => { const el = document.querySelector('.nex-toast .nex-toast-progress');
|
||
return el ? getComputedStyle(el).animationPlayState : 'none'; }""")
|
||
check(state == "paused", f"[{theme}] C 悬停后倒计时条没有暂停(读到 {state})")
|
||
pg.mouse.move(200, 700)
|
||
pg.wait_for_timeout(300)
|
||
state = pg.evaluate(
|
||
"""() => { const el = document.querySelector('.nex-toast .nex-toast-progress');
|
||
return el ? getComputedStyle(el).animationPlayState : 'none'; }""")
|
||
check(state == "running", f"[{theme}] C 移开后倒计时条没有恢复(读到 {state})")
|
||
pg.screenshot(path=f"{SHOTS}/f-{theme}-toast.png")
|
||
|
||
push(pg, "ok", "探针:重复的同一句话")
|
||
push(pg, "ok", "探针:重复的同一句话")
|
||
same = pg.locator(".nex-toast", has=pg.locator(".nex-toast-title", has_text="探针:重复的同一句话"))
|
||
check(same.count() == 1, f"[{theme}] D 同一句话推了两次,屏上出现 {same.count()} 颗(应去重成 1 颗)")
|
||
check(pg.locator(".nex-toast-count").count() >= 1
|
||
and "×2" in pg.locator(".nex-toast-count").first.inner_text(),
|
||
f"[{theme}] D 去重后没有用 ×N 说明真实发生次数")
|
||
|
||
pg.evaluate("async (u) => (await import(u)).clearNotices()", pg.evaluate(IMPORT_STORE, "notice"))
|
||
pg.wait_for_timeout(300)
|
||
for i in range(7):
|
||
push(pg, "info", f"探针:刷屏第 {i + 1} 颗")
|
||
check(toasts.count() == 5, f"[{theme}] D 连推 7 句后屏上有 {toasts.count()} 颗(堆叠上限应为 5)")
|
||
|
||
pg.evaluate("async (u) => (await import(u)).clearNotices()", pg.evaluate(IMPORT_STORE, "notice"))
|
||
pg.wait_for_timeout(300)
|
||
pg.evaluate("""async (u) => { const m = await import(u);
|
||
m.notifyLoading('探针:进行中的长任务'); }""", pg.evaluate(IMPORT_STORE, "notice"))
|
||
pg.wait_for_timeout(300)
|
||
if check(pg.locator(".nex-toast").count() == 1, f"[{theme}] D 进行中吐司没出现"):
|
||
check(pg.locator(".nex-toast .nex-toast-progress").count() == 0,
|
||
f"[{theme}] D 不自动消失的吐司画了倒计时条(时长 0 = 没有进度可言)")
|
||
pg.locator(".nex-toast .nex-toast-close").first.click()
|
||
pg.wait_for_timeout(400)
|
||
check(pg.locator(".nex-toast").count() == 0, f"[{theme}] E 关闭键没能关掉吐司")
|
||
|
||
# ── F:确认框(真实删除入口,按 Esc 取消,不改数据)─────────────────────────
|
||
pg.goto(BASE + "/", wait_until="networkidle")
|
||
pg.wait_for_timeout(1800)
|
||
cards_before = pg.locator('[title="删除这个项目"]').count()
|
||
check(cards_before >= 1, f"[{theme}] F 工作台找不到删除入口,确认框这一项没验到")
|
||
if cards_before:
|
||
pg.locator('[title="删除这个项目"]').first.click()
|
||
pg.wait_for_timeout(600)
|
||
confirm = pg.locator(".nex-confirm")
|
||
check(confirm.count() >= 1 and confirm.last.is_visible(),
|
||
f"[{theme}] F 删除没有弹出站内确认框(`.nex-confirm` 不可见)")
|
||
check(pg.locator(".ant-message").count() == 0, f"[{theme}] F 反馈链路里混进了 antd <message>")
|
||
check(pg.locator(".nex-confirm-title").count() == 1, f"[{theme}] F 确认框缺「一句问话」")
|
||
check(pg.locator(".nex-confirm-desc").count() == 1, f"[{theme}] F 确认框缺「一层后果」")
|
||
primaries = pg.locator(".nex-confirm .ant-modal-footer button.ant-btn-primary")
|
||
check(primaries.count() == 1, f"[{theme}] F 确认框底部有 {primaries.count()} 颗主按钮(最多一颗)")
|
||
check(primaries.count() == 1 and "ant-btn-dangerous" in (primaries.first.get_attribute("class") or ""),
|
||
f"[{theme}] F 删除这类不可恢复操作,主按钮没有用危险重点色")
|
||
pg.screenshot(path=f"{SHOTS}/f-{theme}-confirm.png")
|
||
pg.keyboard.press("Escape")
|
||
pg.wait_for_timeout(700)
|
||
check(not (pg.locator(".nex-confirm").count()
|
||
and pg.locator(".nex-confirm").last.is_visible()),
|
||
f"[{theme}] F 按 Esc 之后确认框还看得见")
|
||
check(pg.locator('[title="删除这个项目"]').count() == cards_before,
|
||
f"[{theme}] F 取消确认却删掉了项目({cards_before} → 变了)")
|
||
|
||
check(not dialogs, f"[{theme}] A 弹出了浏览器原生对话框:{dialogs}")
|
||
return pg, b
|
||
|
||
|
||
with sync_playwright() as pw:
|
||
for theme in ("light", "dark"):
|
||
pg, b = run_theme(pw, theme)
|
||
pg.close()
|
||
b.close()
|
||
|
||
if fails:
|
||
print("反馈四级表面 %d 处不合格:" % len(fails))
|
||
for f in fails:
|
||
print(" ✗ " + f)
|
||
sys.exit(1)
|
||
print("通过:原生对话框 0 次;吐司右下角 / 悬停暂停 / 去重 ×N / 上限 5 颗 / 关闭键生效;"
|
||
"确认框两层文案 + 唯一危险主按钮,明暗两套主题截图在 %s" % SHOTS)
|