-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_file_operations.py
More file actions
99 lines (83 loc) · 2.6 KB
/
Copy pathtest_file_operations.py
File metadata and controls
99 lines (83 loc) · 2.6 KB
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
95
96
97
98
99
#!/usr/bin/env python3
"""
Integration test: Verify file operation execution works end-to-end.
Tests that file operations actually execute on the filesystem.
"""
import asyncio
import os
import sys
import tempfile
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
FILE_OPERATION_TEST_ERRORS = (
AssertionError,
ImportError,
OSError,
RuntimeError,
TypeError,
ValueError,
)
async def test_file_operations():
"""Test that file operations actually execute."""
from core.skills.file_operation import FileOperationSkill, FileOpInput
# Use a relative path within workspace (file_operation uses cwd as root_dir)
test_file = "test_output.txt"
skill = FileOperationSkill()
# Test 1: Write file
print("Test 1: Writing file...")
result = await skill.execute(FileOpInput(
action="write",
path=test_file,
content="Hello, Aura! This is a real file created by tool execution."
))
print(f" Result: {result}")
# Verify file was created
if os.path.exists(test_file):
print(f" ✓ File created: {test_file}")
with open(test_file, "r") as f:
content = f.read()
print(f" ✓ Content verified: {content[:50]}...")
else:
print(f" ✗ File NOT created!")
return False
# Test 2: Read file
print("\nTest 2: Reading file...")
result = await skill.execute(FileOpInput(
action="read",
path=test_file
))
print(f" Result: {result['ok']}")
print(f" Content length: {len(result.get('content', ''))}")
# Test 3: Append to file
print("\nTest 3: Appending to file...")
result = await skill.execute(FileOpInput(
action="append",
path=test_file,
content="This is appended content."
))
print(f" Result: {result}")
# Verify append worked
with open(test_file, "r") as f:
content = f.read()
if "appended content" in content:
print(f" ✓ Append verified")
else:
print(f" ✗ Append failed!")
return False
# Cleanup
if os.path.exists(test_file):
os.remove(test_file)
return True
if __name__ == "__main__":
try:
result = asyncio.run(test_file_operations())
if result:
print("\n✅ All file operation tests PASSED")
sys.exit(0)
else:
print("\n❌ File operation tests FAILED")
sys.exit(1)
except FILE_OPERATION_TEST_ERRORS as e:
print(f"\n❌ Test error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)