Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(explorer): honour name and description in POST /api/ontology/load (#1654)
gyroscope1110e246df3bc789
diff --git a/semantica/explorer/routes/ontology.py b/semantica/explorer/routes/ontology.pyindex 028cb788..3fa163e4 100644--- a/semantica/explorer/routes/ontology.py+++ b/semantica/explorer/routes/ontology.py@@ -1571,8 +1571,8 @@ async def load_ontology(ontology_uri = ontology_data.data.get("uri", f"temp:{uuid.uuid4().hex[:12]}")registry[ontology_uri] = OntologyEntry(uri=ontology_uri,- name=ontology_data.data.get("name", "Imported Ontology"),- description=ontology_data.data.get("description"),+ name=body.name or ontology_data.data.get("name", "Imported Ontology"),+ description=body.description or ontology_data.data.get("description"),format=fmt,status="external",version=ontology_data.data.get("version", "1.0"),@@ -1587,7 +1587,7 @@ async def load_ontology(return LoadOntologyResponse(uri=ontology_uri,- name=ontology_data.data.get("name", "Imported Ontology"),+ name=body.name or ontology_data.data.get("name", "Imported Ontology"),nodes_added=nodes_added,edges_added=edges_added,format=fmt,@@ -1628,8 +1628,8 @@ async def load_ontology(ontology_uri = metadata.get("uri", f"temp:{uuid.uuid4().hex[:12]}")registry[ontology_uri] = OntologyEntry(uri=ontology_uri,- name=metadata.get("name", "Imported Ontology"),- description=metadata.get("description"),+ name=body.name or metadata.get("name", "Imported Ontology"),+ description=body.description or metadata.get("description"),format=fmt,status="external",version=metadata.get("version", "1.0"),@@ -1644,7 +1644,7 @@ async def load_ontology(return LoadOntologyResponse(uri=ontology_uri,- name=metadata.get("name", "Imported Ontology"),+ name=body.name or metadata.get("name", "Imported Ontology"),nodes_added=nodes_added,edges_added=edges_added,format=fmt,diff --git a/tests/explorer/test_ontology_load_custom_name.py b/tests/explorer/test_ontology_load_custom_name.pynew file mode 100644index 00000000..dd753133--- /dev/null+++ b/tests/explorer/test_ontology_load_custom_name.py@@ -0,0 +1,138 @@+"""Regression tests: ``POST /api/ontology/load`` ignored ``name`` and ``description``.++``LoadOntologyRequest`` declares both fields, and the Explorer's Load Ontology+dialog exposes them under Advanced options as "Custom display name" and+"Description", but the handler never read either. The registry entry and the+response were built from the parsed file's own metadata instead. When that+metadata carries no name, it falls back to the server-side temporary file the+content is written to, so the ontology lands in the registry as e.g.+``tmp9mqzirf8.ttl``.++Both the OntologyIngestor path and the basic-parser fallback path build the+entry, so both are covered.+"""++import pytest++# fastapi ships in the optional `explorer` extra, not in `dev`, so this module+# must skip rather than fail collection when it is absent.+pytest.importorskip("fastapi")++from fastapi.testclient import TestClient # noqa: E402++from semantica.context.context_graph import ContextGraph # noqa: E402+from semantica.explorer.app import create_app # noqa: E402+from semantica.explorer.session import GraphSession # noqa: E402++UNTITLED_URI = "http://example.org/untitled"+UNTITLED = f"""+@prefix owl: <http://www.w3.org/2002/07/owl#> .+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .+<{UNTITLED_URI}> a owl:Ontology .+<{UNTITLED_URI}#Thing> a owl:Class ; rdfs:label "Thing" .+"""++LABELLED_URI = "http://example.org/labelled"+LABELLED = f"""+@prefix owl: <http://www.w3.org/2002/07/owl#> .+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .+<{LABELLED_URI}> a owl:Ontology ; rdfs:label "Labelled Ontology" .+<{LABELLED_URI}#Thing> a owl:Class .+"""+++def _client() -> TestClient:+ return TestClient(create_app(session=GraphSession(ContextGraph(advanced_analytics=False))))+++def _load(client: TestClient, content: str, **fields) -> dict:+ response = client.post(+ "/api/ontology/load", json={"content": content, "format": "turtle", **fields}+ )+ assert response.status_code == 200, response.text+ return response.json()+++def _entry(client: TestClient, uri: str) -> dict:+ registry = client.get("/api/ontology/registry").json()+ matches = [entry for entry in registry if entry["uri"] == uri]+ assert matches, f"{uri} not in registry: {[e['uri'] for e in registry]}"+ return matches[0]+++def test_custom_name_and_description_are_used():+ """Fails before the fix: name is the temp file name, description is None."""+ with _client() as client:+ loaded = _load(client, UNTITLED, name="Custom Name", description="Custom description")+ entry = _entry(client, UNTITLED_URI)++ assert loaded["name"] == "Custom Name"+ assert entry["name"] == "Custom Name"+ assert entry["description"] == "Custom description"+++def test_custom_name_overrides_parsed_label():+ """A caller-supplied name wins over the ontology's own rdfs:label."""+ with _client() as client:+ loaded = _load(client, LABELLED, name="Custom Name")+ entry = _entry(client, LABELLED_URI)++ assert loaded["name"] == "Custom Name"+ assert entry["name"] == "Custom Name"+++def test_parsed_label_still_used_when_name_omitted():+ """Omitting name keeps the existing behaviour of using the parsed label."""+ with _client() as client:+ loaded = _load(client, LABELLED)+ entry = _entry(client, LABELLED_URI)++ assert loaded["name"] == "Labelled Ontology"+ assert entry["name"] == "Labelled Ontology"+++def _force_fallback_parser(monkeypatch) -> None:+ """Make OntologyIngestor raise so the handler takes the basic-parser path."""+ import semantica.ingest.ontology_ingestor as ontology_ingestor++ class _FailingIngestor:+ def __init__(self, *args, **kwargs):+ raise RuntimeError("force the fallback parser")++ monkeypatch.setattr(ontology_ingestor, "OntologyIngestor", _FailingIngestor)+++def test_custom_name_used_on_fallback_parser_path(monkeypatch):+ """The basic-parser fallback builds its own registry entry and must honour+ the same fields."""+ _force_fallback_parser(monkeypatch)++ with _client() as client:+ loaded = _load(client, UNTITLED, name="Custom Name", description="Custom description")+ registry = client.get("/api/ontology/registry").json()++ assert loaded["name"] == "Custom Name"+ entry = next(e for e in registry if e["name"] == "Custom Name")+ assert entry["description"] == "Custom description"++[email protected]("fallback_parser", [False, True], ids=["ingestor", "fallback-parser"])+def test_blank_name_and_description_behave_like_omitted(monkeypatch, fallback_parser):+ """A blank value means "not set", as in the dialog's "Leave blank to use+ ontology title" placeholder (OntologyLoader.tsx already sends+ ``customName || undefined``). Storing "" verbatim would leave a nameless+ row in the registry."""+ if fallback_parser:+ _force_fallback_parser(monkeypatch)++ with _client() as client:+ omitted = _load(client, LABELLED)+ omitted_registry = client.get("/api/ontology/registry").json()+ with _client() as client:+ blank = _load(client, LABELLED, name="", description="")+ blank_registry = client.get("/api/ontology/registry").json()++ assert blank["name"] == omitted["name"] != ""+ assert [(e["name"], e["description"]) for e in blank_registry] == [+ (e["name"], e["description"]) for e in omitted_registry+ ]