TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.
TypeScript graphviewkanban-boardnodejsproductivityproject-managementself-hostedtasktask-managementtask-managertodoapp
wip: tests for MCP
Nikolai Gimana5446ea82534
diff --git a/taskview-packages/taskview-mcp/.env.test b/taskview-packages/taskview-mcp/.env.testindex d03e1c7..e7124a3 100644--- a/taskview-packages/taskview-mcp/.env.test+++ b/taskview-packages/taskview-mcp/.env.test@@ -1,2 +1,3 @@export TASKVIEW_URL=http://127.0.0.1:11401-export TASKVIEW_TOKEN=tvk_a05851cc02d629164838ff5adacab68c440b7f68f77f5c5fd0171f8256d7ee30+export TASKVIEW_LOGIN=user+export TASKVIEW_PASSWORD=user1!#Qdiff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/collaboration.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/collaboration.integration.test.tsindex e3ba1e6..59ecc6f 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/collaboration.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/collaboration.integration.test.ts@@ -72,4 +72,70 @@ describe('collaboration integration', () => {expect(user.email).toBe(email)})++ it('removes a collaborator', async () => {+ const email = `remove-${ts()}@integration-test.com`+ const invited = parse(await call(tools, 'invite_collaborator', { goalId, email }))++ const result = await call(tools, 'remove_collaborator', { goalId, id: invited.id })+ const data = parse(result)+ expect(data.deleted).toBe(true)++ const users = parse(await call(tools, 'list_collaborators_for_goal', { goalId })) as Array<{ email: string }>+ expect(users.find((u) => u.email === email)).toBeUndefined()+ })++ it('toggles collaborator roles', async () => {+ const email = `roles-${ts()}@integration-test.com`+ const invited = parse(await call(tools, 'invite_collaborator', { goalId, email }))++ const roles = parse(await call(tools, 'list_roles', { goalId })) as Array<{ id: number; name: string }>+ const editor = roles.find((r) => r.name === 'editor')+ expect(editor).toBeDefined()++ const result = await call(tools, 'toggle_collaborator_roles', {+ goalId,+ userId: invited.id,+ roles: [editor!.id],+ })+ const data = parse(result)+ expect(Array.isArray(data.roles)).toBe(true)+ expect(data.roles).toContain(editor!.id)++ const users = parse(await call(tools, 'list_collaborators_for_goal', { goalId })) as Array<{ id: number; roles: number[] }>+ const user = users.find((u) => u.id === invited.id)+ expect(user?.roles).toContain(editor!.id)+ })++ it('deletes a role', async () => {+ const created = parse(await call(tools, 'create_role', { goalId, roleName: `delete-me-${ts()}` }))++ const result = await call(tools, 'delete_role', { goalId, id: created.id })+ const data = parse(result)+ expect(data.deleted).toBe(true)++ const roles = parse(await call(tools, 'list_roles', { goalId })) as Array<{ id: number }>+ expect(roles.find((r) => r.id === created.id)).toBeUndefined()+ })++ it('toggles role permission (add and remove)', async () => {+ const role = parse(await call(tools, 'create_role', { goalId, roleName: `perm-role-${ts()}` }))+ const permissions = parse(await call(tools, 'list_permissions')) as Array<{ id: number; name: string }>+ const targetPerm = permissions.find((p) => p.name === 'goal_can_watch_content')+ expect(targetPerm).toBeDefined()++ const addResult = parse(await call(tools, 'toggle_role_permission', {+ roleId: role.id,+ permissionId: targetPerm!.id,+ }))+ expect(addResult.add).toBe(true)++ const removeResult = parse(await call(tools, 'toggle_role_permission', {+ roleId: role.id,+ permissionId: targetPerm!.id,+ }))+ expect(removeResult.add).toBe(false)++ await call(tools, 'delete_role', { goalId, id: role.id }).catch(() => {})+ })})diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/global-setup.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/global-setup.tsnew file mode 100644index 0000000..beeebf5--- /dev/null+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/global-setup.ts@@ -0,0 +1,49 @@+import axios from 'axios'++const TASKVIEW_URL = process.env.TASKVIEW_URL+const TASKVIEW_LOGIN = process.env.TASKVIEW_LOGIN+const TASKVIEW_PASSWORD = process.env.TASKVIEW_PASSWORD+const TASKVIEW_TOKEN_PROVIDED = process.env.TASKVIEW_TOKEN++let createdTokenId: number | null = null+let createdToken: string | null = null++export async function setup() {+ if (!TASKVIEW_URL) return+ if (TASKVIEW_TOKEN_PROVIDED) return+ if (!TASKVIEW_LOGIN || !TASKVIEW_PASSWORD) return++ const loginRes = await axios.post(`${TASKVIEW_URL}/module/auth/login`, {+ login: TASKVIEW_LOGIN,+ password: TASKVIEW_PASSWORD,+ })+ const jwt = loginRes.data.access+ if (!jwt) throw new Error('Login succeeded but no access token returned')++ const tokenRes = await axios.post(+ `${TASKVIEW_URL}/module/api-tokens`,+ { name: `mcp-integration-${Date.now()}` },+ { headers: { Authorization: `Bearer ${jwt}` } },+ )+ const item = tokenRes.data.response?.item+ const token = tokenRes.data.response?.token+ if (!token || !item?.id) throw new Error('Failed to create API token')++ createdTokenId = item.id+ createdToken = token+ process.env.TASKVIEW_TOKEN = token+ process.env.__TASKVIEW_LOGIN_JWT__ = jwt+}++export async function teardown() {+ if (!createdTokenId || !createdToken) return+ const jwt = process.env.__TASKVIEW_LOGIN_JWT__+ if (!jwt) return++ await axios+ .delete(`${TASKVIEW_URL}/module/api-tokens`, {+ data: { id: createdTokenId },+ headers: { Authorization: `Bearer ${jwt}` },+ })+ .catch(() => {})+}diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/goals.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/goals.integration.test.tsindex d3b4bef..0743b92 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/goals.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/goals.integration.test.ts@@ -40,6 +40,27 @@ describe('goals integration', () => {expect(goal.name).toBe(newName)})+ it('updates goal description and color', async () => {+ const description = `New description ${ts()}`+ const color = '#FF6B35'+ const result = await call(tools, 'update_goal', { id: createdGoalIds[0], description, color })+ const goal = parse(result)++ expect(goal.description).toBe(description)+ expect(goal.color).toBe(color)+ })++ it('archives and unarchives a goal', async () => {+ const created = parse(await call(tools, 'create_goal', { name: `Archive Test ${ts()}` }))+ createdGoalIds.push(created.id)++ const archived = parse(await call(tools, 'update_goal', { id: created.id, archive: 1 }))+ expect(archived.archive).toBe(1)++ const unarchived = parse(await call(tools, 'update_goal', { id: created.id, archive: 0 }))+ expect(unarchived.archive).toBe(0)+ })+it('deletes a goal', async () => {const extraName = `ToDelete ${ts()}`const createResult = await call(tools, 'create_goal', { name: extraName })diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/kanban.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/kanban.integration.test.tsindex 426d282..dadf6e3 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/kanban.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/kanban.integration.test.ts@@ -46,6 +46,16 @@ describe('kanban integration', () => {expect(data.updated).toBe(true)})+ it('updates column viewOrder', async () => {+ const result = await call(tools, 'update_kanban_column', { id: columnId, name: `Reordered ${ts()}`, viewOrder: 5 })+ const data = parse(result)+ expect(data.updated).toBe(true)++ const columns = parse(await call(tools, 'list_kanban_columns', { goalId })) as Array<{ id: number; viewOrder: number }>+ const updated = columns.find((c) => c.id === columnId)+ expect(updated?.viewOrder).toBe(5)+ })+it('deletes a column', async () => {const result = await call(tools, 'delete_kanban_column', { id: columnId })const data = parse(result)diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/lists.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/lists.integration.test.tsindex ca36560..abcd13d 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/lists.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/lists.integration.test.ts@@ -46,6 +46,25 @@ describe('lists integration', () => {expect(list.name).toBe(newName)})+ it('updates list description', async () => {+ const newDesc = `New description ${ts()}`+ const result = await call(tools, 'update_list', { id: listId, description: newDesc })+ const list = parse(result)+ expect(list.description).toBe(newDesc)+ })++ it('archives and unarchives a list', async () => {+ const created = parse(await call(tools, 'create_list', { goalId, name: `Archive List ${ts()}` }))++ const archived = parse(await call(tools, 'update_list', { id: created.id, archive: 1 }))+ expect(archived.archive).toBe(1)++ const unarchived = parse(await call(tools, 'update_list', { id: created.id, archive: 0 }))+ expect(unarchived.archive).toBe(0)++ await call(tools, 'delete_list', { id: created.id }).catch(() => {})+ })+it('deletes a list', async () => {const createResult = await call(tools, 'create_list', { goalId, name: `ToDelete ${ts()}` })const created = parse(createResult)diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/notifications.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/notifications.integration.test.tsindex 657745a..1cf73a7 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/notifications.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/notifications.integration.test.ts@@ -13,6 +13,28 @@ describe('notifications integration', () => {expect(data).toBeDefined()})+ it('lists notifications with cursor', async () => {+ const first = parse(await call(tools, 'list_notifications'))+ const items = first?.notifications ?? first+ const cursor = Array.isArray(items) && items.length > 0+ ? items[items.length - 1].id+ : 0++ const result = await call(tools, 'list_notifications', { cursor })+ const data = parse(result)+ expect(data).toBeDefined()+ })++ it('marks a specific notification read', async () => {+ const listResult = parse(await call(tools, 'list_notifications'))+ const items = listResult?.notifications ?? listResult+ const target = Array.isArray(items) && items.length > 0 ? items[0].id : 1++ const result = await call(tools, 'mark_notification_read', { notificationId: target })+ const data = parse(result)+ expect(data.read).toBeDefined()+ })+it('marks all notifications read', async () => {const result = await call(tools, 'mark_all_notifications_read')const data = parse(result)diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/organizations.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/organizations.integration.test.tsindex 37ac65a..1eee808 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/organizations.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/organizations.integration.test.ts@@ -31,6 +31,17 @@ describe('organizations integration', () => {createdOrgIds.push(org.id)})+ it('creates an organization with custom slug', async () => {+ const name = `Custom Slug Org ${ts()}`+ const slug = `custom-slug-${ts()}`+ const result = await call(tools, 'create_organization', { name, slug })+ const org = parse(result)++ expect(org.name).toBe(name)+ expect(org.slug).toBe(slug)+ createdOrgIds.push(org.id)+ })+it('lists organizations including the created one', async () => {const result = await call(tools, 'list_organizations')const orgs = parse(result)@@ -59,6 +70,16 @@ describe('organizations integration', () => {expect(org.name).toBe(newName)})+ it('updates organization logoUrl', async () => {+ const logoUrl = `https://example.com/logo-${ts()}.png`+ const result = await call(tools, 'update_organization', {+ organizationId: createdOrgIds[0],+ logoUrl,+ })+ const org = parse(result)+ expect(org.logoUrl).toBe(logoUrl)+ })+it('adds a member to organization', async () => {const email = `member-${ts()}@test.com`const result = await call(tools, 'add_organization_member', {@@ -72,6 +93,31 @@ describe('organizations integration', () => {expect(member.role).toBe('member')})+ it('adds a member with admin role', async () => {+ const email = `admin-${ts()}@test.com`+ const result = await call(tools, 'add_organization_member', {+ organizationId: createdOrgIds[0],+ email,+ role: 'admin',+ })+ const member = parse(result)++ expect(member.email).toBe(email)+ expect(member.role).toBe('admin')+ })++ it('cannot delete personal workspace', async () => {+ const orgs = parse(await call(tools, 'list_organizations')) as Array<{ id: number; isPersonal?: number }>+ const personal = orgs.find((o) => o.isPersonal === 1)+ if (!personal) return++ const result = await call(tools, 'delete_organization', { organizationId: personal.id })+ if (!result.isError) {+ const data = parse(result)+ expect(data.deleted).toBe(false)+ }+ })+it('lists organization members', async () => {const result = await call(tools, 'list_organization_members', {organizationId: createdOrgIds[0],diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/tasks.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/tasks.integration.test.tsindex 8d7090f..1dc667a 100644--- a/taskview-packages/taskview-mcp/src/__tests__/integration/tasks.integration.test.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/tasks.integration.test.ts@@ -1,11 +1,17 @@import { describe, it, expect, beforeAll, afterAll } from 'vitest'import { registerGoalsTools } from '../../tools/goals.js'import { registerTasksTools } from '../../tools/tasks.js'+import { registerListsTools } from '../../tools/lists.js'+import { registerKanbanTools } from '../../tools/kanban.js'+import { registerCollaborationTools } from '../../tools/collaboration.js'import { api, captureServer, call, parse, ts } from './setup.js'const { server, tools } = captureServer()registerGoalsTools(server, api)registerTasksTools(server, api)+registerListsTools(server, api)+registerKanbanTools(server, api)+registerCollaborationTools(server, api)let goalId: numberlet taskId: number@@ -45,7 +51,7 @@ describe('tasks integration', () => {})it('lists tasks for goal', async () => {- const result = await call(tools, 'list_tasks', { goalId, page: 1, showCompleted: true })+ const result = await call(tools, 'list_tasks', { goalId, page: 0, showCompleted: false })if (result.isError) {expect(result.content[0].text).toContain('403')@@ -92,4 +98,112 @@ describe('tasks integration', () => {expect(data.delete).toBe(true)})++ it('toggles task assignees (add and remove)', async () => {+ const collabs = parse(await call(tools, 'list_collaborators_for_goal', { goalId })) as Array<{ id: number }>+ expect(collabs.length).toBeGreaterThan(0)+ const userId = collabs[0].id++ const created = parse(await call(tools, 'create_task', { goalId, description: `Assignee ${ts()}` }))++ const added = await call(tools, 'toggle_task_assignees', { taskId: created.id, userIds: [userId] })+ parse(added)+ const taskAfter = parse(await call(tools, 'get_task', { taskId: created.id }))+ expect(taskAfter.assignedUsers).toContain(userId)++ const removed = await call(tools, 'toggle_task_assignees', { taskId: created.id, userIds: [] })+ parse(removed)+ const taskFinal = parse(await call(tools, 'get_task', { taskId: created.id }))+ expect(taskFinal.assignedUsers).not.toContain(userId)++ await call(tools, 'delete_task', { taskId: created.id }).catch(() => {})+ })++ it('restores a task from history', async () => {+ const initialDesc = `History Initial ${ts()}`+ const created = parse(await call(tools, 'create_task', { goalId, description: initialDesc }))++ await call(tools, 'update_task', { id: created.id, description: `History Updated ${ts()}` })+ await call(tools, 'update_task', { id: created.id, description: `History Final ${ts()}` })++ const history = parse(await call(tools, 'get_task_history', { taskId: created.id }))+ const initialRecord = history.history.find((h: { description: string }) => h.description === initialDesc)+ expect(initialRecord).toBeDefined()+ expect(initialRecord.historyId).toBeTypeOf('number')++ const restored = await call(tools, 'restore_task_from_history', {+ taskId: created.id,+ historyId: initialRecord.historyId,+ })+ const data = parse(restored)+ expect(data.recovery).toBe(true)++ const final = parse(await call(tools, 'get_task', { taskId: created.id }))+ expect(final.description).toBe(initialDesc)++ await call(tools, 'delete_task', { taskId: created.id }).catch(() => {})+ })++ it('updates task note, dates and moves between lists/columns', async () => {+ const created = parse(await call(tools, 'create_task', { goalId, description: `Drag ${ts()}` }))++ const noteResult = parse(await call(tools, 'update_task', {+ id: created.id,+ note: 'updated note',+ startDate: '2026-05-01',+ endDate: '2026-05-15',+ }))+ expect(noteResult.note).toBe('updated note')+ expect(noteResult.startDate).toBe('2026-05-01')+ expect(noteResult.endDate).toBe('2026-05-15')++ const list = parse(await call(tools, 'create_list', { goalId, name: `Drag List ${ts()}` }))+ const moved = parse(await call(tools, 'update_task', { id: created.id, goalListId: list.id }))+ expect(moved.goalListId).toBe(list.id)++ const columns = parse(await call(tools, 'list_kanban_columns', { goalId })) as Array<{ id: number }>+ if (columns.length > 0) {+ const moveToColumn = parse(await call(tools, 'update_task', { id: created.id, statusId: columns[0].id }))+ expect(moveToColumn.statusId).toBe(columns[0].id)+ }++ await call(tools, 'delete_task', { taskId: created.id }).catch(() => {})+ await call(tools, 'delete_list', { id: list.id }).catch(() => {})+ })++ it('lists tasks with searchText filter', async () => {+ const unique = `searchable-${ts()}`+ const created = parse(await call(tools, 'create_task', { goalId, description: `Find me ${unique}` }))++ const result = await call(tools, 'list_tasks', { goalId, searchText: unique, showCompleted: false })+ if (result.isError) {+ expect(result.content[0].text).toContain('403')+ await call(tools, 'delete_task', { taskId: created.id }).catch(() => {})+ return+ }+ const tasks = parse(result)+ expect(tasks.some((t: { id: number }) => t.id === created.id)).toBe(true)+ expect(tasks.every((t: { description: string }) => t.description.includes(unique))).toBe(true)++ await call(tools, 'delete_task', { taskId: created.id }).catch(() => {})+ })++ it('lists tasks filtered by componentId (list)', async () => {+ const list = parse(await call(tools, 'create_list', { goalId, name: `Filter List ${ts()}` }))+ const inList = parse(await call(tools, 'create_task', { goalId, goalListId: list.id, description: `In-list ${ts()}` }))+ const outOfList = parse(await call(tools, 'create_task', { goalId, description: `Out-of-list ${ts()}` }))++ const result = await call(tools, 'list_tasks', { goalId, componentId: list.id, showCompleted: false })+ if (result.isError) {+ await call(tools, 'delete_list', { id: list.id }).catch(() => {})+ return+ }+ const tasks = parse(result) as Array<{ id: number }>+ expect(tasks.some((t) => t.id === inList.id)).toBe(true)+ expect(tasks.some((t) => t.id === outOfList.id)).toBe(false)++ await call(tools, 'delete_task', { taskId: inList.id }).catch(() => {})+ await call(tools, 'delete_task', { taskId: outOfList.id }).catch(() => {})+ await call(tools, 'delete_list', { id: list.id }).catch(() => {})+ })})diff --git a/taskview-packages/taskview-mcp/src/__tests__/integration/time-tracking.integration.test.ts b/taskview-packages/taskview-mcp/src/__tests__/integration/time-tracking.integration.test.tsnew file mode 100644index 0000000..f9bd95c--- /dev/null+++ b/taskview-packages/taskview-mcp/src/__tests__/integration/time-tracking.integration.test.ts@@ -0,0 +1,408 @@+import { describe, it, expect, beforeAll, afterAll } from 'vitest'+import { registerGoalsTools } from '../../tools/goals.js'+import { registerTasksTools } from '../../tools/tasks.js'+import { registerTimeTrackingTools } from '../../tools/time-tracking.js'+import { api, captureServer, call, parse, ts } from './setup.js'++const { server, tools } = captureServer()+registerGoalsTools(server, api)+registerTasksTools(server, api)+registerTimeTrackingTools(server, api)++let goalId: number+let taskId: number+let secondaryTaskId: number+let organizationId: number++const iso = (offsetMinutes: number) => new Date(Date.now() + offsetMinutes * 60_000).toISOString()++beforeAll(async () => {+ const orgs = await api.organizations.fetch()+ if (!orgs || orgs.length === 0) throw new Error('No organizations available for user')+ organizationId = orgs[0].id++ const goalResult = await call(tools, 'create_goal', { name: `TimeTracking Test ${ts()}`, organizationId })+ goalId = parse(goalResult).id++ const taskResult = await call(tools, 'create_task', { goalId, description: `TT Task ${ts()}` })+ taskId = parse(taskResult).id++ const secondaryResult = await call(tools, 'create_task', { goalId, description: `TT Task 2 ${ts()}` })+ secondaryTaskId = parse(secondaryResult).id++ const active = await call(tools, 'get_active_timer', {})+ const data = parse(active)+ if (data) await call(tools, 'stop_timer', { entryId: data.id }).catch(() => {})+})++afterAll(async () => {+ const active = await call(tools, 'get_active_timer', {}).catch(() => null)+ if (active) {+ const data = parse(active)+ if (data) await call(tools, 'stop_timer', { entryId: data.id }).catch(() => {})+ }+ await call(tools, 'delete_goal', { goalId }).catch(() => {})+})++describe('time-tracking integration', () => {+ it('starts a timer and reports it as active', async () => {+ const started = await call(tools, 'start_timer', { taskId, description: 'integration timer' })+ const { entry, autoStoppedEntry } = parse(started)++ expect(entry.taskId).toBe(taskId)+ expect(entry.endedAt).toBeNull()+ expect(autoStoppedEntry).toBeNull()++ const active = await call(tools, 'get_active_timer', {})+ const activeEntry = parse(active)+ expect(activeEntry.id).toBe(entry.id)+ })++ it('auto-stops previous timer when starting a new one on another task', async () => {+ const second = await call(tools, 'start_timer', { taskId: secondaryTaskId })+ const { entry, autoStoppedEntry } = parse(second)++ expect(entry.taskId).toBe(secondaryTaskId)+ expect(autoStoppedEntry).not.toBeNull()+ expect(autoStoppedEntry.endedAt).not.toBeNull()+ })++ it('stops the active timer and reports no active afterwards', async () => {+ const stopped = await call(tools, 'stop_timer', {})+ const entry = parse(stopped)+ expect(entry.endedAt).not.toBeNull()++ const active = await call(tools, 'get_active_timer', {})+ expect(parse(active)).toBeNull()+ })++ it('logs a manual entry retroactively', async () => {+ const result = await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-60),+ endedAt: iso(-30),+ description: 'manual log',+ billable: true,+ })+ const entry = parse(result)+ expect(entry.taskId).toBe(taskId)+ expect(entry.durationSeconds).toBeGreaterThan(0)+ expect(entry.billable).toBe(true)+ expect(entry.description).toBe('manual log')+ })++ it('rejects manual entry with endedAt before startedAt', async () => {+ const result = await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-30),+ endedAt: iso(-60),+ })+ if (!result.isError) {+ expect(parse(result)).toBeNull()+ } else {+ expect(result.content[0].text).toMatch(/400|invalid|range/i)+ }+ })++ it('lists time entries filtered by goalId', async () => {+ const result = await call(tools, 'list_time_entries', { goalId })+ const entries = parse(result)+ expect(Array.isArray(entries)).toBe(true)+ expect(entries.length).toBeGreaterThan(0)+ for (const e of entries) expect(e.goalId).toBe(goalId)+ })++ it('lists time entries filtered by taskId', async () => {+ const result = await call(tools, 'list_time_entries', { taskId })+ const entries = parse(result)+ expect(Array.isArray(entries)).toBe(true)+ for (const e of entries) expect(e.taskId).toBe(taskId)+ })++ it('returns task summary with totalSeconds and byUser breakdown', async () => {+ const result = await call(tools, 'get_time_summary', { scope: 'task', id: taskId })+ const summary = parse(result)++ expect(typeof summary.totalSeconds).toBe('number')+ expect(summary.totalSeconds).toBeGreaterThan(0)+ expect(Array.isArray(summary.byUser)).toBe(true)+ })++ it('returns goal summary with byTask breakdown', async () => {+ const result = await call(tools, 'get_time_summary', { scope: 'goal', id: goalId })+ const summary = parse(result)++ expect(typeof summary.totalSeconds).toBe('number')+ expect(Array.isArray(summary.byUser)).toBe(true)+ expect(Array.isArray(summary.byTask)).toBe(true)+ expect(summary.byTask.some((t: { taskId: number }) => t.taskId === taskId)).toBe(true)+ })++ it('updates description of a completed entry', async () => {+ const created = await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-120),+ endedAt: iso(-90),+ description: 'before',+ })+ const entry = parse(created)++ const newDesc = `updated ${ts()}`+ const updated = await call(tools, 'update_time_entry', {+ id: entry.id,+ description: newDesc,+ })+ const result = parse(updated)+ expect(result.description).toBe(newDesc)+ })++ it('returns report summary for the organization', async () => {+ const result = await call(tools, 'get_time_report', {+ scope: 'summary',+ organizationId,+ from: iso(-60 * 24 * 7),+ to: iso(60),+ goalIds: [goalId],+ })+ const summary = parse(result)++ expect(typeof summary.totalSeconds).toBe('number')+ expect(typeof summary.totalBillableSeconds).toBe('number')+ expect(typeof summary.entriesCount).toBe('number')+ expect(summary.entriesCount).toBeGreaterThan(0)+ })++ it('returns report by-day grouped rows', async () => {+ const result = await call(tools, 'get_time_report', {+ scope: 'by-day',+ organizationId,+ from: iso(-60 * 24 * 7),+ to: iso(60),+ goalIds: [goalId],+ })+ const rows = parse(result)++ expect(Array.isArray(rows)).toBe(true)+ if (rows.length > 0) {+ expect(typeof rows[0].day).toBe('string')+ expect(typeof rows[0].totalSeconds).toBe('number')+ }+ })++ it('returns report by-user', async () => {+ const result = await call(tools, 'get_time_report', {+ scope: 'by-user',+ organizationId,+ from: iso(-60 * 24 * 7),+ to: iso(60),+ goalIds: [goalId],+ })+ const rows = parse(result)++ expect(Array.isArray(rows)).toBe(true)+ if (rows.length > 0) {+ expect(typeof rows[0].userId).toBe('number')+ expect(typeof rows[0].totalSeconds).toBe('number')+ }+ })++ it('returns report by-task', async () => {+ const result = await call(tools, 'get_time_report', {+ scope: 'by-task',+ organizationId,+ from: iso(-60 * 24 * 7),+ to: iso(60),+ goalIds: [goalId],+ })+ const rows = parse(result)++ expect(Array.isArray(rows)).toBe(true)+ expect(rows.some((r: { taskId: number }) => r.taskId === taskId)).toBe(true)+ })++ it('returns contributors for the goal', async () => {+ const result = await call(tools, 'get_time_contributors', {+ organizationId,+ from: iso(-60 * 24 * 7),+ to: iso(60),+ goalIds: [goalId],+ })+ const rows = parse(result)++ expect(Array.isArray(rows)).toBe(true)+ if (rows.length > 0) {+ expect(typeof rows[0].userId).toBe('number')+ expect(typeof rows[0].totalSeconds).toBe('number')+ }+ })++ it('rejects report request without organizationId', async () => {+ const result = await call(tools, 'get_time_report', {+ scope: 'summary',+ from: iso(-60 * 24),+ to: iso(60),+ } as unknown as Record<string, unknown>)+ expect(result.isError).toBe(true)+ })++ it('deletes a time entry', async () => {+ const created = await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-30),+ endedAt: iso(-15),+ })+ const entry = parse(created)++ const result = await call(tools, 'delete_time_entry', { id: entry.id })+ const data = parse(result)+ expect(data.deleted).toBe(true)++ const list = await call(tools, 'list_time_entries', { taskId })+ const entries = parse(list)+ expect(entries.some((e: { id: number }) => e.id === entry.id)).toBe(false)+ })++ it('stops a specific timer by entryId', async () => {+ const started = parse(await call(tools, 'start_timer', { taskId }))+ expect(started.entry.endedAt).toBeNull()++ const stopped = parse(await call(tools, 'stop_timer', { entryId: started.entry.id }))+ expect(stopped.id).toBe(started.entry.id)+ expect(stopped.endedAt).not.toBeNull()++ const active = parse(await call(tools, 'get_active_timer', {}))+ expect(active).toBeNull()+ })++ it('updates startedAt/endedAt of completed entry and recalculates durationSeconds', async () => {+ const created = parse(await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-60),+ endedAt: iso(-30),+ }))+ const originalDuration = created.durationSeconds++ const newStart = iso(-120)+ const newEnd = iso(-30)+ const updated = parse(await call(tools, 'update_time_entry', {+ id: created.id,+ startedAt: newStart,+ endedAt: newEnd,+ }))+ expect(updated.durationSeconds).not.toBe(originalDuration)+ expect(updated.durationSeconds).toBeGreaterThan(originalDuration)+ expect(new Date(updated.endedAt).getTime() - new Date(updated.startedAt).getTime())+ .toBe(updated.durationSeconds * 1000)++ await call(tools, 'delete_time_entry', { id: created.id }).catch(() => {})+ })++ it('refuses to change startedAt/endedAt of a running timer', async () => {+ const started = parse(await call(tools, 'start_timer', { taskId }))++ const result = await call(tools, 'update_time_entry', {+ id: started.entry.id,+ startedAt: iso(-60),+ })+ expect(result.isError).toBe(true)++ await call(tools, 'stop_timer', { entryId: started.entry.id }).catch(() => {})+ })++ it('allows description-only update on a running timer', async () => {+ const started = parse(await call(tools, 'start_timer', { taskId }))++ const updated = parse(await call(tools, 'update_time_entry', {+ id: started.entry.id,+ description: 'running update',+ }))+ expect(updated.description).toBe('running update')+ expect(updated.endedAt).toBeNull()++ await call(tools, 'stop_timer', { entryId: started.entry.id }).catch(() => {})+ })++ it('lists time entries filtered by from/to date range', async () => {+ const oldEntry = parse(await call(tools, 'log_time', {+ taskId,+ startedAt: '2026-01-01T10:00:00Z',+ endedAt: '2026-01-01T11:00:00Z',+ description: 'old',+ }))+ const recentEntry = parse(await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-30),+ endedAt: iso(-15),+ description: 'recent',+ }))++ const result = parse(await call(tools, 'list_time_entries', {+ taskId,+ from: iso(-60),+ to: iso(60),+ })) as Array<{ id: number }>++ expect(result.some((e) => e.id === recentEntry.id)).toBe(true)+ expect(result.some((e) => e.id === oldEntry.id)).toBe(false)++ await call(tools, 'delete_time_entry', { id: oldEntry.id }).catch(() => {})+ await call(tools, 'delete_time_entry', { id: recentEntry.id }).catch(() => {})+ })++ it('lists time entries with limit and offset', async () => {+ const created: number[] = []+ for (let i = 0; i < 3; i++) {+ const r = parse(await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-60 - i * 10),+ endedAt: iso(-30 - i * 10),+ }))+ created.push(r.id)+ }++ const first = parse(await call(tools, 'list_time_entries', { taskId, limit: 2, offset: 0 })) as unknown[]+ const second = parse(await call(tools, 'list_time_entries', { taskId, limit: 2, offset: 2 })) as unknown[]+ expect(first.length).toBeLessThanOrEqual(2)+ expect(second.length).toBeLessThanOrEqual(2)++ for (const id of created) {+ await call(tools, 'delete_time_entry', { id }).catch(() => {})+ }+ })++ it('reportSummary with billable=true filter returns only billable seconds', async () => {+ const billable = parse(await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-50),+ endedAt: iso(-40),+ billable: true,+ }))+ const nonBillable = parse(await call(tools, 'log_time', {+ taskId,+ startedAt: iso(-30),+ endedAt: iso(-20),+ billable: false,+ }))++ const billableOnly = parse(await call(tools, 'get_time_report', {+ scope: 'summary',+ organizationId,+ from: iso(-60 * 24),+ to: iso(60),+ goalIds: [goalId],+ billable: true,+ }))+ const allOnly = parse(await call(tools, 'get_time_report', {+ scope: 'summary',+ organizationId,+ from: iso(-60 * 24),+ to: iso(60),+ goalIds: [goalId],+ }))++ expect(billableOnly.totalSeconds).toBeLessThan(allOnly.totalSeconds)++ await call(tools, 'delete_time_entry', { id: billable.id }).catch(() => {})+ await call(tools, 'delete_time_entry', { id: nonBillable.id }).catch(() => {})+ })+})diff --git a/taskview-packages/taskview-mcp/src/__tests__/setup.ts b/taskview-packages/taskview-mcp/src/__tests__/setup.tsindex 49004c6..d83b092 100644--- a/taskview-packages/taskview-mcp/src/__tests__/setup.ts+++ b/taskview-packages/taskview-mcp/src/__tests__/setup.ts@@ -26,6 +26,12 @@ export function mockApi(overrides: Record<string, Record<string, unknown>> = {})},graph: { fetchAllEdges: noop, addEdge: noop, deleteEdge: noop },notifications: { fetch: noop, markRead: noop, markAllRead: noop },+ timeTracking: {+ start: noop, stop: noop, getActive: noop, createManual: noop, update: noop, delete: noop,+ fetchEntries: noop, summaryByTask: noop, summaryByGoal: noop,+ reportByDay: noop, reportByUser: noop, reportByTask: noop, reportSummary: noop,+ reportContributors: noop,+ },}for (const [ns, methods] of Object.entries(overrides)) {diff --git a/taskview-packages/taskview-mcp/src/__tests__/time-tracking.test.ts b/taskview-packages/taskview-mcp/src/__tests__/time-tracking.test.tsnew file mode 100644index 0000000..fcf7f07--- /dev/null+++ b/taskview-packages/taskview-mcp/src/__tests__/time-tracking.test.ts@@ -0,0 +1,482 @@+import { describe, it, expect } from 'vitest'+import { registerTimeTrackingTools } from '../tools/time-tracking.js'+import { mockServer, mockApi, apiReturn, apiThrow, findTool, ts } from './setup.js'++describe('time-tracking tools', () => {+ it('registers all time-tracking tools', () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi())++ expect(tools.map((t) => t.name)).toEqual([+ 'start_timer',+ 'stop_timer',+ 'get_active_timer',+ 'log_time',+ 'list_time_entries',+ 'get_time_summary',+ 'update_time_entry',+ 'get_time_report',+ 'get_time_contributors',+ 'delete_time_entry',+ ])+ })++ describe('start_timer', () => {+ it('returns entry and autoStoppedEntry from api', async () => {+ const { server, tools } = mockServer()+ const result = { entry: { id: 1, taskId: 42 }, autoStoppedEntry: null }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { start: apiReturn(result) } }))++ const res = await findTool(tools, 'start_timer').cb({ taskId: 42 })+ expect(res.content[0].text).toContain('"taskId": 42')+ expect(res.content[0].text).toContain('"autoStoppedEntry": null')+ })++ it('passes taskId and description to api', async () => {+ const { server, tools } = mockServer()+ let captured: Record<string, unknown> = {}+ const start = (params: Record<string, unknown>) => {+ captured = params+ return Promise.resolve({ response: null, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { start } }))++ const desc = `working on bug ${ts()}`+ await findTool(tools, 'start_timer').cb({ taskId: 17, description: desc })+ expect(captured.taskId).toBe(17)+ expect(captured.description).toBe(desc)+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { start: apiThrow(`Forbidden ${ts()}`) } }))++ const res = await findTool(tools, 'start_timer').cb({ taskId: 1 })+ expect(res.isError).toBe(true)+ expect(res.content[0].text).toContain('Forbidden')+ })+ })++ describe('stop_timer', () => {+ it('stops user active timer when entryId omitted', async () => {+ const { server, tools } = mockServer()+ let capturedArg: unknown = 'not-called'+ const stop = (data: unknown) => {+ capturedArg = data+ return Promise.resolve({ response: { id: 1, endedAt: '2026-05-14T10:00:00Z' }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { stop } }))++ const res = await findTool(tools, 'stop_timer').cb({})+ expect(capturedArg).toEqual({})+ expect(res.content[0].text).toContain('endedAt')+ })++ it('passes specific entryId when provided', async () => {+ const { server, tools } = mockServer()+ let capturedArg: Record<string, unknown> = {}+ const stop = (data: Record<string, unknown>) => {+ capturedArg = data+ return Promise.resolve({ response: { id: 9 }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { stop } }))++ await findTool(tools, 'stop_timer').cb({ entryId: 9 })+ expect(capturedArg.entryId).toBe(9)+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { stop: apiThrow(`Not found ${ts()}`) } }))++ const res = await findTool(tools, 'stop_timer').cb({})+ expect(res.isError).toBe(true)+ })+ })++ describe('get_active_timer', () => {+ it('returns active entry', async () => {+ const { server, tools } = mockServer()+ const entry = { id: 5, taskId: 99, endedAt: null }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { getActive: apiReturn(entry) } }))++ const res = await findTool(tools, 'get_active_timer').cb({})+ expect(res.content[0].text).toContain('"taskId": 99')+ expect(res.content[0].text).toContain('"endedAt": null')+ })++ it('returns null when no active timer', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { getActive: apiReturn(null) } }))++ const res = await findTool(tools, 'get_active_timer').cb({})+ expect(res.isError).toBeUndefined()+ expect(res.content[0].text).toContain('null')+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { getActive: apiThrow(`Boom ${ts()}`) } }))++ const res = await findTool(tools, 'get_active_timer').cb({})+ expect(res.isError).toBe(true)+ })+ })++ describe('log_time', () => {+ it('passes all fields to createManual', async () => {+ const { server, tools } = mockServer()+ let captured: Record<string, unknown> = {}+ const createManual = (params: Record<string, unknown>) => {+ captured = params+ return Promise.resolve({ response: { id: 1 }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { createManual } }))++ await findTool(tools, 'log_time').cb({+ taskId: 7,+ startedAt: '2026-05-14T09:00:00Z',+ endedAt: '2026-05-14T10:30:00Z',+ description: 'pair programming',+ billable: false,+ })+ expect(captured).toEqual({+ taskId: 7,+ startedAt: '2026-05-14T09:00:00Z',+ endedAt: '2026-05-14T10:30:00Z',+ description: 'pair programming',+ billable: false,+ })+ })++ it('returns created entry', async () => {+ const { server, tools } = mockServer()+ const entry = { id: 33, taskId: 7, durationSeconds: 5400 }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { createManual: apiReturn(entry) } }))++ const res = await findTool(tools, 'log_time').cb({+ taskId: 7,+ startedAt: '2026-05-14T09:00:00Z',+ endedAt: '2026-05-14T10:30:00Z',+ })+ expect(res.content[0].text).toContain('"durationSeconds": 5400')+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { createManual: apiThrow(`Invalid range ${ts()}`) } }))++ const res = await findTool(tools, 'log_time').cb({+ taskId: 1,+ startedAt: '2026-05-14T10:00:00Z',+ endedAt: '2026-05-14T09:00:00Z',+ })+ expect(res.isError).toBe(true)+ })+ })++ describe('list_time_entries', () => {+ it('returns entries', async () => {+ const { server, tools } = mockServer()+ const entries = [+ { id: 1, taskId: 1, durationSeconds: 60 },+ { id: 2, taskId: 1, durationSeconds: 120 },+ ]+ registerTimeTrackingTools(server, mockApi({ timeTracking: { fetchEntries: apiReturn(entries) } }))++ const res = await findTool(tools, 'list_time_entries').cb({ goalId: 5 })+ expect(res.content[0].text).toContain('"durationSeconds": 60')+ expect(res.content[0].text).toContain('"durationSeconds": 120')+ })++ it('passes filters to api', async () => {+ const { server, tools } = mockServer()+ let captured: Record<string, unknown> = {}+ const fetchEntries = (params: Record<string, unknown>) => {+ captured = params+ return Promise.resolve({ response: [], rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { fetchEntries } }))++ await findTool(tools, 'list_time_entries').cb({+ goalId: 5,+ taskId: 10,+ userId: 3,+ from: '2026-05-01T00:00:00Z',+ to: '2026-05-31T23:59:59Z',+ limit: 100,+ offset: 50,+ })+ expect(captured.goalId).toBe(5)+ expect(captured.taskId).toBe(10)+ expect(captured.userId).toBe(3)+ expect(captured.from).toBe('2026-05-01T00:00:00Z')+ expect(captured.to).toBe('2026-05-31T23:59:59Z')+ expect(captured.limit).toBe(100)+ expect(captured.offset).toBe(50)+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { fetchEntries: apiThrow(`Forbidden ${ts()}`) } }))++ const res = await findTool(tools, 'list_time_entries').cb({ goalId: 1 })+ expect(res.isError).toBe(true)+ })+ })++ describe('get_time_summary', () => {+ it('routes scope=task to summaryByTask', async () => {+ const { server, tools } = mockServer()+ let calledTaskWith: number | null = null+ let calledGoalWith: number | null = null+ const summaryByTask = (id: number) => {+ calledTaskWith = id+ return Promise.resolve({ response: { totalSeconds: 360, byUser: [] }, rid: `rid-${ts()}` })+ }+ const summaryByGoal = (id: number) => {+ calledGoalWith = id+ return Promise.resolve({ response: { totalSeconds: 0, byUser: [], byTask: [] }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { summaryByTask, summaryByGoal } }))++ const res = await findTool(tools, 'get_time_summary').cb({ scope: 'task', id: 42 })+ expect(calledTaskWith).toBe(42)+ expect(calledGoalWith).toBeNull()+ expect(res.content[0].text).toContain('"totalSeconds": 360')+ })++ it('routes scope=goal to summaryByGoal', async () => {+ const { server, tools } = mockServer()+ let calledTaskWith: number | null = null+ let calledGoalWith: number | null = null+ const summaryByTask = (id: number) => {+ calledTaskWith = id+ return Promise.resolve({ response: null, rid: `rid-${ts()}` })+ }+ const summaryByGoal = (id: number) => {+ calledGoalWith = id+ return Promise.resolve({ response: { totalSeconds: 7200, byUser: [], byTask: [] }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { summaryByTask, summaryByGoal } }))++ const res = await findTool(tools, 'get_time_summary').cb({ scope: 'goal', id: 17 })+ expect(calledGoalWith).toBe(17)+ expect(calledTaskWith).toBeNull()+ expect(res.content[0].text).toContain('"totalSeconds": 7200')+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { summaryByTask: apiThrow(`Boom ${ts()}`) } }))++ const res = await findTool(tools, 'get_time_summary').cb({ scope: 'task', id: 1 })+ expect(res.isError).toBe(true)+ })+ })++ describe('update_time_entry', () => {+ it('passes fields to update', async () => {+ const { server, tools } = mockServer()+ let captured: Record<string, unknown> = {}+ const update = (params: Record<string, unknown>) => {+ captured = params+ return Promise.resolve({ response: { id: 5 }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { update } }))++ await findTool(tools, 'update_time_entry').cb({+ id: 5,+ startedAt: '2026-05-14T09:00:00Z',+ endedAt: '2026-05-14T10:00:00Z',+ description: 'edit',+ billable: true,+ })+ expect(captured.id).toBe(5)+ expect(captured.startedAt).toBe('2026-05-14T09:00:00Z')+ expect(captured.endedAt).toBe('2026-05-14T10:00:00Z')+ expect(captured.description).toBe('edit')+ expect(captured.billable).toBe(true)+ })++ it('returns updated entry', async () => {+ const { server, tools } = mockServer()+ const entry = { id: 5, description: 'updated' }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { update: apiReturn(entry) } }))++ const res = await findTool(tools, 'update_time_entry').cb({ id: 5, description: 'updated' })+ expect(res.content[0].text).toContain('"description": "updated"')+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { update: apiThrow(`Forbidden ${ts()}`) } }))++ const res = await findTool(tools, 'update_time_entry').cb({ id: 1 })+ expect(res.isError).toBe(true)+ })+ })++ describe('get_time_report', () => {+ const baseParams = {+ organizationId: 1,+ from: '2026-05-01T00:00:00Z',+ to: '2026-05-31T23:59:59Z',+ }++ it('routes scope=by-day to reportByDay', async () => {+ const { server, tools } = mockServer()+ let called: string | null = null+ const reportByDay = () => { called = 'by-day'; return Promise.resolve({ response: [{ day: '2026-05-14', totalSeconds: 3600, entriesCount: 2 }], rid: `rid-${ts()}` }) }+ const reportByUser = () => { called = 'by-user'; return Promise.resolve({ response: [], rid: `rid-${ts()}` }) }+ const reportByTask = () => { called = 'by-task'; return Promise.resolve({ response: [], rid: `rid-${ts()}` }) }+ const reportSummary = () => { called = 'summary'; return Promise.resolve({ response: { totalSeconds: 0, totalBillableSeconds: 0, entriesCount: 0 }, rid: `rid-${ts()}` }) }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportByDay, reportByUser, reportByTask, reportSummary } }))++ const res = await findTool(tools, 'get_time_report').cb({ scope: 'by-day', ...baseParams })+ expect(called).toBe('by-day')+ expect(res.content[0].text).toContain('"day": "2026-05-14"')+ })++ it('routes scope=by-user to reportByUser', async () => {+ const { server, tools } = mockServer()+ let called: string | null = null+ const reportByUser = () => { called = 'by-user'; return Promise.resolve({ response: [{ userId: 1, userEmail: '[email protected]', totalSeconds: 60, entriesCount: 1 }], rid: `rid-${ts()}` }) }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportByUser } }))++ const res = await findTool(tools, 'get_time_report').cb({ scope: 'by-user', ...baseParams })+ expect(called).toBe('by-user')+ expect(res.content[0].text).toContain('"userEmail": "[email protected]"')+ })++ it('routes scope=by-task to reportByTask', async () => {+ const { server, tools } = mockServer()+ let called: string | null = null+ const reportByTask = () => { called = 'by-task'; return Promise.resolve({ response: [{ taskId: 7, taskDescription: 'fix bug', goalId: 1, totalSeconds: 120, entriesCount: 3 }], rid: `rid-${ts()}` }) }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportByTask } }))++ const res = await findTool(tools, 'get_time_report').cb({ scope: 'by-task', ...baseParams })+ expect(called).toBe('by-task')+ expect(res.content[0].text).toContain('"taskId": 7')+ })++ it('routes scope=summary to reportSummary', async () => {+ const { server, tools } = mockServer()+ let called: string | null = null+ const reportSummary = () => { called = 'summary'; return Promise.resolve({ response: { totalSeconds: 480, totalBillableSeconds: 360, entriesCount: 5 }, rid: `rid-${ts()}` }) }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportSummary } }))++ const res = await findTool(tools, 'get_time_report').cb({ scope: 'summary', ...baseParams })+ expect(called).toBe('summary')+ expect(res.content[0].text).toContain('"totalBillableSeconds": 360')+ })++ it('passes filters (goalIds, userId, billable) to report', async () => {+ const { server, tools } = mockServer()+ let captured: Record<string, unknown> = {}+ const reportSummary = (params: Record<string, unknown>) => {+ captured = params+ return Promise.resolve({ response: { totalSeconds: 0, totalBillableSeconds: 0, entriesCount: 0 }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportSummary } }))++ await findTool(tools, 'get_time_report').cb({+ scope: 'summary',+ ...baseParams,+ goalIds: [10, 11],+ userId: 3,+ billable: true,+ })+ expect(captured.organizationId).toBe(1)+ expect(captured.from).toBe(baseParams.from)+ expect(captured.to).toBe(baseParams.to)+ expect(captured.goalIds).toEqual([10, 11])+ expect(captured.userId).toBe(3)+ expect(captured.billable).toBe(true)+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportSummary: apiThrow(`No access ${ts()}`) } }))++ const res = await findTool(tools, 'get_time_report').cb({ scope: 'summary', ...baseParams })+ expect(res.isError).toBe(true)+ })+ })++ describe('get_time_contributors', () => {+ it('returns contributors', async () => {+ const { server, tools } = mockServer()+ const rows = [+ { userId: 1, userEmail: '[email protected]', totalSeconds: 7200, entriesCount: 5 },+ { userId: 2, userEmail: '[email protected]', totalSeconds: 3600, entriesCount: 3 },+ ]+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportContributors: apiReturn(rows) } }))++ const res = await findTool(tools, 'get_time_contributors').cb({+ organizationId: 1,+ from: '2026-05-01T00:00:00Z',+ to: '2026-05-31T23:59:59Z',+ })+ expect(res.content[0].text).toContain('"userId": 1')+ expect(res.content[0].text).toContain('"userId": 2')+ })++ it('passes filters to api', async () => {+ const { server, tools } = mockServer()+ let captured: Record<string, unknown> = {}+ const reportContributors = (params: Record<string, unknown>) => {+ captured = params+ return Promise.resolve({ response: [], rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportContributors } }))++ await findTool(tools, 'get_time_contributors').cb({+ organizationId: 1,+ from: '2026-05-01T00:00:00Z',+ to: '2026-05-31T23:59:59Z',+ goalIds: [5, 6],+ billable: false,+ })+ expect(captured.organizationId).toBe(1)+ expect(captured.goalIds).toEqual([5, 6])+ expect(captured.billable).toBe(false)+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { reportContributors: apiThrow(`Forbidden ${ts()}`) } }))++ const res = await findTool(tools, 'get_time_contributors').cb({+ organizationId: 1,+ from: '2026-05-01T00:00:00Z',+ to: '2026-05-31T23:59:59Z',+ })+ expect(res.isError).toBe(true)+ })+ })++ describe('delete_time_entry', () => {+ it('passes id to delete and returns result', async () => {+ const { server, tools } = mockServer()+ let capturedId: number | null = null+ const del = (id: number) => {+ capturedId = id+ return Promise.resolve({ response: { deleted: true }, rid: `rid-${ts()}` })+ }+ registerTimeTrackingTools(server, mockApi({ timeTracking: { delete: del } }))++ const res = await findTool(tools, 'delete_time_entry').cb({ id: 42 })+ expect(capturedId).toBe(42)+ expect(res.content[0].text).toContain('"deleted": true')+ })++ it('errors when api throws', async () => {+ const { server, tools } = mockServer()+ registerTimeTrackingTools(server, mockApi({ timeTracking: { delete: apiThrow(`Forbidden ${ts()}`) } }))++ const res = await findTool(tools, 'delete_time_entry').cb({ id: 1 })+ expect(res.isError).toBe(true)+ })+ })+})diff --git a/taskview-packages/taskview-mcp/vitest.config.ts b/taskview-packages/taskview-mcp/vitest.config.tsnew file mode 100644index 0000000..c5537a2--- /dev/null+++ b/taskview-packages/taskview-mcp/vitest.config.ts@@ -0,0 +1,7 @@+import { defineConfig } from 'vitest/config'++export default defineConfig({+ test: {+ globalSetup: ['./src/__tests__/integration/global-setup.ts'],+ },+})