1+ """
2+ Basic tests for YAML parsing functionality in the taskflow agent.
3+
4+ Simple parsing + parsing of example taskflows.
5+ """
6+
7+ import pytest
8+ import tempfile
9+ from pathlib import Path
10+ import yaml
11+ from yaml_parser import YamlParser
12+
13+
14+ class TestYamlParser :
15+ """Test suite for YamlParser class."""
16+
17+ def test_yaml_parser_basic_functionality (self ):
18+ """Test basic YAML parsing functionality."""
19+ # create a temporary directory with test yaml files
20+ with tempfile .TemporaryDirectory () as temp_dir :
21+ temp_path = Path (temp_dir )
22+ test_yaml_content = {
23+ 'seclab-taskflow-agent' : {
24+ 'type' : 'taskflow' ,
25+ 'version' : 1
26+ },
27+ 'taskflow' : [
28+ {
29+ 'task' : {
30+ 'agents' : ['assistant' ],
31+ 'user_prompt' : 'Test prompt'
32+ }
33+ }
34+ ]
35+ }
36+
37+ test_file = temp_path / 'test_taskflow.yaml'
38+ with open (test_file , 'w' ) as f :
39+ yaml .dump (test_yaml_content , f )
40+
41+ parser = YamlParser (temp_path )
42+ # get all yaml files in the directory
43+ yaml_files = temp_path .glob ('*.yaml' )
44+ result = parser .get_yaml_dict (yaml_files )
45+
46+ assert 'test_taskflow.yaml' in result
47+ assert result ['test_taskflow.yaml' ]['seclab-taskflow-agent' ]['type' ] == 'taskflow'
48+ assert len (result ['test_taskflow.yaml' ]['taskflow' ]) == 1
49+ assert result ['test_taskflow.yaml' ]['taskflow' ][0 ]['task' ]['agents' ] == ['assistant' ]
50+
51+
52+ class TestRealTaskflowFiles :
53+ """Test parsing of actual taskflow files in the project."""
54+
55+ def test_parse_example_taskflows (self ):
56+ """Test parsing the actual example taskflow files."""
57+ # this test uses the actual taskflows in the project
58+ examples_path = Path ('taskflows/examples' ).absolute ()
59+ parser = YamlParser (examples_path )
60+
61+ # Get all YAML files in the examples directory
62+ yaml_files = examples_path .glob ('*.yaml' )
63+ result = parser .get_yaml_dict (yaml_files )
64+
65+ # should contain example files
66+ assert len (result ) > 0
67+
68+ # check that example.yaml is parsed correctly
69+ example_task_flow = result ['example.yaml' ]
70+ assert 'taskflow' in example_task_flow
71+ assert isinstance (example_task_flow ['taskflow' ], list )
72+ assert len (example_task_flow ['taskflow' ]) == 4 # 4 tasks in taskflow
73+ assert example_task_flow ['taskflow' ][0 ]['task' ]['max_steps' ] == 20
74+
75+ def test_parse_all_taskflows (self ):
76+ """Test parsing all example taskflow files in the project."""
77+ taskflows_path = Path ('taskflows' ).absolute ()
78+ parser = YamlParser (taskflows_path )
79+
80+ yaml_files = taskflows_path .rglob ('*.yaml' )
81+ result = parser .get_yaml_dict (yaml_files )
82+
83+ # should contain all taskflow files (including subdirs)
84+ assert len (result ) == 13
85+
86+ # check access for files with directory structure in names
87+ example_files = [key for key in result .keys () if 'examples/' in key ]
88+ assert len (example_files ) > 0
89+
90+
91+ if __name__ == '__main__' :
92+ pytest .main ([__file__ , '-v' ])
0 commit comments