Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 3s
245 lines
6.4 KiB
TypeScript
245 lines
6.4 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
|
|
import request from 'supertest';
|
|
|
|
import { deleteRecordsByIds } from 'test/integration/utils/delete-records-by-ids';
|
|
|
|
const TOOL_NAMES = {
|
|
createCompany: 'create_one_company',
|
|
createOpportunity: 'create_one_opportunity',
|
|
findManyCompanies: 'find_many_companies',
|
|
findOneCompany: 'find_one_company',
|
|
findOneOpportunity: 'find_one_opportunity',
|
|
} as const;
|
|
|
|
type McpToolCallResult = {
|
|
content?: Array<{ type: string; text: string }>;
|
|
isError?: boolean;
|
|
};
|
|
|
|
type DatabaseToolPayload<TResult> = {
|
|
success: boolean;
|
|
message: string;
|
|
result: TResult;
|
|
warnings?: string[];
|
|
error?: string;
|
|
};
|
|
|
|
type CreatedRecord = { id: string };
|
|
|
|
type FindRecordsResult = {
|
|
records: Array<Record<string, unknown>>;
|
|
count: string | number;
|
|
hasNextPage: boolean;
|
|
};
|
|
|
|
const baseUrl = `http://localhost:${APP_PORT}`;
|
|
const endpoint = '/mcp';
|
|
|
|
const postMcp = (body: Record<string, unknown>) =>
|
|
request(baseUrl)
|
|
.post(endpoint)
|
|
.set('Authorization', `Bearer ${API_KEY_ACCESS_TOKEN}`)
|
|
.set('Content-Type', 'application/json')
|
|
.set('Accept', 'application/json')
|
|
.send(JSON.stringify(body));
|
|
|
|
const callMcpTool = async (
|
|
name: string,
|
|
args: Record<string, unknown>,
|
|
id: string = `call-${randomUUID()}`,
|
|
): Promise<McpToolCallResult> => {
|
|
const res = await postMcp({
|
|
jsonrpc: '2.0',
|
|
method: 'tools/call',
|
|
id,
|
|
params: { name, arguments: args },
|
|
}).expect(200);
|
|
|
|
expect(res.body.id).toBe(id);
|
|
expect(res.body.jsonrpc).toBe('2.0');
|
|
expect(res.body.error).toBeUndefined();
|
|
|
|
return res.body.result as McpToolCallResult;
|
|
};
|
|
|
|
const parseToolPayload = <T>(result: McpToolCallResult): T => {
|
|
expect(result.isError).toBe(false);
|
|
expect(result.content?.[0]?.type).toBe('text');
|
|
|
|
const raw = result.content?.[0]?.text;
|
|
|
|
expect(raw).toBeDefined();
|
|
|
|
return JSON.parse(raw as string) as T;
|
|
};
|
|
|
|
const executeWorkspaceTool = async <TResult>(
|
|
toolName: string,
|
|
args: Record<string, unknown>,
|
|
): Promise<DatabaseToolPayload<TResult>> => {
|
|
const mcpResult = await callMcpTool('execute_tool', {
|
|
toolName,
|
|
arguments: args,
|
|
});
|
|
const payload = parseToolPayload<DatabaseToolPayload<TResult>>(mcpResult);
|
|
|
|
expect(payload.success).toBe(true);
|
|
expect(payload.result).toBeDefined();
|
|
|
|
return payload;
|
|
};
|
|
|
|
describe('MCP find tools relation selection (integration)', () => {
|
|
let companyId: string;
|
|
let opportunityAId: string;
|
|
let opportunityBId: string;
|
|
|
|
const companyName = `mcp-relation-select-company-${randomUUID()}`;
|
|
const opportunityAName = `mcp-relation-select-opportunity-a-${randomUUID()}`;
|
|
const opportunityBName = `mcp-relation-select-opportunity-b-${randomUUID()}`;
|
|
|
|
beforeAll(async () => {
|
|
const company = await executeWorkspaceTool<CreatedRecord>(
|
|
TOOL_NAMES.createCompany,
|
|
{ name: companyName },
|
|
);
|
|
|
|
companyId = company.result.id;
|
|
|
|
const opportunityA = await executeWorkspaceTool<CreatedRecord>(
|
|
TOOL_NAMES.createOpportunity,
|
|
{ name: opportunityAName, companyId },
|
|
);
|
|
|
|
opportunityAId = opportunityA.result.id;
|
|
|
|
const opportunityB = await executeWorkspaceTool<CreatedRecord>(
|
|
TOOL_NAMES.createOpportunity,
|
|
{ name: opportunityBName, companyId },
|
|
);
|
|
|
|
opportunityBId = opportunityB.result.id;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await deleteRecordsByIds(
|
|
'opportunity',
|
|
[opportunityAId, opportunityBId].filter(Boolean),
|
|
);
|
|
await deleteRecordsByIds('company', [companyId].filter(Boolean));
|
|
});
|
|
|
|
it('should hydrate a one-to-many relation selected by name in find_many', async () => {
|
|
const payload = await executeWorkspaceTool<FindRecordsResult>(
|
|
TOOL_NAMES.findManyCompanies,
|
|
{
|
|
id: { eq: companyId },
|
|
select: ['id', 'name', 'opportunities'],
|
|
limit: 1,
|
|
},
|
|
);
|
|
|
|
expect(payload.warnings).toBeUndefined();
|
|
expect(payload.result.records).toHaveLength(1);
|
|
|
|
const record = payload.result.records[0];
|
|
|
|
expect(record.id).toBe(companyId);
|
|
expect(record.name).toBe(companyName);
|
|
|
|
const opportunities = record.opportunities as Array<
|
|
Record<string, unknown>
|
|
>;
|
|
|
|
expect(Array.isArray(opportunities)).toBe(true);
|
|
expect(opportunities).toHaveLength(2);
|
|
expect(opportunities).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: opportunityAId,
|
|
name: opportunityAName,
|
|
}),
|
|
expect.objectContaining({
|
|
id: opportunityBId,
|
|
name: opportunityBName,
|
|
}),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('should hydrate a one-to-many relation selected by name in find_one', async () => {
|
|
const payload = await executeWorkspaceTool<FindRecordsResult>(
|
|
TOOL_NAMES.findOneCompany,
|
|
{
|
|
id: companyId,
|
|
select: ['id', 'name', 'opportunities'],
|
|
},
|
|
);
|
|
|
|
const record = payload.result.records[0];
|
|
|
|
const opportunities = record.opportunities as Array<
|
|
Record<string, unknown>
|
|
>;
|
|
|
|
expect(opportunities).toHaveLength(2);
|
|
});
|
|
|
|
it('should hydrate a many-to-one relation selected by name as a single record', async () => {
|
|
const payload = await executeWorkspaceTool<FindRecordsResult>(
|
|
TOOL_NAMES.findOneOpportunity,
|
|
{
|
|
id: opportunityAId,
|
|
select: ['id', 'name', 'company'],
|
|
},
|
|
);
|
|
|
|
const record = payload.result.records[0];
|
|
|
|
expect(record.id).toBe(opportunityAId);
|
|
expect(record.company).toEqual(
|
|
expect.objectContaining({
|
|
id: companyId,
|
|
name: companyName,
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('should hydrate relation fields in wildcard selection', async () => {
|
|
const payload = await executeWorkspaceTool<FindRecordsResult>(
|
|
TOOL_NAMES.findOneCompany,
|
|
{
|
|
id: companyId,
|
|
select: ['*'],
|
|
},
|
|
);
|
|
|
|
const record = payload.result.records[0];
|
|
|
|
expect(record.name).toBe(companyName);
|
|
|
|
const opportunities = record.opportunities as Array<
|
|
Record<string, unknown>
|
|
>;
|
|
|
|
expect(opportunities).toHaveLength(2);
|
|
});
|
|
|
|
it('should suggest the relation field for a near-miss selection', async () => {
|
|
const payload = await executeWorkspaceTool<FindRecordsResult>(
|
|
TOOL_NAMES.findManyCompanies,
|
|
{
|
|
id: { eq: companyId },
|
|
select: ['name', 'opportunitiez'],
|
|
limit: 1,
|
|
},
|
|
);
|
|
|
|
expect(payload.warnings).toEqual([
|
|
expect.stringContaining("'opportunities'"),
|
|
]);
|
|
expect(payload.result.records[0]).not.toHaveProperty('opportunities');
|
|
});
|
|
});
|