Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
createMcpTask: vi.fn(),
|
||||
setMcpTaskStatus: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./task-backend.js", () => ({
|
||||
createMcpTask: mocks.createMcpTask,
|
||||
setMcpTaskStatus: mocks.setMcpTaskStatus,
|
||||
getVisibleTask: vi.fn(),
|
||||
searchVisibleTasks: vi.fn(),
|
||||
}));
|
||||
|
||||
import type { McpToolContext } from "./context.js";
|
||||
import { createHiveGridMcpServer } from "./server-factory.js";
|
||||
|
||||
const connections: Array<{ client: Client; server: ReturnType<typeof createHiveGridMcpServer> }> = [];
|
||||
|
||||
afterEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
await Promise.all(connections.splice(0).map(async ({ client, server }) => {
|
||||
await client.close().catch(() => undefined);
|
||||
await server.close().catch(() => undefined);
|
||||
}));
|
||||
});
|
||||
|
||||
describe("HiveGrid MCP task write tools", () => {
|
||||
it("passes confirmed creation input to the transactional task backend", async () => {
|
||||
mocks.createMcpTask.mockResolvedValue(task({ linkedEntityType: "project", linkedEntityId: "project_1" }));
|
||||
const { client } = await connect();
|
||||
|
||||
const result = await client.callTool({
|
||||
name: "hg_task_create",
|
||||
arguments: { confirm: true, title: "Angebot nachfassen", linkedEntityType: "project", linkedEntityId: "project_1" },
|
||||
});
|
||||
|
||||
expect(result.isError).not.toBe(true);
|
||||
expect(mocks.createMcpTask).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({ title: "Angebot nachfassen", linkedEntityType: "project", linkedEntityId: "project_1" }),
|
||||
);
|
||||
expect(result.structuredContent).toMatchObject({ task: { id: "task_1" } });
|
||||
});
|
||||
|
||||
it("returns the backend's status no-op without a second mutation", async () => {
|
||||
mocks.setMcpTaskStatus.mockResolvedValue({ task: task({ status: "blocked" }), previousStatus: "blocked", changed: false });
|
||||
const { client } = await connect();
|
||||
|
||||
const result = await client.callTool({ name: "hg_task_set_status", arguments: { confirm: true, taskId: "task_1", status: "blocked" } });
|
||||
|
||||
expect(result.isError).not.toBe(true);
|
||||
expect(mocks.setMcpTaskStatus).toHaveBeenCalledOnce();
|
||||
expect(result.structuredContent).toMatchObject({ changed: false, previousStatus: "blocked" });
|
||||
});
|
||||
|
||||
it("returns the completed status result from the transactional backend", async () => {
|
||||
mocks.setMcpTaskStatus.mockResolvedValue({ task: task({ status: "done", completedAt: "2026-07-12T12:00:00.000Z" }), previousStatus: "open", changed: true });
|
||||
const { client } = await connect();
|
||||
|
||||
const result = await client.callTool({ name: "hg_task_set_status", arguments: { confirm: true, taskId: "task_1", status: "done" } });
|
||||
|
||||
expect(result.isError).not.toBe(true);
|
||||
expect(result.structuredContent).toMatchObject({ changed: true, previousStatus: "open", task: { id: "task_1", status: "done" } });
|
||||
});
|
||||
});
|
||||
|
||||
async function connect(): Promise<{ client: Client; server: ReturnType<typeof createHiveGridMcpServer> }> {
|
||||
const server = createHiveGridMcpServer(context());
|
||||
const client = new Client({ name: "hivegrid-mcp-task-write-test", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const connection = { client, server };
|
||||
connections.push(connection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
function context(): McpToolContext {
|
||||
return {
|
||||
principal: {
|
||||
credential: { kind: "oauth", id: "token_1", name: "Test client" },
|
||||
tenantId: "tenant_1",
|
||||
tenantSlug: "demo",
|
||||
userId: "user_1",
|
||||
scopes: ["mcp:task:write"],
|
||||
permissions: ["tasks.write"],
|
||||
},
|
||||
readDb: {} as McpToolContext["readDb"],
|
||||
writeDb: {} as McpToolContext["writeDb"],
|
||||
request: { id: "request_1", ip: "127.0.0.1" },
|
||||
};
|
||||
}
|
||||
|
||||
function task(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: "task_1",
|
||||
title: "Angebot nachfassen",
|
||||
description: null,
|
||||
status: "open",
|
||||
priority: "normal",
|
||||
deadline: null,
|
||||
assignedToUserId: "user_1",
|
||||
assignedToGroupId: null,
|
||||
linkedEntityType: null,
|
||||
linkedEntityId: null,
|
||||
source: "api",
|
||||
completedAt: null,
|
||||
createdAt: "2026-07-12T10:00:00.000Z",
|
||||
updatedAt: "2026-07-12T10:00:00.000Z",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user