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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user