From 56a2cb24145a8eed9a7da80126aa15ecede0adb0 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Wed, 26 Nov 2025 19:43:07 +0200 Subject: [PATCH 1/3] Validate tests_root directory exists --- codeflash/lsp/beta.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 14d43a1a5..56dbe8f7b 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -184,11 +184,35 @@ def write_config(params: WriteConfigParams) -> dict[str, any]: # the client provided a config path but it doesn't exist create_empty_pyproject_toml(cfg_file) + # Handle both dict and object access for config + def get_config_value(key: str, default: str = "") -> str: + if isinstance(cfg, dict): + return cfg.get(key, default) + return getattr(cfg, key, default) + + tests_root = get_config_value("tests_root", "") + # Validate tests_root directory exists if provided + if tests_root: + # Resolve path relative to config file directory or current working directory + if cfg_file: + base_dir = cfg_file.parent + else: + base_dir = Path.cwd() + tests_root_path = (base_dir / tests_root).resolve() + if not tests_root_path.exists() or not tests_root_path.is_dir(): + return { + "status": "error", + "message": f"Invalid 'tests_root': directory does not exist at {tests_root_path}", + "field_errors": { + "tests_root": f"Directory does not exist at {tests_root_path}", + }, + } + setup_info = VsCodeSetupInfo( - module_root=getattr(cfg, "module_root", ""), - tests_root=getattr(cfg, "tests_root", ""), - test_framework=getattr(cfg, "test_framework", "pytest"), - formatter=get_formatter_cmds(getattr(cfg, "formatter_cmds", "disabled")), + module_root=get_config_value("module_root", ""), + tests_root=tests_root, + test_framework=get_config_value("test_framework", "pytest"), + formatter=get_formatter_cmds(get_config_value("formatter_cmds", "disabled")), ) devnull_writer = open(os.devnull, "w") # noqa From 2340728385ce7c99ae3fa59989e8e26b71ece1f0 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 27 Nov 2025 08:45:30 +0200 Subject: [PATCH 2/3] fix formatting --- codeflash/lsp/beta.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 56dbe8f7b..1af7aa66a 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -203,9 +203,7 @@ def get_config_value(key: str, default: str = "") -> str: return { "status": "error", "message": f"Invalid 'tests_root': directory does not exist at {tests_root_path}", - "field_errors": { - "tests_root": f"Directory does not exist at {tests_root_path}", - }, + "field_errors": {"tests_root": f"Directory does not exist at {tests_root_path}"}, } setup_info = VsCodeSetupInfo( From 14f5b904bf6d8efbef7f909d035bdcfca6498905 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Mon, 1 Dec 2025 19:02:02 +0200 Subject: [PATCH 3/3] fix formmatting --- codeflash/lsp/beta.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 1af7aa66a..e90b8269e 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -194,10 +194,7 @@ def get_config_value(key: str, default: str = "") -> str: # Validate tests_root directory exists if provided if tests_root: # Resolve path relative to config file directory or current working directory - if cfg_file: - base_dir = cfg_file.parent - else: - base_dir = Path.cwd() + base_dir = cfg_file.parent if cfg_file else Path.cwd() tests_root_path = (base_dir / tests_root).resolve() if not tests_root_path.exists() or not tests_root_path.is_dir(): return {