Tools tab shows one block per integration with a group mode (inherited by its tools) and a read-only switch that disables all non-readonly abilities of the group. ExposurePolicy resolves tool override > group override > tool default; lit/guide keeps its default, direct-only tools fall back to direct under a group "indirekt". Group entries live in lit_mcp_exposure under "@group:<id>" and "@readonly:<id>"; the old flat format stays valid. The ability->group map comes lazily from IntegrationRegistry (Divi is not loaded at plugins_loaded). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations;
|
|
|
|
use LIT\MCP\Abilities\Ability;
|
|
use LIT\MCP\Integrations\Integration;
|
|
use LIT\MCP\Integrations\IntegrationRegistry;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
|
|
final class IntegrationRegistryTest extends TestCase
|
|
{
|
|
public function testOnlyAvailableIntegrationsContributeAbilities(): void
|
|
{
|
|
$direct = $this->ability('lit/a', true);
|
|
$indirect = $this->ability('lit/b', false);
|
|
$hidden = $this->ability('lit/c', true);
|
|
|
|
$registry = new IntegrationRegistry(
|
|
$this->integration('core', true, [$direct, $indirect]),
|
|
$this->integration('divi', false, [$hidden])
|
|
);
|
|
|
|
self::assertSame(['core'], array_map(static fn ($i) => $i->id(), $registry->available()));
|
|
self::assertSame([$direct, $indirect], $registry->abilities());
|
|
}
|
|
|
|
public function testGroupsAbilitiesByIntegrationIdAndMapsNamesToGroups(): void
|
|
{
|
|
$guide = $this->ability('lit/guide', true);
|
|
$outline = $this->ability('lit/divi-outline', true);
|
|
$hidden = $this->ability('lit/pods-x', true);
|
|
$divi = Mockery::mock(Integration::class);
|
|
$divi->allows('id')->andReturn('divi');
|
|
$divi->allows('isAvailable')->andReturn(true);
|
|
$divi->expects('abilities')->once()->andReturn([$outline]);
|
|
|
|
$registry = new IntegrationRegistry(
|
|
$this->integration('core', true, [$guide]),
|
|
$divi,
|
|
$this->integration('pods', false, [$hidden])
|
|
);
|
|
|
|
self::assertSame([$guide, $outline], $registry->abilities());
|
|
self::assertSame(['core' => [$guide], 'divi' => [$outline]], $registry->grouped());
|
|
self::assertSame(['lit/guide' => 'core', 'lit/divi-outline' => 'divi'], $registry->groupMap());
|
|
self::assertSame(['core', 'divi', 'pods'], $registry->ids());
|
|
}
|
|
|
|
private function ability(string $name, bool $direct): Ability
|
|
{
|
|
$ability = Mockery::mock(Ability::class);
|
|
$ability->allows('name')->andReturn($name);
|
|
$ability->allows('isDirect')->andReturn($direct);
|
|
|
|
return $ability;
|
|
}
|
|
|
|
/** @param list<Ability> $abilities */
|
|
private function integration(string $id, bool $available, array $abilities): Integration
|
|
{
|
|
$integration = Mockery::mock(Integration::class);
|
|
$integration->allows('id')->andReturn($id);
|
|
$integration->allows('isAvailable')->andReturn($available);
|
|
$integration->allows('abilities')->andReturn($abilities);
|
|
|
|
return $integration;
|
|
}
|
|
}
|