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

71 lines
2.3 KiB
Python

# SPDX-FileCopyrightText: 2026 Art Sea LLC
#
# SPDX-License-Identifier: AGPL-3.0-only
from __future__ import annotations
import logging
from band_aider.ai_client.completion_client import CompletionClient, OpenAIConfig
from band_aider.ai_client.fence_crashing_client import FenceCrashingClient
from band_aider.context.class_meta import ClassMeta
from band_aider.judgement.intent_check import IntentCheck
from band_aider.judgement.prompt_formatter import MarkdownPromptFormatterBuilder
class _Client(CompletionClient):
"""_Client returns one configured completion response."""
model = "default"
api_base = "https://example.invalid"
api_key = "key"
temperature = 0
max_tokens = None
max_attempts = 8
retry_temperature_step = 0.2
max_retry_temperature = 0.8
def __init__(self, response: str) -> None:
"""Store the response returned from complete."""
self.response = response
def complete(self, prompt: str, logger: logging.Logger | None = None) -> str:
"""Return the configured response."""
del prompt, logger
return self.response
@property
def inner(self) -> CompletionClient | None:
"""Declare this client as the root completion boundary."""
return None
@property
def openai_configs(self) -> tuple[OpenAIConfig, ...]:
"""Expose no external config for the stationary response."""
return ()
def test_intent_check_accepts_fenced_and_raw_json() -> None:
"""Verify IntentCheck accepts raw JSON and a single markdown JSON fence."""
candidate = ClassMeta("target.py", "summary", ["relevant"], {"Target": "reason"})
raw = '{"intent": "existing_files", "new_feature": false, "reason": "raw"}'
fenced = """```json
{
"intent": "existing_files",
"new_feature": false,
"reason": "fenced"
}
```"""
raw_check = IntentCheck(changes=[], prompt="change target", client=_Client(raw), prompt_formatter_builder=MarkdownPromptFormatterBuilder())
fenced_check = IntentCheck(changes=[], prompt="change target", client=FenceCrashingClient(_Client(fenced)), prompt_formatter_builder=MarkdownPromptFormatterBuilder())
assert raw_check(candidate) is False
assert raw_check.reason == "raw"
assert fenced_check(candidate) is False
assert fenced_check.reason == "fenced"