nex_animation/scripts/ui/feedbackcheck.py

199 lines
11 KiB
Python
Raw Normal View History

规范与闸门收口:R19 反馈四级、R20 标题前不挂图形写进硬规则,探针补到十道 这一笔只动文档、审计与闸门,代码一行没改——前三笔(b6a1df6 反馈表面、552b6b0 门牌图形) 把事做完了,但规范和闸门还停在第十八条 / 六道探针的状态:新规矩没进 §0 那张硬规则表就 等于没立;探针不落地,下一轮改动照样能悄悄长出第五套反馈皮肤。 补进去的规矩(§0 从 18 条到 20 条): · R19 反馈只有四级表面,各有唯一实现:行内 `ErrorText`/`LineHint` → 页面 `Notice` → 结果 `notify*`(自绘吐司)→ 确认 `confirmAction`(自绘确认框);`window.confirm` / `window.alert` / `Modal.confirm` / antd `message` / `notification` / 裸 `<Alert>` 全站清零,也不许再给它们打样式补丁。新增 §13.3 一整节写四级的分工、吐司的四件事 (右下角堆叠 / 倒计时条与 JS 同源 / 同句去重成 ×N / 一屏最多 5 颗)和确认框的键盘映射。 · R20 标题前面不挂图形:门牌与卡头的一级标题左侧不许出现图标、色块、头像。 · 旧口径逐条纠正(10 处锚点全部命中才落盘):R16 ③ 与 §13.1 那张表里 `Notice`=antd `Alert`、§13.1 正文「图标由 Alert 自带」、§6.5 外壳表里 `App.tsx` 的「系统异常 `Alert` → 页面」、§6.1「Content 里除了异常 Alert 就是 `<Outlet />`」、§15.6 tagcheck 的豁免语「整段 Notice / Alert 保留 antd 语义底」、§13.3 症状里那个被真实换行截断的 code span。站内已经没有 `Alert` 这个名字了,文档留着它就是在教人写回旧写法。 · `docs/工程规范.md`:目录职责图与「谁可以 `import 'antd'`」那段摘掉 `stores/notice.ts` ——吐司自绘之后它不再 import antd,白名单从四处收成三处。 · README:闸门命令块补 `aligncheck` / `symmetrycheck` / `feedbackcheck` 三行,硬规则 摘要补第 6、7 两条审计的说明。 闸门: · `classaudit.mjs` 从五条判据加到七条。第 6 条静态禁反馈默认件(`window.confirm(` / `window.alert(` / `Modal.confirm(` / `message.xxx(` / `notification.xxx(` / 裸 `<Alert`),实现本体白名单只有 `components/ui/{Toast,Confirm,Panel,Button,tone}.tsx` 与 `stores/{notice,confirm}.ts`;第 7 条钉住 R20——门牌与卡头标题里不许再挂前置图形。 同时把第 5 条 R8 的白名单里那第四处 `stores/notice.ts` 删掉:留着它就等于给「以后 谁想在 store 里 import 组件库」开后门。 · 新增第 9 道 `scripts/ui/feedbackcheck.py`:静态审计查不出两件事实——运行时是否真有 某条老路径弹出过原生对话框、自绘吐司是否真的**显示出来了**(`ToastHost` 挂错位、 provider 没渲染、store 被引成第二份实例,都会让 `notify()` 静默返回而静态审计照样 是 0)。它按真实路径逐项验 A~F:全站零 `dialog`、/users 保存后吐司落在右下角且 `.ant-message` 一个不许有、悬停时 `animation-play-state` 必须 paused、同句去重成 ×2、 连推 7 句只留 5 颗、关闭键生效、/ 上点删除出确认框(两层文案 + 恰好一颗 dangerous primary)、Esc 关掉后项目数不变。 · 实测(明暗两档):`classaudit` 七条全 0 · `feedbackcheck` 通过 · `btnrowcheck` `BTNROWS_TOTAL 0` / `HEAD_BREAK_TOTAL 0`(413 组动作排 / 59 处竖排豁免)· `footercheck` `FOOTER_PROBED 30` / `FOOTER_BAD_TOTAL 0` · `aligncheck` 0 · `symmetrycheck` `SYM_TOTAL 0` · `tsc --noEmit` 与 `npm run build` 绿。 手册 12 张插图按「改完 UI 必须重跑 `helpshots.py`」的口径整批重拍(1600×1000@2x → LANCZOS、锁 light、主角项目 12):旧图还是带主色方块门牌与卡头品牌 N 的那一版。
2026-11-03 15:58:44 +00:00
# -*- 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)
pg.locator("button:has-text('保存')").first.click() # 真实路径:PATCH 同一个值
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)