-
Notifications
You must be signed in to change notification settings - Fork 186
Add execute tool + scratch pad tests #4400
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
base: main
Are you sure you want to change the base?
Conversation
| super.setUp(); | ||
| } | ||
|
|
||
| public void testScratchpadSizeLimit() throws Exception { |
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.
thanks for verifying the exception in UT.
01c9af4 to
ddcaf7c
Compare
Seems like we started having a dependency conflict issue. |
3da17ef to
fcf1c94
Compare
|
Failing tests are unrelated |
|
@nathaliellenaa this test is constantly failing, can you try fix the test by downloading another imageurl? we need the required CI passed to merge this. |
fcf1c94 to
e1f019e
Compare
Signed-off-by: Nathalie Jonathan <[email protected]>
Signed-off-by: Nathalie Jonathan <[email protected]>
Signed-off-by: Nathalie Jonathan <[email protected]>
Signed-off-by: Nathalie Jonathan <[email protected]>
Signed-off-by: Nathalie Jonathan <[email protected]>
e1f019e to
6ed156d
Compare
WalkthroughThe PR adds comprehensive test coverage for security and error handling scenarios across tool execution components. Changes include new unit tests for SecurityException handling in tool operations, permission validation in integration tests, and size limit verification for scratchpad functionality. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (5)
ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/WriteToScratchPadToolTests.java (2)
215-225: Consider asserting scratchpad mutation in this JSON-array conversion test
testRun_StringConversion_WithJsonArraynow only checks the response string; asserting the updatedSCRATCHPAD_NOTES_KEYhere as well would better match the test name and keep this path fully covered (even though other tests cover similar mutations).
227-242: SecurityException test does not exerciseWriteToScratchPadToolbehavior
testRun_SecurityExceptiondirectly callslistener.onFailure(securityException)and then verifies the listener, without invokingtool.run(...). That means the test is not validating howWriteToScratchPadToolitself behaves when aSecurityExceptionoccurs; it only checks that Mockito and the listener work as expected.If the goal is tool-level behavior, consider:
- Driving
tool.run(...)and arranging dependencies so aSecurityExceptionflows through the listener, or- Dropping this test and relying on higher‑level tests like
MLToolExecutorTest.test_ToolExecutionFailsWithoutProperPermission, which already validate the permission error path end‑to‑end.ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/ReadFromScratchPadToolTests.java (1)
220-233: SecurityException test does not exerciseReadFromScratchPadToolbehavior
testRun_SecurityExceptionmanually triggerslistener.onFailure(securityException)and verifies the captured exception, but never callstool.run(...). This doesn’t assert anything about howReadFromScratchPadToolhandles permission failures; it just checks the listener wiring.To make this more meaningful, consider:
- Refactoring to drive
tool.run(...)and simulate aSecurityExceptionfrom its internal operations, or- Removing this test and relying on higher‑level permission tests (e.g.,
MLToolExecutorTestand the ITs) for SecurityException coverage.plugin/src/test/java/org/opensearch/ml/tools/ListIndexToolIT.java (1)
44-80: Robust permission IT; only minor polish possibleThis test cleanly verifies that a no‑permission user gets a permission/forbidden/unauthorized error over HTTPS, and it correctly cleans up the client and user. The string‑contains checks are flexible enough to tolerate backend wording differences.
If you want to tighten things later, optional tweaks would be:
- Use
Collections.emptyList()instead ofnew ArrayList<>()for the no‑roles argument.- Use try‑with‑resources for
RestClientinstead of an explicittry/finally.plugin/src/test/java/org/opensearch/ml/tools/ScratchPadToolIT.java (1)
1-39: Effective size‑limit IT; consider tuning payload size / constructionThis IT correctly exercises the WriteToScratchPad tool via the REST endpoint with an oversized payload and asserts that some form of content‑length / 413‑style error is returned, without over‑fitting to a specific exception type or message.
Two optional refinements you might consider:
- Use a payload just over the configured
http.max_content_length(rather than a full 100 MB) to reduce memory pressure in CI while still triggering the same failure.- If you ever change
largeContentto something more complex than"A", switch to building the JSON body via a helper or escaping utility instead of rawString.formatto avoid quoting/escaping pitfalls.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/tool/MLToolExecutorTest.java(1 hunks)ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/ReadFromScratchPadToolTests.java(1 hunks)ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/WriteToScratchPadToolTests.java(1 hunks)plugin/src/test/java/org/opensearch/ml/tools/ListIndexToolIT.java(2 hunks)plugin/src/test/java/org/opensearch/ml/tools/ScratchPadToolIT.java(1 hunks)
🔇 Additional comments (1)
ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/tool/MLToolExecutorTest.java (1)
206-226: Good coverage of permission‑denied tool execution path
test_ToolExecutionFailsWithoutProperPermissioncorrectly simulates aSecurityExceptionfrom the tool and verifies it is propagated unchanged toactionListener, including the message fragment. This nicely complementstest_ToolExecutionFailedand the scratchpad tests.
Description
Add execute tool + scratch pad tests
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Summary by CodeRabbit
Tests
✏️ Tip: You can customize this high-level summary in your review settings.