Files
ProjectE/e2e/mcp.spec.ts
T
mbatchelder e5b7d9e2ee feat: Phase 6 - MCP + Webhooks + Worker + Polish
- MCP server: stateless JSON-RPC 2.0 with 18 tools (tasks, habits, projects, notes, domains, search, activity)
- Webhooks API: CRUD routes under /api/domains/[domainId]/webhooks/ with test endpoint and deliveries log
- Webhook delivery: HMAC-SHA256 signed POST with retry (exponential backoff, max 6)
- Worker rewrite: Drizzle ORM instead of PocketBase, polls jobs table, handles webhook_delivery, recurring_spawn, ai_dispatch
- Rate limiting: token bucket per IP/API key (100 req/min REST, 300 req/min MCP)
- Keyboard help overlay: ? opens Radix Dialog with search/filter, Esc closes
- AI @mention stub: @agent in command palette dispatches CustomEvent
- Mobile responsive: bottom nav, single-column kanban, day view calendar, 44px touch targets
- Accessibility: skip-to-content link, focus rings, aria-labels, color contrast
- E2E tests: mcp.spec.ts, webhooks.spec.ts, realtime.spec.ts added
- Schema: api_keys and webhook_deliveries tables with migration
- Removed old PocketBase-style database.ts from worker
2026-07-29 08:03:28 -04:00

91 lines
2.9 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { login } from './helpers/auth';
test.describe('MCP Server', () => {
test.beforeEach(async ({ page }) => {
await login(page);
});
test('server/discover should return all expected tools', async ({ page }) => {
const response = await page.request.post('/api/mcp', {
data: {
jsonrpc: '2.0',
method: 'server/discover',
id: 1,
},
});
expect(response.ok()).toBeTruthy();
const body = await response.json();
expect(body.jsonrpc).toBe('2.0');
expect(body.result).toBeDefined();
expect(body.result.name).toBe('project-e');
expect(body.result.tools).toBeDefined();
expect(Array.isArray(body.result.tools)).toBeTruthy();
// Verify expected tools exist
const toolNames = body.result.tools.map((t: { name: string }) => t.name);
expect(toolNames).toContain('tasks.list');
expect(toolNames).toContain('tasks.create');
expect(toolNames).toContain('tasks.update');
expect(toolNames).toContain('tasks.delete');
expect(toolNames).toContain('tasks.complete');
expect(toolNames).toContain('habits.list');
expect(toolNames).toContain('habits.create');
expect(toolNames).toContain('habits.complete');
expect(toolNames).toContain('projects.list');
expect(toolNames).toContain('projects.create');
expect(toolNames).toContain('notes.list');
expect(toolNames).toContain('notes.create');
expect(toolNames).toContain('notes.update');
expect(toolNames).toContain('notes.search');
expect(toolNames).toContain('domains.list');
expect(toolNames).toContain('domains.create');
expect(toolNames).toContain('search.query');
expect(toolNames).toContain('activity.list');
});
test('should reject unauthenticated requests', async ({ page }) => {
const response = await page.request.post('/api/mcp', {
data: {
jsonrpc: '2.0',
method: 'server/discover',
id: 1,
},
});
// Without API key, should return 401
expect(response.status()).toBe(401);
});
test('should return error for unknown method', async ({ page }) => {
const response = await page.request.post('/api/mcp', {
data: {
jsonrpc: '2.0',
method: 'unknown.method',
id: 1,
},
});
expect(response.ok()).toBeTruthy();
const body = await response.json();
expect(body.error).toBeDefined();
expect(body.error.code).toBe(-32601); // METHOD_NOT_FOUND
});
test('should reject invalid JSON-RPC request', async ({ page }) => {
const response = await page.request.post('/api/mcp', {
data: { invalid: true },
});
expect(response.status()).toBe(400);
const body = await response.json();
expect(body.error).toBeDefined();
});
test('GET should return 405', async ({ page }) => {
const response = await page.request.get('/api/mcp');
expect(response.status()).toBe(405);
});
});