Initial commit: Agentic OS troubleshooting platform
Self-hosted, Docker-based agentic troubleshooting platform: FastAPI backend + LangGraph agent, Next.js UI, tiered LLM routing (local Ollama -> Gemini -> DeepSeek -> OpenRouter), MCP server manager, encrypted device credentials, RBAC, audit log, project-memory + Obsidian integrations, and editable troubleshooting decision rules tuned for the GeneseasX vessel stack. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
82
backend/tests/test_diagnostic_format.py
Normal file
82
backend/tests/test_diagnostic_format.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""Tests for diagnostic output formatting."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
os.environ.setdefault("SECRET_KEY", "test-secret-key-for-unit-tests-only")
|
||||
|
||||
from app.services.diagnostic_format import ( # noqa: E402
|
||||
diagnostics_to_markdown,
|
||||
format_tool_output_markdown,
|
||||
prepare_report_diagnostics,
|
||||
)
|
||||
|
||||
|
||||
def test_firewall_rules_table_from_json():
|
||||
payload = {
|
||||
"code": 200,
|
||||
"data": [
|
||||
{
|
||||
"type": "pass",
|
||||
"interface": ["vtnet2"],
|
||||
"protocol": "tcp",
|
||||
"source": "any",
|
||||
"destination": "GENESEASX_LOCAL_SERVICES",
|
||||
"descr": "crew to local services",
|
||||
}
|
||||
],
|
||||
}
|
||||
md = format_tool_output_markdown("pfsense_list_firewall_rules", json.dumps(payload))
|
||||
assert "| Action |" in md
|
||||
assert "crew to local services" in md
|
||||
assert "pass" in md
|
||||
|
||||
|
||||
def test_prepare_report_diagnostics_includes_formatted():
|
||||
diags = [
|
||||
{
|
||||
"device": "pfsense",
|
||||
"tool": "pfsense_list_firewall_rules",
|
||||
"ok": True,
|
||||
"output": json.dumps({"data": [{"type": "pass", "descr": "test rule"}]}),
|
||||
}
|
||||
]
|
||||
out = prepare_report_diagnostics(diags)
|
||||
assert len(out) == 1
|
||||
assert out[0]["formatted"]
|
||||
assert "test rule" in out[0]["formatted"]
|
||||
assert out[0]["raw_available"] is True
|
||||
assert "output" not in out[0]
|
||||
|
||||
|
||||
def test_diagnostics_to_markdown_section():
|
||||
diags = prepare_report_diagnostics(
|
||||
[
|
||||
{
|
||||
"device": "pfsense",
|
||||
"tool": "pfsense_list_interfaces",
|
||||
"ok": True,
|
||||
"output": json.dumps({"data": [{"id": "wan", "if": "vtnet0", "descr": "WAN"}]}),
|
||||
}
|
||||
]
|
||||
)
|
||||
md = diagnostics_to_markdown(diags)
|
||||
assert "### [pfsense] pfsense_list_interfaces" in md
|
||||
assert "vtnet0" in md
|
||||
|
||||
|
||||
def test_prepare_report_diagnostics_fallback_output_is_clipped():
|
||||
out = prepare_report_diagnostics(
|
||||
[
|
||||
{
|
||||
"device": "docker",
|
||||
"tool": "unknown_tool",
|
||||
"ok": True,
|
||||
"output": "x" * 5000,
|
||||
}
|
||||
]
|
||||
)
|
||||
assert out[0]["raw_available"] is True
|
||||
assert out[0]["truncated"] is True
|
||||
assert len(out[0]["output"]) < 4100
|
||||
Reference in New Issue
Block a user