Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

test: scope the security-regression guard to the SPARQL class, guard the new decision-route test

dex0shubhamc8a591e89e48
diff --git a/tests/explorer/test_decision_route_timestamp.py b/tests/explorer/test_decision_route_timestamp.py
index 4b568619..3baffaac 100644
--- a/tests/explorer/test_decision_route_timestamp.py
+++ b/tests/explorer/test_decision_route_timestamp.py
@@ -24,14 +24,19 @@ import math
from datetime import datetime
import pytest
-from fastapi.testclient import TestClient
-from pydantic import ValidationError
-
-from semantica.context.context_graph import ContextGraph
-from semantica.explorer.app import create_app
-from semantica.explorer.routes.decisions import _node_to_decision
-from semantica.explorer.schemas import DecisionResponse
-from semantica.explorer.session import GraphSession
+# fastapi ships in the optional `explorer` extra, not in `dev`, so this module
+# must skip rather than fail collection when it is absent. The guard has to sit
+# above the imports below, which need that extra.
+pytest.importorskip("fastapi")
+
+from fastapi.testclient import TestClient # noqa: E402
+from pydantic import ValidationError # noqa: E402
+
+from semantica.context.context_graph import ContextGraph # noqa: E402
+from semantica.explorer.app import create_app # noqa: E402
+from semantica.explorer.routes.decisions import _node_to_decision # noqa: E402
+from semantica.explorer.schemas import DecisionResponse # noqa: E402
+from semantica.explorer.session import GraphSession # noqa: E402
# ---------------------------------------------------------------------------
diff --git a/tests/test_security_regression.py b/tests/test_security_regression.py
index cc4ae542..f133e6ba 100644
--- a/tests/test_security_regression.py
+++ b/tests/test_security_regression.py
@@ -24,14 +24,20 @@ import pytest
# rdf:/rdfs: namespaces) and neither the code nor this test caught it,
# since both had the same bug. Importing the real function makes that class
# of drift impossible.
-# fastapi ships in the optional `explorer` extra, not in `dev`, so this module
-# must skip rather than fail collection when it is absent. The guard has to sit
-# above the import below, which pulls fastapi in transitively.
-pytest.importorskip("fastapi")
-
-from semantica.explorer.routes.sparql import _is_read_only_query # noqa: E402
-
-
+# fastapi ships in the optional `explorer` extra, not in `dev`, so this import
+# fails on a plain dev install. Only the SPARQL class below needs it; the Cypher,
+# XXE, vector-serialization and SSRF classes in this module are independent, so
+# the skip is scoped to the one class rather than the whole file.
+try:
+ from semantica.explorer.routes.sparql import _is_read_only_query
+except ImportError: # pragma: no cover - depends on the installed extras
+ _is_read_only_query = None
+
+
+ _is_read_only_query is None,
+ reason="requires semantica[explorer] (fastapi)",
+)
class TestSparqlReadOnlyValidation:
"""Regression tests for SPARQL injection prevention."""