111 lines
3.4 KiB
Python
111 lines
3.4 KiB
Python
"""Tests for ScanService — integration with real design directory."""
|
|
|
|
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
|
|
|
|
|
|
@pytest.fixture
|
|
def scan_service():
|
|
return ScanService()
|
|
|
|
|
|
@pytest.fixture
|
|
def test_project():
|
|
return Project(
|
|
id="test-proj",
|
|
name="test",
|
|
design_dir="/workspace/arch-design-agent-skill-dashboard/design",
|
|
code_dir=None,
|
|
created_at=datetime(2026, 1, 1),
|
|
)
|
|
|
|
|
|
def test_scan_produces_result(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert result.project_id == "test-proj"
|
|
assert result.scanned_at is not None
|
|
assert len(result.file_statuses) > 0
|
|
assert result.summary.total_files > 0
|
|
|
|
|
|
def test_scan_has_capabilities(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.capabilities) > 0
|
|
assert result.capabilities[0].capability_id.startswith("CAP-")
|
|
|
|
|
|
def test_scan_has_modules(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.modules) > 0
|
|
|
|
|
|
def test_scan_has_traceability_links(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.traceability_links) > 0
|
|
# entity_ids should be a list (space-split)
|
|
assert isinstance(result.traceability_links[0].entity_ids, list)
|
|
|
|
|
|
def test_scan_has_design_documents(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.design_documents) > 0
|
|
|
|
|
|
def test_scan_has_api_contracts(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.api_contracts) > 0
|
|
assert result.api_contracts[0].path.startswith("/")
|
|
|
|
|
|
def test_scan_has_value_flows(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.value_flows) > 0
|
|
|
|
|
|
def test_scan_has_integrations(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.integrations) > 0
|
|
|
|
|
|
def test_scan_has_external_systems(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.external_systems) > 0
|
|
|
|
|
|
def test_scan_has_entities(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
assert len(result.entities) > 0
|
|
|
|
|
|
def test_scan_summary_counts_match(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
s = result.summary
|
|
assert s.total_files == len(result.file_statuses)
|
|
assert s.total_files == s.ok + s.sparse + s.missing + s.placeholder_heavy + s.template_residue
|
|
|
|
|
|
def test_get_latest_scan_none_before_scan(scan_service):
|
|
assert scan_service.get_latest_scan("nonexistent") is None
|
|
|
|
|
|
def test_get_latest_scan_cached(scan_service, test_project):
|
|
scan_service.scan(test_project)
|
|
cached = scan_service.get_latest_scan("test-proj")
|
|
assert cached is not None
|
|
assert cached.project_id == "test-proj"
|
|
|
|
|
|
def test_scan_has_singleton_fields(scan_service, test_project):
|
|
result = scan_service.scan(test_project)
|
|
# These MD files have frontmatter and should produce singleton entities
|
|
assert result.system_context is not None
|
|
assert result.solution_layer is not None
|
|
assert result.module_boundary_rule is not None
|
|
assert result.runtime_topology is not None
|
|
assert result.operational_baseline is not None
|
|
assert result.release_plan is not None
|