fix(logs): Correct path resolution in LogPruner to handle paths starting with 'logs/'
This commit is contained in:
@@ -10,7 +10,7 @@ class TestLogPruningHeuristic(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.temp_dir = tempfile.TemporaryDirectory()
|
||||
self.registry_path = os.path.join(self.temp_dir.name, "registry.toml")
|
||||
self.logs_dir = os.path.join(self.temp_dir.name, "logs")
|
||||
self.logs_dir = os.path.join(self.temp_dir.name, "logs", "sessions")
|
||||
os.makedirs(self.logs_dir, exist_ok=True)
|
||||
self.registry = LogRegistry(self.registry_path)
|
||||
self.pruner = LogPruner(self.registry, self.logs_dir)
|
||||
@@ -119,5 +119,31 @@ class TestLogPruningHeuristic(unittest.TestCase):
|
||||
self.assertFalse(os.path.exists(session_path))
|
||||
self.assertNotIn(session_id, self.registry.data)
|
||||
|
||||
def test_prune_handles_relative_paths_starting_with_logs(self) -> None:
|
||||
now = datetime.now()
|
||||
# Create a session with a relative path
|
||||
session_id = "rel_path_session"
|
||||
# In this test, self.logs_dir = temp_dir/logs/sessions
|
||||
# project_root will be resolved to temp_dir
|
||||
# So the relative path starting with 'logs/' should be 'logs/rel_path_session'
|
||||
rel_path = f"logs/{session_id}"
|
||||
abs_path = os.path.join(self.temp_dir.name, "logs", session_id)
|
||||
os.makedirs(abs_path, exist_ok=True)
|
||||
|
||||
with open(os.path.join(abs_path, "comms.log"), "w") as f:
|
||||
f.write("small") # Tiny file
|
||||
|
||||
# Register with the RELATIVE path
|
||||
self.registry.register_session(session_id, rel_path, now - timedelta(days=10))
|
||||
self.registry.update_session_metadata(session_id, message_count=1, errors=0, size_kb=0, whitelisted=False, reason="Test")
|
||||
|
||||
self.assertTrue(os.path.exists(abs_path))
|
||||
|
||||
# Prune. It should resolve 'logs/rel_path_session' relative to temp_dir.name
|
||||
self.pruner.prune(max_age_days=1, min_size_kb=1)
|
||||
|
||||
self.assertFalse(os.path.exists(abs_path))
|
||||
self.assertNotIn(session_id, self.registry.data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user