fix: close task3 qdrant and config validation gaps

This commit is contained in:
2026-08-11 07:47:43 +02:00
parent 99e0024973
commit 88d1790728
7 changed files with 235 additions and 36 deletions
+20 -8
View File
@@ -664,13 +664,16 @@ def _validate_internal_embedding_contract(raw: dict[str, Any], path: Path) -> No
)
def _normalize_qdrant_base_url(value: str) -> str:
parsed = urlparse(value)
hostname = (parsed.hostname or "").lower()
def _normalize_qdrant_base_url(value: Any) -> str | None:
"""Normalize a URL, returning ``None`` for untrusted raw YAML values."""
if not isinstance(value, str):
return None
try:
parsed = urlparse(value)
hostname = (parsed.hostname or "").lower()
port = parsed.port
except ValueError:
port = None
except (TypeError, ValueError):
return None
host = f"[{hostname}]" if ":" in hostname and not hostname.startswith("[") else hostname
netloc = f"{host}:{port}" if port is not None else host
return f"{parsed.scheme.lower()}://{netloc}{parsed.path.rstrip('/') or '/'}"
@@ -687,9 +690,18 @@ def _validate_vector_resource_consistency(raw: dict[str, Any], translated: dict[
raise ConfigError(
f"Configurazione non valida in {path}: vectors and resources.vector must both describe qdrant"
)
if _normalize_qdrant_base_url(vectors.get("base_url", "")) != _normalize_qdrant_base_url(
resource.get("base_url", "")
) or vectors.get("collection") != resource.get("collection"):
vector_url = _normalize_qdrant_base_url(vectors.get("base_url"))
resource_url = _normalize_qdrant_base_url(resource.get("base_url"))
vector_collection = vectors.get("collection")
resource_collection = resource.get("collection")
if (
vector_url is None
or resource_url is None
or not isinstance(vector_collection, str)
or not isinstance(resource_collection, str)
or vector_url != resource_url
or vector_collection != resource_collection
):
raise ConfigError(
f"Configurazione non valida in {path}: vectors and resources.vector disagree"
)