Skip to content

Feature/search by oql - #21

Merged
dflaven merged 8 commits into
masterfrom
feature/search-by-oql
Sep 21, 2026
Merged

dflaven merged 8 commits into
masterfrom
feature/search-by-oql

Conversation

@dflaven

@dflaven dflaven commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

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 !

Copilot AI balanced review requested due to automatic review settings September 17, 2026 10:06
@CombodoApplicationsAccount CombodoApplicationsAccount added the internal Work made by Combodo label Sep 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

  • limit is unconstrained; iTop treats any value <= 0 as no SQL limit, so a tool call such as limit: 0 can 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 require page >= 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 thread src/Service/DatamodelService.php Outdated
Comment thread src/Service/DatamodelService.php Outdated
Comment thread src/Tools/core/get/iTopGetTools.php Outdated
Comment on lines +55 to +59
'"' => '\"',
"'" => "\'",
'_' => "\_",
"%" => "\%",
'\\' => '\\\\'
Comment thread tests/phpunit/DatamodelServiceTest.php Outdated
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',

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
@dflaven
dflaven merged commit c892985 into master Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Work made by Combodo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants