107 lines
3.7 KiB
Python
107 lines
3.7 KiB
Python
import pytest
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
from app.modules.project.domain.entities import Project
|
|
from app.modules.scanner.application.services import ScanService
|
|
from app.modules.graph.application.services import GraphService
|
|
|
|
|
|
@pytest.fixture
|
|
def scan_result():
|
|
svc = ScanService()
|
|
project = Project(
|
|
id="test", name="test",
|
|
design_dir="/workspace/arch-design-agent-skill-dashboard/design",
|
|
code_dir=None, created_at=datetime(2026, 1, 1),
|
|
)
|
|
return svc.scan(project)
|
|
|
|
|
|
@pytest.fixture
|
|
def design_dir():
|
|
return "/workspace/arch-design-agent-skill-dashboard/design"
|
|
|
|
|
|
@pytest.fixture
|
|
def graph_service():
|
|
return GraphService()
|
|
|
|
|
|
def test_panorama_has_groups(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
group_ids = {g.id for g in view.groups}
|
|
assert "business" in group_ids
|
|
assert "application" in group_ids
|
|
assert "data" in group_ids
|
|
assert "technology" in group_ids
|
|
assert "cross-layer" in group_ids
|
|
|
|
|
|
def test_panorama_has_capability_nodes(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
cap_nodes = [n for n in view.nodes if n.type == "capability"]
|
|
assert len(cap_nodes) > 0
|
|
assert all(n.group_id == "business" for n in cap_nodes)
|
|
|
|
|
|
def test_panorama_has_module_nodes(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
mod_nodes = [n for n in view.nodes if n.type == "module"]
|
|
assert len(mod_nodes) > 0
|
|
assert all(n.group_id == "application" for n in mod_nodes)
|
|
|
|
|
|
def test_panorama_has_entity_nodes(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
ent_nodes = [n for n in view.nodes if n.type == "entity"]
|
|
assert len(ent_nodes) > 0
|
|
assert all(n.group_id == "data" for n in ent_nodes)
|
|
|
|
|
|
def test_panorama_has_edges(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
assert len(view.edges) > 0
|
|
relations = {e.relation for e in view.edges}
|
|
assert "traces_to" in relations
|
|
|
|
|
|
def test_panorama_depends_on_edges(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
dep_edges = [e for e in view.edges if e.relation == "depends_on"]
|
|
assert len(dep_edges) > 0
|
|
|
|
|
|
def test_neighbors_returns_subgraph(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
# Use a known capability node
|
|
neighbors = graph_service.get_neighbors(view, "CAP-PROJ-REG")
|
|
assert len(neighbors.nodes) > 0
|
|
assert any(n.id == "CAP-PROJ-REG" for n in neighbors.nodes)
|
|
assert len(neighbors.edges) > 0
|
|
|
|
|
|
def test_neighbors_unknown_node(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
neighbors = graph_service.get_neighbors(view, "NONEXISTENT")
|
|
assert len(neighbors.nodes) == 0
|
|
assert len(neighbors.edges) == 0
|
|
|
|
|
|
def test_graph_node_has_parent_field(graph_service, scan_result):
|
|
view = graph_service.build_panorama(scan_result)
|
|
for node in view.nodes:
|
|
assert hasattr(node, 'parent')
|
|
|
|
|
|
def test_panorama_nodes_have_real_status(graph_service, scan_result, design_dir):
|
|
view = graph_service.build_panorama(scan_result, design_dir=design_dir)
|
|
statuses = {n.status for n in view.nodes}
|
|
assert statuses != {"unknown"}, "All nodes still have status='unknown' — status mapping not working"
|
|
|
|
|
|
def test_panorama_status_values_are_valid(graph_service, scan_result, design_dir):
|
|
view = graph_service.build_panorama(scan_result, design_dir=design_dir)
|
|
valid_statuses = {"ok", "sparse", "missing", "template-residue", "placeholder-heavy", "unknown"}
|
|
for node in view.nodes:
|
|
assert node.status in valid_statuses, f"Node {node.id} has invalid status '{node.status}'"
|