Git ingestion part of Milestone 2

This commit is contained in:
2026-04-25 22:37:06 +02:00
parent 3d9032a386
commit ef41a9974a
8 changed files with 185 additions and 7 deletions

View File

@@ -0,0 +1,47 @@
import subprocess
from repo_registry.repo_ingestion.git import GitIngestionService
def run(command, cwd):
subprocess.run(command, cwd=cwd, check=True, capture_output=True, text=True)
def make_git_repo(path):
path.mkdir()
run(["git", "init", "-b", "main"], path)
run(["git", "config", "user.email", "tests@example.com"], path)
run(["git", "config", "user.name", "Tests"], path)
(path / "README.md").write_text("# Clone Me\n", encoding="utf-8")
(path / "app.py").write_text("print('ok')\n", encoding="utf-8")
run(["git", "add", "."], path)
run(["git", "commit", "-m", "initial"], path)
def test_ingestion_keeps_local_paths_local(tmp_path):
source = tmp_path / "source"
source.mkdir()
checkout = GitIngestionService(tmp_path / "checkouts").resolve(str(source))
assert checkout.source_path == source.resolve()
assert checkout.was_cloned is False
def test_ingestion_clones_file_url(tmp_path):
source = tmp_path / "source"
make_git_repo(source)
checkout = GitIngestionService(tmp_path / "checkouts").resolve(source.as_uri())
assert checkout.was_cloned is True
assert checkout.source_path != source.resolve()
assert (checkout.source_path / "README.md").exists()
branch = subprocess.run(
["git", "branch", "--show-current"],
cwd=checkout.source_path,
check=True,
capture_output=True,
text=True,
).stdout.strip()
assert branch == "main"

View File

@@ -1,11 +1,14 @@
import subprocess
from repo_registry.core.service import RegistryService
from repo_registry.repo_ingestion.git import GitIngestionService
from repo_registry.storage.sqlite import NotFoundError, RegistryStore
def make_service(tmp_path):
store = RegistryStore(tmp_path / "registry.sqlite3")
store.initialize()
return RegistryService(store)
return RegistryService(store, ingestion=GitIngestionService(tmp_path / "checkouts"))
def test_manual_registry_builds_ability_map(tmp_path):
@@ -144,3 +147,35 @@ def test_analyze_repository_failure_is_recorded(tmp_path):
assert summary.snapshot is None
assert "does not exist" in (summary.analysis_run.error_message or "")
assert service.get_repository(repository.id).status == "analysis_failed"
def test_analyze_repository_clones_git_url_before_scanning(tmp_path):
source = tmp_path / "git-source"
source.mkdir()
subprocess.run(["git", "init", "-b", "main"], cwd=source, check=True)
subprocess.run(
["git", "config", "user.email", "tests@example.com"],
cwd=source,
check=True,
)
subprocess.run(
["git", "config", "user.name", "Tests"],
cwd=source,
check=True,
)
(source / "README.md").write_text("# Git Source\n", encoding="utf-8")
(source / "requirements.txt").write_text("pytest\n", encoding="utf-8")
subprocess.run(["git", "add", "."], cwd=source, check=True)
subprocess.run(["git", "commit", "-m", "initial"], cwd=source, check=True)
service = make_service(tmp_path)
repository = service.register_repository(name="Git Source", url=source.as_uri())
summary = service.analyze_repository(repository.id)
assert summary.analysis_run.status == "completed"
assert summary.snapshot is not None
assert str(tmp_path / "checkouts") in summary.snapshot.source_path
fact_names = {(fact.kind, fact.name, fact.path) for fact in summary.facts}
assert ("documentation", "README", "README.md") in fact_names
assert ("framework", "pytest", "requirements.txt") in fact_names

View File

@@ -5,7 +5,10 @@ from repo_registry.web_api.app import Settings, app, get_settings
def test_api_manual_registry_loop(tmp_path):
def override_settings():
return Settings(database_path=str(tmp_path / "api.sqlite3"))
return Settings(
database_path=str(tmp_path / "api.sqlite3"),
checkout_root=str(tmp_path / "checkouts"),
)
app.dependency_overrides[get_settings] = override_settings
client = TestClient(app)
@@ -79,7 +82,10 @@ def test_api_analysis_run_loop(tmp_path):
)
def override_settings():
return Settings(database_path=str(tmp_path / "api-analysis.sqlite3"))
return Settings(
database_path=str(tmp_path / "api-analysis.sqlite3"),
checkout_root=str(tmp_path / "api-checkouts"),
)
app.dependency_overrides[get_settings] = override_settings
client = TestClient(app)