Files
RAG/backend/tests/unit/test_provider_smoke.py
YoVinchen 75592af33a
Some checks failed
verify / verify (push) Has been cancelled
Isolate cloud model access before enabling product RAG workflows
The API and ingestion tools now use a fixed internal model gateway while
governed profiles, embedding cache assignments, traceable citations, and
stable API errors establish the boundaries required by later workflows.

Constraint: The current Alibaba Cloud workspace rejects all three live model calls with authentication failures
Rejected: Give the API or seed tools the Bailian key and direct egress | combines database access, cloud credentials, and public network access
Rejected: Mix offline and Bailian vectors in one demo namespace | makes profile activation and retrieval ambiguous
Confidence: high
Scope-risk: moderate
Reversibility: clean
Directive: Keep Bailian credentials and egress exclusive to model-gateway and create a new immutable profile hash for any embedding identity change
Tested: make verify; 121 backend tests; 14 frontend tests; fresh and populated Alembic upgrade-downgrade-upgrade; two idempotent offline seeds; Docker health and HTTP retrieval; isolated provider smoke
Not-tested: Successful live Bailian responses because the supplied workspace credential currently fails authentication
2026-07-13 04:09:06 +08:00

72 lines
2.4 KiB
Python

import pytest
from app.adapters.model_gateway import ModelGatewayAdapter
from app.core.config import Settings
from app.ports.model_providers import ModelProviderError, ProviderErrorKind
from app.tools import provider_smoke
from app.tools.provider_smoke import ProbeResult, failed_probe
def test_provider_smoke_settings_accept_compose_embedding_dimension(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv("EMBEDDING_DIMENSION", "1024")
settings = Settings(_env_file=None)
assert settings.embedding_dimension == 1024
async def test_provider_smoke_entrypoint_accepts_compose_embedding_dimension(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv("EMBEDDING_DIMENSION", "1024")
observed_dimensions: list[int] = []
class StubGateway:
async def aclose(self) -> None:
return None
def fake_gateway(settings: Settings) -> StubGateway:
observed_dimensions.append(settings.embedding_dimension)
return StubGateway()
async def successful_probe(settings: Settings, adapter: StubGateway) -> ProbeResult:
observed_dimensions.append(settings.embedding_dimension)
assert isinstance(adapter, StubGateway)
return ProbeResult(capability="test", status="ok")
monkeypatch.setattr(ModelGatewayAdapter, "from_settings", staticmethod(fake_gateway))
monkeypatch.setattr(provider_smoke, "probe_embedding", successful_probe)
monkeypatch.setattr(provider_smoke, "probe_rerank", successful_probe)
monkeypatch.setattr(provider_smoke, "probe_chat", successful_probe)
exit_code = await provider_smoke.async_main()
assert exit_code == 0
assert observed_dimensions == [1024, 1024, 1024, 1024]
def test_failed_probe_only_exposes_sanitized_provider_fields() -> None:
error = ModelProviderError(
operation="embedding.create",
kind=ProviderErrorKind.AUTHENTICATION,
status_code=401,
provider_code="invalid_api_key",
request_id="req-safe-1",
)
result = failed_probe("embedding", error)
assert result.error_kind == "authentication"
assert result.status_code == 401
assert result.request_id == "req-safe-1"
assert "invalid_api_key" not in repr(result)
def test_unexpected_error_is_reduced_to_fixed_category() -> None:
result = failed_probe("chat", RuntimeError("sensitive content"))
assert result.error_kind == "internal_contract_error"
assert "sensitive content" not in repr(result)