Initial curated RAGcore source from c16667f0c9397e2bfc8dd0255b114fba23c8d05e

This commit is contained in:
Public Source Publisher committed 2026-10-01 01:34:21 +02:00
commit 7ca726caf2
659 files changed
+98171

No files matched your search

@@ -0,0 +1,109 @@
from __future__ import annotations
from pathlib import Path
from uuid import uuid4
import httpx
import pytest
from ragcore.application.models.selection import EmbeddingCutoverRejected
from ragcore.config import Settings
from ragcore.domain.control import DataPolicy
from ragcore.domain.models import EmbeddingProfile, EmbeddingProvider, EmbeddingSelection
from ragcore.infrastructure.models.embedding_factory import create_embedding_adapter_factory
from ragcore.infrastructure.models.selection_verifier import ModelForgeRouteSelectionVerifier
def _profile() -> EmbeddingProfile:
return EmbeddingProfile(
id=uuid4(),
profile="route-check",
version="v1",
provider=EmbeddingProvider.MODELFORGE,
model_identifier="rag.embedding@1",
model_digest="a" * 64,
dimensions=2,
context_limit=4096,
tokenizer="capability-managed",
data_policy=DataPolicy.LOCAL_ONLY,
embedding_space_id=uuid4(),
)
def _factory(client: httpx.AsyncClient, credential_file: Path):
return create_embedding_adapter_factory(
settings=Settings(
env="test",
modelforge_base_url="http://modelforge:8000",
modelforge_credential_file=credential_file,
modelforge_embedding_experiment_route="stale-global-route",
),
http_client=client,
)
def _write_credential(path: Path) -> None:
path.write_text("mf_" + "x" * 48, encoding="utf-8")
path.chmod(0o600)
@pytest.mark.asyncio
async def test_selection_probe_rejects_stale_route_embedding_space(tmp_path: Path) -> None:
profile = _profile()
selection = EmbeddingSelection.from_profile(profile, experiment_route_key="lab-route-current")
credential_file = tmp_path / "credential"
_write_credential(credential_file)
paths: list[str] = []
def respond(request: httpx.Request) -> httpx.Response:
paths.append(request.url.path)
return httpx.Response(
200,
json={
"capability": "rag.embedding@1",
"dimension": profile.dimensions,
"normalized": True,
"embedding_space_id": str(uuid4()),
"data": [[1.0, 0.0]],
"request_id": str(uuid4()),
},
)
async with httpx.AsyncClient(
transport=httpx.MockTransport(respond), follow_redirects=False
) as client:
verifier = ModelForgeRouteSelectionVerifier(_factory(client, credential_file))
with pytest.raises(EmbeddingCutoverRejected, match="identity probe"):
await verifier.verify(selection, profile)
assert paths == ["/api/v1/capability-experiments/lab-route-current/invoke"]
@pytest.mark.asyncio
async def test_selection_probe_records_gateway_request_identity(tmp_path: Path) -> None:
profile = _profile()
selection = EmbeddingSelection.from_profile(profile, experiment_route_key="lab-route-next")
credential_file = tmp_path / "credential"
_write_credential(credential_file)
request_id = uuid4()
def respond(_request: httpx.Request) -> httpx.Response:
return httpx.Response(
200,
json={
"capability": "rag.embedding@1",
"dimension": profile.dimensions,
"normalized": True,
"embedding_space_id": str(profile.embedding_space_id),
"data": [[1.0, 0.0]],
"request_id": str(request_id),
},
)
async with httpx.AsyncClient(
transport=httpx.MockTransport(respond), follow_redirects=False
) as client:
verifier = ModelForgeRouteSelectionVerifier(_factory(client, credential_file))
result = await verifier.verify(selection, profile)
assert result.gateway_request_ids == (request_id,)