77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""Tests for preflight analysis engine."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from cmdforge.preflight import PreflightReport, analyze_tool, _check_config_integrity
|
|
|
|
|
|
class TestPreflightReport:
|
|
def test_empty_report_is_ok(self):
|
|
report = PreflightReport()
|
|
assert report.ok
|
|
|
|
def test_errors_make_not_ok(self):
|
|
report = PreflightReport(errors=["bad"])
|
|
assert not report.ok
|
|
|
|
def test_merge(self):
|
|
a = PreflightReport(errors=["e1"], warnings=["w1"])
|
|
b = PreflightReport(errors=["e2"], suggestions=["s1"])
|
|
c = a.merge(b)
|
|
assert c.errors == ["e1", "e2"]
|
|
assert c.warnings == ["w1"]
|
|
assert c.suggestions == ["s1"]
|
|
|
|
|
|
class TestAnalyzeTool:
|
|
def test_no_steps_warns(self, tmp_path):
|
|
from cmdforge.tool import Tool, save_tool
|
|
|
|
with patch("cmdforge.tool.TOOLS_DIR", tmp_path / ".cmdforge"):
|
|
tool = Tool(name="empty-tool")
|
|
save_tool(tool)
|
|
|
|
report = analyze_tool(tool)
|
|
assert report.ok
|
|
assert any("no steps" in w.lower() for w in report.warnings)
|
|
|
|
def test_missing_name(self, tmp_path):
|
|
from cmdforge.tool import Tool
|
|
|
|
report = PreflightReport()
|
|
tool = Tool(name="")
|
|
_check_config_integrity(tool, report)
|
|
assert not report.ok
|
|
|
|
def test_invalid_version(self, tmp_path):
|
|
from cmdforge.tool import Tool
|
|
|
|
report = PreflightReport()
|
|
tool = Tool(name="test", version="not-semver")
|
|
_check_config_integrity(tool, report)
|
|
assert not report.ok
|
|
|
|
def test_ok_tool(self, tmp_path):
|
|
from cmdforge.tool import Tool
|
|
|
|
report = PreflightReport()
|
|
tool = Tool(name="ok-tool", version="1.0.0")
|
|
_check_config_integrity(tool, report)
|
|
assert report.ok
|
|
|
|
def test_secret_pattern_in_prompt(self, tmp_path):
|
|
from cmdforge.tool import Tool, PromptStep
|
|
|
|
tool = Tool(
|
|
name="leaky",
|
|
steps=[PromptStep(
|
|
prompt="Use api_key: abc123 to auth",
|
|
provider="mock",
|
|
output_var="out",
|
|
)],
|
|
)
|
|
report = PreflightReport()
|
|
from cmdforge.preflight import _check_secrets
|
|
_check_secrets(tool, report)
|
|
assert any("secret" in w.lower() for w in report.warnings)
|