galaxis-agent/tests/test_prompt_loading.py

59 lines
1.8 KiB
Python
Raw Permalink Normal View History

import pytest
from unittest.mock import MagicMock
from dataclasses import dataclass
@dataclass
class FakeExecuteResponse:
output: str
exit_code: int = 0
@pytest.fixture
def mock_sandbox():
sandbox = MagicMock()
return sandbox
@pytest.mark.asyncio
async def test_reads_agents_md_and_claude_md(mock_sandbox):
def fake_execute(cmd, **kwargs):
if "AGENTS.md" in cmd:
return FakeExecuteResponse(output="# AGENTS.md\n## Rules\n- rule 1", exit_code=0)
if "CLAUDE.md" in cmd:
return FakeExecuteResponse(output="# CLAUDE.md\n## Overview\n- info 1", exit_code=0)
return FakeExecuteResponse(output="", exit_code=1)
mock_sandbox.execute = MagicMock(side_effect=fake_execute)
from agent.utils.agents_md import read_repo_instructions
result = await read_repo_instructions(mock_sandbox, "/workspace/galaxis-po")
assert "Rules" in result
assert "Overview" in result
@pytest.mark.asyncio
async def test_agents_md_only(mock_sandbox):
def fake_execute(cmd, **kwargs):
if "AGENTS.md" in cmd:
return FakeExecuteResponse(output="# AGENTS rules", exit_code=0)
return FakeExecuteResponse(output="", exit_code=1)
mock_sandbox.execute = MagicMock(side_effect=fake_execute)
from agent.utils.agents_md import read_repo_instructions
result = await read_repo_instructions(mock_sandbox, "/workspace/galaxis-po")
assert result is not None
assert "AGENTS" in result
@pytest.mark.asyncio
async def test_no_instruction_files(mock_sandbox):
mock_sandbox.execute = MagicMock(
return_value=FakeExecuteResponse(output="", exit_code=1)
)
from agent.utils.agents_md import read_repo_instructions
result = await read_repo_instructions(mock_sandbox, "/workspace/galaxis-po")
assert result == ""