generated from coulomb/repo-seed
157 lines
4.9 KiB
Python
157 lines
4.9 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from repo_registry.cli import main
|
|
from repo_registry.core.service import RegistryService
|
|
from repo_registry.repo_ingestion.git import GitIngestionService
|
|
from repo_registry.storage.sqlite import RegistryStore
|
|
|
|
|
|
def make_service(tmp_path):
|
|
store = RegistryStore(tmp_path / "registry.sqlite3")
|
|
store.initialize()
|
|
return RegistryService(store, ingestion=GitIngestionService(tmp_path / "checkouts"))
|
|
|
|
|
|
def write_repo(tmp_path):
|
|
source = tmp_path / "repo"
|
|
source.mkdir()
|
|
(source / "README.md").write_text("# CLI Rebuild\nReports health.\n", encoding="utf-8")
|
|
(source / "app.py").write_text('@app.get("/health")\ndef health():\n return {}\n', encoding="utf-8")
|
|
return source
|
|
|
|
|
|
def approved_repository(tmp_path):
|
|
service = make_service(tmp_path)
|
|
source = write_repo(tmp_path)
|
|
repository = service.register_repository(name="CLI Rebuild", url=str(source))
|
|
summary = service.analyze_repository(repository.id, use_llm_assistance=False)
|
|
service.approve_candidate_graph(repository.id, summary.analysis_run.id)
|
|
return service, repository
|
|
|
|
|
|
def test_rebuild_cli_dry_run_preserves_approved_characteristics(tmp_path, capsys):
|
|
service, repository = approved_repository(tmp_path)
|
|
|
|
exit_code = main(
|
|
[
|
|
"rebuild-characteristics",
|
|
"--repo",
|
|
str(repository.id),
|
|
"--dry-run",
|
|
"--no-llm",
|
|
"--database-path",
|
|
str(tmp_path / "registry.sqlite3"),
|
|
"--checkout-root",
|
|
str(tmp_path / "checkouts"),
|
|
]
|
|
)
|
|
|
|
output = capsys.readouterr().out
|
|
assert exit_code == 0
|
|
assert "repo=1:CLI Rebuild" in output
|
|
assert "latest_analysis_run=2" in output
|
|
assert "candidate_source=deterministic" in output
|
|
assert "dry_run=True" in output
|
|
assert "cleared_approved=False" in output
|
|
assert service.ability_map(repository.id).abilities
|
|
|
|
|
|
def test_rebuild_cli_confirmed_single_repo_clears_approved_characteristics(tmp_path, capsys):
|
|
_service, repository = approved_repository(tmp_path)
|
|
|
|
exit_code = main(
|
|
[
|
|
"rebuild-characteristics",
|
|
"--repo",
|
|
str(repository.id),
|
|
"--no-llm",
|
|
"--confirm",
|
|
"--database-path",
|
|
str(tmp_path / "registry.sqlite3"),
|
|
"--checkout-root",
|
|
str(tmp_path / "checkouts"),
|
|
]
|
|
)
|
|
|
|
service = make_service(tmp_path)
|
|
output = capsys.readouterr().out
|
|
assert exit_code == 0
|
|
assert "dry_run=False" in output
|
|
assert "cleared_approved=True" in output
|
|
assert service.ability_map(repository.id).abilities == []
|
|
|
|
|
|
def test_rebuild_cli_refuses_destructive_all_without_confirm_all(tmp_path):
|
|
approved_repository(tmp_path)
|
|
|
|
with pytest.raises(SystemExit) as exc:
|
|
main(
|
|
[
|
|
"rebuild-characteristics",
|
|
"--all",
|
|
"--confirm",
|
|
"--database-path",
|
|
str(tmp_path / "registry.sqlite3"),
|
|
"--checkout-root",
|
|
str(tmp_path / "checkouts"),
|
|
]
|
|
)
|
|
|
|
assert exc.value.code == 2
|
|
|
|
|
|
def test_export_assessment_cli_writes_completed_run_artifact(tmp_path):
|
|
service = make_service(tmp_path)
|
|
source = write_repo(tmp_path)
|
|
repository = service.register_repository(name="CLI Export", url=str(source))
|
|
summary = service.analyze_repository(repository.id, use_llm_assistance=False)
|
|
output_path = tmp_path / "assessment.json"
|
|
|
|
exit_code = main(
|
|
[
|
|
"export-assessment",
|
|
"--repo",
|
|
str(repository.id),
|
|
"--analysis-run",
|
|
str(summary.analysis_run.id),
|
|
"--output",
|
|
str(output_path),
|
|
"--database-path",
|
|
str(tmp_path / "registry.sqlite3"),
|
|
"--checkout-root",
|
|
str(tmp_path / "checkouts"),
|
|
]
|
|
)
|
|
|
|
artifact = json.loads(output_path.read_text(encoding="utf-8"))
|
|
assert exit_code == 0
|
|
assert artifact["target_repository"]["repo_slug"] == "cli-export"
|
|
assert artifact["execution"]["analysis_run_id"] == summary.analysis_run.id
|
|
assert artifact["assessment"]["role"] == "challenger"
|
|
assert artifact["generated_tree"]["abilities"]
|
|
|
|
|
|
def test_compare_assessment_cli_writes_markdown_report(tmp_path):
|
|
output_path = tmp_path / "comparison.md"
|
|
|
|
exit_code = main(
|
|
[
|
|
"compare-assessment",
|
|
"--golden",
|
|
"docs/self-scoping/golden/repo-scoping-golden-profile.v1.json",
|
|
"--assessment",
|
|
"docs/self-scoping/assessments/repo-scoping-known-bad-2026-05-15-run-39.json",
|
|
"--output",
|
|
str(output_path),
|
|
"--format",
|
|
"markdown",
|
|
]
|
|
)
|
|
|
|
report = output_path.read_text(encoding="utf-8")
|
|
assert exit_code == 0
|
|
assert "Status: `regression`" in report
|
|
assert "Route LLM Requests Across Providers" in report
|