mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-30 12:40:44 +00:00
test(cli): cover MCP resource edge cases
This commit is contained in:
parent
5b2dc78897
commit
5087426af7
1 changed files with 97 additions and 0 deletions
|
|
@ -386,6 +386,103 @@ describe('handleAtCommand', () => {
|
|||
expect(mockAddItem).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not expand MCP resources in untrusted folders', async () => {
|
||||
(mockConfig as unknown as { getMcpServers: () => unknown }).getMcpServers =
|
||||
() =>
|
||||
({
|
||||
github: {},
|
||||
}) as unknown;
|
||||
const configWithTrust = mockConfig as unknown as {
|
||||
isTrustedFolder: () => boolean;
|
||||
};
|
||||
configWithTrust.isTrustedFolder = () => false;
|
||||
|
||||
const readMcpResourceSpy = vi.spyOn(registry, 'readMcpResource');
|
||||
|
||||
const query = 'Show me the data from @github: repos/owner/repo/issues';
|
||||
|
||||
const result = await handleAtCommand({
|
||||
query,
|
||||
config: mockConfig,
|
||||
addItem: mockAddItem,
|
||||
onDebugMessage: mockOnDebugMessage,
|
||||
messageId: 1004,
|
||||
signal: abortController.signal,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
processedQuery: null,
|
||||
shouldProceed: false,
|
||||
});
|
||||
expect(readMcpResourceSpy).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'tool_group',
|
||||
tools: [
|
||||
expect.objectContaining({
|
||||
status: ToolCallStatus.Error,
|
||||
resultDisplay: expect.stringContaining('untrusted'),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
1004,
|
||||
);
|
||||
});
|
||||
|
||||
it('should preserve trailing punctuation after an MCP resource reference', async () => {
|
||||
(mockConfig as unknown as { getMcpServers: () => unknown }).getMcpServers =
|
||||
() =>
|
||||
({
|
||||
github: {},
|
||||
}) as unknown;
|
||||
|
||||
vi.spyOn(registry, 'readMcpResource').mockResolvedValue({
|
||||
contents: [
|
||||
{
|
||||
uri: 'github://repos/owner/repo/issues',
|
||||
mimeType: 'application/json',
|
||||
text: '{"ok":true}',
|
||||
},
|
||||
],
|
||||
} as unknown as Awaited<ReturnType<ToolRegistry['readMcpResource']>>);
|
||||
|
||||
const query = 'Show me the data from @github: repos/owner/repo/issues.';
|
||||
|
||||
const result = await handleAtCommand({
|
||||
query,
|
||||
config: mockConfig,
|
||||
addItem: mockAddItem,
|
||||
onDebugMessage: mockOnDebugMessage,
|
||||
messageId: 1005,
|
||||
signal: abortController.signal,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
processedQuery: [
|
||||
{ text: 'Show me the data from @github:repos/owner/repo/issues.' },
|
||||
{ text: '\n--- Content from referenced MCP resources ---' },
|
||||
{ text: '\nContent from @github:repos/owner/repo/issues:\n' },
|
||||
{ text: '{"ok":true}' },
|
||||
{ text: '\n--- End of MCP resource content ---' },
|
||||
],
|
||||
shouldProceed: true,
|
||||
});
|
||||
expect(registry.readMcpResource).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'tool_group',
|
||||
tools: [expect.objectContaining({ status: ToolCallStatus.Success })],
|
||||
}),
|
||||
1005,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle query with text before and after @command', async () => {
|
||||
const fileContent = 'Markdown content.';
|
||||
const filePath = await createTestFile(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue