1414
1515from codeflash .code_utils .git_utils import git_root_dir , mirror_path
1616from codeflash .discovery .functions_to_optimize import FunctionToOptimize
17- from codeflash .languages .base import CodeContext , FunctionFilterCriteria , HelperFunction , Language , TestInfo , TestResult
17+ from codeflash .languages .base import (
18+ CodeContext ,
19+ FunctionFilterCriteria ,
20+ HelperFunction ,
21+ Language ,
22+ SetupError ,
23+ TestInfo ,
24+ TestResult ,
25+ )
1826from codeflash .languages .javascript .treesitter import TreeSitterAnalyzer , TreeSitterLanguage , get_analyzer_for_file
1927from codeflash .languages .registry import register_language
2028from codeflash .models .models import FunctionParent
@@ -1950,11 +1958,13 @@ def prepare_module(
19501958
19511959 return prepare_javascript_module (module_code , module_path )
19521960
1953- def setup_test_config (self , test_cfg : TestConfig , file_path : Path , current_worktree : Path | None ) -> None :
1961+ def setup_test_config (self , test_cfg : TestConfig , file_path : Path , current_worktree : Path | None ) -> bool :
19541962 from codeflash .languages .javascript .optimizer import verify_js_requirements
19551963 from codeflash .languages .javascript .test_runner import find_node_project_root
19561964
19571965 test_cfg .js_project_root = find_node_project_root (file_path )
1966+ if test_cfg .js_project_root is None :
1967+ return False
19581968 if current_worktree is not None :
19591969 original_js_root = git_root_dir ()
19601970 worktree_node_modules = test_cfg .js_project_root / "node_modules"
@@ -1970,7 +1980,11 @@ def setup_test_config(self, test_cfg: TestConfig, file_path: Path, current_workt
19701980 original_root_node_modules = original_js_root / "node_modules"
19711981 if original_root_node_modules .exists () and not worktree_root_node_modules .exists ():
19721982 worktree_root_node_modules .symlink_to (original_root_node_modules )
1973- verify_js_requirements (test_cfg )
1983+ setup_errors = verify_js_requirements (test_cfg )
1984+ if any (e .should_abort for e in setup_errors ):
1985+ return False
1986+
1987+ return True
19741988
19751989 def adjust_test_config_for_discovery (self , test_cfg : TestConfig ) -> None :
19761990 test_cfg .tests_project_rootdir = test_cfg .tests_root
@@ -2243,7 +2257,7 @@ def get_module_path(self, source_file: Path, project_root: Path, tests_root: Pat
22432257 return path_without_ext + ".js"
22442258 return path_without_ext
22452259
2246- def verify_requirements (self , project_root : Path , test_framework : str = "jest" ) -> tuple [bool , list [str ]]:
2260+ def verify_requirements (self , project_root : Path , test_framework : str = "jest" ) -> tuple [bool , list [SetupError ]]:
22472261 """Verify that all JavaScript requirements are met.
22482262
22492263 Checks for:
@@ -2263,27 +2277,40 @@ def verify_requirements(self, project_root: Path, test_framework: str = "jest")
22632277 Tuple of (success, list of error messages).
22642278
22652279 """
2266- errors : list [str ] = []
2280+ errors : list [SetupError ] = []
22672281
22682282 # Check Node.js
22692283 try :
22702284 result = subprocess .run (["node" , "--version" ], check = False , capture_output = True , text = True , timeout = 10 )
22712285 if result .returncode != 0 :
2272- errors .append ("Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" )
2286+ errors .append (
2287+ SetupError (
2288+ "Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" ,
2289+ should_abort = True ,
2290+ )
2291+ )
22732292 except FileNotFoundError :
2274- errors .append ("Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" )
2293+ errors .append (
2294+ SetupError (
2295+ "Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" , should_abort = True
2296+ )
2297+ )
22752298 except Exception as e :
2276- errors .append (f"Failed to check Node.js: { e } " )
2299+ errors .append (SetupError ( f"Failed to check Node.js: { e } " , should_abort = True ) )
22772300
22782301 # Check npm
22792302 try :
22802303 result = subprocess .run (["npm" , "--version" ], check = False , capture_output = True , text = True , timeout = 10 )
22812304 if result .returncode != 0 :
2282- errors .append ("npm is not available. Please ensure npm is installed with Node.js." )
2305+ errors .append (
2306+ SetupError ("npm is not available. Please ensure npm is installed with Node.js." , should_abort = True )
2307+ )
22832308 except FileNotFoundError :
2284- errors .append ("npm is not available. Please ensure npm is installed with Node.js." )
2309+ errors .append (
2310+ SetupError ("npm is not available. Please ensure npm is installed with Node.js." , should_abort = True )
2311+ )
22852312 except Exception as e :
2286- errors .append (f"Failed to check npm: { e } " )
2313+ errors .append (SetupError ( f"Failed to check npm: { e } " , should_abort = True ) )
22872314
22882315 # Check test framework is installed (with monorepo support)
22892316 # Uses find_node_modules_with_package which searches up the directory tree
@@ -2297,12 +2324,17 @@ def verify_requirements(self, project_root: Path, test_framework: str = "jest")
22972324 local_node_modules = project_root / "node_modules"
22982325 if not local_node_modules .exists ():
22992326 errors .append (
2300- f"node_modules not found in { project_root } . Please run 'npm install' to install dependencies."
2327+ SetupError (
2328+ f"node_modules not found in { project_root } . Please run 'npm install' to install dependencies." ,
2329+ should_abort = True ,
2330+ )
23012331 )
23022332 else :
23032333 errors .append (
2304- f"{ test_framework } is not installed. "
2305- f"Please run 'npm install --save-dev { test_framework } ' to install it."
2334+ SetupError (
2335+ f"{ test_framework } is not installed. Please run 'npm install --save-dev { test_framework } ' to install it." ,
2336+ should_abort = True ,
2337+ )
23062338 )
23072339
23082340 return len (errors ) == 0 , errors
0 commit comments