Merge pull request #1 from cx-alberto-simoes/Test

Validate if files exist, instead of just lookint to yml extension
This commit is contained in:
Alberto Simões authored and GitHub committed 2026-01-09 09:20:56 +00:00
commit 4cdc2a7405
1 file changed
+26 -2
+26 -2
View File
@@ -124,8 +124,20 @@ 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)
# 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))
@@ -225,8 +237,20 @@ 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)
# 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