Agents/tests/test_agent.py

43 lines
1.6 KiB
Python

import pytest
from pathlib import Path
from antigravity.core.md_loader import MarkdownInstructionLoader
from antigravity.tools.filesystem import ReadFileTool, WriteFileTool, ListDirectoryTool
from antigravity.tools.shell import ShellExecuteTool
from antigravity.core.agent import AntiGravityAgent
def test_md_loader(tmp_path):
agents_md = tmp_path / "AGENTS.md"
agents_md.write_text("Rule 1: Always write unit tests.", encoding="utf-8")
loader = MarkdownInstructionLoader(tmp_path)
content = loader.load_all_instructions()
assert "Rule 1: Always write unit tests." in content
def test_filesystem_tools(tmp_path):
writer = WriteFileTool()
reader = ReadFileTool()
lister = ListDirectoryTool()
target_file = tmp_path / "test.txt"
w_res = writer.execute(path=str(target_file), content="Hello Anti-Gravity")
assert w_res.success is True
r_res = reader.execute(path=str(target_file))
assert r_res.success is True
assert r_res.output == "Hello Anti-Gravity"
l_res = lister.execute(path=str(tmp_path))
assert l_res.success is True
assert "test.txt" in l_res.output
def test_shell_tool():
shell_tool = ShellExecuteTool()
res = shell_tool.execute(command="echo AntiGravityTest")
assert res.success is True
assert "AntiGravityTest" in res.output
def test_agent_initialization(tmp_path):
(tmp_path / "AGENTS.md").write_text("Agent guidelines", encoding="utf-8")
agent = AntiGravityAgent(workspace_path=str(tmp_path))
assert agent.workspace_path == tmp_path.resolve()
assert "Agent guidelines" in agent.system_prompt