Additive-only — no existing files modified. Services (php/Mcp/Services/): - CircuitBreaker (3-state, Cache::add trial lock) - DataRedactor (28 sensitive + 16 PII keys, partial-redact algorithm) - McpHealthService (YAML registry + JSON-RPC stdio ping protocolVersion 2024-11-05) - McpMetricsService (p50/p95/p99 linear interpolation) - McpWebhookDispatcher (mcp.tool.executed → WebhookEndpoints) - OpenApiGenerator (OpenAPI 3.0.3) - ToolRateLimiter (Cache::put first, Cache::increment after — no reset) - AgentSessionService (php/Mod/Mcp/Services/ namespace per spec) Transport (php/Mcp/Transport/): - McpContext (transport-agnostic callbacks) - Contracts/McpToolHandler interface Resources (php/Mcp/Resources/): - AppConfig, ContentResource, DatabaseSchema Config: php/resources/mcp/registry.yaml. Pest Feature tests _Good/_Bad/_Ugly per AX-10 for each new class. Co-authored-by: Codex <noreply@openai.com> Closes tasks.lthn.sh/view.php?id=842
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__).'/Support/bootstrap.php';
|
|
|
|
mcpDefineLaravelMcpStubs();
|
|
mcpRequire('Mcp/Resources/DatabaseSchema.php');
|
|
|
|
use Core\Mcp\Resources\DatabaseSchema;
|
|
use Laravel\Mcp\Request;
|
|
|
|
test('DatabaseSchema_handle_Good_serialises_each_table_description_as_pretty_json', function (): void {
|
|
$resource = new class extends DatabaseSchema
|
|
{
|
|
protected function tables(): array
|
|
{
|
|
return ['users'];
|
|
}
|
|
|
|
protected function describeTable(string $tableName): array
|
|
{
|
|
return [['Field' => 'id', 'Type' => 'bigint']];
|
|
}
|
|
};
|
|
|
|
$payload = json_decode($resource->handle(new Request)->content, true, 512, JSON_THROW_ON_ERROR);
|
|
|
|
expect($payload['users'][0]['Field'])->toBe('id');
|
|
});
|
|
|
|
test('DatabaseSchema_handle_Bad_returns_an_empty_json_object_when_no_tables_are_available', function (): void {
|
|
$resource = new class extends DatabaseSchema
|
|
{
|
|
protected function tables(): array
|
|
{
|
|
return [];
|
|
}
|
|
};
|
|
|
|
expect($resource->handle(new Request)->content)->toBe('[]');
|
|
});
|
|
|
|
test('DatabaseSchema_handle_Ugly_aggregates_multiple_tables_in_a_single_response', function (): void {
|
|
$resource = new class extends DatabaseSchema
|
|
{
|
|
protected function tables(): array
|
|
{
|
|
return ['users', 'posts'];
|
|
}
|
|
|
|
protected function describeTable(string $tableName): array
|
|
{
|
|
return [['table' => $tableName]];
|
|
}
|
|
};
|
|
|
|
$payload = json_decode($resource->handle(new Request)->content, true, 512, JSON_THROW_ON_ERROR);
|
|
|
|
expect(array_keys($payload))->toBe(['users', 'posts']);
|
|
});
|