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 both max_global_items and max_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.settings and to the per-agent mapping in ai_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

  1. 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.
  2. Set a valid combination (for example global 0, total 5) and confirm it saves.
  3. 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.php

AI usage

This change was generated by an AI assistant under my review. I am responsible for the code and can explain every decision.

Merge request reports

Loading