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,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Abilities;
|
||||
|
||||
use LIT\MCP\Abilities\Cursor;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
|
||||
final class CursorTest extends TestCase
|
||||
{
|
||||
public function testRoundTrip(): void
|
||||
{
|
||||
self::assertSame(40, Cursor::decode(Cursor::encode(40)));
|
||||
}
|
||||
|
||||
public function testMissingCursorStartsAtZero(): void
|
||||
{
|
||||
self::assertSame(0, Cursor::decode(null));
|
||||
self::assertSame(0, Cursor::decode(''));
|
||||
}
|
||||
|
||||
public function testTamperedCursorIsRejected(): void
|
||||
{
|
||||
self::assertNull(Cursor::decode('not-a-cursor'));
|
||||
self::assertNull(Cursor::decode(base64_encode('o:-5')));
|
||||
self::assertNull(Cursor::decode(base64_encode('o:12;DROP')));
|
||||
}
|
||||
|
||||
public function testLimitIsClamped(): void
|
||||
{
|
||||
self::assertSame(20, Cursor::limit(null));
|
||||
self::assertSame(1, Cursor::limit(0));
|
||||
self::assertSame(100, Cursor::limit(500));
|
||||
self::assertSame(7, Cursor::limit(7));
|
||||
}
|
||||
|
||||
public function testPageDetectsMoreRows(): void
|
||||
{
|
||||
$page = Cursor::page([1, 2, 3], 2, 10);
|
||||
|
||||
self::assertSame([1, 2], $page['items']);
|
||||
self::assertSame(12, Cursor::decode($page['next_cursor']));
|
||||
self::assertNull(Cursor::page([1, 2], 2, 0)['next_cursor']);
|
||||
}
|
||||
|
||||
public function testInvalidCursorErrorIsAValidationError(): void
|
||||
{
|
||||
self::assertSame('lit_validation_failed', Cursor::invalid()->get_error_code());
|
||||
}
|
||||
|
||||
public function testInputPropertiesDescribeLimitAndCursor(): void
|
||||
{
|
||||
$properties = Cursor::inputProperties();
|
||||
|
||||
self::assertSame(100, $properties['limit']['maximum']);
|
||||
self::assertSame('string', $properties['cursor']['type']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user