Repository navigation
Conversation
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.
What does this PR do?
find_files()now checks containment withPath.is_relative_to()instead of a string prefix, so a sibling directory whose name starts with the project root's name can no longer be searched.Fixes #114
Root cause / motivation
/srv/project-privatestarts with/srv/projectwithout being inside it, sofind_files({"path": "../project-private"})was allowed and listed files outside the project. This is the same patternfile_tools._within_roots()already fixed withis_relative_to(); the search tool kept the old spelling.Changes
devagent/tools/search_tools.py: containment check is nowsearch_root.is_relative_to(root), with a comment pointing at the rulefile_toolsuses.tests/test_search_tool_containment.py: new regression tests — a name-prefix sibling is rejected, plain..traversal is rejected, and files inside the project are still listed.Test plan
The sibling test fails on the unmodified checkout (it listed
secret.txtfromproj-private), and passes with the change.python -m pytest tests/ -qpasses (no new failures introduced) — ran the containment and Phase 41 suites (20 passed); the full suite needs the optional provider SDKs installed, which this change does not touchruff check devagent/ tests/is cleanNotes for reviewers
The
greptool in the same module also takes a path from the model. It shells out to ripgrep withrootas its working directory and does not accept a caller-supplied root, so it is not affected by this containment rule — worth a look if you would rather have both tools share one_within_roots()-style helper.