Files
manual_slop/tests/test_bias_integration.py

48 lines
1.8 KiB
Python

import pytest
from src import ai_client
from src.models import ToolPreset, Tool, BiasProfile
from unittest.mock import MagicMock, patch
def test_system_prompt_biasing():
# Setup
preset = ToolPreset(name="TestPreset", categories={
"General": [Tool(name="read_file", weight=5)]
})
bias = BiasProfile(name="TestBias", category_multipliers={"General": 1.5})
with patch("src.ai_client._active_tool_preset", preset):
with patch("src.ai_client._active_bias_profile", bias):
prompt = ai_client._get_combined_system_prompt()
assert "Tooling Strategy" in prompt
assert "read_file" in prompt
assert "General" in prompt
def test_tool_declaration_biasing_anthropic():
preset = ToolPreset(name="TestPreset", categories={
"General": [Tool(name="read_file", weight=5)]
})
with patch("src.ai_client._active_tool_preset", preset):
with patch("src.ai_client._agent_tools", {"read_file": True}):
# _get_anthropic_tools calls _build_anthropic_tools which should now use the bias engine
with patch("src.ai_client._CACHED_ANTHROPIC_TOOLS", None):
tools = ai_client._get_anthropic_tools()
read_file_tool = next(t for t in tools if t["name"] == "read_file")
assert "[HIGH PRIORITY]" in read_file_tool["description"]
@pytest.mark.asyncio
async def test_set_tool_preset_with_objects():
# This tests that set_tool_preset correctly handles the new Tool objects
preset = ToolPreset(name="ObjTest", categories={
"General": [Tool(name="read_file", approval="auto")]
})
with patch("src.tool_presets.ToolPresetManager.load_all", return_value={"ObjTest": preset}):
ai_client.set_tool_preset("ObjTest")
assert ai_client._agent_tools["read_file"] is True
assert ai_client._tool_approval_modes["read_file"] == "auto"
assert ai_client._active_tool_preset == preset