diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/app/graph/__init__.py b/backend/app/graph/__init__.py new file mode 100644 index 00000000..5e6b9a08 --- /dev/null +++ b/backend/app/graph/__init__.py @@ -0,0 +1 @@ +# Populated in Task 4 once factory.py exists diff --git a/backend/app/graph/base.py b/backend/app/graph/base.py new file mode 100644 index 00000000..83e4037e --- /dev/null +++ b/backend/app/graph/base.py @@ -0,0 +1,38 @@ +"""Abstract graph backend interface.""" +from abc import ABC, abstractmethod +from typing import Any, Dict, List, Optional + + +class GraphBackend(ABC): + @abstractmethod + def create_graph(self, graph_id: str, name: str, description: str = "") -> None: ... + + @abstractmethod + def set_ontology(self, graph_ids: List[str], entities: Dict[str, Any], edges: Dict[str, Any]) -> None: ... + + @abstractmethod + def add_batch(self, graph_id: str, episodes: List[Any]) -> List[str]: ... + + @abstractmethod + def get_episode(self, uuid_: str) -> Any: ... + + @abstractmethod + def get_all_nodes(self, graph_id: str) -> List[Dict[str, Any]]: ... + + @abstractmethod + def get_all_edges(self, graph_id: str) -> List[Dict[str, Any]]: ... + + @abstractmethod + def get_node(self, uuid_: str) -> Dict[str, Any]: ... + + @abstractmethod + def get_node_edges(self, node_uuid: str) -> List[Dict[str, Any]]: ... + + @abstractmethod + def search(self, graph_id: str, query: str, limit: int = 10, scope: str = "edges") -> Dict[str, Any]: ... + + @abstractmethod + def add_text(self, graph_id: str, data: str) -> None: ... + + @abstractmethod + def delete_graph(self, graph_id: str) -> None: ... diff --git a/backend/tests/__init__.py b/backend/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/tests/test_graph_factory.py b/backend/tests/test_graph_factory.py new file mode 100644 index 00000000..64b6b261 --- /dev/null +++ b/backend/tests/test_graph_factory.py @@ -0,0 +1,13 @@ +import pytest +from unittest.mock import MagicMock, patch + + +def test_graph_backend_has_required_methods(): + from backend.app.graph.base import GraphBackend + required = [ + "create_graph", "set_ontology", "add_batch", "get_episode", + "get_all_nodes", "get_all_edges", "get_node", "get_node_edges", + "search", "add_text", "delete_graph", + ] + for method in required: + assert hasattr(GraphBackend, method), f"GraphBackend missing: {method}" diff --git a/conftest.py b/conftest.py new file mode 100644 index 00000000..f4eca67f --- /dev/null +++ b/conftest.py @@ -0,0 +1,5 @@ +import sys +import os + +# Allow `import backend.app.*` from the project root +sys.path.insert(0, os.path.dirname(__file__))