galaxis-agent/tests/test_prompt_loading.py
머니페니 af7bd2cdc3 feat: add prompt loading pipeline and path validator
- Add read_repo_instructions() to read both AGENTS.md and CLAUDE.md
- Add path_validator.validate_paths() for writable/blocked path enforcement
- Add 10 passing tests (test_prompt_loading.py, test_path_validator.py)
- All 71 tests pass
2026-03-20 17:42:34 +09:00

59 lines
1.8 KiB
Python

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 == ""