SuperAPI AI 工具集

generate-python-runnability-test

编程与开发

查看项目

更新于 10-15 21:53

技能介绍

用途:为 core/python/、contrib/python/ 或 skills/<vertical>/<solution>/ 下的 Python recipe 生成 tests/test_runnability.py,配合 python-validate-recipe.yml 的 Check 4。测试刻意最小化,只验证 agent 模块可导入并定义预期全局量;业务逻辑测试另在别处。

主要能力:脚本会定位最浅层的 agent.py(跳过 .venv、venv、env、build、dist、pycache、node_modules、tests、*.egg-info 和点目录);用 ast 解析 agent.py 及其所有祖先包 init.py,检测顶层赋值(root_agent、app)、导入期调用(vertexai.init、google.auth.default)和环境变量读取(GOOGLE_CLOUD_PROJECT,仅读取)。同时扫描整个 recipe 树的 .py 文件中的 INTEGRATION_TEST 读取。无副作用时生成最小测试,有副作用时生成带 patch 与环境变量默认值的受保护测试,并在可用时经 ruff format 格式化。

导入解析:生成测试执行 import <module>,需 recipe 根目录在 sys.path 上。脚本会报告 import_support,取值 installable(pyproject.toml 有 [build-system])、pythonpath-ini、existing-conftest 或 generated-conftest,必要时写入 tests/conftest.py 路径垫片。

使用方式:干跑 uv run --no-project python3 .agents/skills/generate-python-runnability-test/scripts/generate_runnability_test.py --recipe-dir <RECIPE_DIR> --dry-run;应用时去掉 --dry-run;覆盖已有测试需 --overwrite;非标准入口用 --agent-file。脚本仅用标准库,无需 --with。

限制:每次仅生成一个文件;不读取或写入目标 recipe 目录以外的文件;不静默覆盖已有 tests/test_runnability.py,也不覆盖任何已有 tests/conftest.py(即使加 --overwrite,会跳过并警告);不提交改动。生成后需自行运行 cd <RECIPE_DIR> && uv run pytest tests/test_runnability.py -v 验证。