From 9aea32eb4c081f552a6b1a3cce36c6feac1ef830 Mon Sep 17 00:00:00 2001 From: Alex Schose <286504050+alex-schose@users.noreply.github.com> Date: Thu, 18 Jun 2026 17:57:57 +0200 Subject: [PATCH] Use validate_relative_path instead of assert for new-file path confinement --- src/serena/tools/file_tools.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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)