band-aider-pub/tests/band_aider/test_strategy_registration.py
2026-10-17 11:57:37 -07:00

80 lines
2.4 KiB
Python

# SPDX-FileCopyrightText: 2026 Art Sea LLC
#
# SPDX-License-Identifier: AGPL-3.0-only
"""Fresh-process coverage for explicit strategy registration and import order."""
from __future__ import annotations
import json
from pathlib import Path
import subprocess
import sys
import pytest
def _run_fresh(program: str) -> subprocess.CompletedProcess[str]:
"""Run one import-order witness without pytest's initialized module graph."""
return subprocess.run(
(sys.executable, "-c", program),
cwd=Path(__file__).resolve().parents[2],
capture_output=True,
text=True,
check=False,
timeout=10,
)
@pytest.mark.integration
def test_strategy_package_import_does_not_register_concrete_handlers() -> None:
"""Importing factory contracts leaves concrete runtime composition untouched."""
completed = _run_fresh(
"import json, sys\n"
"import band_aider.strategies as strategies\n"
"print(json.dumps({\n"
" 'languages': strategies.language_strategy_set_factory.keys(),\n"
" 'predictive_loaded': (\n"
" 'band_aider.judgement.predictive_failure_source_candidate_selection_strategy'\n"
" in sys.modules\n"
" ),\n"
"}, sort_keys=True))\n"
)
assert (completed.returncode, completed.stderr) == (0, "")
assert json.loads(completed.stdout) == {
"languages": [],
"predictive_loaded": False,
}
@pytest.mark.integration
def test_contextual_file_renderer_imports_before_runtime_registration() -> None:
"""A renderer-first process does not depend on strategy package import order."""
completed = _run_fresh(
"from band_aider.judgement.contextual_file_renderer import ContextualFileRenderer\n"
"print(ContextualFileRenderer.__name__)\n"
)
assert (completed.returncode, completed.stderr) == (0, "")
assert completed.stdout.strip() == "ContextualFileRenderer"
@pytest.mark.integration
def test_cli_help_composes_strategies_in_a_fresh_process() -> None:
"""The executable entry point registers handlers before consulting the CLI language."""
completed = subprocess.run(
(sys.executable, "-m", "band_aider.cli", "--help"),
cwd=Path(__file__).resolve().parents[2],
capture_output=True,
text=True,
check=False,
timeout=10,
)
assert (completed.returncode, completed.stderr) == (0, "")
assert "usage: band-aider" in completed.stdout