From 201db5afcbc8f5984eab3249f063ed8e3c9ef58c Mon Sep 17 00:00:00 2001 From: Alberto Simoes <104087721+cx-alberto-simoes@users.noreply.github.com> Date: Thu, 8 Jan 2026 15:00:00 +0000 Subject: [PATCH 1/2] Instead of checking for extension, check if file exists --- src/serena/config/context_mode.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/serena/config/context_mode.py b/src/serena/config/context_mode.py index 205e9141..83298ab4 100644 --- a/src/serena/config/context_mode.py +++ b/src/serena/config/context_mode.py @@ -124,7 +124,9 @@ class SerenaAgentMode(ToolInclusionDefinition, ToStringMixin): @classmethod def load(cls, name_or_path: str | Path) -> Self: - if str(name_or_path).endswith(".yml"): + # Check if it's a file path that exists + path = Path(name_or_path) + if path.exists() and path.is_file(): return cls.from_yaml(name_or_path) return cls.from_name(str(name_or_path)) @@ -225,7 +227,9 @@ class SerenaAgentContext(ToolInclusionDefinition, ToStringMixin): @classmethod def load(cls, name_or_path: str | Path) -> Self: - if str(name_or_path).endswith(".yml"): + # Check if it's a file path that exists + path = Path(name_or_path) + if path.exists() and path.is_file(): return cls.from_yaml(name_or_path) return cls.from_name(str(name_or_path)) From c25fb662629d67a505dc41fb4c263628880e8ecb Mon Sep 17 00:00:00 2001 From: Alberto Simoes <104087721+cx-alberto-simoes@users.noreply.github.com> Date: Thu, 8 Jan 2026 15:02:22 +0000 Subject: [PATCH 2/2] Instead of checking for extension, check if file exists --- src/serena/config/context_mode.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/serena/config/context_mode.py b/src/serena/config/context_mode.py index 83298ab4..80528108 100644 --- a/src/serena/config/context_mode.py +++ b/src/serena/config/context_mode.py @@ -128,6 +128,16 @@ class SerenaAgentMode(ToolInclusionDefinition, ToStringMixin): path = Path(name_or_path) if path.exists() and path.is_file(): return cls.from_yaml(name_or_path) + + # 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")) + ): + raise FileNotFoundError(f"Mode file not found: {path.resolve()}") + return cls.from_name(str(name_or_path)) @@ -231,6 +241,16 @@ class SerenaAgentContext(ToolInclusionDefinition, ToStringMixin): path = Path(name_or_path) if path.exists() and path.is_file(): return cls.from_yaml(name_or_path) + + # 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")) + ): + raise FileNotFoundError(f"Context file not found: {path.resolve()}") + return cls.from_name(str(name_or_path)) @classmethod