- 新增 task_report 任务级聚合指标 task_metrics - 补充创建任务幂等与失败路径/冲突测试 - 将后端测试基线提升到 20 passed - 新增 edge-agent 初始化代码、启动脚本与打包脚本 - 新增 http_health_check、check_port、check_process、grep_log 执行器 - 补充 edge-agent 基础测试并提升基线到 10 passed - 同步更新 backend README 与当前进度总结
38 lines
985 B
Python
38 lines
985 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from app.executors.log_executor import GrepLogExecutor
|
|
|
|
|
|
def test_grep_log_executor_matches_keyword(tmp_path: Path) -> None:
|
|
log_file = tmp_path / "app.log"
|
|
log_file.write_text("INFO start\nERROR failed to boot\nINFO done\n", encoding="utf-8")
|
|
|
|
success, message, data, evidence = GrepLogExecutor().execute(
|
|
{
|
|
"path": str(log_file),
|
|
"keyword": "ERROR",
|
|
"limit": 10,
|
|
}
|
|
)
|
|
|
|
assert success is True
|
|
assert message == "keyword matched"
|
|
assert data["matched_count"] == 1
|
|
assert evidence["matches"][0]["line_number"] == 2
|
|
|
|
|
|
def test_grep_log_executor_missing_file() -> None:
|
|
success, message, data, evidence = GrepLogExecutor().execute(
|
|
{
|
|
"path": "not-exists.log",
|
|
"keyword": "ERROR",
|
|
}
|
|
)
|
|
|
|
assert success is False
|
|
assert "not found" in message
|
|
assert data == {}
|
|
assert evidence == {}
|