nex_animation/scripts/ui/gateprobe.py

334 lines
19 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 -*-
"""反向验证:证明七张像素闸门的十一条判据「坏了会响、好了不响」(2026-11 第七轮起常驻)。
`gridcheck` / `rhythmcheck` / `tagcheck` / `btnrowcheck` / `footercheck` / `btnclustercheck` /
`tableaudit` 都是对着渲染结果量像素的探针,它们自己也需要被体检一次:豁免写宽一格、阈值调松一档,
闸门就会永远安静地返回 0,而页面该修的地方一个都没修。
这里不碰源码、不触发 HMR——直接在页面上种两块 fixture:
· `pb-*`(bad) :故意造出十二种缺陷——同族子块该用栅格却自然排列、流程条横向滚动、
同一行裸控件没坐进控件行(中心差 35px)、同一容器两档纵向间距、
收缩错位、标签铺语义色块、按钮组被劈成 2+1、
格子里并排内容越出单元格、整句散文当只读标签捅出容器右缘、
卡头行里还剩一整块没挪走却先把标题切成两行、
header 里那组横排按钮被劈成 2+1(第 17 轮删掉的旧豁免不许复活)、
浮层底部三颗按钮挤成 2+1(footercheck 管的那一族)、
不带任何类名的一簇按钮挤成 2+1(btnclustercheck 管的那一族)
——十二条缺陷,每条判据必须**点名**到它;
· `pg-*`(good):故意造出十二种**合法**形态(卡底 mt-auto 钉底、整块居中的排版、
正文 max-w-[72ch] 栏宽、.nex-chipbar 胶囊流、
容器自适应的流程条、让位后与字段同行的复选框、
放得下的「进度条 + 百分数」单元格、
kit Tag 自己收窄成 ellipsis 的长标签、
右端整块掉到第二行之后标题拿到整行的卡头、
整组竖排等宽的按钮组(现行唯一那条豁免)、
整组竖排等宽的浮层底部(ActionGroup 翻竖排之后的形状),闸门必须放行。
任何一条对不上就退出 1——说明闸门瞎了或者过敏,先修闸门再谈页面。
用法:
.venv/bin/python scripts/ui/gateprobe.py
"""
import importlib.util
import os
import pathlib
import sys
from playwright.sync_api import sync_playwright
HERE = pathlib.Path(__file__).resolve().parent
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
USER = os.environ.get("NEX_USER", "admin")
PWD = os.environ.get("NEX_PASS", "admin1234")
def load(mod_name: str):
"""按路径加载闸门模块,直接复用它们的探针 JS,避免同一份判据写两遍。"""
spec = importlib.util.spec_from_file_location(mod_name, HERE / f"{mod_name}.py")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
tagcheck = load("tagcheck")
rhythmcheck = load("rhythmcheck")
gridcheck = load("gridcheck")
btnrowcheck = load("btnrowcheck")
footercheck = load("footercheck")
btnclustercheck = load("btnclustercheck")
tableaudit = load("tableaudit")
FIXTURE = r"""() => {
const old = document.getElementById('nex-gateprobe'); if (old) old.remove();
const host = document.createElement('div');
host.id = 'nex-gateprobe';
host.style.cssText = 'padding:24px;display:flex;flex-direction:column;gap:0';
host.innerHTML = `
<div class="pb-gap" style="display:flex;flex-direction:column;width:400px">
<div style="height:30px"></div>
<div style="height:30px;margin-top:8px"></div>
<div style="height:30px;margin-top:20px"></div>
</div>
<span class="ant-tag pb-tag" style="display:inline-block;width:120px;height:24px;
background:#f6ffed;color:#237804;border:1px solid #b7eb8f">反向验证标签</span>
<div class="pb-rag" style="display:flex;flex-direction:column;align-items:flex-start;width:400px">
<div style="width:400px;height:30px"></div>
<div style="width:150px;height:30px"></div>
<div style="width:250px;height:30px"></div>
</div>
<div class="pb-grid" style="display:flex;flex-direction:row;flex-wrap:wrap;gap:8px;width:900px">
<input class="ant-input" style="width:120px" value="甲" />
<input class="ant-input" style="width:300px" value="乙" />
<input class="ant-input" style="width:160px" value="丙" />
</div>
<div class="pg-pin" style="display:flex;flex-direction:column;height:200px;width:400px">
<div style="height:40px"></div>
<div style="height:40px"></div>
<div class="mt-auto" style="height:40px"></div>
</div>
<div class="pg-center" style="display:flex;flex-direction:column;align-items:center;width:400px">
<div style="width:400px;height:30px;align-self:center"></div>
<div style="width:150px;height:30px;align-self:center"></div>
<div style="width:200px;height:30px;align-self:center"></div>
</div>
<div class="pg-measure" style="display:flex;flex-direction:column;width:400px">
<div style="height:30px"></div>
<div style="height:30px;max-width:200px"></div>
<div style="height:30px;max-width:240px"></div>
</div>
<div class="nex-action-group pb-btn" style="display:flex;flex-direction:row;flex-wrap:wrap;gap:8px;width:260px">
<button class="ant-btn" style="width:120px;height:32px">甲</button>
<button class="ant-btn" style="width:120px;height:32px">乙</button>
<button class="ant-btn" style="width:120px;height:32px">丙</button>
</div>
<!-- 判据① 唯一的豁免(第 17 轮起):竖排等宽里子项本来就在不同水平线,必须放行 -->
<div class="nex-action-group ant-flex-vertical pg-stack"
style="display:flex;flex-direction:column;gap:8px;width:260px">
<button class="ant-btn" style="width:260px;height:32px">甲</button>
<button class="ant-btn" style="width:260px;height:32px">乙</button>
</div>
<!-- 被删掉的那条「<header> 里的组在 <1024 允许分行」不许悄悄回来:
坐在 header 里的横排组被劈成 2+1,一样要响 -->
<header><div class="nex-action-group pb-header"
style="display:flex;flex-direction:row;flex-wrap:wrap;gap:8px;width:260px">
<button class="ant-btn" style="width:120px;height:32px">甲</button>
<button class="ant-btn" style="width:120px;height:32px">乙</button>
<button class="ant-btn" style="width:120px;height:32px">丙</button>
</div></header>
<div class="nex-chipbar pg-chipbar" style="display:flex;flex-direction:row;flex-wrap:wrap;gap:8px;width:900px">
<span class="nex-chip ant-tag ant-tag-checkable" style="display:inline-block;width:80px;height:24px">甲</span>
<span class="nex-chip ant-tag ant-tag-checkable" style="display:inline-block;width:210px;height:24px">乙乙乙</span>
<span class="nex-chip ant-tag ant-tag-checkable" style="display:inline-block;width:120px;height:24px">丙丙</span>
</div>
<div role="list" class="pb-rail" style="display:flex;flex-direction:row;gap:8px;width:400px;
overflow-x:auto">
<div style="flex:none;width:200px;height:30px">完整视频</div>
<div style="flex:none;width:200px;height:30px">音效</div>
<div style="flex:none;width:200px;height:30px">字幕</div>
<div style="flex:none;width:200px;height:30px">交付包</div>
</div>
<div role="list" class="pg-rail" style="display:grid;width:900px;gap:8px;
grid-template-columns:repeat(auto-fill,minmax(140px,1fr))">
<div style="min-width:0;height:30px">完整视频</div>
<div style="min-width:0;height:30px">音效</div>
<div style="min-width:0;height:30px">字幕</div>
<div style="min-width:0;height:30px">交付包</div>
</div>
<div class="ant-row nex-form-row pb-ctl" style="display:flex;width:700px">
<div class="ant-col" style="width:300px">
<div class="ant-form-item">
<div class="ant-form-item-label" style="height:30px;line-height:30px;padding:0">环境声</div>
<div class="ant-form-item-control"><div class="ant-form-item-control-input"
style="height:32px"><input class="ant-input" style="width:100%" value="底噪"></div></div>
</div>
</div>
<div class="ant-col" style="width:300px">
<label class="ant-checkbox-wrapper" style="display:inline-block;margin-top:0;height:auto">启用字幕</label>
</div>
</div>
<div class="ant-row nex-form-row pg-ctl" style="display:flex;width:700px">
<div class="ant-col" style="width:300px">
<div class="ant-form-item">
<div class="ant-form-item-label" style="height:30px;line-height:30px;padding:0">环境声</div>
<div class="ant-form-item-control"><div class="ant-form-item-control-input"
style="height:32px"><input class="ant-input" style="width:100%" value="底噪"></div></div>
</div>
</div>
<div class="ant-col" style="width:300px">
<label class="ant-checkbox-wrapper" style="display:flex;align-items:center;height:32px;margin-top:30px">启用字幕</label>
</div>
</div>
<div class="nex-taggroup" style="width:220px"><span class="ant-tag pb-spill"
style="white-space:nowrap">反向验证长标签整句散文当只读标签必然捅出容器右缘</span></div>
<div class="nex-taggroup" style="width:220px"><span class="ant-tag nex-tag pg-spill"
><span class="nex-tag-text">合法长标签整句散文当只读标签由 kit 收在容器内</span></span></div>
<div class="ant-card" style="width:320px"><div class="ant-card-head-title">pb-tspill</div>
<div class="ant-table-wrapper"><div class="ant-table-content">
<table style="table-layout:fixed;width:300px"><tbody class="ant-table-tbody"><tr>
<td style="width:300px;padding:8px;white-space:nowrap;text-align:right">
<div style="display:inline-block;width:284px;height:6px;background:#1677ff"></div>
<small class="pb-tspill">100%</small>
</td>
</tr></tbody></table>
</div></div>
</div>
<div class="ant-card" style="width:320px"><div class="ant-card-head-title">pg-tspill</div>
<div class="ant-table-wrapper"><div class="ant-table-content">
<table style="table-layout:fixed;width:300px"><tbody class="ant-table-tbody"><tr>
<td style="width:300px;padding:8px;white-space:nowrap;text-align:right">
<div style="display:inline-block;width:220px;height:6px;background:#1677ff"></div>
<small class="pg-tspill">100%</small>
</td>
</tr></tbody></table>
</div></div>
</div>
<!-- 判据②(btnrowcheck.HEAD):320 的卡头里标题只剩 82px,
「还有一整块可以挪下去」却把标题切成两行 = 必须响 -->
<div class="ant-card nex-panel" style="width:320px"><div class="ant-card-head">
<div class="ant-card-head-wrapper" style="display:flex;flex-wrap:wrap">
<div class="ant-card-head-title" style="flex:1 1 0">
<span>pb-head镜头质检结论汇总清单表</span></div>
<div class="ant-card-extra" style="flex:0 0 auto;width:190px">重新质检 / 导出报告</div>
</div></div>
</div>
<!-- 浮层底部(footercheck):和页头同一个毛病,只是它长在抽屉里。
300 宽 260 内宽里三颗 120 的按钮挤成 2+1 = 必须响 -->
<div class="ant-drawer-footer pb-footer"
style="width:300px;padding:12px 20px;display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end">
<button class="ant-btn" style="width:120px;height:32px">甲</button>
<button class="ant-btn" style="width:120px;height:32px">乙</button>
<button class="ant-btn" style="width:120px;height:32px">丙</button>
</div>
<!-- 裸按钮簇(btnclustercheck):没有 kit 类名、不是浮层底部,前两道按钮闸结构上扫不到。
260px 里三颗 120 的按钮挤成 2+1 = 必须响(证明这把新尺子真的在看 DOM) -->
<div class="pb-cluster" style="width:260px;display:flex;flex-wrap:wrap;gap:8px">
<button class="ant-btn" style="width:120px;height:32px">甲</button>
<button class="ant-btn" style="width:120px;height:32px">乙</button>
<button class="ant-btn" style="width:120px;height:32px">丙</button>
</div>
<!-- 同一簇整组换行、每颗占满内宽(ActionGroup 的竖排档就是这个形状)= 必须放行 -->
<div class="pg-cluster" style="width:260px;display:flex;flex-wrap:wrap;gap:8px">
<button class="ant-btn" style="width:100%;height:32px">甲</button>
<button class="ant-btn" style="width:100%;height:32px">乙</button>
<button class="ant-btn" style="width:100%;height:32px">丙</button>
</div>
<!-- 底部交给 ActionGroup 之后窄屏的样子:整组竖排等宽 = 必须放行 -->
<div class="ant-drawer-footer pg-footer"
style="width:300px;padding:12px 20px;display:flex;flex-direction:column;gap:8px">
<button class="ant-btn" style="width:100%;height:32px">甲</button>
<button class="ant-btn" style="width:100%;height:32px">乙</button>
</div>
<!-- 同一句长标题,右端整块掉到第二行(kit 的 nex-head-stack 就是这个形状):
标题拿到整行,折行是排版 = 必须放行 -->
<div class="ant-card nex-panel" style="width:320px"><div class="ant-card-head">
<div class="ant-card-head-wrapper" style="display:flex;flex-wrap:wrap;row-gap:8px">
<div class="ant-card-head-title" style="flex:1 1 auto">
<span>pg-head模型配置已迁移至独立管理中心请前往模型控制台</span></div>
<div class="ant-card-extra" style="flex:1 1 100%">重新质检 / 导出报告</div>
</div></div>
</div>`;
(document.querySelector('main') || document.body).appendChild(host);
return [...host.querySelectorAll('[class]')].length;
}"""
def names(rows, key):
"""把检出结果摊平成「元素标记串」,再用 fixture 的类名点名。
`key` 可以是字段名,也可以是函数:tableaudit 的 PROBE 会把页面上**每一张**表
都返回(不管有没有违规),按 `title` 摊平的话合法 fixture 也会出现在串里,
「必须放行」永远对不上——所以给它一个只摊平违规明细的函数。
"""
if callable(key):
return " | ".join(str(x) for r in rows for x in key(r))
return " | ".join(str(r.get(key, "")) for r in rows)
def main() -> int:
fails = []
with sync_playwright() as pw:
b = pw.chromium.launch()
pg = b.new_context(viewport={"width": 1440, "height": 1600}).new_page()
pg.set_default_timeout(20000)
pg.goto(BASE + "/login")
pg.wait_for_selector("#login-user")
pg.fill("#login-user", USER)
pg.fill("#login-pass", PWD)
pg.click("button[type=submit]")
pg.wait_for_url(lambda u: "/login" not in u, timeout=20000)
pg.goto(BASE + "/assets")
pg.wait_for_timeout(1400)
n = pg.evaluate(FIXTURE)
pg.wait_for_timeout(300)
print("fixture nodes:", n)
checks = [
("tagcheck", tagcheck.JS, "el", [("pb-tag", True), ("ant-input", False)]),
# 整句散文当只读标签、捅出容器右缘必须响;换成 kit Tag(max-width+ellipsis 自己收窄)必须放行
("tagcheck.SPILL", tagcheck.SPILL, "el",
[("pb-spill", True), ("pg-spill", False)]),
("rhythmcheck.GAP", rhythmcheck.GAP, "el",
[("pb-gap", True), ("pg-pin", False)]),
("rhythmcheck.RAG", rhythmcheck.RAG, "el",
[("pb-rag", True), ("pg-center", False), ("pg-measure", False)]),
("gridcheck", gridcheck.JS, "el",
[("pb-grid", True), ("pg-chipbar", False),
# 流程条横滚必须响;容器自适应 grid 铺开的流程条必须放行
("pb-rail", True), ("pg-rail", False),
# 同行裸复选框贴着标签行(中心差 35px)必须响;
# 让出标签块、坐进 32px 控件行的必须放行(glue ⑥ 的形态)
("pb-ctl", True), ("pg-ctl", False)]),
# 按钮组被劈成 2+1 必须响;栅格那块(三种宽度三种控件的横排)与胶囊流不是它管的
("btnrowcheck", btnrowcheck.JS, "el",
[("pb-btn", True), ("pb-grid", False), ("pg-chipbar", False)]),
# 唯一那条豁免必须放行;旧那条「父级是 header 的组在 <1024 允许分行」
# 第 17 轮删了,这里钉住它不许悄悄复活:header 里的横排组被劈成 2+1 一样要响
("btnrowcheck.exempt", btnrowcheck.JS, "el",
[("pg-stack", False), ("pb-header", True)]),
# 卡头标题被切成两行(行里还剩着一整块没挪走)必须响;
# 右端整块掉到下一行、标题拿到整行的必须放行——判据②的两面
("btnrowcheck.HEAD", btnrowcheck.HEAD, "el",
[("pb-head", True), ("pg-head", False)]),
# 浮层底部(第 17 轮补):抽屉/对话框吸底那几条按钮以前不在任何闸门的路线表里,
# 现在 Overlay.DRAWER_ACTIONS = ActionGroup,底部由 footercheck 开层量。
# 摊平用函数:只看判据算下来真违规的那几条的类名。
("footercheck", footercheck.JS,
(lambda r: [r["cls"]] if r.get("bad") else []),
[("pb-footer", True), ("pg-footer", False)]),
# 裸按钮簇(第 17 轮续):不带任何 kit 类名的一组按钮被劈成 2+1 必须响;
# 整簇换行、每颗占满内宽必须放行——这把尺子的价值全在「不认类名」,
# 没有这对 fixture,它绿了也证明不了自己在看东西。
("btnclustercheck", btnclustercheck.JS,
(lambda r: [r["cls"]] if r.get("bad") else []),
[("pb-cluster", True), ("pg-cluster", False)]),
# 格子里并排内容越出单元格 / 互相压叠必须响,放得下必须放行。
# 摊平用函数:只看 spill 明细里的元素标识,不看那些本来就没违规的表名。
("tableaudit", tableaudit.PROBE,
lambda r: [it["k"] for it in r.get("spill", [])],
[("pb-tspill", True), ("pg-tspill", False)]),
]
for label, js, key, expectations in checks:
rows = pg.evaluate(js)
hay = names(rows, key)
for marker, should_fire in expectations:
hit = marker in hay
ok = hit == should_fire
print(f"{'OK ' if ok else 'FAIL'} {label:<18} {marker:<12} "
f"{'必须点名' if should_fire else '必须放行'} "
f"→ {'点名了' if hit else '没点名'}")
if not ok:
fails.append(f"{label}/{marker}")
print(" 实际:", hay[:400])
b.close()
if fails:
print("GATEPROBE_FAIL", " ".join(fails))
print("→ 闸门本身出问题:不是漏检(豁免写宽了)就是误报(豁免没生效),先修闸门")
return 1
print(f"GATEPROBE_OK {len(checks)}/{len(checks)} 闸门坏了会响、好了不响")
return 0
if __name__ == "__main__":
sys.exit(main())