- An answer past Antigravity's size is filed away unread (eight LoRA searches in the exam): search_models answers small (loaders once, four trigger words, a LoRA's author weight); describe_canvas gives a big canvas's last nodes a line each; mcp_fit.py keeps any other list answer within the size and names what it left out. - An empty canvas: run_workflow, describe_canvas and get_situation say to open a workflow first; get_image_info says a picture's workflow opens with open_workflow. - ask_user does not put a "test" question to the user; a task's picture count counts what its runs made. - AMB failed to load now and then: ComfyUI loads every file at once and ui_ai_workbench.js set ui_ai_toolbox.js's sideHost before it was made when the toolbox file ran first. Connected on first draw now; tests/load_order.mjs runs every file first. - input_facts moved to api/picture_mask.py to keep mcp_tools.py short. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5.2 KiB
测试怎么跑
tests/ 里是插件自己的测试:Python 测试检查后端(扫描、文件读写、回收站、模型下载、MCP 等),.mjs 测试检查前端里不依赖浏览器的规则(提示词词块、搭配的空位、往画布插 LoRA、撤销等)。改代码或提 PR 之前跑一遍,就知道有没有弄坏别的地方。
English summary at the end.
1. 准备
- 插件要装在一个 ComfyUI 的
custom_nodes里。Python 测试会用到 ComfyUI 自己的模块(folder_paths、server等)和它带的包(aiohttp、Pillow、av)。 - 装好 Node.js(18 或更新)。
- 不需要联网,不需要显卡,也不会碰你真实的模型库:测试只在临时文件夹里建假文件,跑完就删。
2. 一条命令全跑
在插件文件夹(custom_nodes/Anomalous_Model_Browser)里打开终端:
node tools/run_tests.mjs
它依次跑结构检查、每个 tests/*.mjs、全部 Python 测试,最后写 All passed. 或者列出失败的项目。其中 tests/load_order.mjs 把 web/ 里的每个文件都当成第一个加载的试一遍(ComfyUI 会同时加载全部 js 文件,谁先跑不一定),用 tests/load_order/ 里的假页面顶替浏览器和 ComfyUI,有文件碰到“还没准备好的变量”就失败。
Python 用哪个:
- 设置了环境变量
PYTHON就用它; - 否则用便携版 ComfyUI 的
python_embeded(就在 ComfyUI 文件夹旁边); - 都没有就用系统的
python。用 venv 或 conda 装的 ComfyUI,先激活那个环境再跑。
3. 只跑一部分
# 结构检查:每个源码文件都登记在架构文档里、前端模块都能被引用到、文件长度不超线、CSS 没有按 style 属性匹配的 :has()
node tools/check_structure.mjs
# 一个前端测试
node tests/combo_slots.mjs
node tests/lora_nodes.mjs
node tests/third_party_loras.mjs
# 全部 Python 测试(便携版 ComfyUI 的写法;其他安装方式换成自己的 python)
../../../python_embeded/python.exe -B -m unittest discover -s tests -p "test_*.py"
# 一个 Python 测试文件
../../../python_embeded/python.exe -B -m unittest discover -s tests -p "test_model_download.py"
4. 写新测试
结果集成的浏览器回归测试是 tests/ai_results.html:验证勾选两张图对比(视频和临时文件不能勾、第三张替换最早的、清除)、真实参数对比的读取/应用/撤销、撤销按钮的遮罩层级、保存菜单、视频没有参数工具、图片按需展开,以及安全的画布前后值展示。只替换网络与宿主图边界,加载真实插件模块。通过时页面末尾显示 ALL PASSED;它需要单独用浏览器运行,不包含在下面的命令行测试里。
展台的浏览器回归测试是 tests/ai_side.html:在插件目录启动仅本机可访问的静态服务器
(python -m http.server 8202 --bind 127.0.0.1),用浏览器打开 /tests/ai_side.html。
页面应显示 ALL PASSED,覆盖旧记录、长面板、面板更新、图片加载、翻阅时保留位置和隐藏标签页。
它加载实际展台模块及样式,只替换不用的 ComfyUI 画布接口;不包含在上面的一键命令中。
同一静态服务器上的 tests/ai_drafts.html 验证展台和底部提问条的回答草稿同步、重画保留文字和选区、同时刷新不抢错焦点。它加载实际组件,仅替换网络和宿主边界;页面应显示 ALL PASSED,不包含在一键命令中。
同一静态服务器上的 tests/snapshot_bar.html 验证存档条和存档页重画时控件都留在页面上(元素离开页面,按着的那一下就没有 click)、正在输入的次数不被清掉、一格不会串到别的存档、没变的图不重画、运行等得到刚改的次数、次数没存上时框里退回实际的次数、按着存档页的按钮时列表不动。它加载实际的存档条和存档页,只替换 ComfyUI 和存档接口;页面应显示 ALL PASSED,不包含在上面的一键命令中。
- 前端规则测试放
tests/<名字>.mjs,用node:assert,直接导入web/modules/里的真实模块,只替换浏览器和 ComfyUI 这些外部部分。 - 后端测试放
tests/test_<名字>.py,用unittest。文件一律建在tempfile的临时文件夹里,网络请求用unittest.mock换掉。 - 测试里不要写自己电脑上的真实路径、真实模型名或个人信息。
- 修 bug 时,先写一个能重现这个 bug 的测试。
English summary
tests/ holds the plugin's own tests: Python tests for the backend and .mjs tests for the browser-free frontend rules. They need the plugin inside a ComfyUI custom_nodes folder (the Python tests import ComfyUI's modules) and Node.js 18 or newer; no network, no GPU, and they only touch temporary folders.
Run everything from the plugin folder with node tools/run_tests.mjs: the structure check, every tests/*.mjs, then all Python tests with $PYTHON, the portable build's python_embeded, or python. Single parts: node tools/check_structure.mjs, node tests/<name>.mjs, python -B -m unittest discover -s tests -p "test_*.py". New tests import the real modules and replace only outside systems; keep real paths and personal data out of them.