Issue #3586272: Add validation that max_global_items cannot exceed max_items
Description
Adds cross-field validation so max_global_items cannot exceed max_items, closing the gap deferred from #3580910 (closed).
- New
ContextLimitsConstraint+ validator. It applies to any mapping that exposes bothmax_global_itemsandmax_items, and only compares when both are set so an omitted cap still falls back to its inherited default. - Schema: the constraint is attached to
ai_context.settingsand to the per-agent mapping inai_context.agents, so invalid combinations fail config validation on import (CMI parity). - General settings form: the schema constraint surfaces through
#config_target, so no extra form code is needed there. - Agent overrides form: adds a
validateForm()backstop, since that form builds config manually rather than using#config_target.
Runtime selection behavior in AiContextSelector::mergeByPriority() is unchanged. This is about admin UX and config integrity.
Closes #3586272.
Testing instructions
- Visit
/admin/config/ai/context/settings/general, set Max global context items to 10 and Max context items to inject to 5, and save. The form is rejected with a validation message on the global items field. - Set a valid combination (for example global 0, total 5) and confirm it saves.
- On an agent override form, set both caps with global above total and confirm the same rejection.
Automated coverage:
vendor/bin/phpunit web/modules/contrib/ai_context/tests/src/Kernel/AiContextLimitsConfigValidationTest.php
vendor/bin/phpunit web/modules/contrib/ai_context/tests/src/Kernel/AiContextSettingsConfigValidationTest.phpAI usage
This change was generated by an AI assistant under my review. I am responsible for the code and can explain every decision.