Issue #3586391: Resolve use_default provider for conditional subcontext.

Description

Default ai_context.settings ships with provider_config.use_default: true and empty provider / model values, expecting the site-wide AI chat default from ai.settings. Runtime code only checked the raw provider and model strings, so conditional subcontext AI calls were silently skipped on typical installs even when a chat default was configured.

This MR adds AiContextProviderConfigResolver (ai_context.provider_config_resolver) to resolve the effective chat provider/model:

  1. Explicit provider + model in ai_context.settings win.
  2. When those are empty and use_default is true, resolve via AiProviderPluginManager::getDefaultProviderForOperationType('chat').
  3. Otherwise return NULL.

The resolver is used in:

  • AiContextSubcontextResolver — conditional subcontext AI calls
  • AiContextRenderer — token chunker model selection
  • AiContextItemForm — provider-required UI checks
  • AiContextSettingsForm — validation and provider warnings

Additional fixes:

  • Enable #default_provider_allowed => TRUE on the settings form so the Default option matches shipped config and can be saved/managed in the UI.
  • When use_default is enabled, add ai.settings as a render cache dependency so site default model changes invalidate cached context output.

No public API or hook changes. The new service is @internal.

Closes #3586391

Testing instructions

Automated (from project root):

cd web/modules/contrib/ai_context
./lint.sh
ddev phpunit web/modules/contrib/ai_context/tests/src/Kernel/AiContextProviderConfigResolverTest.php
ddev phpunit web/modules/contrib/ai_context/tests/src/Kernel/AiContextSubcontextResolverTest.php
ddev phpunit web/modules/contrib/ai_context/tests/src/Kernel/AiContextRendererTest.php
ddev phpunit web/modules/contrib/ai_context/tests/src/Functional/AiContextAdminSettingsTest.php
ddev phpunit web/modules/contrib/ai_context/tests/src/FunctionalJavascript/AiContextSettingsJavascriptTest.php

Manual:

  1. Ensure the site has an AI chat default configured (/admin/config/ai/settings or equivalent).
  2. Go to /admin/config/ai/context/settings/general.
  3. Confirm the provider select includes Default when a site chat default exists.
  4. With Default selected (or fresh install defaults), create a published parent context item with a published conditional subcontext child.
  5. Trigger context selection (agent prompt or relevant API path) and confirm the conditional child is evaluated via AI rather than skipped.
  6. Change the site chat default model and confirm rendered context output reflects the new chunker behavior after cache rebuild.

Checklist

  • I have updated the MR title to use format: Issue #1234: My issue title.
  • I have updated the MR description to include: Closes #1234
  • I have performed a self-review of my own code
  • I have added or updated tests, or explained in the description why this change is not covered by tests
  • I have written testing instructions and verified them locally
  • I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
  • This MR contains no breaking API or hook changes, or they are explicitly documented in the description

Not applicable:

  • I have updated documentation for any new or changed functionality

Documentation: No user-facing docs update needed. This aligns runtime behavior with existing shipped config and the AI module’s provider configuration element; no new admin workflow.

Post-merge: Standard cache rebuild on deploy (drush cr). No config import or update hook required.

AI Compliance

Note

Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.

  • AI Assisted Code
    Mainly written by a human; AI used for autocomplete or partial generation under full human supervision.

  • AI Generated Code
    Mainly generated by AI, reviewed and approved by a human before this MR was created.

  • Vibe Coded
    Generated by AI and only functionally reviewed before this MR was created.

Edited by Kristen Pol

Merge request reports

Loading