mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-16 02:15:49 +00:00
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:
1 file changed
+26
-2
@@ -124,8 +124,20 @@ class SerenaAgentMode(ToolInclusionDefinition, ToStringMixin):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, name_or_path: str | Path) -> Self:
|
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_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))
|
return cls.from_name(str(name_or_path))
|
||||||
|
|
||||||
|
|
||||||
@@ -225,8 +237,20 @@ class SerenaAgentContext(ToolInclusionDefinition, ToStringMixin):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, name_or_path: str | Path) -> Self:
|
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_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))
|
return cls.from_name(str(name_or_path))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in new issue
Block a user