konveyor / kai

Konveyor AI - static code analysis driven migration to new targets via Generative AI
Apache License 2.0
25 stars 32 forks source link

Issue: `process_log_dir_replacements` Function Not Handling Relative Paths Correctly #278

Closed brf153 closed 3 months ago

brf153 commented 3 months ago

Description

The process_log_dir_replacements function is intended to replace $pwd in log_dir with the location of the Kai project directory, which is one level up from the current script's location. However, the function is currently not working as expected. It returns paths with redundant or incorrect components, causing errors in path resolution.

Expected Behavior

When $pwd is replaced with the Kai project directory, the resulting path should be an absolute path without redundant parts. For example, if the current working directory is /home/k8smaster/Desktop/kai/kai, and the log directory placeholder is $pwd/../logs, the expected output should be /home/k8smaster/Desktop/kai/logs.

Actual Behavior

The function returns paths that include redundant components, such as /home/k8smaster/Desktop/kai/kai/..//logs, rather than the clean path /home/k8smaster/Desktop/kai/logs.

Error Message

image

System

Ubuntu 22.04

jwmatthews commented 3 months ago

hi @brf153

Thank you for capturing this. I think your suggestion to clean up the path is nice, thank you.

I would like to know more about where you saw this fail to function, you mention errors in path resolution, would you help me to understand where you saw this fail?

brf153 commented 3 months ago

Hello @jwmatthews,

Thank you for the feedback. I was writing unit tests for kai_logging.py. While testing the function process_log_dir_replacements, I came across this error. The relevant part of my test code is below:

class TestLoggingSetup(unittest.TestCase):
    def setUp(self):
        self.test_log_dir = tempfile.mkdtemp()
        self.console_log_level = "INFO"
        self.file_log_level = "DEBUG"
        self.log_file = "kai_server.log"
        self.log_dir_with_placeholder = "$pwd/logs"

        # Mock KaiConfig
        self.config = MagicMock(spec=KaiConfig)
        self.config.log_level = self.console_log_level
        self.config.file_log_level = self.file_log_level
        self.config.log_dir = self.log_dir_with_placeholder
        self.config.incident_store = MagicMock(spec=KaiConfigIncidentStore)
        self.config.models = KaiConfigModels(
            provider="FakeProvider",
            args={},
        )
        self.config.solution_consumers = []

    def tearDown(self):
        shutil.rmtree(self.test_log_dir)

    @patch('os.getcwd')
    def test_process_log_dir_replacements(self, mock_getcwd):
        mock_getcwd.return_value = '/home/k8smaster/Desktop/kai/kai'
        print(f"Mocked getcwd: {mock_getcwd.return_value}")
        print(f"Original log_dir: {self.config.log_dir}")

        actual_log_dir = process_log_dir_replacements(self.config.log_dir)

        print(f"Processed log_dir: {actual_log_dir}")
        expected_log_dir = '/home/k8smaster/Desktop/kai/logs'
        print(f"Expected log_dir: {expected_log_dir}")

        self.assertEqual(expected_log_dir, actual_log_dir)

Please note that the directories are hard-coded for testing purposes. The issue was that the processed log directory did not resolve correctly.

My Environment:

jwmatthews commented 3 months ago

Thank you @brf153, this helped clarify.
Nicely done with the test example.