mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-03 05:41:07 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Platform\Ai\Contracts\AiDriver;
|
|
use App\Platform\Ai\Data\AiChatResponse;
|
|
use App\Platform\Ai\Drivers\AiDriverFactory;
|
|
use App\Platform\Ai\Drivers\OpenRouterDriver;
|
|
use InvoiceShelf\Modules\Registry;
|
|
|
|
test('make resolves the built-in openrouter driver', function () {
|
|
$driver = AiDriverFactory::make('openrouter', 'fake-key');
|
|
|
|
expect($driver)->toBeInstanceOf(OpenRouterDriver::class);
|
|
});
|
|
|
|
test('make resolves Registry-only drivers via metadata', function () {
|
|
$fakeClass = new class('', []) extends AiDriver
|
|
{
|
|
public function chatCompletion(array $messages, string $model, array $tools = [], array $options = []): AiChatResponse
|
|
{
|
|
return new AiChatResponse(message: 'test');
|
|
}
|
|
|
|
public function textCompletion(string $prompt, string $model, array $options = []): string
|
|
{
|
|
return 'test';
|
|
}
|
|
|
|
public function validateConnection(): array
|
|
{
|
|
return ['ok' => true];
|
|
}
|
|
};
|
|
|
|
Registry::registerAiDriver('registry_only_ai', [
|
|
'class' => $fakeClass::class,
|
|
'label' => 'test.ai.label',
|
|
]);
|
|
|
|
try {
|
|
$driver = AiDriverFactory::make('registry_only_ai', 'fake-key');
|
|
expect($driver)->toBeInstanceOf(AiDriver::class);
|
|
} finally {
|
|
unset(Registry::$drivers['ai']['registry_only_ai']);
|
|
}
|
|
});
|
|
|
|
test('make throws for unknown drivers', function () {
|
|
expect(fn () => AiDriverFactory::make('definitely_not_a_real_ai_driver', 'k'))
|
|
->toThrow(InvalidArgumentException::class);
|
|
});
|
|
|
|
test('availableDrivers merges built-in and Registry-registered drivers', function () {
|
|
Registry::registerAiDriver('extra_ai_driver', [
|
|
'class' => OpenRouterDriver::class,
|
|
'label' => 'extra.label',
|
|
]);
|
|
|
|
try {
|
|
$available = AiDriverFactory::availableDrivers();
|
|
|
|
expect($available)
|
|
->toContain('openrouter')
|
|
->toContain('extra_ai_driver');
|
|
} finally {
|
|
unset(Registry::$drivers['ai']['extra_ai_driver']);
|
|
}
|
|
});
|