haiku.rag/tests/sources/test_sources_base.py
Yiorgis Gozadinos ab19f78507
Move source adapters out of the ingester package
haiku.rag.ingester.sources was never ingester-only: one-shot client
ingestion resolves adapters through it (create_document_from_source), and
convert() now fetches through HTTPSource, so the core client imported into
the ingester package to reach them.

Move the package to haiku.rag.sources and update every import. No shims:
haiku.rag.ingester.sources is gone.

The haiku.rag.sources plugin entry-point group is unchanged, so third-party
source packages need no edit — the group name now matches the module path it
always implied.

Source unit tests move to tests/sources/. test_source_plugins.py stays in
tests/ingester/: it drives a PeriodicPoller against the job repo, so it is
plugin wiring through ingester machinery rather than a source test.
2026-08-20 11:46:55 +03:00

74 lines
1.8 KiB
Python

from datetime import UTC, datetime
from haiku.rag.sources.base import (
FetchResult,
Source,
SourceEvent,
SourceEventKind,
)
def test_source_event_kind_values():
assert SourceEventKind.UPSERT.value == "upsert"
assert SourceEventKind.DELETE.value == "delete"
assert SourceEventKind.UNCHANGED.value == "unchanged"
def test_source_event_round_trip():
event = SourceEvent(
source_id="fs:/tmp/docs",
uri="file:///tmp/docs/a.md",
kind=SourceEventKind.UPSERT,
revision="123456",
discovered_at=datetime(2026, 5, 20, 12, 0, 0, tzinfo=UTC),
)
raw = event.model_dump_json()
again = SourceEvent.model_validate_json(raw)
assert again == event
def test_fetch_result_round_trip():
result = FetchResult(
uri="file:///tmp/docs/a.md",
body=b"hello",
content_type="text/markdown",
content_hash="abcd1234",
revision="123456",
extra_metadata={"source": "fs"},
)
raw = result.model_dump_json()
again = FetchResult.model_validate_json(raw)
assert again == result
def test_fetch_result_defaults_extra_metadata_to_empty():
result = FetchResult(
uri="file:///tmp/docs/a.md",
body=b"x",
content_type="text/markdown",
content_hash="x",
revision=None,
)
assert result.extra_metadata == {}
def test_source_protocol_runtime_checkable():
class Dummy:
source_id = "dummy"
def supports(self, uri: str) -> bool:
return True
async def aclose(self) -> None:
pass
async def head(self, uri: str):
return None
async def fetch(self, uri: str):
raise NotImplementedError
def discover(self, since=None):
raise NotImplementedError
assert isinstance(Dummy(), Source)