generated from coulomb/repo-seed
improved scanner
This commit is contained in:
@@ -2,7 +2,7 @@ from repo_registry.candidate_graph.generator import CandidateGraphGenerator
|
||||
from repo_registry.core.models import ContentChunk, ObservedFact, Repository
|
||||
|
||||
|
||||
def fact(id, kind, name, path="", value=""):
|
||||
def fact(id, kind, name, path="", value="", metadata=None):
|
||||
return ObservedFact(
|
||||
id=id,
|
||||
repository_id=1,
|
||||
@@ -12,7 +12,7 @@ def fact(id, kind, name, path="", value=""):
|
||||
path=path,
|
||||
name=name,
|
||||
value=value,
|
||||
metadata={},
|
||||
metadata=metadata or {},
|
||||
)
|
||||
|
||||
|
||||
@@ -310,11 +310,44 @@ def test_candidate_generator_maps_llm_provider_facts_to_capability():
|
||||
)
|
||||
facts = [
|
||||
fact(1, "documentation", "README", "README.md"),
|
||||
fact(2, "llm_provider", "OpenRouter", "providers.py", "openrouter"),
|
||||
fact(3, "llm_provider", "Claude", "providers.py", "claude"),
|
||||
fact(4, "credential_config", "OpenRouter API key", ".env.example", "OPENROUTER_API_KEY"),
|
||||
fact(5, "provider_registry", "LLM provider registry", "providers.py"),
|
||||
fact(6, "fallback_policy", "LLM provider fallback policy", "providers.py"),
|
||||
fact(
|
||||
2,
|
||||
"llm_provider",
|
||||
"OpenRouter",
|
||||
"providers.py",
|
||||
"openrouter",
|
||||
{"source_role": "implementation_source", "utility_relationship": "adapter"},
|
||||
),
|
||||
fact(
|
||||
3,
|
||||
"llm_provider",
|
||||
"Claude",
|
||||
"providers.py",
|
||||
"claude",
|
||||
{"source_role": "implementation_source", "utility_relationship": "adapter"},
|
||||
),
|
||||
fact(
|
||||
4,
|
||||
"credential_config",
|
||||
"OpenRouter API key",
|
||||
".env.example",
|
||||
"OPENROUTER_API_KEY",
|
||||
{"source_role": "configuration", "utility_relationship": "configure"},
|
||||
),
|
||||
fact(
|
||||
5,
|
||||
"provider_registry",
|
||||
"LLM provider registry",
|
||||
"providers.py",
|
||||
metadata={"source_role": "implementation_source", "utility_relationship": "adapter"},
|
||||
),
|
||||
fact(
|
||||
6,
|
||||
"fallback_policy",
|
||||
"LLM provider fallback policy",
|
||||
"providers.py",
|
||||
metadata={"source_role": "implementation_source", "utility_relationship": "adapter"},
|
||||
),
|
||||
]
|
||||
|
||||
graph = CandidateGraphGenerator().generate(repository, facts)
|
||||
@@ -329,6 +362,7 @@ def test_candidate_generator_maps_llm_provider_facts_to_capability():
|
||||
assert {"llm-provider", "openrouter", "claude", "fallback-policy"} <= set(
|
||||
capability.attributes
|
||||
)
|
||||
assert {"utility-adapter", "utility-configure"} <= set(capability.attributes)
|
||||
feature_names = {feature.name for feature in capability.features}
|
||||
assert {"Use OpenRouter Models", "Use Claude Models"} <= feature_names
|
||||
assert "Configure LLM Provider Credentials" in feature_names
|
||||
@@ -338,4 +372,34 @@ def test_candidate_generator_maps_llm_provider_facts_to_capability():
|
||||
feature for feature in capability.features if feature.name == "Use OpenRouter Models"
|
||||
)
|
||||
assert openrouter_feature.primary_class == "integration"
|
||||
|
||||
|
||||
def test_candidate_generator_does_not_promote_llm_provider_mentions_to_capability():
|
||||
repository = Repository(
|
||||
id=1,
|
||||
name="MentionOnly",
|
||||
url="/tmp/mention-only",
|
||||
description=None,
|
||||
branch="main",
|
||||
status="analyzed",
|
||||
)
|
||||
facts = [
|
||||
fact(1, "documentation", "README", "README.md"),
|
||||
fact(
|
||||
2,
|
||||
"llm_provider",
|
||||
"Claude",
|
||||
"README.md",
|
||||
"claude",
|
||||
{"source_role": "product_documentation", "utility_relationship": "mention"},
|
||||
),
|
||||
]
|
||||
|
||||
graph = CandidateGraphGenerator().generate(repository, facts)
|
||||
|
||||
assert [
|
||||
capability.name
|
||||
for capability in graph[0].capabilities
|
||||
if capability.name == "Route LLM Requests Across Providers"
|
||||
] == []
|
||||
assert {"llm-provider", "openrouter"} <= set(openrouter_feature.attributes)
|
||||
|
||||
@@ -142,6 +142,20 @@ def test_scanner_records_llm_provider_and_fallback_facts(tmp_path):
|
||||
assert ("provider_registry", "LLM provider registry", "providers.py") in facts
|
||||
assert ("fallback_policy", "LLM provider fallback policy", "README.md") in facts
|
||||
|
||||
by_key = {(fact.kind, fact.name, fact.path): fact for fact in result.facts}
|
||||
assert by_key[("llm_provider", "OpenRouter", "README.md")].metadata[
|
||||
"utility_relationship"
|
||||
] == "mention"
|
||||
assert by_key[("llm_provider", "OpenRouter", "providers.py")].metadata[
|
||||
"utility_relationship"
|
||||
] == "adapter"
|
||||
assert by_key[("credential_config", "OpenRouter API key", ".env.example")].metadata[
|
||||
"utility_relationship"
|
||||
] == "configure"
|
||||
assert by_key[("provider_registry", "LLM provider registry", "providers.py")].metadata[
|
||||
"utility_relationship"
|
||||
] == "adapter"
|
||||
|
||||
|
||||
def test_scanner_does_not_treat_agent_guidance_as_llm_provider(tmp_path):
|
||||
repo = tmp_path / "key-cape-like"
|
||||
|
||||
Reference in New Issue
Block a user