feat: MCP profile tools; ProfileUpdater/ProfilePresenter shared with /me; docs and Caddy snippet for /mcp

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-05 06:14:31 -03:00
parent ed45a1d516
commit 8ee8a30fb5
12 changed files with 220 additions and 50 deletions

View File

@@ -36,4 +36,18 @@ class McpAuthTest extends TestCase
->assertOk()
->assertJsonPath('result.serverInfo.name', 'Hado');
}
public function test_lists_all_tools_over_http(): void
{
$user = User::create(['login' => 'nikita', 'tz' => 'UTC']);
AgentToken::create(['user_id' => $user->id, 'token_hash' => hash('sha256', 'secret')]);
$names = collect($this->postJson('/mcp', ['jsonrpc' => '2.0', 'id' => 2, 'method' => 'tools/list'], ['Authorization' => 'Bearer secret'])
->assertOk()->json('result.tools'))->pluck('name')->all();
$this->assertSame([
'list_events', 'get_event', 'create_event', 'update_event', 'delete_event',
'mark_done', 'mark_ack', 'get_profile', 'update_profile',
], $names);
}
}

View File

@@ -36,7 +36,7 @@ class McpToolsTest extends TestCase
parent::setUp();
config(['hado.default_tz' => 'UTC']);
CarbonImmutable::setTestNow('2026-09-05T12:00:00Z');
$this->user = User::create(['login' => 'nikita', 'tz' => 'UTC']);
$this->user = User::create(['login' => 'nikita', 'tz' => 'UTC'])->fresh(); // дефолты тихих часов — из БД
$this->docs = Source::create(['name' => 'docs', 'token_hash' => hash('sha256', 'x')]);
// Как AuthenticateAgent: пользователь токена лежит в атрибутах текущего запроса
$this->app['request']->attributes->set('user', $this->user);
@@ -168,6 +168,48 @@ class McpToolsTest extends TestCase
$this->assertSame(EventState::Today, $docs->fresh()->state);
}
// --- действия пользователя: любой источник ---
public function test_mark_done_closes_foreign_event_like_the_inbox_button(): void
{
$docs = $this->docsEvent($this->user);
HadoServer::tool(MarkDone::class, ['id' => $docs->id])->assertOk()
->assertStructuredContent(fn (AssertableJson $j) => $j->where('state', 'done')->where('editable', false)->etc());
$this->assertNotNull($docs->fresh()->done_at);
// повторно — no-op, без ошибки
HadoServer::tool(MarkDone::class, ['id' => $docs->id])->assertOk();
}
public function test_mark_ack_silences_until_next_checkpoint(): void
{
$docs = $this->docsEvent($this->user);
$before = $docs->quiet_until;
HadoServer::tool(MarkAck::class, ['id' => $docs->id])->assertOk()
->assertStructuredContent(fn (AssertableJson $j) => $j->where('state', 'today')->etc());
$this->assertTrue($docs->fresh()->quiet_until->gt($before));
$other = User::create(['login' => 'other', 'tz' => 'UTC']);
HadoServer::tool(MarkAck::class, ['id' => $this->docsEvent($other, EventState::Today, 'f')->id])->assertHasErrors(['не найдено']);
}
// --- профиль ---
public function test_profile_is_readable_and_editable_with_inbox_rules(): void
{
HadoServer::tool(GetProfile::class)->assertOk()
->assertStructuredContent(fn (AssertableJson $j) => $j->where('login', 'nikita')->where('tz', 'UTC')->where('quiet_start', '22:00')->where('quiet_end', '09:00')->etc());
HadoServer::tool(UpdateProfile::class, ['tz' => 'America/Montevideo', 'quiet_start' => '23:30'])->assertOk()
->assertStructuredContent(fn (AssertableJson $j) => $j->where('tz', 'America/Montevideo')->where('quiet_start', '23:30')->where('quiet_end', '09:00')->etc());
$this->assertSame('America/Montevideo', $this->user->fresh()->tz);
HadoServer::tool(UpdateProfile::class, ['tz' => 'Mars/Olympus'])->assertHasErrors(['tz']);
HadoServer::tool(UpdateProfile::class, ['quiet_end' => '23:45'])->assertHasErrors(['полночь']);
}
public function test_delete_event_withdraws_own_event(): void
{
$id = $this->createOwn();