feat: site-status test tool and core integration
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Core;
|
||||
|
||||
use LIT\MCP\Access;
|
||||
use LIT\MCP\Guides\GuideRepository;
|
||||
use LIT\MCP\Integrations\Integration;
|
||||
|
||||
final class CoreIntegration implements Integration
|
||||
{
|
||||
public function __construct(private string $guidesDirectory)
|
||||
{
|
||||
}
|
||||
|
||||
public function id(): string
|
||||
{
|
||||
return 'core';
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function abilities(): array
|
||||
{
|
||||
return [
|
||||
new GuideAbility(new GuideRepository($this->guidesDirectory)),
|
||||
new SiteStatusAbility(new EnvironmentProbe(), new Access()),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Core;
|
||||
|
||||
/**
|
||||
* Detects the themes/plugins LIT MCP integrates with.
|
||||
*/
|
||||
class EnvironmentProbe
|
||||
{
|
||||
/** @return list<array{id: string, active: bool, version: ?string}> */
|
||||
public function components(): array
|
||||
{
|
||||
$theme = wp_get_theme();
|
||||
$isDivi = $theme->get_template() === 'Divi';
|
||||
$parent = $theme->parent();
|
||||
$diviVersion = $isDivi ? (string) ($parent ? $parent->get('Version') : $theme->get('Version')) : null;
|
||||
|
||||
$tecActive = class_exists('Tribe__Events__Main');
|
||||
|
||||
return [
|
||||
['id' => 'divi', 'active' => $isDivi, 'version' => $diviVersion],
|
||||
[
|
||||
'id' => 'pods',
|
||||
'active' => defined('PODS_VERSION'),
|
||||
'version' => defined('PODS_VERSION') ? (string) PODS_VERSION : null,
|
||||
],
|
||||
[
|
||||
'id' => 'the-events-calendar',
|
||||
'active' => $tecActive,
|
||||
'version' => $tecActive ? (string) constant('Tribe__Events__Main::VERSION') : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Core;
|
||||
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Access;
|
||||
use WP_Error;
|
||||
|
||||
final class SiteStatusAbility implements Ability
|
||||
{
|
||||
public function __construct(private EnvironmentProbe $probe, private Access $access)
|
||||
{
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'lit/site-status';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Website-Status';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Überblick: Website, WordPress-Version, eigener Benutzer und Rollen, '
|
||||
. 'erkannte Integrationen (Divi, Pods, The Events Calendar).';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
{
|
||||
return ['type' => 'object', 'properties' => [], 'additionalProperties' => false];
|
||||
}
|
||||
|
||||
public function outputSchema(): ?array
|
||||
{
|
||||
return [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'site' => ['type' => 'object'],
|
||||
'wordpress' => ['type' => 'string'],
|
||||
'user' => ['type' => 'object'],
|
||||
'allowed_roles' => ['type' => 'array', 'items' => ['type' => 'string']],
|
||||
'components' => ['type' => 'array'],
|
||||
],
|
||||
'required' => ['site', 'wordpress', 'user', 'allowed_roles', 'components'],
|
||||
];
|
||||
}
|
||||
|
||||
public function annotations(): array
|
||||
{
|
||||
return ['readonly' => true, 'destructive' => false, 'idempotent' => true];
|
||||
}
|
||||
|
||||
public function isDirect(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function permission(array $input): bool|WP_Error
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function execute(array $input): mixed
|
||||
{
|
||||
$user = wp_get_current_user();
|
||||
|
||||
return [
|
||||
'site' => ['name' => get_bloginfo('name'), 'url' => home_url()],
|
||||
'wordpress' => get_bloginfo('version'),
|
||||
'user' => ['id' => $user->ID, 'roles' => array_values($user->roles)],
|
||||
'allowed_roles' => $this->access->allowedRoles(),
|
||||
'components' => $this->probe->components(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Core;
|
||||
|
||||
use LIT\MCP\Integrations\Core\CoreIntegration;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
|
||||
final class CoreIntegrationTest extends TestCase
|
||||
{
|
||||
public function testIsAlwaysAvailableAndProvidesGuideAndStatus(): void
|
||||
{
|
||||
$core = new CoreIntegration(dirname(__DIR__, 3) . '/Fixtures/guides');
|
||||
|
||||
self::assertSame('core', $core->id());
|
||||
self::assertTrue($core->isAvailable());
|
||||
self::assertSame(
|
||||
['lit/guide', 'lit/site-status'],
|
||||
array_map(static fn ($a) => $a->name(), $core->abilities())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Core;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Access;
|
||||
use LIT\MCP\Integrations\Core\EnvironmentProbe;
|
||||
use LIT\MCP\Integrations\Core\SiteStatusAbility;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
use WP_User;
|
||||
|
||||
final class SiteStatusAbilityTest extends TestCase
|
||||
{
|
||||
public function testReportsSiteUserAndComponents(): void
|
||||
{
|
||||
Functions\when('get_bloginfo')->alias(static fn (string $key) => ['name' => 'Kunde', 'version' => '7.0.3'][$key]);
|
||||
Functions\when('home_url')->justReturn('https://kunde.de');
|
||||
Functions\when('wp_get_current_user')->justReturn(new WP_User(3, ['editor']));
|
||||
Functions\when('get_option')->justReturn(['administrator', 'editor']);
|
||||
|
||||
// EnvironmentProbe is deliberately non-final so it can be mocked; Access is final, so use the real one.
|
||||
$probe = Mockery::mock(EnvironmentProbe::class);
|
||||
$probe->allows('components')->andReturn([['id' => 'divi', 'active' => true, 'version' => '5.2.1']]);
|
||||
|
||||
$result = (new SiteStatusAbility($probe, new Access()))->execute([]);
|
||||
|
||||
self::assertSame(['name' => 'Kunde', 'url' => 'https://kunde.de'], $result['site']);
|
||||
self::assertSame('7.0.3', $result['wordpress']);
|
||||
self::assertSame(['id' => 3, 'roles' => ['editor']], $result['user']);
|
||||
self::assertSame(['administrator', 'editor'], $result['allowed_roles']);
|
||||
self::assertSame('divi', $result['components'][0]['id']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user