71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib
|
|
import json
|
|
|
|
|
|
def test_ingestion_catalog_project_and_gateway_are_opt_in(monkeypatch):
|
|
from pathlib import Path
|
|
|
|
from services.runtime import state_sync
|
|
|
|
catalog = Path(__file__).resolve().parents[1] / "catalog"
|
|
monkeypatch.delenv("INGESTION_CONNECTOR_ENABLED", raising=False)
|
|
module = importlib.reload(state_sync)
|
|
assert all(slug != "itworx-ingestion" for slug, _ in module.CONNECTOR_GATEWAYS)
|
|
assert all(
|
|
item["metadata"]["slug"] != "knowledge-hub"
|
|
for item in module._project_documents(catalog)
|
|
)
|
|
|
|
monkeypatch.setenv("INGESTION_CONNECTOR_ENABLED", "true")
|
|
module = importlib.reload(state_sync)
|
|
assert ("itworx-ingestion", "http://connector-ingestion:8080/mcp") in module.CONNECTOR_GATEWAYS
|
|
assert any(
|
|
item["metadata"]["slug"] == "knowledge-hub"
|
|
for item in module._project_documents(catalog)
|
|
)
|
|
|
|
monkeypatch.delenv("INGESTION_CONNECTOR_ENABLED", raising=False)
|
|
importlib.reload(state_sync)
|
|
|
|
|
|
def test_disabled_ingestion_binding_is_ignored_while_feature_is_off(monkeypatch):
|
|
from pathlib import Path
|
|
|
|
from services.control_api.persistence import Base, create_engine_from_url, session_factory
|
|
from services.control_api.persistence.models import ClientBindingRow, ClientRow
|
|
from services.runtime import state_sync
|
|
|
|
catalog = Path(__file__).resolve().parents[1] / "catalog"
|
|
binding = [{
|
|
"clientId": "11111111-1111-4111-8111-111111111111",
|
|
"subject": "disabled-knowledge-intake",
|
|
"project": "knowledge-hub",
|
|
"environment": "prod",
|
|
"enabled": False,
|
|
}]
|
|
with monkeypatch.context() as disabled_feature:
|
|
disabled_feature.setenv("INGESTION_CONNECTOR_ENABLED", "false")
|
|
disabled_feature.setenv("MCP_CLIENT_BINDINGS_JSON", json.dumps(binding))
|
|
module = importlib.reload(state_sync)
|
|
engine = create_engine_from_url("sqlite:///:memory:")
|
|
Base.metadata.create_all(engine)
|
|
sessions = session_factory(engine)
|
|
try:
|
|
with sessions() as session, session.begin():
|
|
module.sync_runtime_state(
|
|
session,
|
|
catalog,
|
|
"https://auth.itworx.test/application/o/itworx/",
|
|
)
|
|
with sessions() as session:
|
|
assert session.query(ClientRow).filter_by(
|
|
subject="disabled-knowledge-intake"
|
|
).one_or_none() is None
|
|
assert session.query(ClientBindingRow).one_or_none() is None
|
|
finally:
|
|
engine.dispose()
|
|
|
|
importlib.reload(state_sync)
|