diff --git a/src/serena/tools/file_tools.py b/src/serena/tools/file_tools.py index 2b7f1a9b2..08054ae43 100644 --- a/src/serena/tools/file_tools.py +++ b/src/serena/tools/file_tools.py @@ -69,9 +69,10 @@ def apply(self, relative_path: str, content: str) -> str: if will_overwrite_existing: self.project.validate_relative_path(relative_path, require_not_ignored=True) else: - assert abs_path.is_relative_to(self.get_project_root()), ( - f"Cannot create file outside of the project directory, got {relative_path=}" - ) + # Use the always-on containment guard rather than a bare `assert`, which is + # compiled out under `python -O` / PYTHONOPTIMIZE and would otherwise leave the + # new-file branch with no path-containment check. + self.project.validate_relative_path(relative_path) # writing the file abs_path.parent.mkdir(parents=True, exist_ok=True)