AiAgentOverrideApplier assigns NULL to typed-array $tool_settings — 3 kernel tests fail
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3584634. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !258 >>> <p>[Tracker]<br> <strong>Update Summary: </strong>[One-line status update for stakeholders]<br> <strong>Short Description: </strong>Override applier assigns null to AiAgent::$tool_settings (typed array), breaking three kernel tests on CI.<br> <strong>Check-in Date: </strong>MM/DD/YYYY<br> [/Tracker]</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>CI job <a href="https://git.drupalcode.org/project/ai_agents/-/jobs/9355918">9355918</a> fails on <code>Drupal\Tests\ai_agents\Kernel\Override\AiAgentOverrideKernelTest</code> with 3 errors / 2 passes. All three errors have the same root cause:</p> <p><code>TypeError: Cannot assign null to property Drupal\ai_agents\Entity\AiAgent::$tool_settings of type array</code></p> <p>Failing tests:</p> <ul> <li><code>testOverridesAreAppliedToAgent</code></li> <li><code>testAgentFormAllowsTogglingOverrides</code></li> <li><code>testToolLibraryDisplaysSelectedToolsAndOverrideEnforcement</code></li> </ul> <p>Stack trace points at <code>AiAgentOverrideApplier</code> writing override values back into the parent agent entity:</p> <ul> <li><code>src/Service/AiAgentOverrideApplier.php:120</code> - the <code>set()</code> / assignment that fails</li> <li><code>src/Service/AiAgentOverrideApplier.php:88</code></li> <li><code>src/Service/AiAgentOverrideApplier.php:39</code></li> <li>Drupal core: <code>web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:180</code> (the <code>set()</code> that types the value)</li> </ul> <p><code>AiAgent::$tool_settings</code> is declared as a non-nullable <code>array</code>, so when the override payload for a given agent has no <code>tool_settings</code> key (or an explicitly-null value), the applier passes <code>NULL</code> into <code>ConfigEntityBase::set()</code> and PHP throws.</p> <p>Separately, the same test file also triggers a deprecation: <em>"Kernel test classes must specify the #[RunTestsInSeparateProcesses] attribute"</em> - worth fixing in the same MR since we are already touching the test, per <a href="https://www.drupal.org/node/3548485">https://www.drupal.org/node/3548485</a>.</p> <h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <ol> <li>Check out the ai_agents branch used in job 9355918 (see the job page for the MR/ref).</li> <li>Run <code>vendor/bin/phpunit --group ai_agents web/modules/contrib/ai_agents/tests/src/Kernel/Override/AiAgentOverrideKernelTest.php</code>.</li> <li>Observe 3 errors in the class with the TypeError above.</li> </ol> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>In <code>AiAgentOverrideApplier</code>, coalesce any array-typed field to <code>[]</code> before calling the entity's <code>set()</code> - at minimum <code>tool_settings</code>, but audit the other array-typed AiAgent properties the applier writes.</li> <li>Alternatively, change <code>AiAgent::$tool_settings</code> (and peers) to <code>?array</code> if null is actually a valid state, and update readers to handle null - but the safer fix is to keep the type and normalise at the applier boundary.</li> <li>Add a regression test that exercises an override payload missing <code>tool_settings</code>.</li> <li>Add <code>#[RunTestsInSeparateProcesses]</code> to <code>AiAgentOverrideKernelTest</code> to clear the deprecation warning.</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