generated from coulomb/repo-seed
first usable curator UI
This commit is contained in:
@@ -6,7 +6,7 @@ The Repository Ability Registry maps repositories from usefulness to implementat
|
||||
Ability -> Capability -> Feature -> Evidence -> Code location
|
||||
```
|
||||
|
||||
The first implementation slice is a Python registry core plus FastAPI HTTP API for manual repository profiles. It deliberately separates the manual/canonical registry path from the later analyzer pipeline.
|
||||
The first implementation slice is a Python registry core plus FastAPI HTTP API and a small curator UI. Repository registration imports basic metadata from the repository itself, then analysis builds observed facts and candidate review entries.
|
||||
|
||||
## Local Development
|
||||
|
||||
@@ -37,10 +37,10 @@ The API creates a local SQLite database at `var/repo-registry.sqlite3` by defaul
|
||||
```bash
|
||||
curl -X POST http://127.0.0.1:8000/repos \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"name":"MailRouter","url":"https://example.com/mail-router.git"}'
|
||||
-d '{"url":"https://example.com/mail-router.git"}'
|
||||
```
|
||||
|
||||
Then add abilities, capabilities, features, and evidence under that repository and inspect:
|
||||
The registry imports name and description from `pyproject.toml`, `package.json`, or README where possible. Then add abilities, capabilities, features, and evidence under that repository and inspect:
|
||||
|
||||
```bash
|
||||
curl http://127.0.0.1:8000/repos/1/ability-map
|
||||
|
||||
@@ -10,6 +10,7 @@ readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"fastapi>=0.115",
|
||||
"python-multipart>=0.0.20",
|
||||
"uvicorn[standard]>=0.30",
|
||||
"pydantic-settings>=2.4",
|
||||
]
|
||||
|
||||
@@ -13,6 +13,7 @@ from repo_registry.core.models import (
|
||||
)
|
||||
from repo_registry.candidate_graph.generator import CandidateGraphGenerator
|
||||
from repo_registry.repo_ingestion.git import GitIngestionService
|
||||
from repo_registry.repo_ingestion.metadata import RepositoryMetadataExtractor
|
||||
from repo_registry.repo_scanning.scanner import DeterministicScanner
|
||||
from repo_registry.storage.sqlite import RegistryStore
|
||||
|
||||
@@ -28,20 +29,27 @@ class RegistryService:
|
||||
self.store = store
|
||||
self.scanner = DeterministicScanner()
|
||||
self.ingestion = ingestion or GitIngestionService()
|
||||
self.metadata_extractor = RepositoryMetadataExtractor()
|
||||
self.candidate_generator = CandidateGraphGenerator()
|
||||
|
||||
def register_repository(
|
||||
self,
|
||||
*,
|
||||
name: str,
|
||||
url: str,
|
||||
name: str | None = None,
|
||||
description: str | None = None,
|
||||
branch: str = "main",
|
||||
) -> Repository:
|
||||
if name is None or description is None:
|
||||
checkout = self.ingestion.resolve(url, branch=branch)
|
||||
metadata = self.metadata_extractor.extract(checkout.source_path, url)
|
||||
else:
|
||||
metadata = None
|
||||
return self.store.create_repository(
|
||||
name=name,
|
||||
name=name or (metadata.name if metadata is not None else "repository"),
|
||||
url=url,
|
||||
description=description,
|
||||
description=description
|
||||
or (metadata.description if metadata is not None else None),
|
||||
branch=branch,
|
||||
)
|
||||
|
||||
|
||||
86
src/repo_registry/repo_ingestion/metadata.py
Normal file
86
src/repo_registry/repo_ingestion/metadata.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import tomllib
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RepositoryMetadata:
|
||||
name: str
|
||||
description: str | None
|
||||
|
||||
|
||||
class RepositoryMetadataExtractor:
|
||||
def extract(self, source_path: str | Path, url: str) -> RepositoryMetadata:
|
||||
root = Path(source_path)
|
||||
pyproject = self._from_pyproject(root)
|
||||
package = self._from_package_json(root)
|
||||
readme = self._from_readme(root)
|
||||
fallback_name = self._name_from_url_or_path(url)
|
||||
|
||||
return RepositoryMetadata(
|
||||
name=pyproject.name or package.name or readme.name or fallback_name,
|
||||
description=(
|
||||
pyproject.description
|
||||
or package.description
|
||||
or readme.description
|
||||
),
|
||||
)
|
||||
|
||||
def _from_pyproject(self, root: Path) -> RepositoryMetadata:
|
||||
path = root / "pyproject.toml"
|
||||
if not path.exists():
|
||||
return RepositoryMetadata(name="", description=None)
|
||||
try:
|
||||
project = tomllib.loads(path.read_text(encoding="utf-8")).get("project", {})
|
||||
except (OSError, tomllib.TOMLDecodeError):
|
||||
return RepositoryMetadata(name="", description=None)
|
||||
return RepositoryMetadata(
|
||||
name=str(project.get("name") or ""),
|
||||
description=project.get("description"),
|
||||
)
|
||||
|
||||
def _from_package_json(self, root: Path) -> RepositoryMetadata:
|
||||
path = root / "package.json"
|
||||
if not path.exists():
|
||||
return RepositoryMetadata(name="", description=None)
|
||||
try:
|
||||
package = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError):
|
||||
return RepositoryMetadata(name="", description=None)
|
||||
return RepositoryMetadata(
|
||||
name=str(package.get("name") or ""),
|
||||
description=package.get("description"),
|
||||
)
|
||||
|
||||
def _from_readme(self, root: Path) -> RepositoryMetadata:
|
||||
for readme in sorted(root.glob("README*")):
|
||||
if not readme.is_file():
|
||||
continue
|
||||
try:
|
||||
lines = readme.read_text(encoding="utf-8", errors="ignore").splitlines()
|
||||
except OSError:
|
||||
continue
|
||||
title = ""
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
cleaned = stripped.strip("#").strip()
|
||||
if stripped.startswith("#") and cleaned and not title:
|
||||
title = cleaned
|
||||
continue
|
||||
if cleaned:
|
||||
return RepositoryMetadata(name=title, description=cleaned)
|
||||
if title:
|
||||
return RepositoryMetadata(name=title, description=None)
|
||||
return RepositoryMetadata(name="", description=None)
|
||||
|
||||
def _name_from_url_or_path(self, value: str) -> str:
|
||||
parsed = urlparse(value)
|
||||
path = parsed.path if parsed.scheme else value
|
||||
name = Path(path.rstrip("/")).name or "repository"
|
||||
if name.endswith(".git"):
|
||||
name = name[:-4]
|
||||
return name or "repository"
|
||||
@@ -29,8 +29,8 @@ def get_service(settings: Settings = Depends(get_settings)) -> RegistryService:
|
||||
|
||||
|
||||
class RepositoryCreate(BaseModel):
|
||||
name: str
|
||||
url: str
|
||||
name: str | None = None
|
||||
description: str | None = None
|
||||
branch: str = "main"
|
||||
|
||||
@@ -76,6 +76,11 @@ class CandidateGraphApproval(BaseModel):
|
||||
app = FastAPI(title="Repository Ability Registry", version="0.1.0")
|
||||
|
||||
|
||||
from repo_registry.web_ui.views import router as ui_router
|
||||
|
||||
app.include_router(ui_router)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health() -> dict[str, str]:
|
||||
return {"status": "ok"}
|
||||
@@ -88,7 +93,7 @@ def create_repository(
|
||||
) -> dict[str, object]:
|
||||
try:
|
||||
repository = service.register_repository(**payload.model_dump())
|
||||
except ValueError as exc:
|
||||
except (RuntimeError, ValueError) as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
return asdict(repository)
|
||||
|
||||
|
||||
1
src/repo_registry/web_ui/__init__.py
Normal file
1
src/repo_registry/web_ui/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Small server-rendered curator UI."""
|
||||
403
src/repo_registry/web_ui/views.py
Normal file
403
src/repo_registry/web_ui/views.py
Normal file
@@ -0,0 +1,403 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from html import escape
|
||||
|
||||
from fastapi import APIRouter, Depends, Form
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
|
||||
from repo_registry.core.service import RegistryService
|
||||
from repo_registry.web_api.app import get_service
|
||||
|
||||
|
||||
router = APIRouter(include_in_schema=False)
|
||||
|
||||
|
||||
def page(title: str, body: str) -> HTMLResponse:
|
||||
return HTMLResponse(
|
||||
f"""
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{escape(title)} · Repository Ability Registry</title>
|
||||
<style>
|
||||
:root {{
|
||||
color-scheme: light;
|
||||
--bg: #f7f8fa;
|
||||
--panel: #ffffff;
|
||||
--text: #1f2933;
|
||||
--muted: #637381;
|
||||
--line: #d9dee7;
|
||||
--accent: #0f766e;
|
||||
--accent-dark: #115e59;
|
||||
--warn: #9a3412;
|
||||
}}
|
||||
* {{ box-sizing: border-box; }}
|
||||
body {{
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
}}
|
||||
header {{
|
||||
background: #17212b;
|
||||
color: #fff;
|
||||
padding: 14px 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}}
|
||||
header a {{ color: #e6fffb; text-decoration: none; }}
|
||||
main {{ max-width: 1180px; margin: 0 auto; padding: 24px; }}
|
||||
h1 {{ font-size: 24px; margin: 0 0 18px; }}
|
||||
h2 {{ font-size: 18px; margin: 28px 0 10px; }}
|
||||
h3 {{ font-size: 15px; margin: 16px 0 6px; }}
|
||||
p {{ margin: 0 0 10px; }}
|
||||
a {{ color: var(--accent-dark); }}
|
||||
.grid {{ display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }}
|
||||
.panel {{
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
}}
|
||||
.stack {{ display: grid; gap: 12px; }}
|
||||
.muted {{ color: var(--muted); }}
|
||||
.pill {{
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 999px;
|
||||
color: var(--muted);
|
||||
background: #fbfcfd;
|
||||
font-size: 12px;
|
||||
}}
|
||||
table {{ width: 100%; border-collapse: collapse; background: var(--panel); }}
|
||||
th, td {{ text-align: left; border-bottom: 1px solid var(--line); padding: 10px 8px; vertical-align: top; }}
|
||||
th {{ color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }}
|
||||
input, textarea {{
|
||||
width: 100%;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
padding: 9px 10px;
|
||||
font: inherit;
|
||||
}}
|
||||
label {{ display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }}
|
||||
button, .button {{
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 34px;
|
||||
padding: 7px 12px;
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: 6px;
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
font: inherit;
|
||||
font-weight: 650;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}}
|
||||
.button.secondary, button.secondary {{
|
||||
color: var(--accent-dark);
|
||||
background: white;
|
||||
}}
|
||||
.tree ul {{ margin: 8px 0 0 20px; padding: 0; }}
|
||||
.tree li {{ margin: 6px 0; }}
|
||||
.source {{ color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }}
|
||||
.actions {{ display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }}
|
||||
@media (max-width: 780px) {{
|
||||
header {{ padding: 12px 16px; }}
|
||||
main {{ padding: 16px; }}
|
||||
.grid {{ grid-template-columns: 1fr; }}
|
||||
table, tbody, tr, td {{ display: block; width: 100%; }}
|
||||
thead {{ display: none; }}
|
||||
td {{ border-bottom: 0; padding: 6px 0; }}
|
||||
tr {{ border-bottom: 1px solid var(--line); padding: 10px 0; display: block; }}
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<a href="/ui"><strong>Repository Ability Registry</strong></a>
|
||||
<a href="/docs">API Docs</a>
|
||||
</header>
|
||||
<main>{body}</main>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
@router.get("/ui")
|
||||
def repository_index(service: RegistryService = Depends(get_service)) -> HTMLResponse:
|
||||
repositories = service.list_repositories()
|
||||
rows = "\n".join(
|
||||
f"""
|
||||
<tr>
|
||||
<td><a href="/ui/repos/{repo.id}">{escape(repo.name)}</a></td>
|
||||
<td><span class="pill">{escape(repo.status)}</span></td>
|
||||
<td class="source">{escape(repo.branch)}</td>
|
||||
<td class="source">{escape(repo.url)}</td>
|
||||
</tr>
|
||||
"""
|
||||
for repo in repositories
|
||||
)
|
||||
body = f"""
|
||||
<h1>Repositories</h1>
|
||||
<div class="grid">
|
||||
<section class="panel">
|
||||
<h2>Register Repository</h2>
|
||||
<form class="stack" method="post" action="/ui/repos">
|
||||
<label>Git URL or local path <input name="url" required></label>
|
||||
<label>Branch <input name="branch" value="main"></label>
|
||||
<button type="submit">Register</button>
|
||||
</form>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<h2>Registry</h2>
|
||||
<table>
|
||||
<thead><tr><th>Name</th><th>Status</th><th>Branch</th><th>Source</th></tr></thead>
|
||||
<tbody>{rows or '<tr><td colspan="4" class="muted">No repositories yet.</td></tr>'}</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</div>
|
||||
"""
|
||||
return page("Repositories", body)
|
||||
|
||||
|
||||
@router.post("/ui/repos")
|
||||
def create_repository_from_form(
|
||||
url: str = Form(...),
|
||||
branch: str = Form("main"),
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> RedirectResponse:
|
||||
repository = service.register_repository(
|
||||
url=url,
|
||||
branch=branch or "main",
|
||||
)
|
||||
return RedirectResponse(f"/ui/repos/{repository.id}", status_code=303)
|
||||
|
||||
|
||||
@router.get("/ui/repos/{repository_id}")
|
||||
def repository_detail(
|
||||
repository_id: int,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> HTMLResponse:
|
||||
repository = service.get_repository(repository_id)
|
||||
runs = service.list_analysis_runs(repository_id)
|
||||
ability_map = service.ability_map(repository_id)
|
||||
run_rows = "\n".join(
|
||||
f"""
|
||||
<tr>
|
||||
<td><a href="/ui/repos/{repository_id}/analysis-runs/{run.id}">#{run.id}</a></td>
|
||||
<td><span class="pill">{escape(run.status)}</span></td>
|
||||
<td class="source">{escape(run.started_at)}</td>
|
||||
<td>{escape(run.error_message or '')}</td>
|
||||
</tr>
|
||||
"""
|
||||
for run in runs
|
||||
)
|
||||
body = f"""
|
||||
<div class="actions">
|
||||
<h1 style="margin-right:auto">{escape(repository.name)}</h1>
|
||||
<a class="button secondary" href="/ui">Back</a>
|
||||
</div>
|
||||
<p class="muted">{escape(repository.description or '')}</p>
|
||||
<p><span class="pill">{escape(repository.status)}</span> <span class="source">{escape(repository.url)}</span></p>
|
||||
<div class="grid">
|
||||
<section class="panel">
|
||||
<h2>Run Analysis</h2>
|
||||
<form class="stack" method="post" action="/ui/repos/{repository_id}/analysis-runs">
|
||||
<label>Override source path <input name="source_path" placeholder="Optional local path"></label>
|
||||
<button type="submit">Analyze</button>
|
||||
</form>
|
||||
<h2>Analysis Runs</h2>
|
||||
<table>
|
||||
<thead><tr><th>Run</th><th>Status</th><th>Started</th><th>Error</th></tr></thead>
|
||||
<tbody>{run_rows or '<tr><td colspan="4" class="muted">No runs yet.</td></tr>'}</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<h2>Approved Ability Map</h2>
|
||||
{render_ability_map(asdict(ability_map))}
|
||||
</section>
|
||||
</div>
|
||||
"""
|
||||
return page(repository.name, body)
|
||||
|
||||
|
||||
@router.post("/ui/repos/{repository_id}/analysis-runs")
|
||||
def create_analysis_run_from_form(
|
||||
repository_id: int,
|
||||
source_path: str = Form(""),
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> RedirectResponse:
|
||||
summary = service.analyze_repository(
|
||||
repository_id,
|
||||
source_path=source_path or None,
|
||||
)
|
||||
return RedirectResponse(
|
||||
f"/ui/repos/{repository_id}/analysis-runs/{summary.analysis_run.id}",
|
||||
status_code=303,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}")
|
||||
def analysis_run_detail(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> HTMLResponse:
|
||||
repository = service.get_repository(repository_id)
|
||||
candidate_graph = service.candidate_graph(repository_id, analysis_run_id)
|
||||
facts = service.list_observed_facts(repository_id, analysis_run_id)
|
||||
fact_rows = "\n".join(
|
||||
f"""
|
||||
<tr>
|
||||
<td>{escape(fact.kind)}</td>
|
||||
<td>{escape(fact.name)}</td>
|
||||
<td class="source">{escape(fact.path)}</td>
|
||||
<td class="source">{escape(fact.value)}</td>
|
||||
</tr>
|
||||
"""
|
||||
for fact in facts
|
||||
)
|
||||
body = f"""
|
||||
<div class="actions">
|
||||
<h1 style="margin-right:auto">{escape(repository.name)} · Run #{analysis_run_id}</h1>
|
||||
<a class="button secondary" href="/ui/repos/{repository_id}">Repository</a>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<section class="panel">
|
||||
<div class="actions">
|
||||
<h2 style="margin-right:auto">Candidate Graph</h2>
|
||||
<form method="post" action="/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}/candidate-graph/approve">
|
||||
<button type="submit">Approve</button>
|
||||
</form>
|
||||
</div>
|
||||
{render_candidate_graph(asdict(candidate_graph))}
|
||||
</section>
|
||||
<section class="panel">
|
||||
<h2>Observed Facts</h2>
|
||||
<table>
|
||||
<thead><tr><th>Kind</th><th>Name</th><th>Path</th><th>Value</th></tr></thead>
|
||||
<tbody>{fact_rows or '<tr><td colspan="4" class="muted">No observed facts.</td></tr>'}</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</div>
|
||||
"""
|
||||
return page(f"{repository.name} Run {analysis_run_id}", body)
|
||||
|
||||
|
||||
@router.post("/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}/candidate-graph/approve")
|
||||
def approve_candidate_graph_from_form(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> RedirectResponse:
|
||||
service.approve_candidate_graph(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
notes="Approved from web UI",
|
||||
)
|
||||
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
||||
|
||||
|
||||
def render_candidate_graph(graph: dict) -> str:
|
||||
abilities = graph.get("abilities", [])
|
||||
if not abilities:
|
||||
return '<p class="muted">No candidates generated.</p>'
|
||||
items = []
|
||||
for ability in abilities:
|
||||
capabilities = "".join(render_candidate_capability(capability) for capability in ability["capabilities"])
|
||||
items.append(
|
||||
f"""
|
||||
<li>
|
||||
<strong>{escape(ability['name'])}</strong>
|
||||
<span class="pill">{escape(ability['status'])}</span>
|
||||
<span class="pill">{ability['confidence']:.2f}</span>
|
||||
<p class="muted">{escape(ability['description'])}</p>
|
||||
{render_sources(ability['source_refs'])}
|
||||
<ul>{capabilities}</ul>
|
||||
</li>
|
||||
"""
|
||||
)
|
||||
return f'<div class="tree"><ul>{"".join(items)}</ul></div>'
|
||||
|
||||
|
||||
def render_candidate_capability(capability: dict) -> str:
|
||||
features = "".join(
|
||||
f'<li>{escape(feature["name"])} <span class="pill">{escape(feature["type"])}</span> <span class="source">{escape(feature["location"])}</span></li>'
|
||||
for feature in capability["features"]
|
||||
)
|
||||
evidence = "".join(
|
||||
f'<li>{escape(item["type"])} <span class="pill">{escape(item["strength"])}</span> <span class="source">{escape(item["reference"])}</span></li>'
|
||||
for item in capability["evidence"]
|
||||
)
|
||||
return f"""
|
||||
<li>
|
||||
<strong>{escape(capability['name'])}</strong>
|
||||
<span class="pill">{escape(capability['status'])}</span>
|
||||
<span class="pill">{capability['confidence']:.2f}</span>
|
||||
<p class="muted">{escape(capability['description'])}</p>
|
||||
{render_sources(capability['source_refs'])}
|
||||
<h3>Features</h3>
|
||||
<ul>{features or '<li class="muted">No feature candidates.</li>'}</ul>
|
||||
<h3>Evidence</h3>
|
||||
<ul>{evidence or '<li class="muted">No evidence candidates.</li>'}</ul>
|
||||
</li>
|
||||
"""
|
||||
|
||||
|
||||
def render_ability_map(ability_map: dict) -> str:
|
||||
abilities = ability_map.get("abilities", [])
|
||||
if not abilities:
|
||||
return '<p class="muted">No approved entries yet.</p>'
|
||||
items = []
|
||||
for ability in abilities:
|
||||
capabilities = []
|
||||
for capability in ability["capabilities"]:
|
||||
features = "".join(
|
||||
f'<li>{escape(feature["name"])} <span class="pill">{escape(feature["type"])}</span> <span class="source">{escape(feature["location"])}</span></li>'
|
||||
for feature in capability["features"]
|
||||
)
|
||||
evidence = "".join(
|
||||
f'<li>{escape(item["type"])} <span class="pill">{escape(item["strength"])}</span> <span class="source">{escape(item["reference"])}</span></li>'
|
||||
for item in capability["evidence"]
|
||||
)
|
||||
capabilities.append(
|
||||
f"""
|
||||
<li>
|
||||
<strong>{escape(capability['name'])}</strong>
|
||||
<p class="muted">{escape(capability['description'])}</p>
|
||||
<ul>{features}{evidence}</ul>
|
||||
</li>
|
||||
"""
|
||||
)
|
||||
items.append(
|
||||
f"""
|
||||
<li>
|
||||
<strong>{escape(ability['name'])}</strong>
|
||||
<p class="muted">{escape(ability['description'])}</p>
|
||||
<ul>{''.join(capabilities)}</ul>
|
||||
</li>
|
||||
"""
|
||||
)
|
||||
return f'<div class="tree"><ul>{"".join(items)}</ul></div>'
|
||||
|
||||
|
||||
def render_sources(source_refs: list[dict]) -> str:
|
||||
if not source_refs:
|
||||
return ""
|
||||
sources = ", ".join(
|
||||
f'<span class="source">{escape(ref["kind"])}:{escape(ref["path"] or ref["name"])}</span>'
|
||||
for ref in source_refs[:5]
|
||||
)
|
||||
if len(source_refs) > 5:
|
||||
sources += f' <span class="muted">+{len(source_refs) - 5} more</span>'
|
||||
return f"<p>{sources}</p>"
|
||||
@@ -66,6 +66,7 @@ def test_search_matches_approved_abilities_and_capabilities(tmp_path):
|
||||
repository = service.register_repository(
|
||||
name="MailRouter",
|
||||
url="https://example.com/mail-router.git",
|
||||
description="Manual test repository.",
|
||||
)
|
||||
ability_id = service.add_ability(
|
||||
repository.id,
|
||||
@@ -87,10 +88,34 @@ def test_search_matches_approved_abilities_and_capabilities(tmp_path):
|
||||
assert results[0].match_name == "Classify Incoming Email"
|
||||
|
||||
|
||||
def test_register_repository_imports_metadata_when_name_is_omitted(tmp_path):
|
||||
source = tmp_path / "metadata-source"
|
||||
source.mkdir()
|
||||
(source / "pyproject.toml").write_text(
|
||||
'[project]\nname = "metadata-source"\ndescription = "Imported description."\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
service = make_service(tmp_path)
|
||||
|
||||
repository = service.register_repository(url=str(source))
|
||||
|
||||
assert repository.name == "metadata-source"
|
||||
assert repository.description == "Imported description."
|
||||
|
||||
|
||||
def test_capability_must_belong_to_repository(tmp_path):
|
||||
service = make_service(tmp_path)
|
||||
first = service.register_repository(name="First", url="https://example.com/first.git")
|
||||
second = service.register_repository(name="Second", url="https://example.com/second.git")
|
||||
first = service.register_repository(
|
||||
name="First",
|
||||
url="https://example.com/first.git",
|
||||
description="Manual first repository.",
|
||||
)
|
||||
second = service.register_repository(
|
||||
name="Second",
|
||||
url="https://example.com/second.git",
|
||||
description="Manual second repository.",
|
||||
)
|
||||
ability_id = service.add_ability(first.id, name="Document Classification")
|
||||
|
||||
try:
|
||||
@@ -186,6 +211,7 @@ def test_analyze_repository_failure_is_recorded(tmp_path):
|
||||
repository = service.register_repository(
|
||||
name="Missing",
|
||||
url=str(tmp_path / "does-not-exist"),
|
||||
description="Manual missing repository.",
|
||||
)
|
||||
|
||||
summary = service.analyze_repository(repository.id)
|
||||
|
||||
43
tests/test_repository_metadata.py
Normal file
43
tests/test_repository_metadata.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from repo_registry.repo_ingestion.metadata import RepositoryMetadataExtractor
|
||||
|
||||
|
||||
def test_metadata_prefers_pyproject(tmp_path):
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
(repo / "pyproject.toml").write_text(
|
||||
'[project]\nname = "invoice-tools"\ndescription = "Extract invoice data."\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
metadata = RepositoryMetadataExtractor().extract(repo, str(repo))
|
||||
|
||||
assert metadata.name == "invoice-tools"
|
||||
assert metadata.description == "Extract invoice data."
|
||||
|
||||
|
||||
def test_metadata_uses_package_json(tmp_path):
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
(repo / "package.json").write_text(
|
||||
'{"name":"frontend-registry","description":"Browse repository abilities."}',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
metadata = RepositoryMetadataExtractor().extract(repo, str(repo))
|
||||
|
||||
assert metadata.name == "frontend-registry"
|
||||
assert metadata.description == "Browse repository abilities."
|
||||
|
||||
|
||||
def test_metadata_falls_back_to_readme_title(tmp_path):
|
||||
repo = tmp_path / "repo-name"
|
||||
repo.mkdir()
|
||||
(repo / "README.md").write_text(
|
||||
"# Useful Registry\n\nExtra details follow.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
metadata = RepositoryMetadataExtractor().extract(repo, str(repo))
|
||||
|
||||
assert metadata.name == "Useful Registry"
|
||||
assert metadata.description == "Extra details follow."
|
||||
@@ -72,6 +72,33 @@ def test_api_manual_registry_loop(tmp_path):
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
def test_api_registers_repository_from_url_metadata(tmp_path):
|
||||
source = tmp_path / "metadata-api"
|
||||
source.mkdir()
|
||||
(source / "package.json").write_text(
|
||||
'{"name":"metadata-api","description":"Imported through the API."}',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
def override_settings():
|
||||
return Settings(
|
||||
database_path=str(tmp_path / "metadata-api.sqlite3"),
|
||||
checkout_root=str(tmp_path / "metadata-api-checkouts"),
|
||||
)
|
||||
|
||||
app.dependency_overrides[get_settings] = override_settings
|
||||
client = TestClient(app)
|
||||
try:
|
||||
response = client.post("/repos", json={"url": str(source)})
|
||||
|
||||
assert response.status_code == 201
|
||||
repository = response.json()
|
||||
assert repository["name"] == "metadata-api"
|
||||
assert repository["description"] == "Imported through the API."
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
def test_api_analysis_run_loop(tmp_path):
|
||||
source = tmp_path / "repo"
|
||||
source.mkdir()
|
||||
@@ -139,3 +166,70 @@ def test_api_analysis_run_loop(tmp_path):
|
||||
assert ("framework", "Vite", "package.json") in fact_names
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
def test_ui_register_analyze_and_approve_loop(tmp_path):
|
||||
source = tmp_path / "repo"
|
||||
source.mkdir()
|
||||
(source / "README.md").write_text("# UI Repo\n", encoding="utf-8")
|
||||
(source / "app.py").write_text(
|
||||
"from fastapi import FastAPI\n"
|
||||
"app = FastAPI()\n"
|
||||
'@app.get("/status")\n'
|
||||
"def status():\n"
|
||||
" return {}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
def override_settings():
|
||||
return Settings(
|
||||
database_path=str(tmp_path / "ui.sqlite3"),
|
||||
checkout_root=str(tmp_path / "ui-checkouts"),
|
||||
)
|
||||
|
||||
app.dependency_overrides[get_settings] = override_settings
|
||||
client = TestClient(app)
|
||||
try:
|
||||
index_response = client.get("/ui")
|
||||
assert index_response.status_code == 200
|
||||
assert "Register Repository" in index_response.text
|
||||
|
||||
create_response = client.post(
|
||||
"/ui/repos",
|
||||
data={
|
||||
"url": str(source),
|
||||
"branch": "main",
|
||||
},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert create_response.status_code == 303
|
||||
repository_path = create_response.headers["location"]
|
||||
|
||||
detail_response = client.get(repository_path)
|
||||
assert detail_response.status_code == 200
|
||||
assert "Run Analysis" in detail_response.text
|
||||
|
||||
run_response = client.post(
|
||||
f"{repository_path}/analysis-runs",
|
||||
data={"source_path": ""},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert run_response.status_code == 303
|
||||
run_path = run_response.headers["location"]
|
||||
|
||||
run_detail = client.get(run_path)
|
||||
assert run_detail.status_code == 200
|
||||
assert "Candidate Graph" in run_detail.text
|
||||
|
||||
approve_response = client.post(
|
||||
f"{run_path}/candidate-graph/approve",
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert approve_response.status_code == 303
|
||||
|
||||
approved_detail = client.get(approve_response.headers["location"])
|
||||
assert approved_detail.status_code == 200
|
||||
assert "Approved Ability Map" in approved_detail.text
|
||||
assert "Review UI Repo Repository Usefulness" in approved_detail.text
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
Reference in New Issue
Block a user