Skip to content

Commit a3c3171

Browse files
author
SentienceDEV
committed
fix tests
1 parent bb43056 commit a3c3171

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

tests/test_screenshot_storage.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ def test_extract_screenshots_from_trace(self):
4242
}
4343
)
4444

45-
# Close to write file
46-
sink.close(blocking=False)
47-
48-
# Wait a bit for file to be written
49-
import time
50-
51-
time.sleep(0.1)
45+
# Finalize trace file synchronously (closes file handle properly)
46+
# Using _finalize_trace_file_for_upload instead of close(blocking=False)
47+
# to avoid Windows file locking issues in tests
48+
sink._finalize_trace_file_for_upload()
5249

5350
# Extract screenshots
5451
screenshots = sink._extract_screenshots_from_trace()
@@ -59,7 +56,7 @@ def test_extract_screenshots_from_trace(self):
5956
assert screenshots[1]["format"] == "png"
6057
assert screenshots[1]["step_id"] == "step-1"
6158

62-
# Cleanup
59+
# Cleanup - file handle is already closed
6360
cache_dir = Path.home() / ".sentience" / "traces" / "pending"
6461
trace_path = cache_dir / f"{run_id}.jsonl"
6562
if trace_path.exists():
@@ -93,15 +90,15 @@ def test_extract_screenshots_handles_multiple(self):
9390
}
9491
)
9592

96-
sink.close(blocking=False)
97-
import time
98-
99-
time.sleep(0.1)
93+
# Finalize trace file synchronously (closes file handle properly)
94+
# Using _finalize_trace_file_for_upload instead of close(blocking=False)
95+
# to avoid Windows file locking issues in tests
96+
sink._finalize_trace_file_for_upload()
10097

10198
screenshots = sink._extract_screenshots_from_trace()
10299
assert len(screenshots) == 3
103100

104-
# Cleanup
101+
# Cleanup - file handle is already closed
105102
cache_dir = Path.home() / ".sentience" / "traces" / "pending"
106103
trace_path = cache_dir / f"{run_id}.jsonl"
107104
if trace_path.exists():
@@ -130,15 +127,15 @@ def test_extract_screenshots_skips_events_without_screenshots(self):
130127
}
131128
)
132129

133-
sink.close(blocking=False)
134-
import time
135-
136-
time.sleep(0.1)
130+
# Finalize trace file synchronously (closes file handle properly)
131+
# Using _finalize_trace_file_for_upload instead of close(blocking=False)
132+
# to avoid Windows file locking issues in tests
133+
sink._finalize_trace_file_for_upload()
137134

138135
screenshots = sink._extract_screenshots_from_trace()
139136
assert len(screenshots) == 0
140137

141-
# Cleanup
138+
# Cleanup - file handle is already closed
142139
cache_dir = Path.home() / ".sentience" / "traces" / "pending"
143140
trace_path = cache_dir / f"{run_id}.jsonl"
144141
if trace_path.exists():
@@ -174,10 +171,8 @@ def test_create_cleaned_trace_removes_screenshot_fields(self):
174171
}
175172
)
176173

177-
sink.close(blocking=False)
178-
import time
179-
180-
time.sleep(0.1)
174+
# Finalize trace file synchronously to avoid Windows file locking issues
175+
sink._finalize_trace_file_for_upload()
181176

182177
# Create cleaned trace
183178
cache_dir = Path.home() / ".sentience" / "traces" / "pending"
@@ -223,10 +218,8 @@ def test_create_cleaned_trace_preserves_other_events(self):
223218
}
224219
)
225220

226-
sink.close(blocking=False)
227-
import time
228-
229-
time.sleep(0.1)
221+
# Finalize trace file synchronously to avoid Windows file locking issues
222+
sink._finalize_trace_file_for_upload()
230223

231224
# Create cleaned trace
232225
cache_dir = Path.home() / ".sentience" / "traces" / "pending"
@@ -436,10 +429,8 @@ def test_upload_removes_screenshot_base64_from_trace(self):
436429
}
437430
)
438431

439-
sink.close(blocking=False)
440-
import time
441-
442-
time.sleep(0.1)
432+
# Finalize trace file synchronously to avoid Windows file locking issues
433+
sink._finalize_trace_file_for_upload()
443434

444435
# Mock gateway and upload responses
445436
mock_upload_urls = {

0 commit comments

Comments
 (0)