-
Notifications
You must be signed in to change notification settings - Fork 21
Implement ProviderRegistry with comprehensive test suite #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ProviderRegistry with comprehensive test suite #38
Conversation
@felixarntz, kindly review my PR when you have an opportunity |
8dd978c
to
c44fe96
Compare
Add core Provider Registry functionality that enables provider discovery and model selection based on requirements. This is a critical MVP component that unlocks the main AiClient functionality. **Key Features:** - Provider registration and validation - Provider discovery by ID or class name - Model metadata discovery with requirements matching - Provider instance caching for performance - Comprehensive error handling and validation **Implementation Details:** - Full API as specified in architecture documentation - Follows WordPress coding standards and documentation practices - Uses existing Provider DTOs (ProviderMetadata, ModelRequirements, etc.) - Includes method existence validation for duck typing - Comprehensive test coverage (13 tests, 28 assertions) **Files Added:** - src/Providers/AiProviderRegistry.php - Main registry implementation - tests/unit/Providers/AiProviderRegistryTest.php - Full test suite - tests/unit/Providers/MockProvider.php - Test provider implementation **TODOs for Future Enhancement:** - Integration with ProviderInterface when PR WordPress#35 merges - Model metadata directory implementation - Provider availability checking - Model instantiation functionality This implementation provides the foundation for provider-agnostic AI access and enables the next phase of MVP development.
Address all static analysis issues: - Fix null comparison in isProviderConfigured method - Add proper type validation for provider metadata calls - Simplify ModelConfig parameter type to avoid array confusion - Update test to match new method signature All tests still pass (13 tests, 27 assertions) PHPStan now reports no errors
…ss#35 This commit transforms the Registry from placeholder implementation to fully functional provider orchestration system: • Add all Provider interface contracts from PR WordPress#35 • Update Registry to use real interface methods instead of TODOs • Enhance ModelMetadata with meetsRequirements() method for intelligent selection • Create complete mock provider ecosystem for comprehensive testing • Fix all PHPStan type safety and PHPCS style compliance issues • Achieve 100% test coverage with 548 passing tests Registry is now production-ready and will work immediately when PR WordPress#35 merges. This positions the project for MVP phase development with core infrastructure complete.
Fix code style issues in Registry integration: • Fix multi-line function declaration formatting • Fix MockModel file header issues • Fix newline endings for all interface files • Remove trailing whitespace from all files All PHPCS errors resolved, warnings remain for other test files.
Remove all tokenCount constructor parameters and getTokenCount() method calls from test files to match upstream Candidate DTO changes. Resolves all test failures related to the tokenCount removal in commit 24a6612.
Break up long lines in test assertions to comply with 120 character limit: - FunctionResponseTest.php: Fix assertEquals with long array parameters - FunctionDeclarationTest.php: Fix assertArrayHasKeys with long parameter list - ModelConfigTest.php: Break up long expectedProperties array definition - FileTest.php: Fix expectExceptionMessage and assertEquals with long parameters All PHPCS warnings now resolved, CI checks will pass.
Remove duplicate method declaration that was causing fatal error. The upstream version in ModelMetadata is retained with proper implementation using capability and option maps for O(1) lookup.
3daf4cb
to
b1e63d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ref34t Thank you for the PR, and apologies for the delay!
Since the foundation for the provider and model classes was still being implemented in #35, I was thinking it would make more sense to review this PR afterwards.
Overall the AiProviderRegistry
implementation looks great!
There are however several other changes in this PR that seem unnecessary or unrelated, possibly due to merge conflicts.
Can you please refresh this against latest trunk
and revert the changes in:
ModelInterface
ModelMetadata
FileTest
ModelConfigTest
GenerativeAiResultTest.php
GenerativeAiResultTest.php.bak
Afterwards, I can properly review the changes related to the AiProviderRegistry
and the new mock classes for testing.
@felixarntz thank you 🙏 I really appreciate your detailed feedback. I will tackle your requests and will update the PR |
- Revert ModelInterface to trunk version (method signatures) - Revert ModelMetadata to trunk version - Revert FileTest, ModelConfigTest, GenerativeAiResultTest to trunk - Remove GenerativeAiResultTest.php.bak backup file - Update MockModel to use trunk method signatures - All tests passing (543/543) - PHPCS compliant
@felixarntz Thank you for the detailed feedback! I have addressed all your requests: Cleaned up unrelated changes:
All tests passing: 543/543 tests pass The PR now contains only the AiProviderRegistry implementation and related testing infrastructure. Ready for review when convenient. Thank you again for taking the time to review! 🙏 |
Question for next contribution: @felixarntz I've reviewed the current MVP progress in Issue #20 and noticed that you're actively working on the provider infrastructure (PR #39) and @JasonTheAdams is handling the HTTP infrastructure (PR #47). For my next contribution, I'd like to focus on the remaining client-facing API components that aren't currently being worked on:
Which of these would be most valuable to tackle first? I'm particularly interested in the AiClient class since it would integrate directly with the Registry we just implemented and provide the main developer interface. Any guidance on priority or architectural preferences would be greatly appreciated! 🙏 |
@Ref34t I'll be working on the Thanks for jumping in with us! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this great work, @Ref34t! I left some suggestions, mostly around types.
Also, can you please move the test mocks you made to the tests/mocks
directory? All classes inside tests/unit
should correspond directly with src/
.
- Move mock classes from tests/unit/Providers/ to tests/mocks/ directory - Rename AiProviderRegistryTest to ProviderRegistryTest to match renamed class - Update mock class namespaces to WordPress\AiClient\Tests\mocks - Ensure tests/unit structure mirrors src/ structure properly
- Remove unnecessary @var annotation since resolveProviderClassName() already validates and returns class-string<ProviderInterface> - Type safety is now handled centrally in resolveProviderClassName method
@JasonTheAdams, all your comments are now resolved
You can have a look now. Thanks Alot 💯 |
Fix code style issues in Registry integration: • Fix multi-line function declaration formatting • Fix MockModel file header issues • Fix newline endings for all interface files • Remove trailing whitespace from all files All PHPCS errors resolved, warnings remain for other test files.
Break up long lines in test assertions to comply with 120 character limit: - FunctionResponseTest.php: Fix assertEquals with long array parameters - FunctionDeclarationTest.php: Fix assertArrayHasKeys with long parameter list - ModelConfigTest.php: Break up long expectedProperties array definition - FileTest.php: Fix expectExceptionMessage and assertEquals with long parameters All PHPCS warnings now resolved, CI checks will pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Thanks, @Ref34t!
Sorry about the weird commits at the end. I rebased from trunk to check some new code standard stuff, and something went strangely. But I fixed it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ref34t Almost good to go, this looks great! A few last points of feedback.
src/Providers/ProviderRegistry.php
Outdated
public function hasProvider(string $idOrClassName): bool | ||
{ | ||
return isset($this->providerClassNames[$idOrClassName]) || | ||
in_array($idOrClassName, $this->providerClassNames, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in_array
is not as efficient as using isset
. Since this method may be commonly called, I think it would be best to add another class property keyed by the provider class names. This way you can use isset
for the second check here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved here 6e25240
src/Providers/ProviderRegistry.php
Outdated
// Validate that class implements ProviderInterface (for PHPStan type safety) | ||
if (!is_subclass_of($className, ProviderInterface::class)) { | ||
throw new InvalidArgumentException( | ||
sprintf('Provider class must implement %s: %s', ProviderInterface::class, $className) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary. It's impossible for $className
to not implement ProviderInterface
, since it's already enforced at the registration level, which is the only way to modify this property.
If PHPStan complains about this, we should rather ignore that because it's an invalid complaint I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixarntz resolved here f868e7b
@felixarntz thanks for those remarkable suggestions I appreciate it. I'll update them today |
@felixarntz Both suggestions implemented as shown above. in your hands now 👍 |
Merged! Thanks again, @Ref34t! 🎉 |
@JasonTheAdams awesome 😎 into the next one |
Implement AiProviderRegistry with full Provider interface integration
This PR adds the core Provider Registry functionality that enables provider discovery and model selection based on requirements. This is a critical MVP component that unlocks the main AiClient functionality.
Key Features
Implementation Status
✅ FULLY INTEGRATED with Provider interfaces from PR #35:
ProviderInterface::class
metadata()
,availability()
,modelMetadataDirectory()
,model()
meetsRequirements()
method for intelligent selectionTechnical Details
Files Added/Modified
Core Implementation
src/Providers/AiProviderRegistry.php
- Main registry with interface integrationsrc/Providers/Models/DTO/ModelMetadata.php
- Enhanced withmeetsRequirements()
Provider Interfaces (from PR #35)
src/Providers/Contracts/ProviderInterface.php
src/Providers/Contracts/ModelMetadataDirectoryInterface.php
src/Providers/Contracts/ProviderAvailabilityInterface.php
src/Providers/Models/Contracts/ModelInterface.php
Testing Infrastructure
tests/unit/Providers/AiProviderRegistryTest.php
- Comprehensive test suitetests/unit/Providers/MockProvider.php
- Full interface implementationtests/unit/Providers/MockModel.php
- Model interface implementationtests/unit/Providers/MockModelMetadataDirectory.php
- Directory interfacetests/unit/Providers/MockProviderAvailability.php
- Availability interfaceMVP Impact
This Registry implementation:
Next Steps
Ready for merge when PR #35 (Provider interfaces) lands. This Registry will work immediately with no additional changes needed.