Mock provider request matching breaks when new keys are added to input toArray()
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3582585. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !1389 !1388 >>> <p>[Tracker]<br> <strong>Update Summary: </strong>[One-line status update for stakeholders]<br> <strong>Short Description: </strong>Mock provider request matching breaks when new keys are added to input toArray()<br> <strong>Check-in Date: </strong>MM/DD/YYYY<br> [/Tracker]</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Needed for <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-14"><a href="https://www.drupal.org/project/ai/issues/3546954" title="Status: Reviewed &amp; tested by the community">#3546954: Normalize file api's to allow providers to use them</a></span>.</p> <p>The EchoProvider's <code>getMatchingRequest()</code> method in <code>ai_test</code> compares the current request against stored YAML fixtures using strict JSON equality (<code>Json::encode($request['request']) === Json::encode($array)</code>, line 406 of <code>EchoProvider.php</code>). When a new key with a default value is added to an input type's <code>toArray()</code> (e.g. <code>remote_files</code> added to <code>ChatInput</code>), all existing YAML test fixtures break because they do not contain the new key - even though the default value is functionally irrelevant.</p> <p>This means every time a new property with a default value is added to any input type, all existing test YAML files for that operation type must be manually updated. This is fragile and creates unnecessary churn.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>Change the comparison in <code>EchoProvider::getMatchingRequest()</code> so that it automatically fills in default values for keys that are present in the current input's <code>toArray()</code> but missing from the stored YAML request, before comparing.</li> <li>This way existing YAML fixtures continue to work even after new keys with default values are added to input types.</li> <li>One approach: iterate the keys of <code>$array</code> (the current input) and for any key missing in <code>$request['request']</code>, add the default value from the input before comparison. Alternatively, only compare the keys that exist in the YAML fixture (subset matching) rather than requiring exact equality.</li> </ul> <h3 id="summary-ai-usage">AI usage (if applicable)</h3> <p>[x] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p> <p>[ ] AI Assisted Code<br> [ ] AI Generated Code<br> [ ] Vibe Coded</p> <p>- <strong>This issue was created with the help of AI</strong></p>
issue