generated from coulomb/repo-seed
101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
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
|