generated from coulomb/repo-seed
first content-indexing slice
This commit is contained in:
67
tests/test_content_indexing.py
Normal file
67
tests/test_content_indexing.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from repo_registry.content_indexing.extractor import ContentExtractor
|
||||
from repo_registry.core.models import ObservedFact
|
||||
|
||||
|
||||
def fact(id, kind, name, path="", line=None):
|
||||
metadata = {}
|
||||
if line is not None:
|
||||
metadata["line"] = line
|
||||
return ObservedFact(
|
||||
id=id,
|
||||
repository_id=1,
|
||||
analysis_run_id=1,
|
||||
snapshot_id=1,
|
||||
kind=kind,
|
||||
path=path,
|
||||
name=name,
|
||||
value="",
|
||||
metadata=metadata,
|
||||
)
|
||||
|
||||
|
||||
def test_content_extractor_chunks_docs_and_interface_line_ranges(tmp_path):
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
(repo / "README.md").write_text(
|
||||
"\n".join(f"readme line {number}" for number in range(1, 46)),
|
||||
encoding="utf-8",
|
||||
)
|
||||
(repo / "app.py").write_text(
|
||||
"\n".join(f"line {number}" for number in range(1, 21)),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
chunks = ContentExtractor().extract(
|
||||
repo,
|
||||
[
|
||||
fact(1, "documentation", "README", "README.md"),
|
||||
fact(2, "interface", "python route decorator", "app.py", line=10),
|
||||
],
|
||||
)
|
||||
|
||||
readme_chunks = [chunk for chunk in chunks if chunk.path == "README.md"]
|
||||
interface_chunks = [chunk for chunk in chunks if chunk.path == "app.py"]
|
||||
assert [(chunk.start_line, chunk.end_line) for chunk in readme_chunks] == [
|
||||
(1, 40),
|
||||
(41, 45),
|
||||
]
|
||||
assert len(interface_chunks) == 1
|
||||
assert interface_chunks[0].start_line == 5
|
||||
assert interface_chunks[0].end_line == 20
|
||||
assert "line 10" in interface_chunks[0].text
|
||||
|
||||
|
||||
def test_content_extractor_ignores_unindexed_and_missing_paths(tmp_path):
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
(repo / "README.md").write_text("# ok\n", encoding="utf-8")
|
||||
|
||||
chunks = ContentExtractor().extract(
|
||||
repo,
|
||||
[
|
||||
fact(1, "language", "Python"),
|
||||
fact(2, "documentation", "missing", "missing.md"),
|
||||
],
|
||||
)
|
||||
|
||||
assert chunks == []
|
||||
@@ -343,6 +343,11 @@ def test_analyze_repository_records_snapshot_and_observed_facts(tmp_path):
|
||||
assert ("documentation", "README", "README.md") in fact_names
|
||||
assert ("framework", "FastAPI", "requirements.txt") in fact_names
|
||||
assert ("interface", "python route decorator", "app.py") in fact_names
|
||||
chunks = service.list_content_chunks(repository.id, summary.analysis_run.id)
|
||||
chunk_sources = {(chunk.kind, chunk.path) for chunk in chunks}
|
||||
assert ("documentation", "README.md") in chunk_sources
|
||||
assert ("manifest", "requirements.txt") in chunk_sources
|
||||
assert ("interface", "app.py") in chunk_sources
|
||||
|
||||
candidate_graph = service.candidate_graph(repository.id, summary.analysis_run.id)
|
||||
assert candidate_graph.repository.name == "Example"
|
||||
|
||||
@@ -25,9 +25,16 @@ def test_initialize_is_idempotent_and_applies_expected_columns(tmp_path):
|
||||
evidence_columns = {
|
||||
row[1] for row in connection.execute("PRAGMA table_info(approved_evidence)")
|
||||
}
|
||||
tables = {
|
||||
row[0]
|
||||
for row in connection.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type = 'table'"
|
||||
)
|
||||
}
|
||||
|
||||
assert "source_refs" in feature_columns
|
||||
assert "source_refs" in evidence_columns
|
||||
assert "content_chunks" in tables
|
||||
|
||||
|
||||
def test_delete_repository_cascades_registry_and_review_rows(tmp_path):
|
||||
@@ -72,6 +79,7 @@ def test_delete_repository_cascades_registry_and_review_rows(tmp_path):
|
||||
"approved_features",
|
||||
"approved_evidence",
|
||||
"analysis_runs",
|
||||
"content_chunks",
|
||||
"review_decisions",
|
||||
):
|
||||
count = connection.execute(f"SELECT COUNT(*) FROM {table}").fetchone()[0]
|
||||
|
||||
@@ -320,6 +320,15 @@ def test_api_analysis_run_loop(tmp_path):
|
||||
assert ("documentation", "README", "README.md") in fact_names
|
||||
assert ("framework", "React", "package.json") in fact_names
|
||||
assert ("framework", "Vite", "package.json") in fact_names
|
||||
|
||||
chunks_response = client.get(
|
||||
f"/repos/{repository_id}/analysis-runs/"
|
||||
f"{run['analysis_run']['id']}/content-chunks"
|
||||
)
|
||||
assert chunks_response.status_code == 200
|
||||
assert {
|
||||
(chunk["kind"], chunk["path"]) for chunk in chunks_response.json()
|
||||
} >= {("documentation", "README.md"), ("manifest", "package.json")}
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
@@ -392,6 +401,8 @@ def test_ui_register_analyze_and_approve_loop(tmp_path):
|
||||
run_detail = client.get(run_path)
|
||||
assert run_detail.status_code == 200
|
||||
assert "Candidate Graph" in run_detail.text
|
||||
assert "Content Chunks" in run_detail.text
|
||||
assert "README.md:1-1" in run_detail.text
|
||||
assert "ID " in run_detail.text
|
||||
assert "No review decisions yet." in run_detail.text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user