generated from coulomb/repo-seed
first steps to better scanning of repos
This commit is contained in:
@@ -2,10 +2,12 @@ from repo_registry.content_indexing.extractor import ContentExtractor
|
||||
from repo_registry.core.models import ObservedFact
|
||||
|
||||
|
||||
def fact(id, kind, name, path="", line=None):
|
||||
def fact(id, kind, name, path="", line=None, source_role=""):
|
||||
metadata = {}
|
||||
if line is not None:
|
||||
metadata["line"] = line
|
||||
if source_role:
|
||||
metadata["source_role"] = source_role
|
||||
return ObservedFact(
|
||||
id=id,
|
||||
repository_id=1,
|
||||
@@ -82,3 +84,20 @@ def test_content_extractor_chunks_provider_related_config(tmp_path):
|
||||
assert len(chunks) == 1
|
||||
assert chunks[0].path == ".env.example"
|
||||
assert "OPENROUTER_API_KEY" in chunks[0].text
|
||||
|
||||
|
||||
def test_content_extractor_preserves_source_role_metadata(tmp_path):
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
(repo / "SCOPE.md").write_text("# SCOPE\n\nProvides OIDC.\n", encoding="utf-8")
|
||||
|
||||
chunks = ContentExtractor().extract(
|
||||
repo,
|
||||
[
|
||||
fact(1, "scope", "SCOPE", "SCOPE.md", source_role="scope_summary"),
|
||||
],
|
||||
)
|
||||
|
||||
assert len(chunks) == 1
|
||||
assert chunks[0].kind == "scope"
|
||||
assert chunks[0].metadata["source_role"] == "scope_summary"
|
||||
|
||||
@@ -42,6 +42,22 @@ def test_deterministic_scanner_extracts_structural_facts(tmp_path):
|
||||
assert languages == {"Python": 2}
|
||||
|
||||
|
||||
def test_scanner_records_scope_with_source_role(tmp_path):
|
||||
repo = tmp_path / "sample"
|
||||
repo.mkdir()
|
||||
(repo / "SCOPE.md").write_text(
|
||||
"# SCOPE\n\n## One-liner\n\nProvides OIDC profile enforcement.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = DeterministicScanner().scan(repo)
|
||||
|
||||
scope_fact = next(fact for fact in result.facts if fact.kind == "scope")
|
||||
assert scope_fact.name == "SCOPE"
|
||||
assert scope_fact.path == "SCOPE.md"
|
||||
assert scope_fact.metadata["source_role"] == "scope_summary"
|
||||
|
||||
|
||||
def test_scanner_readme_only_fixture_records_docs_without_interfaces(tmp_path):
|
||||
repo = write_readme_only_repo(tmp_path)
|
||||
|
||||
@@ -116,3 +132,28 @@ def test_scanner_records_llm_provider_and_fallback_facts(tmp_path):
|
||||
assert ("credential_config", "Anthropic API key", ".env.example") in facts
|
||||
assert ("provider_registry", "LLM provider registry", "providers.py") in facts
|
||||
assert ("fallback_policy", "LLM provider fallback policy", "README.md") in facts
|
||||
|
||||
|
||||
def test_scanner_does_not_treat_agent_guidance_as_llm_provider(tmp_path):
|
||||
repo = tmp_path / "key-cape-like"
|
||||
repo.mkdir()
|
||||
(repo / "README.md").write_text(
|
||||
"# KeyCape\n\n"
|
||||
"Backend adapters live in src/internal/adapters.\n\n"
|
||||
"See `CLAUDE.md` for agent session protocol.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(repo / "CLAUDE.md").write_text(
|
||||
"# CLAUDE.md\n\n"
|
||||
"This file provides guidance to Claude Code when working in this repo.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(repo / "src").mkdir()
|
||||
(repo / "src" / "go.mod").write_text("module keycape\n", encoding="utf-8")
|
||||
|
||||
result = DeterministicScanner().scan(repo)
|
||||
|
||||
facts = {(fact.kind, fact.name, fact.path) for fact in result.facts}
|
||||
assert ("llm_provider", "Claude", "CLAUDE.md") not in facts
|
||||
assert ("llm_provider", "Claude", "README.md") not in facts
|
||||
assert ("provider_registry", "LLM provider registry", "README.md") not in facts
|
||||
|
||||
Reference in New Issue
Block a user