- 新增 task_report 任务级聚合指标 task_metrics - 补充创建任务幂等与失败路径/冲突测试 - 将后端测试基线提升到 20 passed - 新增 edge-agent 初始化代码、启动脚本与打包脚本 - 新增 http_health_check、check_port、check_process、grep_log 执行器 - 补充 edge-agent 基础测试并提升基线到 10 passed - 同步更新 backend README 与当前进度总结
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
from app.executors.process_executor import ProcessCheckExecutor
|
|
|
|
|
|
class DummyCompletedProcess:
|
|
def __init__(self, stdout: str) -> None:
|
|
self.stdout = stdout
|
|
|
|
|
|
def test_process_check_executor_windows_match() -> None:
|
|
with (
|
|
patch("app.executors.process_executor.platform.system", return_value="Windows"),
|
|
patch(
|
|
"app.executors.process_executor.subprocess.run",
|
|
return_value=DummyCompletedProcess('"python.exe","1234","Console","1","10,000 K"\n'),
|
|
),
|
|
):
|
|
success, message, data, evidence = ProcessCheckExecutor().execute({"process_name": "python"})
|
|
|
|
assert success is True
|
|
assert message == "process found"
|
|
assert data["matched_count"] == 1
|
|
assert evidence["matches"][0]["pid"] == 1234
|
|
|
|
|
|
def test_process_check_executor_unix_pid_miss() -> None:
|
|
with (
|
|
patch("app.executors.process_executor.platform.system", return_value="Linux"),
|
|
patch(
|
|
"app.executors.process_executor.subprocess.run",
|
|
return_value=DummyCompletedProcess("1234 python python app.py\n"),
|
|
),
|
|
):
|
|
success, message, data, evidence = ProcessCheckExecutor().execute({"pid": 9999})
|
|
|
|
assert success is False
|
|
assert message == "process not found"
|
|
assert data["matched_count"] == 0
|
|
assert evidence["matches"] == []
|