66import os
77import tempfile
88import time
9+ import uuid
910from pathlib import Path
1011from unittest .mock import MagicMock , Mock , patch
1112
@@ -22,7 +23,7 @@ class TestCloudTraceSink:
2223 def test_cloud_trace_sink_upload_success (self ):
2324 """Test CloudTraceSink successfully uploads trace to cloud."""
2425 upload_url = "https://sentience.nyc3.digitaloceanspaces.com/user123/run456/trace.jsonl.gz"
25- run_id = "test-run-123 "
26+ run_id = f "test-run-{ uuid . uuid4 (). hex [: 8 ] } "
2627
2728 with patch ("sentience.cloud_tracing.requests.put" ) as mock_put :
2829 # Mock successful response
@@ -69,7 +70,7 @@ def test_cloud_trace_sink_upload_success(self):
6970 def test_cloud_trace_sink_upload_failure_preserves_trace (self , capsys ):
7071 """Test CloudTraceSink preserves trace locally on upload failure."""
7172 upload_url = "https://sentience.nyc3.digitaloceanspaces.com/user123/run456/trace.jsonl.gz"
72- run_id = "test-run-456 "
73+ run_id = f "test-run-{ uuid . uuid4 (). hex [: 8 ] } "
7374
7475 with patch ("sentience.cloud_tracing.requests.put" ) as mock_put :
7576 # Mock failed response
@@ -103,7 +104,8 @@ def test_cloud_trace_sink_upload_failure_preserves_trace(self, capsys):
103104 def test_cloud_trace_sink_emit_after_close_raises (self ):
104105 """Test CloudTraceSink raises error when emitting after close."""
105106 upload_url = "https://test.com/upload"
106- sink = CloudTraceSink (upload_url , run_id = "test-run-789" )
107+ run_id = f"test-run-{ uuid .uuid4 ().hex [:8 ]} "
108+ sink = CloudTraceSink (upload_url , run_id = run_id )
107109 # Emit at least one event so file exists
108110 sink .emit ({"v" : 1 , "type" : "test" , "seq" : 1 })
109111 sink .close ()
@@ -117,7 +119,8 @@ def test_cloud_trace_sink_context_manager(self):
117119 mock_put .return_value = Mock (status_code = 200 )
118120
119121 upload_url = "https://test.com/upload"
120- with CloudTraceSink (upload_url , run_id = "test-run-context" ) as sink :
122+ run_id = f"test-run-{ uuid .uuid4 ().hex [:8 ]} "
123+ with CloudTraceSink (upload_url , run_id = run_id ) as sink :
121124 sink .emit ({"v" : 1 , "type" : "test" , "seq" : 1 })
122125
123126 # Verify upload was called
@@ -126,7 +129,7 @@ def test_cloud_trace_sink_context_manager(self):
126129 def test_cloud_trace_sink_network_error_graceful_degradation (self , capsys ):
127130 """Test CloudTraceSink handles network errors gracefully."""
128131 upload_url = "https://sentience.nyc3.digitaloceanspaces.com/user123/run456/trace.jsonl.gz"
129- run_id = "test-run-network-error "
132+ run_id = f "test-run-{ uuid . uuid4 (). hex [: 8 ] } "
130133
131134 with patch ("sentience.cloud_tracing.requests.put" ) as mock_put :
132135 # Simulate network error
@@ -159,7 +162,8 @@ def test_cloud_trace_sink_multiple_close_safe(self):
159162 mock_put .return_value = Mock (status_code = 200 )
160163
161164 upload_url = "https://test.com/upload"
162- sink = CloudTraceSink (upload_url , run_id = "test-run-multiple-close" )
165+ run_id = f"test-run-{ uuid .uuid4 ().hex [:8 ]} "
166+ sink = CloudTraceSink (upload_url , run_id = run_id )
163167 sink .emit ({"v" : 1 , "type" : "test" , "seq" : 1 })
164168
165169 # Close multiple times
@@ -173,7 +177,7 @@ def test_cloud_trace_sink_multiple_close_safe(self):
173177 def test_cloud_trace_sink_persistent_cache_directory (self ):
174178 """Test CloudTraceSink uses persistent cache directory instead of temp file."""
175179 upload_url = "https://test.com/upload"
176- run_id = "test-run-persistent "
180+ run_id = f "test-run-{ uuid . uuid4 (). hex [: 8 ] } "
177181
178182 sink = CloudTraceSink (upload_url , run_id = run_id )
179183 sink .emit ({"v" : 1 , "type" : "test" , "seq" : 1 })
@@ -192,7 +196,7 @@ def test_cloud_trace_sink_persistent_cache_directory(self):
192196 def test_cloud_trace_sink_non_blocking_close (self ):
193197 """Test CloudTraceSink.close(blocking=False) returns immediately."""
194198 upload_url = "https://test.com/upload"
195- run_id = "test-run-nonblocking "
199+ run_id = f "test-run-{ uuid . uuid4 (). hex [: 8 ] } "
196200
197201 with patch ("sentience.cloud_tracing.requests.put" ) as mock_put :
198202 mock_put .return_value = Mock (status_code = 200 )
@@ -217,7 +221,7 @@ def test_cloud_trace_sink_non_blocking_close(self):
217221 def test_cloud_trace_sink_progress_callback (self ):
218222 """Test CloudTraceSink.close() with progress callback."""
219223 upload_url = "https://test.com/upload"
220- run_id = "test-run-progress "
224+ run_id = f "test-run-{ uuid . uuid4 (). hex [: 8 ] } "
221225 progress_calls = []
222226
223227 def progress_callback (uploaded : int , total : int ):
@@ -239,7 +243,7 @@ def progress_callback(uploaded: int, total: int):
239243 def test_cloud_trace_sink_uploads_screenshots_after_trace (self ):
240244 """Test that CloudTraceSink uploads screenshots after trace upload succeeds."""
241245 upload_url = "https://sentience.nyc3.digitaloceanspaces.com/user123/run456/trace.jsonl.gz"
242- run_id = "test-screenshot-integration-1 "
246+ run_id = f "test-run- { uuid . uuid4 (). hex [: 8 ] } "
243247 api_key = "sk_test_123"
244248
245249 # Create test screenshot
@@ -400,23 +404,20 @@ def test_create_tracer_pro_tier_success(self, capsys):
400404 # Mock upload response
401405 mock_put .return_value = Mock (status_code = 200 )
402406
403- tracer = create_tracer (
404- api_key = "sk_pro_test123" , run_id = "test-run" , upload_trace = True
405- )
407+ run_id = f"test-run-{ uuid .uuid4 ().hex [:8 ]} "
408+ tracer = create_tracer (api_key = "sk_pro_test123" , run_id = run_id , upload_trace = True )
406409
407410 # Verify Pro tier message
408411 captured = capsys .readouterr ()
409412 assert "☁️ [Sentience] Cloud tracing enabled (Pro tier)" in captured .out
410413
411414 # Verify tracer works
412- assert tracer .run_id == "test-run"
415+ assert tracer .run_id == run_id
413416 # Check if sink is CloudTraceSink (it should be)
414- from sentience .cloud_tracing import CloudTraceSink
415-
416417 assert isinstance (
417418 tracer .sink , CloudTraceSink
418419 ), f"Expected CloudTraceSink, got { type (tracer .sink )} "
419- assert tracer .sink .run_id == "test-run" # Verify run_id is passed
420+ assert tracer .sink .run_id == run_id # Verify run_id is passed
420421
421422 # Verify the init API was called
422423 assert mock_post .called
0 commit comments