Feature/search by oql - #21
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
OQL escaping and class extraction reject valid inputs, and the new search path permits unbounded result retrieval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds an MCP tool for paginated searches using OQL and strengthens query-value escaping.
Changes:
- Adds arbitrary OQL search support with datamodel-derived output fields.
- Adds OQL parsing, escaping, and related tests.
- Includes total-result metadata in object output.
File summaries
| File | Description |
|---|---|
tests/phpunit/ToolsFromTemplateTest.php |
Tests OQL value escaping. |
tests/phpunit/DatamodelServiceTest.php |
Tests class extraction from OQL. |
templates/searchAnyObjectByOql-input.json.twig |
Builds the REST search request. |
templates/Anything-output.toon.twig |
Displays total result information. |
src/Tools/iTopRestTools.php |
Adds OQL string escaping. |
src/Tools/core/get/iTopGetTools.php |
Exposes the new search tool and escapes existing queries. |
src/Service/DatamodelService.php |
Extracts class names from OQL. |
src/Kernel.php |
Prevents test-time constant redefinition. |
Review details
Suppressed comments (1)
src/Tools/core/get/iTopGetTools.php:129
limitis unconstrained; iTop treats any value<= 0as no SQL limit, so a tool call such aslimit: 0can load an entire large class despite this parameter being documented as a page size. Enforce a minimum of 1 and a reasonable upper bound (and likewise requirepage >= 1) before issuing the request.
public function searchAnyObjectByOql(string $oql, int $limit = 20, int $page = 1 ): string
- Files reviewed: 8/8 changed files
- Comments generated: 7
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+55
to
+59
| '"' => '\"', | ||
| "'" => "\'", | ||
| '_' => "\_", | ||
| "%" => "\%", | ||
| '\\' => '\\\\' |
Comment on lines
+124
to
+128
| $this->assertEquals("Line1\\nLine2", iTopGetTools::quoteString("Line1\nLine2")); | ||
| $this->assertEquals("Tab\\tSeparated", iTopGetTools::quoteString("Tab\tSeparated")); | ||
| $this->assertEquals("Percent\\%Sign", iTopGetTools::quoteString("Percent%Sign")); | ||
| $this->assertEquals("Underscore\\_Test", iTopGetTools::quoteString("Underscore_Test")); | ||
| $this->assertEquals("Backslash\\\\Test", iTopGetTools::quoteString("Backslash\\Test")); |
Comment on lines
+129
to
+133
| public function searchAnyObjectByOql(string $oql, int $limit = 20, int $page = 1 ): string | ||
| { | ||
| $className = $this->datamodel->getClassFromOQL($oql); | ||
| $outputFields = $this->datamodel->getListZlist($className); | ||
| return $this->runToolFromTemplates('searchAnyObjectByOql', 'Anything', |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The OQL parser rejects valid bare and multiline queries already used by the repository.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 3
Open (4)
Accept valid bare and multiline OQL queries · New These assertions lock in escape sequences that iTop's OQL lexer does not accept in single-quoted… These mappings produce escapes such as\",\n,\%, and\_inside single-quoted OQL… The new public tool has no template-level test, although comparable get tools are tested in…
Resolved since last review (4)
The first expected exception terminates this test, so the secondexpectException()and…$meis undefined and unused, so every telephone search emits anUndefined variable $mewarning… The method promises to validate against the current datamodel, but it returns any syntactically… This regex does not cover valid iTop OQL forms: leading whitespace is legal, and `SELECT P FROM…
Comment on lines
+226
to
+227
| if (!preg_match('/^SELECT +([_a-zA-Z][_a-zA-Z0-9]*) +(?:JOIN|WHERE|AS)/', $oql, $aMatches)) { | ||
| if (!preg_match('/^SELECT +(?:[_a-zA-Z][_a-zA-Z0-9, ]*) +FROM +([_a-zA-Z][_a-zA-Z0-9]*)/', $oql, $aMatches)) { |
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.


This PR adds a new tool to perform a search of any class of objects, based on an OQL query.
The agent has to generate a valid OQL query for this tool... by checking the list of classes and their schema first !