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,99 @@
"""Integration tests against real local Git object databases."""
from __future__ import annotations
import shutil
import subprocess
from pathlib import Path
from uuid import uuid4
import pytest
from ragcore.domain.sources import GitSourceConfig
from ragcore.infrastructure.connectors.git import GitConnector
def git(root: Path, *arguments: str) -> str:
git_executable = shutil.which("git")
if git_executable is None:
raise RuntimeError("git is required for this integration test")
result = subprocess.run( # noqa: S603 - test arguments are passed without a shell
[git_executable, *arguments],
cwd=root,
check=True,
capture_output=True,
text=True,
)
return result.stdout.strip()
def repository(tmp_path: Path) -> tuple[Path, str]:
root = tmp_path / "repository"
root.mkdir()
git(root, "init", "--quiet")
git(root, "config", "user.email", "tests@example.invalid")
git(root, "config", "user.name", "RAGCore Tests")
(root / "README.md").write_text("read me", encoding="utf-8")
(root / "src").mkdir()
(root / "src" / "main.py").write_text("print('safe')\n", encoding="utf-8")
git(root, "add", "README.md", "src/main.py")
git(root, "commit", "--quiet", "-m", "initial")
return root, git(root, "rev-parse", "HEAD")
def make_connector(root: Path, commit: str, *, max_items: int = 256) -> GitConnector:
return GitConnector(
uuid4(),
GitSourceConfig("local-checkout", commit, root.resolve()),
allowed_roots=(root.resolve(),),
max_items=max_items,
)
@pytest.mark.integration
@pytest.mark.anyio
async def test_scan_and_acquire_store_commit_path_and_language_provenance(
tmp_path: Path,
) -> None:
root, commit = repository(tmp_path)
current = make_connector(root, commit)
result = await current.scan()
item = next(item for item in result.items if item.locator == "src/main.py")
acquisition = await current.acquire(item)
assert result.complete is True
assert item.external_id == f"{commit}:src/main.py"
assert item.metadata["commit"] == commit
assert item.metadata["path"] == "src/main.py"
assert item.metadata["language"] == "python"
assert b"".join([chunk async for chunk in acquisition.stream]) == b"print('safe')\n"
assert acquisition.fingerprint == current.fingerprint(item)
@pytest.mark.integration
@pytest.mark.anyio
async def test_same_pinned_commit_scan_is_idempotent_and_cursorable(tmp_path: Path) -> None:
root, commit = repository(tmp_path)
current = make_connector(root, commit, max_items=1)
first = await current.scan()
second = await current.scan()
assert first == second
assert first.complete is False
assert first.next_cursor is not None
remainder = await current.scan(first.next_cursor)
assert remainder.complete is False
assert remainder.next_cursor is None
assert all(item.external_id.startswith(f"{commit}:") for item in remainder.items)
(root / "src" / "second.py").write_text("value = 2\n", encoding="utf-8")
git(root, "add", "src/second.py")
git(root, "commit", "--quiet", "-m", "second")
latest = git(root, "rev-parse", "HEAD")
old_scan = await current.scan()
latest_scan = await make_connector(root, latest).scan()
assert all(item.metadata["commit"] == commit for item in old_scan.items)
assert all(item.metadata["commit"] == latest for item in latest_scan.items)
assert any(item.locator == "src/second.py" for item in latest_scan.items)