fix: admin UI review round 1 (S47) - Art labels, usage only on success, result fallback
- Art column: only lit/media-delete and lit/divi-delete say "löscht", lit/post-trash "Papierkorb", other destructive tools "überschreibt". - ConnectionUsage records only responses with status < 400 (mcp-oauth answers auth failures with WP_REST_Response 401, not WP_Error). - Log result column: translated "unbekannt" instead of the raw value. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,11 @@ use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Admin\ConnectionUsage;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use WP_Error;
|
||||
use WP_HTTP_Response;
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
|
||||
require_once __DIR__ . '/Fixtures/HttpResponses.php';
|
||||
|
||||
final class ConnectionUsageTest extends TestCase
|
||||
{
|
||||
@@ -64,6 +68,37 @@ final class ConnectionUsageTest extends TestCase
|
||||
self::assertSame([], $this->recorded);
|
||||
}
|
||||
|
||||
/** @dataProvider failedStatuses */
|
||||
public function testDoesNotRecordRequestsAnsweredWithAnErrorStatus(int $status): void
|
||||
{
|
||||
Functions\when('get_current_user_id')->justReturn(7);
|
||||
$claims = ['sub' => 7, 'app_pass_id' => 'uuid-1'];
|
||||
// mcp-oauth answers auth failures with a WP_REST_Response (OAuthHttpTransport::build_auth_error_response).
|
||||
$rest = new WP_REST_Response(['error' => 'invalid_token'], $status);
|
||||
|
||||
self::assertSame($rest, $this->usage($claims)->record($rest, [], $this->request()));
|
||||
$this->usage($claims)->record(new WP_HTTP_Response(null, $status), [], $this->request());
|
||||
|
||||
self::assertSame([], $this->recorded);
|
||||
}
|
||||
|
||||
/** @return list<list<int>> */
|
||||
public static function failedStatuses(): array
|
||||
{
|
||||
return [[401], [403], [500]];
|
||||
}
|
||||
|
||||
public function testRecordsSuccessfulRestResponses(): void
|
||||
{
|
||||
Functions\when('get_current_user_id')->justReturn(7);
|
||||
$claims = ['sub' => 7, 'app_pass_id' => 'uuid-1'];
|
||||
|
||||
$this->usage($claims)->record(new WP_REST_Response([], 200), [], $this->request());
|
||||
$this->usage($claims)->record(new WP_REST_Response([], 202), [], $this->request());
|
||||
|
||||
self::assertSame([[7, 'uuid-1'], [7, 'uuid-1']], $this->recorded);
|
||||
}
|
||||
|
||||
public function testNeverBreaksTheResponseWhenDecodingOrRecordingFails(): void
|
||||
{
|
||||
Functions\when('get_current_user_id')->justReturn(7);
|
||||
|
||||
Reference in New Issue
Block a user