fix(tools): correct Python-fallback bugs in calculator, file tools, a…#236
Open
TacoengineerIT wants to merge 1 commit intoopen-jarvis:mainfrom
Open
fix(tools): correct Python-fallback bugs in calculator, file tools, a…#236TacoengineerIT wants to merge 1 commit intoopen-jarvis:mainfrom
TacoengineerIT wants to merge 1 commit intoopen-jarvis:mainfrom
Conversation
…nd git tool - calculator: add `ln` alias for `math.log`, replace `^` with `**` before AST parsing so caret-as-power works, convert SyntaxError → ValueError for consistent error handling, and return `math.inf` on division by zero (matching the documented meval behaviour) instead of raising an exception - file_read / file_write: replace the hardcoded `str(path).startswith(str(d) + "/") guard with `Path.is_relative_to()` so allowed-directory checks work on Windows (and any OS whose separator is not `/`) - git_tool: catch `NotADirectoryError` raised by `subprocess.run` on Windows when `cwd` points to a non-existent path, returning a proper error result Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed 9 real bugs across 4 source files discovered via static analysis and
manual code review. All bugs affect the Python fallback path (active when the
Rust extension is not compiled); two are cross-platform regressions that fail
on Windows.
Problem
1.
calculator.py— 6 bugs in the Python AST fallbacksafe_eval("2^10")1024.0ValueError— Python^is XOR, not powersafe_eval("ln(e)")1.0ValueError: Unknown function: lnsafe_eval("1/0")math.infZeroDivisionErrorunhandledsafe_eval("2 +")ValueErrorSyntaxError— brokepytest.raises(ValueError)safe_eval("x + 1")"unknown variable"Ubroke regex matchCalculatorTool.execute("1/0")success=True, content="inf"success=False2.
file_read.py/file_write.py— cross-platform path check_is_path_allowedusedstr(path).startswith(str(d) + "/")with a hardcoded/separator. On Windows (os.sep = \) this never matched, soallowed_dirsalways denied access — even to permitted paths.3.
git_tool.py— unhandledNotADirectoryErroron Windows_run_gitdid not catchNotADirectoryError(WinError 267), raised bysubprocess.runwhencwdis a non-existent directory. The exceptionpropagated instead of returning
ToolResult(success=False).Solution
^→**, addlnalias, convertSyntaxError→ValueError, returnmath.infondivision by zero, fix error message casing
startswith(str(d) + "/")withPath.is_relative_to(d)(OS-agnostic, Python ≥3.9)
except NotADirectoryErrorhandler in_run_gitTesting
uv run pytest tests/ -v)tests/tools/test_calculator.py— 25/25 (was 6 failed)tests/tools/test_file_read.py—test_allowed_dirs_permitspassestests/tools/test_file_write.py—test_allowed_dirs_permitspassestests/tools/test_git_tool.py—test_invalid_repo_pathpassesNotes
Found via static analysis + manual code review of the full codebase. Bugs live
in the Python fallback path — invisible when
openjarvis_rustis compiled, butthey surface immediately for contributors who skip
maturin develop.