From ff68b53397336b598c24fdbffc85a442e1f44ff1 Mon Sep 17 00:00:00 2001 From: Alberto Simoes <104087721+cx-alberto-simoes@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:35:01 +0000 Subject: [PATCH] Fix context and mode file detection logic - Replace .yml extension check with proper file existence check - Check if path exists as a file first before treating as name - Raise FileNotFoundError for paths that look like files but don't exist (contains path separators or ends with .yml/.yaml) - Improves error messages when file paths are invalid --- src/serena/config/context_mode.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/serena/config/context_mode.py b/src/serena/config/context_mode.py index 80528108..9238d806 100644 --- a/src/serena/config/context_mode.py +++ b/src/serena/config/context_mode.py @@ -131,11 +131,7 @@ class SerenaAgentMode(ToolInclusionDefinition, ToStringMixin): # If it looks like a file path but doesn't exist, raise FileNotFoundError name_or_path_str = str(name_or_path) - if ( - os.sep in name_or_path_str - or (os.altsep and os.altsep in name_or_path_str) - or name_or_path_str.endswith((".yml", ".yaml")) - ): + if os.sep in name_or_path_str or (os.altsep and os.altsep in name_or_path_str) or name_or_path_str.endswith((".yml", ".yaml")): raise FileNotFoundError(f"Mode file not found: {path.resolve()}") return cls.from_name(str(name_or_path)) @@ -244,11 +240,7 @@ class SerenaAgentContext(ToolInclusionDefinition, ToStringMixin): # If it looks like a file path but doesn't exist, raise FileNotFoundError name_or_path_str = str(name_or_path) - if ( - os.sep in name_or_path_str - or (os.altsep and os.altsep in name_or_path_str) - or name_or_path_str.endswith((".yml", ".yaml")) - ): + if os.sep in name_or_path_str or (os.altsep and os.altsep in name_or_path_str) or name_or_path_str.endswith((".yml", ".yaml")): raise FileNotFoundError(f"Context file not found: {path.resolve()}") return cls.from_name(str(name_or_path))