52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
import logging
|
||
|
|
|
||
|
|
from nmfs_agents.agents.developer import AgentResult
|
||
|
|
from nmfs_agents.config import AgentsConfig
|
||
|
|
from nmfs_agents.core.queue import Task
|
||
|
|
from nmfs_agents.tools.device_agent import DeviceAgent
|
||
|
|
from nmfs_agents.tools.file_tools import run_command
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class TesterAgent:
|
||
|
|
def __init__(self, config: AgentsConfig) -> None:
|
||
|
|
self._config = config
|
||
|
|
|
||
|
|
def run(self, task: Task) -> AgentResult:
|
||
|
|
proj_cfg = self._config.projects.get(task.project)
|
||
|
|
if not proj_cfg:
|
||
|
|
return AgentResult(status="failed", summary=f"项目不存在: {task.project}")
|
||
|
|
|
||
|
|
lines = []
|
||
|
|
# 1. 本地测试
|
||
|
|
local_result = run_command(
|
||
|
|
"source venv/bin/activate && pytest tests/ -v --tb=short -q",
|
||
|
|
cwd=str(proj_cfg.path),
|
||
|
|
)
|
||
|
|
lines.append(f"=== 本地测试 ===\n{local_result}")
|
||
|
|
|
||
|
|
# 2. 设备端测试(如有配置)
|
||
|
|
if proj_cfg.device_workspace and self._config.devices:
|
||
|
|
dev_name = next(iter(self._config.devices))
|
||
|
|
dev_cfg = self._config.devices[dev_name]
|
||
|
|
device = DeviceAgent(dev_cfg)
|
||
|
|
# 先同步
|
||
|
|
sync_result = device.sync(str(proj_cfg.path), proj_cfg.device_workspace)
|
||
|
|
lines.append(f"=== 设备同步 ===\n{sync_result}")
|
||
|
|
# 然后运行板端测试
|
||
|
|
board_result = device.run_command(
|
||
|
|
"pytest tests/ -v --tb=short -q",
|
||
|
|
proj_cfg.device_workspace,
|
||
|
|
)
|
||
|
|
lines.append(f"=== 板端测试 ({dev_name}) ===\n{board_result}")
|
||
|
|
|
||
|
|
summary = "\n\n".join(lines)
|
||
|
|
failed = "FAILED" in summary or "ERROR" in summary
|
||
|
|
return AgentResult(
|
||
|
|
status="failed" if failed else "done",
|
||
|
|
summary=summary,
|
||
|
|
)
|