-
Notifications
You must be signed in to change notification settings - Fork 6k
/
Copy pathtest_microagent_no_header.py
94 lines (77 loc) · 3.18 KB
/
test_microagent_no_header.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from pathlib import Path
from openhands.microagent.microagent import BaseMicroagent, RepoMicroagent
from openhands.microagent.types import MicroagentType
def test_load_markdown_without_frontmatter():
"""Test loading a markdown file without frontmatter."""
content = '# Test Content\nThis is a test markdown file without frontmatter.'
path = Path('test.md')
# Load the agent from content using keyword argument
agent = BaseMicroagent.load(path=path, file_content=content)
# Verify it's loaded as a repo agent with default values
assert isinstance(agent, RepoMicroagent)
assert agent.name == 'default'
assert agent.content == content
assert agent.type == MicroagentType.REPO_KNOWLEDGE
assert agent.metadata.agent == 'CodeActAgent'
assert agent.metadata.version == '1.0.0'
def test_load_markdown_with_empty_frontmatter():
"""Test loading a markdown file with empty frontmatter."""
content = (
'---\n---\n# Test Content\nThis is a test markdown file with empty frontmatter.'
)
path = Path('test.md')
# Load the agent from content using keyword argument
agent = BaseMicroagent.load(path=path, file_content=content)
# Verify it's loaded as a repo agent with default values
assert isinstance(agent, RepoMicroagent)
assert agent.name == 'default'
assert (
agent.content
== '# Test Content\nThis is a test markdown file with empty frontmatter.'
)
assert agent.type == MicroagentType.REPO_KNOWLEDGE
assert agent.metadata.agent == 'CodeActAgent'
assert agent.metadata.version == '1.0.0'
def test_load_markdown_with_partial_frontmatter():
"""Test loading a markdown file with partial frontmatter."""
content = """---
name: custom_name
---
# Test Content
This is a test markdown file with partial frontmatter."""
path = Path('test.md')
# Load the agent from content using keyword argument
agent = BaseMicroagent.load(path=path, file_content=content)
# Verify it uses provided name but default values for other fields
assert isinstance(agent, RepoMicroagent)
assert agent.name == 'custom_name'
assert (
agent.content
== '# Test Content\nThis is a test markdown file with partial frontmatter.'
)
assert agent.type == MicroagentType.REPO_KNOWLEDGE
assert agent.metadata.agent == 'CodeActAgent'
assert agent.metadata.version == '1.0.0'
def test_load_markdown_with_full_frontmatter():
"""Test loading a markdown file with full frontmatter still works."""
content = """---
name: test_agent
type: repo
agent: CustomAgent
version: 2.0.0
---
# Test Content
This is a test markdown file with full frontmatter."""
path = Path('test.md')
# Load the agent from content using keyword argument
agent = BaseMicroagent.load(path=path, file_content=content)
# Verify all provided values are used
assert isinstance(agent, RepoMicroagent)
assert agent.name == 'test_agent'
assert (
agent.content
== '# Test Content\nThis is a test markdown file with full frontmatter.'
)
assert agent.type == MicroagentType.REPO_KNOWLEDGE
assert agent.metadata.agent == 'CustomAgent'
assert agent.metadata.version == '2.0.0'