mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-07-09 17:19:02 +00:00
fix: sdk mcp tests
This commit is contained in:
parent
9bccd49711
commit
7311a01874
2 changed files with 32 additions and 17 deletions
|
|
@ -35,6 +35,10 @@ const SHARED_TEST_OPTIONS = {
|
|||
permissionMode: 'yolo' as const,
|
||||
};
|
||||
|
||||
// MCP tool names are generated with the pattern: mcp__<serverName>__<toolName>
|
||||
const MCP_ADD_TOOL = 'mcp__test-math-server__add';
|
||||
const MCP_MULTIPLY_TOOL = 'mcp__test-math-server__multiply';
|
||||
|
||||
describe('MCP Server Integration (E2E)', () => {
|
||||
let helper: SDKTestHelper;
|
||||
let serverScriptPath: string;
|
||||
|
|
@ -82,7 +86,7 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
messages.push(message);
|
||||
|
||||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(message, 'add');
|
||||
const toolUseBlocks = findToolUseBlocks(message, MCP_ADD_TOOL);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
}
|
||||
|
|
@ -133,7 +137,7 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
messages.push(message);
|
||||
|
||||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(message, 'multiply');
|
||||
const toolUseBlocks = findToolUseBlocks(message, MCP_MULTIPLY_TOOL);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
}
|
||||
|
|
@ -238,8 +242,8 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
}
|
||||
|
||||
// Validate both tools were called
|
||||
expect(toolCalls).toContain('add');
|
||||
expect(toolCalls).toContain('multiply');
|
||||
expect(toolCalls).toContain(MCP_ADD_TOOL);
|
||||
expect(toolCalls).toContain(MCP_MULTIPLY_TOOL);
|
||||
|
||||
// Validate result: (10 + 5) * 2 = 30
|
||||
expect(assistantText).toMatch(/30/);
|
||||
|
|
@ -278,7 +282,7 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
messages.push(message);
|
||||
|
||||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(message, 'add');
|
||||
const toolUseBlocks = findToolUseBlocks(message, MCP_ADD_TOOL);
|
||||
addToolCalls.push(...toolUseBlocks);
|
||||
assistantText += extractText(message.message.content);
|
||||
}
|
||||
|
|
@ -366,8 +370,8 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
}
|
||||
}
|
||||
|
||||
expect(toolCalls).toContain('add');
|
||||
expect(toolCalls).toContain('multiply');
|
||||
expect(toolCalls).toContain(MCP_ADD_TOOL);
|
||||
expect(toolCalls).toContain(MCP_MULTIPLY_TOOL);
|
||||
expect(assistantText).toMatch(/5/);
|
||||
expect(assistantText).toMatch(/20/);
|
||||
|
||||
|
|
@ -454,10 +458,10 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
}
|
||||
}
|
||||
|
||||
expect(toolCalls).toContain('add');
|
||||
expect(toolCalls).toContain('multiply');
|
||||
expect(toolCalls).toContain(MCP_ADD_TOOL);
|
||||
expect(toolCalls).toContain(MCP_MULTIPLY_TOOL);
|
||||
expect(canUseToolCalls.map((call) => call.toolName)).toEqual(
|
||||
expect.arrayContaining(['add', 'multiply']),
|
||||
expect.arrayContaining([MCP_ADD_TOOL, MCP_MULTIPLY_TOOL]),
|
||||
);
|
||||
expect(assistantText).toMatch(/10/);
|
||||
expect(assistantText).toMatch(/12/);
|
||||
|
|
@ -499,7 +503,7 @@ describe('MCP Server Integration (E2E)', () => {
|
|||
const toolUseBlocks = findToolUseBlocks(message);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
expect(toolUseBlocks[0].name).toBe('add');
|
||||
expect(toolUseBlocks[0].name).toBe(MCP_ADD_TOOL);
|
||||
expect(toolUseBlocks[0].input).toBeDefined();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,14 @@ const SHARED_TEST_OPTIONS = {
|
|||
permissionMode: 'yolo' as const,
|
||||
};
|
||||
|
||||
// MCP tool names are generated with the pattern: mcp__<serverName>__<toolName>
|
||||
const MCP_CALCULATE_SUM = 'mcp__sdk-calculator__calculate_sum';
|
||||
const MCP_REVERSE_STRING = 'mcp__sdk-string-utils__reverse_string';
|
||||
const MCP_SDK_ADD = 'mcp__sdk-math__sdk_add';
|
||||
const MCP_SDK_MULTIPLY = 'mcp__sdk-math__sdk_multiply';
|
||||
const MCP_MAYBE_FAIL = 'mcp__sdk-error-test__maybe_fail';
|
||||
const MCP_DELAYED_RESPONSE = 'mcp__sdk-async__delayed_response';
|
||||
|
||||
describe('SDK MCP Server Integration (E2E)', () => {
|
||||
let helper: SDKTestHelper;
|
||||
let testDir: string;
|
||||
|
|
@ -91,7 +99,7 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||
messages.push(message);
|
||||
|
||||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(message, 'calculate_sum');
|
||||
const toolUseBlocks = findToolUseBlocks(message, MCP_CALCULATE_SUM);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
}
|
||||
|
|
@ -157,7 +165,10 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||
messages.push(message);
|
||||
|
||||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(message, 'reverse_string');
|
||||
const toolUseBlocks = findToolUseBlocks(
|
||||
message,
|
||||
MCP_REVERSE_STRING,
|
||||
);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
}
|
||||
|
|
@ -244,8 +255,8 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||
}
|
||||
|
||||
// Validate both tools were called
|
||||
expect(toolCalls).toContain('sdk_add');
|
||||
expect(toolCalls).toContain('sdk_multiply');
|
||||
expect(toolCalls).toContain(MCP_SDK_ADD);
|
||||
expect(toolCalls).toContain(MCP_SDK_MULTIPLY);
|
||||
|
||||
// Validate result: (10 + 5) * 3 = 45
|
||||
expect(assistantText).toMatch(/45/);
|
||||
|
|
@ -361,7 +372,7 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||
messages.push(message);
|
||||
|
||||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(message, 'maybe_fail');
|
||||
const toolUseBlocks = findToolUseBlocks(message, MCP_MAYBE_FAIL);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
}
|
||||
|
|
@ -430,7 +441,7 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||
if (isSDKAssistantMessage(message)) {
|
||||
const toolUseBlocks = findToolUseBlocks(
|
||||
message,
|
||||
'delayed_response',
|
||||
MCP_DELAYED_RESPONSE,
|
||||
);
|
||||
if (toolUseBlocks.length > 0) {
|
||||
foundToolUse = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue