-
-
Notifications
You must be signed in to change notification settings - Fork 78
fix: implement search_stackoverflow_threads and standardize tool interface #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaishree-verma
wants to merge
3
commits into
jenkinsci:main
Choose a base branch
from
jaishree-verma:fix/search-stackoverflow-threads
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
67c2e78
fix: implement search_stackoverflow_threads and standardize tool inte…
jaishree-verma cff738d
fix: remove inline comment from config files per review feedback
jaishree-verma ba1543b
fix: remove all inline comments from config files per review feedback
jaishree-verma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Unit tests for the tools module.""" | ||
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
|
|
||
| class TestSearchStackoverflowThreads(unittest.TestCase): | ||
| """Test suite for search_stackoverflow_threads tool.""" | ||
|
|
||
| def _make_logger(self): | ||
| return MagicMock() | ||
|
|
||
| @patch("api.tools.tools.retrieve_documents") | ||
| @patch("api.tools.tools.extract_top_chunks") | ||
| def test_returns_extract_top_chunks_result(self, mock_extract, mock_retrieve): | ||
| """Test that the function returns the result of extract_top_chunks.""" | ||
| mock_retrieve.return_value = ([], [], [], []) | ||
| mock_extract.return_value = "some result" | ||
|
|
||
| from api.tools.tools import search_stackoverflow_threads | ||
| result = search_stackoverflow_threads("how to use jenkins", "jenkins", self._make_logger()) | ||
|
|
||
| self.assertEqual(result, "some result") | ||
|
|
||
| @patch("api.tools.tools.retrieve_documents") | ||
| @patch("api.tools.tools.extract_top_chunks") | ||
| def test_calls_retrieve_documents_with_correct_args(self, mock_extract, mock_retrieve): | ||
| """Test that retrieve_documents is called with query and keywords.""" | ||
| mock_retrieve.return_value = ([], [], [], []) | ||
| mock_extract.return_value = "" | ||
| logger = self._make_logger() | ||
|
|
||
| from api.tools.tools import search_stackoverflow_threads | ||
| search_stackoverflow_threads("pipeline error", "pipeline", logger) | ||
|
|
||
| mock_retrieve.assert_called_once() | ||
| call_kwargs = mock_retrieve.call_args.kwargs | ||
| self.assertEqual(call_kwargs["query"], "pipeline error") | ||
| self.assertEqual(call_kwargs["keywords"], "pipeline") | ||
|
|
||
| @patch("api.tools.tools.retrieve_documents") | ||
| @patch("api.tools.tools.extract_top_chunks") | ||
| def test_does_not_return_hardcoded_nothing_relevant(self, mock_extract, mock_retrieve): | ||
| """Test that the stub behaviour is gone — never returns hardcoded 'Nothing relevant'.""" | ||
| mock_retrieve.return_value = ([], [], [], []) | ||
| mock_extract.return_value = "No context available." | ||
|
|
||
| from api.tools.tools import search_stackoverflow_threads | ||
| result = search_stackoverflow_threads("any query", "any", self._make_logger()) | ||
|
|
||
| self.assertNotEqual(result, "Nothing relevant") | ||
|
|
||
|
|
||
| class TestToolSignatures(unittest.TestCase): | ||
| """Test that all tools have consistent signatures.""" | ||
|
|
||
| def test_stackoverflow_has_keywords_in_signature(self): | ||
| """Test that TOOL_SIGNATURES includes keywords for stackoverflow.""" | ||
| from api.tools.utils import TOOL_SIGNATURES | ||
| self.assertIn("keywords", TOOL_SIGNATURES["search_stackoverflow_threads"]) | ||
|
|
||
| def test_default_tool_calls_include_keywords_for_stackoverflow(self): | ||
| """Test that get_default_tools_call includes keywords for stackoverflow.""" | ||
| from api.tools.utils import get_default_tools_call | ||
| calls = get_default_tools_call("test query") | ||
| so_call = next(c for c in calls if c["tool"] == "search_stackoverflow_threads") | ||
| self.assertIn("keywords", so_call["params"]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the first, second, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review @berviantoleo!
I checked PR #172. The key difference in my PR is that it also standardizes the tool interface by adding keywords and logger parameters to match the contract of the other 3 search tools (search_jenkins_docs, search_plugin_docs, search_community_threads).
PR #172 keeps search_stackoverflow_threads(query) only, which leaves the interface inconsistency unfixed.
I will remove the inline comment (#-> first change) from both config files as requested. Should I also address the interface standardization separately or keep it in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to comment on existing PR, suggest the what you found that the contributor will miss. It's another way to contribute. Contribution doesn't mean you need to be an author; as a pair-reviewer, it's also valuable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood! I will go to PR #172 and leave a review comment there pointing out the interface inconsistency.
Thank you for the guidance @berviantoleo!