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
83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__).'/Support/bootstrap.php';
|
|
|
|
mcpDefineLaravelMcpStubs();
|
|
mcpRequire('Mcp/Resources/ContentResource.php');
|
|
|
|
use Core\Mcp\Resources\ContentResource;
|
|
use Illuminate\Support\Collection;
|
|
use Laravel\Mcp\Request;
|
|
|
|
test('ContentResource_handle_Good_renders_frontmatter_excerpt_and_markdown_body', function (): void {
|
|
$workspace = (object) ['id' => 1, 'slug' => 'host'];
|
|
$item = (object) [
|
|
'title' => 'Launch Post',
|
|
'slug' => 'launch-post',
|
|
'type' => 'post',
|
|
'status' => 'publish',
|
|
'author' => (object) ['name' => 'Virgil'],
|
|
'categories' => [(object) ['name' => 'News']],
|
|
'tags' => [(object) ['name' => 'Launch']],
|
|
'excerpt' => 'Big launch.',
|
|
'content_markdown' => '# Hello',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
];
|
|
|
|
$resource = new class($workspace, $item) extends ContentResource
|
|
{
|
|
public function __construct(private object $workspaceFixture, private object $itemFixture)
|
|
{
|
|
}
|
|
|
|
protected function resolveWorkspace(string $identifier): ?object
|
|
{
|
|
return $this->workspaceFixture;
|
|
}
|
|
|
|
protected function resolveContentItem(object $workspace, string $identifier): ?object
|
|
{
|
|
return $this->itemFixture;
|
|
}
|
|
};
|
|
|
|
$content = $resource->handle(new Request(['uri' => 'content://host/launch-post']))->content;
|
|
|
|
expect($content)->toContain("title: Launch Post")
|
|
->and($content)->toContain('> Big launch.')
|
|
->and($content)->toContain('# Hello');
|
|
});
|
|
|
|
test('ContentResource_handle_Bad_rejects_invalid_content_uris', function (): void {
|
|
$resource = new class extends ContentResource {};
|
|
|
|
expect($resource->handle(new Request(['uri' => 'invalid://x']))->content)
|
|
->toBe('Invalid URI format. Expected: content://{workspace}/{slug}');
|
|
});
|
|
|
|
test('ContentResource_list_Ugly_can_be_overridden_to_surface_resource_lists_without_the_database', function (): void {
|
|
$resource = new class extends ContentResource
|
|
{
|
|
protected function listResources(): array
|
|
{
|
|
return [[
|
|
'uri' => 'content://host/launch-post',
|
|
'name' => 'Launch Post',
|
|
'description' => 'Post: Launch Post',
|
|
'mimeType' => 'text/markdown',
|
|
]];
|
|
}
|
|
};
|
|
|
|
expect(mcpInvokeProtected($resource, 'listResources'))->toBe([[
|
|
'uri' => 'content://host/launch-post',
|
|
'name' => 'Launch Post',
|
|
'description' => 'Post: Launch Post',
|
|
'mimeType' => 'text/markdown',
|
|
]]);
|
|
});
|