Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

test(web-app): follow the consent-gated tool call contract

thinhlpgb471aca11dab
diff --git a/web-app/src/lib/__tests__/agentTools.test.ts b/web-app/src/lib/__tests__/agentTools.test.ts
index 9943e1e51..1c868cd37 100644
--- a/web-app/src/lib/__tests__/agentTools.test.ts
+++ b/web-app/src/lib/__tests__/agentTools.test.ts
@@ -205,7 +205,8 @@ describe('agentTools', () => {
false,
undefined,
false,
- 'thread'
+ 'thread',
+ undefined
)
})
@@ -231,7 +232,8 @@ describe('agentTools', () => {
true,
undefined,
false,
- 'thread'
+ 'thread',
+ undefined
)
})
@@ -265,7 +267,8 @@ describe('agentTools', () => {
false,
undefined,
false,
- 'thread'
+ 'thread',
+ undefined
)
})
@@ -289,7 +292,8 @@ describe('agentTools', () => {
false,
'/home/u/repo',
false,
- 'thread'
+ 'thread',
+ undefined
)
})
@@ -334,7 +338,8 @@ describe('agentTools', () => {
true,
'/repo',
true,
- 'session'
+ 'session',
+ undefined
)
})
@@ -392,7 +397,8 @@ describe('agentTools', () => {
false,
undefined,
false,
- 'thread'
+ 'thread',
+ undefined
)
})
diff --git a/web-app/src/services/__tests__/mcp.test.ts b/web-app/src/services/__tests__/mcp.test.ts
index 9e69a16eb..33c8bda5f 100644
--- a/web-app/src/services/__tests__/mcp.test.ts
+++ b/web-app/src/services/__tests__/mcp.test.ts
@@ -298,119 +298,8 @@ describe('TauriMCPService', () => {
})
})
- describe('callTool', () => {
- it('should call tool with correct arguments and return result', async () => {
- const toolArgs = {
- toolName: 'file_read',
- arguments: { path: '/path/to/file.txt' },
- }
-
- const mockResult = {
- error: '',
- content: [{ text: 'File content here' }],
- }
-
- mockCore.api.callTool.mockResolvedValue(mockResult)
-
- const result = await mcpService.callTool(toolArgs)
-
- expect(mockCore.api.callTool).toHaveBeenCalledWith(toolArgs)
- expect(result).toEqual(mockResult)
- })
-
- it('should handle tool call with error', async () => {
- const toolArgs = {
- toolName: 'file_read',
- arguments: { path: '/nonexistent/file.txt' },
- }
-
- const mockResult = {
- error: 'File not found',
- content: [],
- }
-
- mockCore.api.callTool.mockResolvedValue(mockResult)
-
- const result = await mcpService.callTool(toolArgs)
-
- expect(result.error).toBe('File not found')
- expect(result.content).toEqual([])
- })
-
- it('should handle complex tool arguments', async () => {
- const toolArgs = {
- toolName: 'database_query',
- arguments: {
- query: 'SELECT * FROM users WHERE age > ?',
- params: [18],
- limit: 100,
- },
- }
-
- const mockResult = {
- error: '',
- content: [{ text: 'Query results...' }],
- }
-
- mockCore.api.callTool.mockResolvedValue(mockResult)
-
- const result = await mcpService.callTool(toolArgs)
-
- expect(mockCore.api.callTool).toHaveBeenCalledWith(toolArgs)
- expect(result).toEqual(mockResult)
- })
-
- it('should handle API rejection', async () => {
- const toolArgs = {
- toolName: 'file_read',
- arguments: { path: '/path/to/file.txt' },
- }
-
- const mockError = new Error('Tool execution failed')
- mockCore.api.callTool.mockRejectedValue(mockError)
-
- await expect(mcpService.callTool(toolArgs)).rejects.toThrow('Tool execution failed')
- })
-
- it('should handle undefined window.core.api', async () => {
- const originalCore = window.core
- // @ts-ignore
- window.core = undefined
-
- const toolArgs = {
- toolName: 'test_tool',
- arguments: {},
- }
-
- const result = await mcpService.callTool(toolArgs)
-
- expect(result).toBeUndefined()
-
- window.core = originalCore
- })
-
- it('should handle empty arguments object', async () => {
- const toolArgs = {
- toolName: 'simple_tool',
- arguments: {},
- }
-
- const mockResult = {
- error: '',
- content: [{ text: 'Success' }],
- }
-
- mockCore.api.callTool.mockResolvedValue(mockResult)
-
- const result = await mcpService.callTool(toolArgs)
-
- expect(mockCore.api.callTool).toHaveBeenCalledWith(toolArgs)
- expect(result).toEqual(mockResult)
- })
- })
-
describe('integration tests', () => {
- it('should handle full MCP workflow: config -> restart -> get tools -> call tool', async () => {
+ it('should handle full MCP workflow: config -> restart -> get tools', async () => {
const config = '{"filesystem": {"command": "filesystem-server"}}'
const tools: MCPTool[] = [
{
@@ -420,41 +309,27 @@ describe('TauriMCPService', () => {
},
]
const servers = ['filesystem']
- const toolResult = {
- error: '',
- content: [{ text: 'File content' }],
- }
mockCore.api.saveMcpConfigs.mockResolvedValue(undefined)
mockCore.api.restartMcpServers.mockResolvedValue(undefined)
mockCore.api.getTools.mockResolvedValue(tools)
mockCore.api.getConnectedServers.mockResolvedValue(servers)
- mockCore.api.callTool.mockResolvedValue(toolResult)
// Execute workflow
await mcpService.updateMCPConfig(config)
await mcpService.restartMCPServers()
const availableTools = await mcpService.getTools()
const connectedServers = await mcpService.getConnectedServers()
- const result = await mcpService.callTool({
- toolName: 'read_file',
- arguments: { path: '/test.txt' },
- })
// Verify all calls were made correctly
expect(mockCore.api.saveMcpConfigs).toHaveBeenCalledWith({ configs: config })
expect(mockCore.api.restartMcpServers).toHaveBeenCalled()
expect(mockCore.api.getTools).toHaveBeenCalled()
expect(mockCore.api.getConnectedServers).toHaveBeenCalled()
- expect(mockCore.api.callTool).toHaveBeenCalledWith({
- toolName: 'read_file',
- arguments: { path: '/test.txt' },
- })
// Verify results
expect(availableTools).toEqual(tools)
expect(connectedServers).toEqual(servers)
- expect(result).toEqual(toolResult)
})
})