[DX regression] Canvas AI: Add 'YAML Path Equals' and 'YAML Path Exists' plugins
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3579681. -->
Reported by: [akhil babu](https://www.drupal.org/user/3632866)
Related to !737
>>>
<h3 id="overview">Overview</h3>
<p>Parent issue: <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3579471" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3579471</a></span></p>
<p>Creating a test with the AI Agents Test module involves the following steps, at a high level:</p>
<ul>
<li>Selecting the agent</li>
<li>Defining the input prompt</li>
<li>Defining rules per tool (a tool should/should not run at a specific loop)</li>
<li>Defining rules to validate the tool parameter inputs given by the agent</li>
</ul>
<p>The rules mentioned in the final step are called parameter rules, and the module defines them as <code>AgentsParameterTest</code> plugins. The plugins available out of the box are:</p>
<ul>
<li>No rules</li>
<li>Equals</li>
<li>Less Than</li>
<li>Not One Of</li>
<li>Not Set</li>
<li>LLM Test</li>
<li>Not Equals</li>
<li>Isset</li>
<li>Greater Than</li>
<li>One Of</li>
</ul>
<p>The Drupal Canvas Page Builder and Template Builder agents generate tool input in YAML format like below:</p>
<pre>operations:<br> - target: 'content'<br> reference_uuid: '72384115-a8ee-44bc-9a13-de1c7a4d9b96'<br> placement: 'above'<br> components:<br> - sdc.canvas_test_sdc.heading:<br> props:<br> text: 'Above existing component'<br> element: 'h2'<br><br> - target: 'content'<br> reference_uuid: '72384115-a8ee-44bc-9a13-de1c7a4d9b96'<br> placement: 'below'<br> components:<br> - sdc.canvas_test_sdc.heading:<br> props:<br> text: 'Below existing component'<br> element: 'h2'</pre><pre>content:<br> - sdc.canvas_test_sdc.my-hero:<br> props:<br> heading: 'My Hero'<br> subheading: 'SubSnub'<br> cta1: 'View it!'<br> cta1href: 'https://canvas-example.com'<br> cta2: 'Click it!'<br> - sdc.canvas_test_sdc.card:<br> props:<br> title: 'Test Card'<br> content: 'Test content'<br> loading: 'lazy'<br> image:<br> src: /modules/contrib/canvas/tests/modules/canvas_test_sdc/components/card/bal<br> alt: 'Hot air balloons'<br> width: 640<br> height: 427<br> - sdc.canvas_test_sdc.heading:<br> props:<br> text: 'Some text'<br> element: 'h1'</pre><p>So, in order to validate that the YAML is generated correctly, we need to create new plugins specifically for this.</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p>Create a new module Canvas AI Agents Test.</p>
<h2>Proposed plugins</h2>
<ul>
<li><code>YAML Path Exists</code>: Checks if a specific YAML path exists in the tool input, like <code>operations.0.components.0.sdc\.canvas_test_sdc\.heading.props.heading_level</code>. Useful in cases where we just want to verify that the YAML contains specific data, but we do not care about the exact value. For example, when the test prompt is "Add a heading component with the name of a color", we can verify that the agent has provided some value for the heading text prop by giving the expected path as <code>operations.0.components.0.sdc\.canvas_test_sdc\.heading.props.heading_text</code>.</li>
<li><code>YAML Path Equals</code>: Checks that the value at a specific path is exactly the same as expected. For example, if the prompt is "Add a second-level heading component with the name of a color", then we can validate that <code>operations.0.components.0.sdc\.canvas_test_sdc\.heading.props.heading_level=h2</code>.</li>
</ul>
<p><em>This issue summary was refined with AI</em></p>
<h3 id="ui-changes">User interface changes</h3>
<h3 id="">Testing steps</h3>
<ul>
<li>Add this line to settings.php if not present : <code>$settings['extension_discovery_scan_tests'] = TRUE;</code></li>
<li>Install Canvas AI Agents test module</li>
<li>Go to <code>/admin/content/ai-agents-test </code>and click on 'Add AI Agents Test'.</li>
<li>Under 'Usage' select 'Drupal Canvas Page Builder Agent'</li>
<li>Under 'Rules', Click 'Add rule'</li>
<li>Select 'Set Component Structure' in 'Rules for the tool' dropdown and 'Should be run' in 'Tool Rules' dropdown</li>
<li>A new detail element 'Parameter Component structure in yml format' would appear now</li>
<li>Click on the 'Rule' Dropdown.</li>
<li>The new rules <code>YAML Path Exists</code> and <code>YAML Path Equals</code> should be there in the list.</li>
</ul>
<p><img src="https://www.drupal.org/files/issues/2026-03-23/Add-Agent-Test-Drush-Site-Install-03-23-2026_01_27_PM.png" alt="/files/issues/2026-03-23/Add-Agent-Test-Drush-Site-Install-03-23-2026_01_27_PM.png"></p>
> Related issue: [Issue #3579471](https://www.drupal.org/node/3579471)
issue