Closes the 12 MAJ raised by the release/0.5.0 audit pipeline (cf.
docs/audit/reports/release-0.5.0/summary.md → summary-reaudit.md).
Volet 1 — Reasoning architecture (audits 01/02/06/07 strengthening)
* Domain ports: LLMProvider, ReasoningRunner, ReasoningParseError
* Domain DTOs: LLMProviderType, ReasoningResult, ReasoningIteration
* infra/llm/ollama_provider.py — OllamaProvider with health_check
* infra/docling_agent_reasoning.py — runner adapter, encapsulates the
private _rag_loop call (tracked at docling-project/docling-agent#26),
commits OLLAMA_HOST once at boot (eliminates the per-request env race),
translates upstream IndexError into ReasoningParseError
* api/reasoning.py — zero coupling to docling-agent / mellea / docling-core,
consumes app.state.reasoning_runner via the port
* main.py — DI wires OllamaProvider + DoclingAgentReasoningRunner at boot
when REASONING_ENABLED=true and deps are importable
* Rename RAG_* env vars → REASONING_*, endpoint /rag → /reasoning,
type RAGResult → ReasoningResult, frontend feature flag wiring,
i18n strings, tests, docs (BREAKING — pre-1.0 surface, no external
consumers in production)
* 17 new tests: adapter unit tests with sys.modules stubs, OllamaProvider
httpx tests, R3 concurrent-host isolation, R6 multi-iteration trace
serialization, R13 Protocol conformance via isinstance
* E2E Karate scenario: nav-reasoning hidden when REASONING_ENABLED=false
* README — Live Reasoning section (env vars, archi, link to issue #26)
Bloc B — Security (audit 08, dev-only context)
* docker-compose.yml — DEV DEFAULTS header, OpenSearch DISABLE_SECURITY_PLUGIN
flagged as dev-only with link to OpenSearch security docs
* main.py — boot warning if NEO4J_URI is set with the default 'changeme'
password, so prod operators can't silently inherit it
Bloc C — DRY frontend (audit 05)
* shared/storage/keys.ts — STORAGE_KEYS centralised (theme, locale)
* features/settings/store.ts — dead apiUrl ref + orphan i18n keys removed
* api/schemas.py — DOCUMENT_STATUS_UPLOADED constant
Bloc D — Quality (audits 02/06/07/09/10/12)
* domain/ports.py — DocumentConverter.supports_page_batching property
(LSP fix, replaces isinstance(ServeConverter) check)
* domain/ports.py — VectorStore.ping() (encapsulation, replaces
_vector_store._client.info() reach-around)
* api/analyses.py + api/ingestion.py — path params {job_id} → {analysis_id}
aligned with the user-facing terminology (URLs unchanged)
* api/documents.py — Path.read_bytes() + generate_preview() wrapped in
asyncio.to_thread, unblocks the FastAPI event loop on /preview
* infra/docling_tree.py — PEP 604 union for isinstance (Ruff UP038)
* src/__tests__/integration/ — cross-feature integration test relocated
out of features/history/ so feature folders stay self-contained
* Tightened terminal `assert X is not None` checks (isinstance(.., datetime),
exact value comparisons)
Validation
* 446 backend pytest, 202 frontend vitest — all green
* ruff + ruff format + ESLint + Prettier + vue-tsc clean
* Re-audit verdict: 0 CRIT / 0 MAJ, score ~94/100, GO
Closes #200
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
"""Tests for `infra.llm.ollama_provider.OllamaProvider`.
|
|
|
|
Network is stubbed via `httpx` MockTransport so the tests don't depend on a
|
|
running Ollama instance.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import httpx
|
|
|
|
from domain.ports import LLMProvider
|
|
from domain.value_objects import LLMProviderType
|
|
from infra.llm.ollama_provider import OllamaProvider
|
|
|
|
if TYPE_CHECKING:
|
|
import pytest
|
|
|
|
|
|
def test_provider_satisfies_llmprovider_protocol() -> None:
|
|
"""R13 — `OllamaProvider` is structurally a `LLMProvider`."""
|
|
p = OllamaProvider(host="http://localhost:11434", default_model_id="m")
|
|
assert isinstance(p, LLMProvider)
|
|
|
|
|
|
def test_provider_exposes_type_host_default_model_id() -> None:
|
|
p = OllamaProvider(host="http://ollama:11434", default_model_id="gpt-oss:20b")
|
|
assert p.type is LLMProviderType.OLLAMA
|
|
assert p.host == "http://ollama:11434"
|
|
assert p.default_model_id == "gpt-oss:20b"
|
|
|
|
|
|
def test_host_trailing_slash_is_stripped() -> None:
|
|
p = OllamaProvider(host="http://localhost:11434/", default_model_id="m")
|
|
assert p.host == "http://localhost:11434"
|
|
|
|
|
|
def test_health_check_returns_true_on_200(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
assert request.url.path == "/api/tags"
|
|
return httpx.Response(200, json={"models": []})
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
real_get = httpx.get
|
|
|
|
def fake_get(url: str, **kwargs): # type: ignore[no-untyped-def]
|
|
with httpx.Client(transport=transport) as client:
|
|
return client.get(url, **kwargs)
|
|
|
|
monkeypatch.setattr(httpx, "get", fake_get)
|
|
p = OllamaProvider(host="http://localhost:11434", default_model_id="m")
|
|
assert p.health_check() is True
|
|
|
|
# Restore (defensive, MonkeyPatch handles it but explicit is fine)
|
|
monkeypatch.setattr(httpx, "get", real_get)
|
|
|
|
|
|
def test_health_check_returns_false_on_connection_error(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
def fake_get(url: str, **kwargs): # type: ignore[no-untyped-def]
|
|
raise httpx.ConnectError("connection refused")
|
|
|
|
monkeypatch.setattr(httpx, "get", fake_get)
|
|
p = OllamaProvider(host="http://nowhere:11434", default_model_id="m")
|
|
assert p.health_check() is False
|
|
|
|
|
|
def test_health_check_returns_false_on_non_200(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
return httpx.Response(500)
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
|
|
def fake_get(url: str, **kwargs): # type: ignore[no-untyped-def]
|
|
with httpx.Client(transport=transport) as client:
|
|
return client.get(url, **kwargs)
|
|
|
|
monkeypatch.setattr(httpx, "get", fake_get)
|
|
p = OllamaProvider(host="http://localhost:11434", default_model_id="m")
|
|
assert p.health_check() is False
|