nex_animation/scripts/ui/footercheck.py

160 lines
8.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""浮层底部动作条探针:抽屉/对话框吸底那几条按钮,同样不许「同一组乱跨行」(UI规范 §7 · 用户第 2 条)。
为什么单独一道闸(第 17 轮补):btnrowcheck 量的是页面上的 `.nex-action-group`,
而它只在**路线加载完**那一刻量——浮层是点出来的,一条都不在它的路线表里。
浮层底部于是从来没有被量过:`Overlay.DRAWER_ACTIONS` 一直是裸 flex-wrap,
2026-11-03 实测 430 档「项目概况」抽屉底部 3 颗折成 2+1、进入删除确认态 4 颗折成 2+2,
两道既有闸门全绿。把底部交给 ActionGroup(同一个自动竖排量法)之后,
这条探针就是它的守门人:**打开浮层 → 量底部 → Esc**,一条一条走。
判据(和 btnrowcheck 同一条尺子,量渲染结果不读 class):
同一个底部里可见按钮的垂直中心落在两条以上水平线 = 这一组被劈开;
唯一合法的多行 = **整组竖排等宽**(每一行一颗、每颗宽 ≥ 底部内宽的 92%)。
于是 2+1、2+2 这种「按字数挤出来的多行」点名,430 档三颗满宽竖排放行。
返回结构带 `bad`(判据在 JS 里算一次,main 与 gateprobe 共用同一条尺子)和 `cls`
(gateprobe 靠它在 fixture 上点名:`pb-footer` 横排挤成 2+1 必须响、`pg-footer` 整组
竖排等宽必须放行)。
底线:`FOOTER_PROBED` 报实测到的底部条数。它掉到地板(< MIN_PROBED)=
触发器/选择器漂了,闸门在假装通过——按故障退出,不算通过。
用法:
NEX_WIDTHS=1440,576,430 .venv/bin/python scripts/ui/footercheck.py
退出码:0 = 干净;1 = 有点名;2 = 一道都没量到(闸门自己坏了)。
"""
import os
import sys
from playwright.sync_api import sync_playwright
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
WIDTHS = [int(x) for x in os.environ.get("NEX_WIDTHS", "1440,576,430").split(",")]
THEMES = os.environ.get("NEX_THEMES", "light").split(",")
USER, PWD = os.environ.get("NEX_USER", "admin"), os.environ.get("NEX_PASS", "admin1234")
MIN_PROBED = int(os.environ.get("NEX_MIN_PROBED", "8"))
# (路线, 是否先勾一行, [打开浮层的按钮]) —— 覆盖 Overlay.Drawer / Modal 的全部底部形态:
# 2 颗(取消+主行动)、3 颗(辅助 mr-auto + 取消 + 主行动)、4 颗(二次确认多一颗取消)。
# 按钮默认按**可见文案**找;行内那种只有图形的图标按钮没有文案,用 `@无障碍名`
# 按 aria-label 找(用户管理的「编辑 / 重置密码」就是这一类)。
CASES = [
("/assets", False, ["编辑", "新建人物", "引入项目"]),
("/assets", True, ["打标签", "批量", "删除"]),
("/users", False, ["新建账号", "@编辑账号", "@重置密码"]),
("/projects/10/library", False, ["新建人物", "新建场景", "新建声线", "打开生成台", "编辑"]),
("/models", False, ["添加大模型", "配置"]),
("/projects/10/storyboard", False, ["导入脚本 / 关键帧"]),
]
# 头部「流程控制台」展开的项目概况抽屉:全站唯一 4 颗按钮的底部(第二次点删除进确认态)
BRIEF_ROUTE = "/projects/10/overview"
BRIEF_TRIGGER = "button.nex-console"
JS = r"""() => {
const out = [];
const sels = ['.ant-drawer-footer', '.ant-modal-footer', '.ant-modal-confirm-btns'];
for (const sel of sels) for (const foot of document.querySelectorAll(sel)) {
const layer = foot.closest('.ant-drawer, .ant-modal-wrap, .ant-modal-confirm');
if (layer && layer.style && layer.style.display === 'none') continue;
// 底部里的按钮 = 这一组;嵌套在按钮里的不算第二遍
const btns = [...foot.querySelectorAll('button')].filter((b) => {
const r = b.getBoundingClientRect();
return r.width > 1 && r.height > 1;
});
if (btns.length < 2) continue;
const lines = [];
for (const b of btns) {
const r = b.getBoundingClientRect(), y = r.top + r.height / 2;
if (!lines.some((v) => Math.abs(v - y) < 8)) lines.push(y);
}
const cs = getComputedStyle(foot);
const inner = foot.getBoundingClientRect().width - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
const full = btns.every((b) => b.getBoundingClientRect().width >= inner * 0.92);
// 多行只有一种合法:整组竖排等宽(每行一颗、每颗满宽)。2+1 / 2+2 都是被字数挤出来的。
const bad = lines.length > 1 && !(full && lines.length === btns.length);
out.push({
sel, n: btns.length, lines: lines.length, full, bad,
cls: typeof foot.className === 'string' ? foot.className : '',
w: Math.round(foot.getBoundingClientRect().width),
texts: btns.map((b) => (b.innerText || b.getAttribute('aria-label') || b.tagName).trim().replace(/\s+/g, ' ').slice(0, 8)),
});
}
return out;
}"""
def main():
hits = []
with sync_playwright() as p:
b = p.chromium.launch()
page = b.new_page(viewport={"width": WIDTHS[0], "height": 900})
page.goto(BASE + "/login", wait_until="networkidle")
page.fill("#login-user", USER)
page.fill("#login-pass", PWD)
page.click("button[type=submit]")
page.wait_for_timeout(1800)
if page.locator("#login-pass").count():
print("LOGIN FAILED")
return 2
for width in WIDTHS:
page.set_viewport_size({"width": width, "height": 900})
for theme in THEMES:
page.evaluate("(t) => localStorage.setItem('nex-the', t)", theme)
for route, tick, triggers in CASES:
for trig in triggers:
page.goto(BASE + route, wait_until="networkidle")
page.wait_for_timeout(700)
if tick:
box = page.locator("main input[type=checkbox]")
if box.count():
box.first.click()
page.wait_for_timeout(300)
if trig.startswith("@"):
loc = page.locator('main button[aria-label="%s"]' % trig[1:])
else:
loc = page.locator("main button:has-text('%s')" % trig)
if not loc.count():
continue
try:
loc.first.click()
except Exception:
continue
page.wait_for_timeout(900)
for h in page.evaluate(JS):
hits.append((width, theme, route + "·" + trig, h))
page.keyboard.press("Escape")
page.wait_for_timeout(300)
# 概况抽屉:3 颗 → 点删除进二次确认态 4 颗
page.goto(BASE + BRIEF_ROUTE, wait_until="networkidle")
page.wait_for_timeout(800)
if page.locator(BRIEF_TRIGGER).count():
page.locator(BRIEF_TRIGGER).first.click()
page.wait_for_timeout(900)
for h in page.evaluate(JS):
hits.append((width, theme, BRIEF_ROUTE + "·概况抽屉", h))
dele = page.locator(".ant-drawer-footer button:has-text('删除项目')")
if dele.count():
dele.first.click()
page.wait_for_timeout(600)
for h in page.evaluate(JS):
hits.append((width, theme, BRIEF_ROUTE + "·概况删除确认态", h))
page.keyboard.press("Escape")
b.close()
bad = 0
for width, theme, where, h in hits:
if h["bad"]:
bad += 1
print("VIOLATION %s/%s %s %s 宽%s 按钮%s 行%s 满宽%s %s"
% (width, theme, where, h["sel"], h["w"], h["n"], h["lines"], h["full"], "|".join(h["texts"])))
print("FOOTER_PROBED %d FOOTER_BAD_TOTAL %d" % (len(hits), bad))
if not hits or len(hits) < MIN_PROBED:
print("!! 只量到 %d 条浮层底部(底线 %d)——触发器或选择器漂了,闸门在假装通过" % (len(hits), MIN_PROBED))
return 2
return 1 if bad else 0
if __name__ == "__main__":
sys.exit(main())