Add SensitiveContentStream guardrail and kernel test for StreamableGuardrailInterface mid-stream buffering and evaluation
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3584951. --> Reported by: [abhisekmazumdar](https://www.drupal.org/user/3557964) >>> [Tracker] **Update Summary:** SensitiveContentStream plugin added; kernel tests pass; pipeline green on 1.x **Short Description:** Add a concrete streaming guardrail plugin that suppresses marked content mid-stream **Check-in Date:** 06/04/2026 *Metadata is used by the [AI Tracker](https://www.drupalstarforge.ai/). Docs and additional fields [here](https://www.drupalstarforge.ai/ai-dashboard/docs).* [/Tracker] ## Problem/Motivation #3582179 introduced `StreamableGuardrailInterface` — a guardrail capability that hooks into the stream iterator in real time, buffers content between configurable start/stop patterns, and evaluates it before it reaches the consumer. That infrastructure shipped with no concrete plugin implementation. There is no way to use streaming guardrails out of the box, and no kernel test covering the full stack end-to-end. ## Proposed resolution Add a `SensitiveContentStream` guardrail plugin and full kernel test coverage. **New plugin: `SensitiveContentStream`** (`src/Plugin/AiGuardrail/SensitiveContentStream.php`) - Implements `StreamableGuardrailInterface` - Buffers streamed content and suppresses everything between a configurable `start_marker` and `stop_marker` - Replaces suppressed content with a configurable `replacement_message` **Config schema** (`config/schema/ai.schema.yml`) - Adds `ai.guardrail.settings.sensitive_content_stream` with `start_marker`, `stop_marker`, and `replacement_message` **Kernel tests** (`tests/src/Kernel/Plugin/AiGuardrail/StreamingGuardrailKernelTest.php`) - `testPluginDiscovery` — plugin is discovered by the plugin manager - `testStreamingGuardrailIsRegisteredOnIterator` — subscriber registers the guardrail on the iterator via `addStreamingGuardrail()` - `testCleanStreamPassesThrough` — content without markers streams through unchanged - `testNonStreamedRequestIgnoresStreamingGuardrail` — non-streamed responses are unaffected - `testMaxGuardrailBufferSizeConfiguration` — buffer size getter/setter (default 8192) - `testMultipleStreamingGuardrailsRegistered` — multiple streaming guardrails coexist on the same iterator ## Remaining tasks - [x] Write the kernel test class. - [x] Ensure the virtual/mock provider supports streaming in the kernel test environment. ## User interface changes None. ## API changes None. Adds a new plugin implementing the existing `StreamableGuardrailInterface`. ## Data model changes None. ## AI usage [x] AI Assisted Code This code was mainly written by a human, with AI used for analysis and partial generation under full human supervision. > Related issue: [Issue #3582179](https://www.drupal.org/node/3582179)
issue