feat: structured errors with hint, ToolResult, cursor pagination
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,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Abilities;
|
||||
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
|
||||
final class ErrorsTest extends TestCase
|
||||
{
|
||||
public function testMessageCarriesCodeMessageHintAndFieldsAsJson(): void
|
||||
{
|
||||
$error = Errors::invalidInput('Titel fehlt.', ['title' => 'Pflichtfeld']);
|
||||
|
||||
self::assertSame('lit_validation_failed', $error->get_error_code());
|
||||
$payload = json_decode($error->get_error_message(), true);
|
||||
self::assertSame('validation_failed', $payload['code']);
|
||||
self::assertSame('Titel fehlt.', $payload['message']);
|
||||
self::assertNotSame('', $payload['hint']);
|
||||
self::assertSame(['title' => 'Pflichtfeld'], $payload['fields']);
|
||||
self::assertSame(400, $error->get_error_data()['status']);
|
||||
self::assertSame($payload['hint'], $error->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
public function testUmlautsStayReadableInTheMessage(): void
|
||||
{
|
||||
$error = Errors::forbidden('Dein Benutzerkonto ist für LIT MCP nicht freigegeben.');
|
||||
|
||||
self::assertStringContainsString('für LIT MCP nicht freigegeben', $error->get_error_message());
|
||||
}
|
||||
|
||||
public function testInUseCarriesTheUsages(): void
|
||||
{
|
||||
$error = Errors::inUse('Bild wird verwendet.', [['post_id' => 7, 'where' => 'featured']]);
|
||||
|
||||
$payload = json_decode($error->get_error_message(), true);
|
||||
self::assertSame('lit_in_use', $error->get_error_code());
|
||||
self::assertSame(7, $payload['usages'][0]['post_id']);
|
||||
}
|
||||
|
||||
public function testEveryFactoryUsesLitPrefixAndANonEmptyHint(): void
|
||||
{
|
||||
$errors = [
|
||||
Errors::forbidden('x'),
|
||||
Errors::notFound('x'),
|
||||
Errors::revMismatch(),
|
||||
Errors::confirmRequired('x'),
|
||||
Errors::unsupported('x', 'y'),
|
||||
Errors::internal(),
|
||||
];
|
||||
|
||||
foreach ($errors as $error) {
|
||||
self::assertStringStartsWith('lit_', $error->get_error_code());
|
||||
self::assertNotSame('', json_decode($error->get_error_message(), true)['hint']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user