Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion includes/Vendor/AiClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,25 @@ upstream whenever a later PR touches the embedding execution path.

## Modifications applied

**None.** Unlike the `Secrets` vendor directory, these files keep their real
**One prefixed import.** WordPress core scopes the PHP AI Client's PSR dependencies under
`WordPress\AiClientDependencies\`, so the unprefixed names do not exist under a WordPress
bootstrap. `src/Builders/EmbeddingBuilder.php` imports
`Psr\EventDispatcher\EventDispatcherInterface`, and the vendored copy uses core's prefixed name.
Only the `use` line differs from upstream; the class body is byte-identical.

| File | Upstream import | Vendored import |
| --- | --- | --- |
| `src/Builders/EmbeddingBuilder.php` | `Psr\EventDispatcher\EventDispatcherInterface` | `WordPress\AiClientDependencies\Psr\EventDispatcher\EventDispatcherInterface` |

This is a vendoring adaptation, not an upstream bug: upstream installs its PSR packages through
Composer, where the bare name is correct. It is not a change to send upstream.

`SDK_OverlayTest::test_vendored_files_use_the_prefixed_psr_dependencies()` asserts that no vendored
file imports an unprefixed `Nyholm\…` or `Psr\…` symbol, so a future re-vendor cannot silently
reintroduce one. It matches every `Psr\` namespace rather than `Psr\Http\` alone, because core
prefixes `Psr\EventDispatcher\` and `Psr\SimpleCache\` the same way.

Otherwise unchanged. Unlike the `Secrets` vendor directory, these files keep their real
`WordPress\AiClient\…` namespace unchanged. That is required: the updated OpenAI/Google/Ollama
provider plugins must implement *this* `EmbeddingGenerationModelInterface` symbol, so it has to be
the canonical class, not a re-namespaced copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WordPress\AiClient\Builders;

use Psr\EventDispatcher\EventDispatcherInterface;
use WordPress\AiClientDependencies\Psr\EventDispatcher\EventDispatcherInterface;
use WordPress\AiClient\Builders\Traits\ModelConfigurationTrait;
use WordPress\AiClient\Common\AbstractEnum;
use WordPress\AiClient\Common\Contracts\AiClientExceptionInterface;
Expand Down
40 changes: 40 additions & 0 deletions tests/Integration/Includes/SDK_OverlayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,44 @@ public function test_plan_served_classes_ignores_non_activated_features(): void
SDK_Overlay::plan_served_classes( $features, array( 'embeddings' => 'activate' ) )
);
}

/**
* Vendored files import core's prefixed PSR/Nyholm dependencies, never the bare names.
*
* WordPress core scopes its PSR dependencies under `WordPress\AiClientDependencies\`. An
* unprefixed import resolves to nothing and fatals at runtime.
*
* The match covers every `Psr\` namespace rather than `Psr\Http\` alone. Core scopes more
* than PSR-7 -- `Psr\EventDispatcher\` and `Psr\SimpleCache\` are prefixed the same way --
* and a narrower pattern let an unprefixed `Psr\EventDispatcher\` import sit in the vendored
* tree undetected. It stayed latent only because the symbol appeared solely as a nullable type,
* which PHP never resolves while the value is null; passing a real dispatcher would have raised
* a TypeError, because the prefixed interface does not satisfy the unprefixed name.
*/
public function test_vendored_files_use_the_prefixed_psr_dependencies(): void {
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( SDK_Overlay::src_dir(), \FilesystemIterator::SKIP_DOTS )
);

$checked = 0;

foreach ( $files as $file ) {
if ( 'php' !== $file->getExtension() ) {
continue;
}

++$checked;

$this->assertDoesNotMatchRegularExpression(
'/^use (Nyholm|Psr)\\\\/m',
(string) file_get_contents( $file->getPathname() ),
sprintf(
'%s imports an unprefixed PSR dependency; core scopes these under WordPress\\AiClientDependencies\\.',
$file->getPathname()
)
);
}

$this->assertGreaterThan( 0, $checked, 'The vendored tree must contain PHP files.' );
}
}
Loading