Public changes compared with the previous published export: 89 files changed. Affected areas: - backend/app: 21 files - dependencies: 5 files - deployment and CI: 6 files - documentation: 2 files - frontend: 3 files - frontend/src: 20 files - project files: 1 file - tests: 30 files - unraid: 1 file Changed files: - Updated: ".env.example" - Updated: "Dockerfile.unraid" - Updated: "README.md" - Updated: "backend/Dockerfile" - Added: "backend/app/alerts.py" - Updated: "backend/app/auth.py" - Added: "backend/app/backups.py" - Updated: "backend/app/config_io.py" - Updated: "backend/app/demo.py" - Updated: "backend/app/discovery.py" - Updated: "backend/app/discovery_store.py" - Updated: "backend/app/docker_discovery.py" - Updated: "backend/app/events.py" - Updated: "backend/app/evidence.py" - Updated: "backend/app/health.py" - Updated: "backend/app/incidents.py" - Added: "backend/app/loops.py" - Updated: "backend/app/main.py" - Updated: "backend/app/models.py" - Updated: "backend/app/observation.py" - Updated: "backend/app/probes.py" - Added: "backend/app/response_cache.py" - Updated: "backend/app/scheduler.py" - Updated: "backend/app/semantic.py" - Updated: "backend/app/store.py" - Updated: "backend/pyproject.toml" - Updated: "backend/tests/test_api.py" - Updated: "backend/tests/test_config_io.py" - Updated: "backend/tests/test_demo.py" - Updated: "backend/tests/test_discovery_v120.py" - Updated: "backend/tests/test_health.py" - Updated: "backend/tests/test_probes.py" - Updated: "backend/tests/test_scheduler.py" - Updated: "backend/tests/test_v130_probe_reachability.py" - Updated: "backend/tests/test_v160_evidence_changes.py" - Added: "backend/tests/test_v163_alerts.py" - Added: "backend/tests/test_v163_backups.py" - Added: "backend/tests/test_v163_data_integrity.py" - Added: "backend/tests/test_v163_efficiency.py" - Added: "backend/tests/test_v163_health_performance.py" - Added: "backend/tests/test_v163_loops.py" - Added: "backend/tests/test_v163_management.py" - Added: "backend/tests/test_v163_realtime.py" - Added: "backend/tests/test_v163_security.py" - Added: "backend/tests/test_v163_semantic_etag.py" - Added: "compose.demo.yaml" - Updated: "compose.yaml" - Added: "docker-compose.broker.yml" - Updated: "docker-compose.yml" - Updated: "docs/ARCHITECTURE.md" - Added: "frontend/e2e/a11y.spec.ts" - Updated: "frontend/e2e/demo.spec.ts" - Updated: "frontend/index.html" - Updated: "frontend/nginx.conf" - Updated: "frontend/package-lock.json" - Updated: "frontend/package.json" - Updated: "frontend/playwright.config.ts" - Updated: "frontend/src/App.tsx" - Updated: "frontend/src/LivingEdge.tsx" - Added: "frontend/src/activityView.test.ts" - Added: "frontend/src/activityView.ts" - Updated: "frontend/src/api.ts" - Added: "frontend/src/apiAuth.test.ts" - Added: "frontend/src/components/ActionsMenu.tsx" - Added: "frontend/src/components/ConfirmDialog.test.tsx" - Added: "frontend/src/components/ConfirmDialog.tsx" - Added: "frontend/src/components/StatusIcon.tsx" - Updated: "frontend/src/demo/DemoWalkthrough.test.ts" - Updated: "frontend/src/demo/DemoWalkthrough.tsx" - Added: "frontend/src/elk-worker-url.d.ts" - Added: "frontend/src/labels.ts" - Updated: "frontend/src/main.tsx" - Added: "frontend/src/realtime/refreshPlan.test.ts" - Added: "frontend/src/realtime/refreshPlan.ts" - Updated: "frontend/src/realtime/useRealtimeEvents.ts" - Added: "frontend/src/routing/urlState.test.ts" - Added: "frontend/src/routing/urlState.ts" - Updated: "frontend/src/styles.css" - Added: "frontend/src/topology/GraphListView.test.tsx" - Added: "frontend/src/topology/GraphListView.tsx" - Updated: "frontend/src/topology/ServiceNode.tsx" - Updated: "frontend/src/topology/TopologyCommandBar.tsx" - Added: "frontend/src/topology/semanticGraph.test.ts" - Updated: "frontend/src/topology/semanticGraph.ts" - Added: "frontend/src/topologyLayout.test.ts" - Updated: "frontend/src/topologyLayout.ts" - Updated: "package-lock.json" - Updated: "package.json" - Updated: "unraid/my-servicemap.xml" Export provenance/manifests refreshed; excluded from the change summary. Publish curated ServiceMap source from af46f684e468dffd3a5190e28d3b572d4c26bfd7
207 lines
6.6 KiB
Python
207 lines
6.6 KiB
Python
import sqlite3
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from app.config_io import export_document, import_document, parse_document, serialize_document
|
|
from app.models import ServiceCreate, ServiceKind
|
|
from app.store import Store
|
|
|
|
CONFIG = """
|
|
version: 1
|
|
services:
|
|
- name: Database
|
|
kind: tcp
|
|
host: db.local
|
|
port: 5432
|
|
depends_on: []
|
|
- name: API
|
|
kind: http
|
|
url: https://api.local
|
|
depends_on: [Database]
|
|
"""
|
|
|
|
|
|
def test_yaml_import_export_round_trip(tmp_path: Path) -> None:
|
|
store = Store(str(tmp_path / "servicemap.db"))
|
|
result = import_document(store, parse_document(CONFIG, "yaml"), "replace")
|
|
|
|
assert result.created == 2
|
|
services = store.list_services()
|
|
assert len(services) == 2
|
|
api = store.get_service_by_name("API")
|
|
database = store.get_service_by_name("Database")
|
|
assert api is not None and database is not None
|
|
assert api.depends_on == [database.id]
|
|
|
|
exported = export_document(store)
|
|
yaml_text = serialize_document(exported, "yaml")
|
|
reparsed = parse_document(yaml_text, "yaml")
|
|
assert [service.name for service in reparsed.services] == [service.name for service in exported.services]
|
|
|
|
|
|
def test_merge_can_reference_existing_service_not_in_document(tmp_path: Path) -> None:
|
|
store = Store(str(tmp_path / "servicemap.db"))
|
|
database = store.create_service(
|
|
ServiceCreate(name="Database", kind=ServiceKind.TCP, host="db.local", port=5432)
|
|
)
|
|
document = parse_document(
|
|
"""
|
|
version: 1
|
|
services:
|
|
- name: API
|
|
kind: http
|
|
url: https://api.local
|
|
depends_on: [Database]
|
|
""",
|
|
"yaml",
|
|
)
|
|
|
|
result = import_document(store, document, "merge")
|
|
|
|
assert result.created == 1
|
|
assert result.updated == 0
|
|
api = store.get_service_by_name("API")
|
|
assert api is not None
|
|
assert api.depends_on == [database.id]
|
|
|
|
|
|
def test_import_rejects_missing_dependency_and_cycles(tmp_path: Path) -> None:
|
|
store = Store(str(tmp_path / "servicemap.db"))
|
|
missing = parse_document(
|
|
"""
|
|
version: 1
|
|
services:
|
|
- name: API
|
|
kind: http
|
|
url: https://api.local
|
|
depends_on: [Database]
|
|
""",
|
|
"yaml",
|
|
)
|
|
with pytest.raises(ValueError, match="onbekende afhankelijkheden"):
|
|
import_document(store, missing, "replace")
|
|
|
|
cyclic = """
|
|
version: 1
|
|
services:
|
|
- name: A
|
|
kind: http
|
|
url: https://a.local
|
|
depends_on: [B]
|
|
- name: B
|
|
kind: http
|
|
url: https://b.local
|
|
depends_on: [A]
|
|
"""
|
|
with pytest.raises(ValueError, match="kring"):
|
|
parse_document(cyclic, "yaml")
|
|
|
|
with pytest.raises(ValueError, match="1 of lager"):
|
|
parse_document("version: 2\nservices: []", "yaml")
|
|
|
|
|
|
def test_replace_import_rolls_back_on_mid_transaction_failure(
|
|
tmp_path: Path,
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
store = Store(str(tmp_path / "servicemap.db"))
|
|
original = store.create_service(
|
|
ServiceCreate(name="Original", kind=ServiceKind.HTTP, url="https://original.local")
|
|
)
|
|
document = parse_document(
|
|
"""
|
|
version: 1
|
|
services:
|
|
- name: First
|
|
kind: http
|
|
url: https://first.local
|
|
depends_on: []
|
|
- name: Second
|
|
kind: http
|
|
url: https://second.local
|
|
depends_on: []
|
|
""",
|
|
"yaml",
|
|
)
|
|
monkeypatch.setattr("app.store.uuid4", lambda: "duplicate-id")
|
|
|
|
with pytest.raises(sqlite3.IntegrityError):
|
|
import_document(store, document, "replace")
|
|
|
|
remaining = store.list_services()
|
|
assert [(service.id, service.name) for service in remaining] == [(original.id, "Original")]
|
|
|
|
|
|
def test_export_keeps_operator_fields_and_merge_preserves_unmentioned_ones(tmp_path: Path) -> None:
|
|
from app.models import (
|
|
ComponentRole,
|
|
Criticality,
|
|
DiscoveryCategory,
|
|
DiscoveryLifecycle,
|
|
DiscoveryVisibility,
|
|
)
|
|
|
|
store = Store(str(tmp_path / "servicemap.db"))
|
|
database = store.create_service(ServiceCreate(name="Database", kind=ServiceKind.TCP, host="db.local", port=5432))
|
|
api = store.create_service(
|
|
ServiceCreate(
|
|
name="API",
|
|
kind=ServiceKind.HTTP,
|
|
url="https://api.local",
|
|
depends_on=[database.id],
|
|
owner="platform-team",
|
|
application="Northstar",
|
|
application_locked=True,
|
|
domain="Commerce",
|
|
domain_locked=True,
|
|
component_role=ComponentRole.API,
|
|
component_role_locked=True,
|
|
criticality=Criticality.HIGH,
|
|
category=DiscoveryCategory.APPLICATION,
|
|
visibility=DiscoveryVisibility.HIDDEN,
|
|
lifecycle=DiscoveryLifecycle.ACTIVE,
|
|
expected_status_min=200,
|
|
expected_status_max=204,
|
|
layout_x=120.0,
|
|
layout_y=40.0,
|
|
layout_pinned=True,
|
|
runtime_state="running",
|
|
)
|
|
)
|
|
|
|
exported = export_document(store)
|
|
exported_api = next(item for item in exported.services if item.name == "API")
|
|
assert exported_api.application == "Northstar" and exported_api.application_locked
|
|
assert exported_api.domain == "Commerce" and exported_api.component_role == ComponentRole.API
|
|
assert exported_api.visibility == DiscoveryVisibility.HIDDEN and exported_api.layout_pinned
|
|
assert exported_api.depends_on == ["Database"]
|
|
# Observed runtime state is not configuration.
|
|
assert "runtime_state" not in serialize_document(exported, "yaml")
|
|
|
|
# Round trip into an empty store keeps every operator field.
|
|
other = Store(str(tmp_path / "other.db"))
|
|
import_document(other, parse_document(serialize_document(exported, "yaml"), "yaml"), "replace")
|
|
restored = next(item for item in other.list_services() if item.name == "API")
|
|
for field in ("owner", "application", "application_locked", "domain", "component_role", "criticality",
|
|
"category", "visibility", "expected_status_min", "expected_status_max",
|
|
"layout_x", "layout_y", "layout_pinned"):
|
|
assert getattr(restored, field) == getattr(api, field), field
|
|
|
|
# A merge that mentions only one field changes only that field.
|
|
result = import_document(
|
|
store,
|
|
parse_document(
|
|
"version: 2\nservices:\n - name: API\n kind: http\n url: https://api.local\n description: Public API\n",
|
|
"yaml",
|
|
),
|
|
"merge",
|
|
)
|
|
assert result.updated == 1
|
|
merged = store.get_service(api.id)
|
|
assert merged.description == "Public API"
|
|
for field in ("owner", "application", "application_locked", "domain", "component_role", "criticality",
|
|
"visibility", "expected_status_min", "layout_x", "layout_pinned", "url", "runtime_state"):
|
|
assert getattr(merged, field) == getattr(api, field), field
|
|
assert merged.depends_on == [database.id]
|