ai-cli-mcp 2.18.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.ja.md +37 -11
  3. package/README.md +44 -11
  4. package/dist/app/cli.js +2 -1
  5. package/dist/app/mcp.js +65 -13
  6. package/dist/cli-builder.js +13 -6
  7. package/dist/cli-process-service.js +81 -95
  8. package/dist/cli-utils.js +6 -0
  9. package/dist/cli.js +1 -1
  10. package/dist/model-catalog.js +3 -2
  11. package/dist/parsers.js +111 -8
  12. package/dist/process-service.js +5 -4
  13. package/package.json +26 -2
  14. package/server.json +3 -3
  15. package/.gemini/settings.json +0 -11
  16. package/.github/dependabot.yml +0 -28
  17. package/.github/pull_request_template.md +0 -28
  18. package/.github/workflows/ci.yml +0 -34
  19. package/.github/workflows/dependency-review.yml +0 -22
  20. package/.github/workflows/publish.yml +0 -89
  21. package/.github/workflows/test.yml +0 -20
  22. package/.github/workflows/watch-session-prs.yml +0 -276
  23. package/.husky/pre-commit +0 -1
  24. package/.mcp.json +0 -11
  25. package/.releaserc.json +0 -18
  26. package/.vscode/settings.json +0 -3
  27. package/CONTRIBUTING.md +0 -81
  28. package/dist/__tests__/app-cli.test.js +0 -392
  29. package/dist/__tests__/cli-bin-smoke.test.js +0 -101
  30. package/dist/__tests__/cli-builder.test.js +0 -442
  31. package/dist/__tests__/cli-process-service.test.js +0 -655
  32. package/dist/__tests__/cli-utils.test.js +0 -171
  33. package/dist/__tests__/e2e.test.js +0 -256
  34. package/dist/__tests__/edge-cases.test.js +0 -130
  35. package/dist/__tests__/error-cases.test.js +0 -292
  36. package/dist/__tests__/mcp-contract.test.js +0 -636
  37. package/dist/__tests__/mocks.js +0 -32
  38. package/dist/__tests__/model-alias.test.js +0 -36
  39. package/dist/__tests__/parsers.test.js +0 -500
  40. package/dist/__tests__/peek.test.js +0 -36
  41. package/dist/__tests__/process-management.test.js +0 -871
  42. package/dist/__tests__/server.test.js +0 -809
  43. package/dist/__tests__/setup.js +0 -11
  44. package/dist/__tests__/utils/claude-mock.js +0 -80
  45. package/dist/__tests__/utils/mcp-client.js +0 -121
  46. package/dist/__tests__/utils/opencode-mock.js +0 -91
  47. package/dist/__tests__/utils/persistent-mock.js +0 -28
  48. package/dist/__tests__/utils/test-helpers.js +0 -11
  49. package/dist/__tests__/validation.test.js +0 -308
  50. package/dist/__tests__/version-print.test.js +0 -65
  51. package/dist/__tests__/wait.test.js +0 -260
  52. package/docs/RELEASE_CHECKLIST.md +0 -65
  53. package/docs/cli-architecture.md +0 -275
  54. package/docs/concept.md +0 -154
  55. package/docs/development.md +0 -156
  56. package/docs/e2e-testing.md +0 -148
  57. package/docs/prd.md +0 -146
  58. package/docs/session-stacking.md +0 -67
  59. package/src/__tests__/app-cli.test.ts +0 -495
  60. package/src/__tests__/cli-bin-smoke.test.ts +0 -136
  61. package/src/__tests__/cli-builder.test.ts +0 -549
  62. package/src/__tests__/cli-process-service.test.ts +0 -759
  63. package/src/__tests__/cli-utils.test.ts +0 -200
  64. package/src/__tests__/e2e.test.ts +0 -311
  65. package/src/__tests__/edge-cases.test.ts +0 -176
  66. package/src/__tests__/error-cases.test.ts +0 -370
  67. package/src/__tests__/mcp-contract.test.ts +0 -755
  68. package/src/__tests__/mocks.ts +0 -35
  69. package/src/__tests__/model-alias.test.ts +0 -44
  70. package/src/__tests__/parsers.test.ts +0 -564
  71. package/src/__tests__/peek.test.ts +0 -44
  72. package/src/__tests__/process-management.test.ts +0 -1043
  73. package/src/__tests__/server.test.ts +0 -1020
  74. package/src/__tests__/setup.ts +0 -13
  75. package/src/__tests__/utils/claude-mock.ts +0 -87
  76. package/src/__tests__/utils/mcp-client.ts +0 -159
  77. package/src/__tests__/utils/opencode-mock.ts +0 -108
  78. package/src/__tests__/utils/persistent-mock.ts +0 -33
  79. package/src/__tests__/utils/test-helpers.ts +0 -13
  80. package/src/__tests__/validation.test.ts +0 -369
  81. package/src/__tests__/version-print.test.ts +0 -81
  82. package/src/__tests__/wait.test.ts +0 -302
  83. package/src/app/cli.ts +0 -424
  84. package/src/app/mcp.ts +0 -466
  85. package/src/bin/ai-cli-mcp.ts +0 -7
  86. package/src/bin/ai-cli.ts +0 -11
  87. package/src/cli-builder.ts +0 -274
  88. package/src/cli-parse.ts +0 -105
  89. package/src/cli-process-service.ts +0 -708
  90. package/src/cli-utils.ts +0 -258
  91. package/src/cli.ts +0 -124
  92. package/src/model-catalog.ts +0 -87
  93. package/src/parsers.ts +0 -840
  94. package/src/peek.ts +0 -95
  95. package/src/process-result.ts +0 -88
  96. package/src/process-service.ts +0 -367
  97. package/src/server.ts +0 -10
  98. package/tsconfig.json +0 -16
  99. package/vitest.config.e2e.ts +0 -27
  100. package/vitest.config.ts +0 -22
  101. package/vitest.config.unit.ts +0 -28
@@ -1,171 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { accessSync } from 'node:fs';
3
- vi.mock('node:fs', () => ({
4
- accessSync: vi.fn(),
5
- constants: { X_OK: 1 },
6
- }));
7
- const mockAccessSync = vi.mocked(accessSync);
8
- describe('cli-utils doctor status', () => {
9
- const originalEnv = process.env;
10
- const originalPlatform = process.platform;
11
- beforeEach(() => {
12
- vi.resetModules();
13
- mockAccessSync.mockReset();
14
- process.env = { ...originalEnv };
15
- delete process.env.CLAUDE_CLI_NAME;
16
- delete process.env.CODEX_CLI_NAME;
17
- delete process.env.GEMINI_CLI_NAME;
18
- delete process.env.FORGE_CLI_NAME;
19
- delete process.env.OPENCODE_CLI_NAME;
20
- process.env.PATH = '/mock/bin:/usr/bin';
21
- });
22
- afterEach(() => {
23
- process.env = originalEnv;
24
- Object.defineProperty(process, 'platform', { value: originalPlatform });
25
- });
26
- it('marks PATH binaries available when they are executable', async () => {
27
- mockAccessSync.mockImplementation((filePath) => {
28
- if (filePath === '/mock/bin/claude') {
29
- return undefined;
30
- }
31
- throw new Error('not executable');
32
- });
33
- const { getCliDoctorStatus } = await import('../cli-utils.js');
34
- const status = getCliDoctorStatus();
35
- expect(status.claude).toEqual({
36
- configuredCommand: 'claude',
37
- resolvedPath: '/mock/bin/claude',
38
- available: true,
39
- lookup: 'path',
40
- });
41
- expect(status.forge).toEqual({
42
- configuredCommand: 'forge',
43
- resolvedPath: null,
44
- available: false,
45
- lookup: 'path',
46
- });
47
- expect(status.opencode).toEqual({
48
- configuredCommand: 'opencode',
49
- resolvedPath: null,
50
- available: false,
51
- lookup: 'path',
52
- });
53
- });
54
- it('does not mark non-executable PATH entries as available', async () => {
55
- mockAccessSync.mockImplementation(() => {
56
- throw new Error('not executable');
57
- });
58
- const { getCliDoctorStatus } = await import('../cli-utils.js');
59
- const status = getCliDoctorStatus();
60
- expect(status.claude).toEqual({
61
- configuredCommand: 'claude',
62
- resolvedPath: null,
63
- available: false,
64
- lookup: 'path',
65
- });
66
- expect(status.forge).toEqual({
67
- configuredCommand: 'forge',
68
- resolvedPath: null,
69
- available: false,
70
- lookup: 'path',
71
- });
72
- expect(status.opencode).toEqual({
73
- configuredCommand: 'opencode',
74
- resolvedPath: null,
75
- available: false,
76
- lookup: 'path',
77
- });
78
- });
79
- it('reports invalid relative env paths as doctor errors', async () => {
80
- process.env.CLAUDE_CLI_NAME = './relative/claude';
81
- const { getCliDoctorStatus } = await import('../cli-utils.js');
82
- const status = getCliDoctorStatus();
83
- expect(status.claude.available).toBe(false);
84
- expect(status.claude.lookup).toBe('env');
85
- expect(status.claude.error).toContain('Invalid CLAUDE_CLI_NAME');
86
- });
87
- it('reports missing absolute env paths as unavailable', async () => {
88
- process.env.CLAUDE_CLI_NAME = '/missing/claude';
89
- mockAccessSync.mockImplementation(() => {
90
- throw new Error('missing');
91
- });
92
- const { getCliDoctorStatus } = await import('../cli-utils.js');
93
- const status = getCliDoctorStatus();
94
- expect(status.claude).toEqual({
95
- configuredCommand: '/missing/claude',
96
- resolvedPath: '/missing/claude',
97
- available: false,
98
- lookup: 'env',
99
- });
100
- });
101
- it('falls back cleanly when PATH is empty', async () => {
102
- process.env.PATH = '';
103
- mockAccessSync.mockImplementation(() => {
104
- throw new Error('missing');
105
- });
106
- const { getCliDoctorStatus } = await import('../cli-utils.js');
107
- const status = getCliDoctorStatus();
108
- expect(status.codex).toEqual({
109
- configuredCommand: 'codex',
110
- resolvedPath: null,
111
- available: false,
112
- lookup: 'path',
113
- });
114
- });
115
- it('supports Windows commands that already include an executable suffix', async () => {
116
- Object.defineProperty(process, 'platform', { value: 'win32' });
117
- process.env.PATHEXT = '.EXE;.CMD';
118
- process.env.CLAUDE_CLI_NAME = 'claude.cmd';
119
- process.env.PATH = '/mock/bin';
120
- mockAccessSync.mockImplementation((filePath) => {
121
- if (filePath === '/mock/bin/claude.cmd') {
122
- return undefined;
123
- }
124
- throw new Error('not executable');
125
- });
126
- const { getCliDoctorStatus } = await import('../cli-utils.js');
127
- const status = getCliDoctorStatus();
128
- expect(status.claude).toEqual({
129
- configuredCommand: 'claude.cmd',
130
- resolvedPath: '/mock/bin/claude.cmd',
131
- available: true,
132
- lookup: 'env',
133
- });
134
- });
135
- it('supports forge lookup via FORGE_CLI_NAME', async () => {
136
- process.env.FORGE_CLI_NAME = 'forge-custom';
137
- mockAccessSync.mockImplementation((filePath) => {
138
- if (filePath === '/mock/bin/forge-custom') {
139
- return undefined;
140
- }
141
- throw new Error('not executable');
142
- });
143
- const { getCliDoctorStatus, findForgeCli } = await import('../cli-utils.js');
144
- const status = getCliDoctorStatus();
145
- expect(status.forge).toEqual({
146
- configuredCommand: 'forge-custom',
147
- resolvedPath: '/mock/bin/forge-custom',
148
- available: true,
149
- lookup: 'env',
150
- });
151
- expect(findForgeCli()).toBe('forge-custom');
152
- });
153
- it('supports OpenCode lookup via OPENCODE_CLI_NAME', async () => {
154
- process.env.OPENCODE_CLI_NAME = 'opencode-custom';
155
- mockAccessSync.mockImplementation((filePath) => {
156
- if (filePath === '/mock/bin/opencode-custom') {
157
- return undefined;
158
- }
159
- throw new Error('not executable');
160
- });
161
- const { getCliDoctorStatus, findOpencodeCli } = await import('../cli-utils.js');
162
- const status = getCliDoctorStatus();
163
- expect(status.opencode).toEqual({
164
- configuredCommand: 'opencode-custom',
165
- resolvedPath: '/mock/bin/opencode-custom',
166
- available: true,
167
- lookup: 'env',
168
- });
169
- expect(findOpencodeCli()).toBe('opencode-custom');
170
- });
171
- });
@@ -1,256 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, afterAll } from 'vitest';
2
- import { mkdtempSync, rmSync, readFileSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { tmpdir } from 'node:os';
5
- import { createTestClient } from './utils/mcp-client.js';
6
- import { getSharedMock, cleanupSharedMock } from './utils/persistent-mock.js';
7
- import { createOpenCodeMock } from './utils/opencode-mock.js';
8
- describe('Claude Code MCP E2E Tests', () => {
9
- let client;
10
- let testDir;
11
- beforeEach(async () => {
12
- // Ensure mock exists
13
- await getSharedMock();
14
- // Create a temporary directory for test files
15
- testDir = mkdtempSync(join(tmpdir(), 'claude-code-test-'));
16
- client = createTestClient();
17
- await client.connect();
18
- });
19
- afterEach(async () => {
20
- // Disconnect client
21
- await client.disconnect();
22
- // Clean up test directory
23
- rmSync(testDir, { recursive: true, force: true });
24
- });
25
- afterAll(async () => {
26
- // Only cleanup mock at the very end
27
- await cleanupSharedMock();
28
- });
29
- describe('Tool Registration', () => {
30
- it('should register run tool', async () => {
31
- const tools = await client.listTools();
32
- expect(tools).toHaveLength(7);
33
- const claudeCodeTool = tools.find((t) => t.name === 'run');
34
- expect(claudeCodeTool.inputSchema.properties.model.description).toContain('sonnet');
35
- expect(claudeCodeTool.inputSchema.properties.model.description).toContain('opencode');
36
- expect(claudeCodeTool.inputSchema.properties.model.description).toContain('oc-<provider/model>');
37
- expect(claudeCodeTool.inputSchema.properties.reasoning_effort.description).toContain('OpenCode');
38
- // Verify other tools exist
39
- expect(tools.some((t) => t.name === 'list_processes')).toBe(true);
40
- expect(tools.some((t) => t.name === 'get_result')).toBe(true);
41
- expect(tools.some((t) => t.name === 'peek')).toBe(true);
42
- expect(tools.some((t) => t.name === 'kill_process')).toBe(true);
43
- });
44
- });
45
- describe('Basic Operations', () => {
46
- it('should execute a simple prompt', async () => {
47
- const response = await client.callTool('run', {
48
- prompt: 'create a file called test.txt with content "Hello World"',
49
- workFolder: testDir,
50
- });
51
- expect(response).toEqual([{
52
- type: 'text',
53
- text: expect.stringContaining('successfully'),
54
- }]);
55
- });
56
- it('should handle process management correctly', async () => {
57
- // run now returns a PID immediately
58
- const response = await client.callTool('run', {
59
- prompt: 'error',
60
- workFolder: testDir,
61
- });
62
- expect(response).toEqual([{
63
- type: 'text',
64
- text: expect.stringContaining('pid'),
65
- }]);
66
- // Extract PID from response
67
- const responseText = response[0].text;
68
- const pidMatch = responseText.match(/"pid":\s*(\d+)/);
69
- expect(pidMatch).toBeTruthy();
70
- });
71
- it('should reject missing workFolder', async () => {
72
- await expect(client.callTool('run', {
73
- prompt: 'List files in current directory',
74
- })).rejects.toThrow(/workFolder/i);
75
- });
76
- });
77
- describe('Working Directory Handling', () => {
78
- it('should respect custom working directory', async () => {
79
- const response = await client.callTool('run', {
80
- prompt: 'Show current working directory',
81
- workFolder: testDir,
82
- });
83
- expect(response).toBeTruthy();
84
- });
85
- it('should reject non-existent working directory', async () => {
86
- const nonExistentDir = join(testDir, 'non-existent');
87
- await expect(client.callTool('run', {
88
- prompt: 'Test prompt',
89
- workFolder: nonExistentDir,
90
- })).rejects.toThrow(/does not exist/i);
91
- });
92
- });
93
- describe('Timeout Handling', () => {
94
- it('should respect timeout settings', async () => {
95
- // This would require modifying the mock to simulate a long-running command
96
- // Since we're testing locally, we'll skip the actual timeout test
97
- expect(true).toBe(true);
98
- });
99
- });
100
- describe('Model Alias Handling', () => {
101
- it('should resolve haiku alias when calling run', async () => {
102
- const response = await client.callTool('run', {
103
- prompt: 'Test with haiku model',
104
- workFolder: testDir,
105
- model: 'haiku'
106
- });
107
- expect(response).toEqual([{
108
- type: 'text',
109
- text: expect.stringContaining('pid'),
110
- }]);
111
- // Extract PID from response
112
- const responseText = response[0].text;
113
- const pidMatch = responseText.match(/"pid":\s*(\d+)/);
114
- expect(pidMatch).toBeTruthy();
115
- // Get the PID and check the process using get_result
116
- const pid = parseInt(pidMatch[1]);
117
- const result = await client.callTool('get_result', { pid });
118
- const resultText = result[0].text;
119
- const processData = JSON.parse(resultText);
120
- // Verify that the model was set correctly
121
- expect(processData.model).toBe('haiku');
122
- });
123
- it('should pass non-alias model names unchanged', async () => {
124
- const response = await client.callTool('run', {
125
- prompt: 'Test with sonnet model',
126
- workFolder: testDir,
127
- model: 'sonnet'
128
- });
129
- expect(response).toEqual([{
130
- type: 'text',
131
- text: expect.stringContaining('pid'),
132
- }]);
133
- // Extract PID
134
- const responseText = response[0].text;
135
- const pidMatch = responseText.match(/"pid":\s*(\d+)/);
136
- const pid = parseInt(pidMatch[1]);
137
- // Check the process using get_result
138
- const result = await client.callTool('get_result', { pid });
139
- const resultText = result[0].text;
140
- const processData = JSON.parse(resultText);
141
- // The model should be unchanged
142
- expect(processData.model).toBe('sonnet');
143
- });
144
- it('should work without specifying a model', async () => {
145
- const response = await client.callTool('run', {
146
- prompt: 'Test without model parameter',
147
- workFolder: testDir
148
- });
149
- expect(response).toEqual([{
150
- type: 'text',
151
- text: expect.stringContaining('pid'),
152
- }]);
153
- });
154
- });
155
- describe('OpenCode flows', () => {
156
- it('should execute and resume OpenCode runs through the MCP client', async () => {
157
- await client.disconnect();
158
- const opencodeArgsLogPath = join(testDir, 'opencode-args.log');
159
- const { scriptPath } = createOpenCodeMock(testDir, {
160
- argsLogPath: opencodeArgsLogPath,
161
- defaultSessionId: 'ses-opencode-e2e',
162
- });
163
- client = createTestClient({
164
- debug: false,
165
- env: {
166
- OPENCODE_CLI_NAME: scriptPath,
167
- },
168
- });
169
- await client.connect();
170
- const runResponse = await client.callTool('run', {
171
- prompt: 'e2e OpenCode initial prompt',
172
- workFolder: testDir,
173
- model: 'opencode',
174
- });
175
- const runData = JSON.parse(runResponse[0].text);
176
- expect(runData.agent).toBe('opencode');
177
- const initialWait = JSON.parse((await client.callTool('wait', { pids: [runData.pid], timeout: 5 }))[0].text);
178
- expect(initialWait).toHaveLength(1);
179
- expect(initialWait[0]).toMatchObject({
180
- pid: runData.pid,
181
- agent: 'opencode',
182
- status: 'completed',
183
- exitCode: 0,
184
- model: 'opencode',
185
- session_id: 'ses-opencode-e2e',
186
- agentOutput: {
187
- message: 'Initial: e2e OpenCode initial prompt',
188
- session_id: 'ses-opencode-e2e',
189
- },
190
- });
191
- const resumedResponse = await client.callTool('run', {
192
- prompt: 'e2e OpenCode resumed prompt',
193
- workFolder: testDir,
194
- model: 'oc-openai/gpt-5.4',
195
- session_id: 'ses-opencode-e2e',
196
- });
197
- const resumedRunData = JSON.parse(resumedResponse[0].text);
198
- const resumedWait = JSON.parse((await client.callTool('wait', { pids: [resumedRunData.pid], timeout: 5 }))[0].text);
199
- expect(resumedWait).toHaveLength(1);
200
- expect(resumedWait[0]).toMatchObject({
201
- pid: resumedRunData.pid,
202
- agent: 'opencode',
203
- status: 'completed',
204
- exitCode: 0,
205
- model: 'oc-openai/gpt-5.4',
206
- session_id: 'ses-opencode-e2e',
207
- agentOutput: {
208
- message: 'Resumed model openai/gpt-5.4: e2e OpenCode resumed prompt',
209
- session_id: 'ses-opencode-e2e',
210
- },
211
- });
212
- const invocationLog = readFileSync(opencodeArgsLogPath, 'utf-8').trim().split('\n');
213
- expect(invocationLog[0]).toContain(`--dir ${testDir}`);
214
- expect(invocationLog[0]).not.toContain('--model');
215
- expect(invocationLog[1]).toContain('--session ses-opencode-e2e');
216
- expect(invocationLog[1]).toContain('--model openai/gpt-5.4');
217
- });
218
- });
219
- describe('Debug Mode', () => {
220
- it('should log debug information when enabled', async () => {
221
- // Debug logs go to stderr, which we capture in the client
222
- const response = await client.callTool('run', {
223
- prompt: 'Debug test prompt',
224
- workFolder: testDir,
225
- });
226
- expect(response).toBeTruthy();
227
- });
228
- });
229
- });
230
- describe('Integration Tests (Local Only)', () => {
231
- let client;
232
- let testDir;
233
- beforeEach(async () => {
234
- testDir = mkdtempSync(join(tmpdir(), 'claude-code-integration-'));
235
- // Initialize client without mocks for real Claude testing
236
- client = createTestClient({ claudeCliName: '' });
237
- });
238
- afterEach(async () => {
239
- if (client) {
240
- await client.disconnect();
241
- }
242
- rmSync(testDir, { recursive: true, force: true });
243
- });
244
- // This smoke test only verifies that a real Claude CLI can be invoked.
245
- it.skip('should invoke the real Claude CLI', async () => {
246
- await client.connect();
247
- const response = await client.callTool('run', {
248
- prompt: 'Reply with hi',
249
- workFolder: testDir,
250
- });
251
- expect(response).toEqual([{
252
- type: 'text',
253
- text: expect.stringContaining('pid'),
254
- }]);
255
- });
256
- });
@@ -1,130 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, afterAll } from 'vitest';
2
- import { mkdtempSync, rmSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { tmpdir } from 'node:os';
5
- import { createTestClient } from './utils/mcp-client.js';
6
- import { getSharedMock, cleanupSharedMock } from './utils/persistent-mock.js';
7
- describe('Claude Code Edge Cases', () => {
8
- let client;
9
- let testDir;
10
- beforeEach(async () => {
11
- // Ensure mock exists
12
- await getSharedMock();
13
- // Create test directory
14
- testDir = mkdtempSync(join(tmpdir(), 'claude-code-edge-'));
15
- client = createTestClient();
16
- await client.connect();
17
- });
18
- afterEach(async () => {
19
- await client.disconnect();
20
- rmSync(testDir, { recursive: true, force: true });
21
- });
22
- afterAll(async () => {
23
- // Cleanup mock only at the end
24
- await cleanupSharedMock();
25
- });
26
- describe('Input Validation', () => {
27
- it('should reject missing prompt', async () => {
28
- await expect(client.callTool('run', {
29
- workFolder: testDir,
30
- })).rejects.toThrow(/prompt/i);
31
- });
32
- it('should reject invalid prompt type', async () => {
33
- await expect(client.callTool('run', {
34
- prompt: 123, // Should be string
35
- workFolder: testDir,
36
- })).rejects.toThrow();
37
- });
38
- it('should reject invalid workFolder type', async () => {
39
- await expect(client.callTool('run', {
40
- prompt: 'Test prompt',
41
- workFolder: 123, // Should be string
42
- })).rejects.toThrow(/workFolder/i);
43
- });
44
- it('should reject empty prompt', async () => {
45
- await expect(client.callTool('run', {
46
- prompt: '',
47
- workFolder: testDir,
48
- })).rejects.toThrow(/prompt/i);
49
- });
50
- });
51
- describe('Special Characters', () => {
52
- it.skip('should handle prompts with quotes', async () => {
53
- // Skipping: This test fails in CI when mock is not found at expected path
54
- const response = await client.callTool('run', {
55
- prompt: 'Create a file with content "Hello \\"World\\""',
56
- workFolder: testDir,
57
- });
58
- expect(response).toBeTruthy();
59
- });
60
- it('should handle prompts with newlines', async () => {
61
- const response = await client.callTool('run', {
62
- prompt: 'Create a file with content:\\nLine 1\\nLine 2',
63
- workFolder: testDir,
64
- });
65
- expect(response).toBeTruthy();
66
- });
67
- it('should handle prompts with shell special characters', async () => {
68
- const response = await client.callTool('run', {
69
- prompt: 'Create a file named test$file.txt',
70
- workFolder: testDir,
71
- });
72
- expect(response).toBeTruthy();
73
- });
74
- });
75
- describe('Error Recovery', () => {
76
- it('should handle Claude CLI not found gracefully', async () => {
77
- // Create a client with a different binary name that doesn't exist
78
- const errorClient = createTestClient({ claudeCliName: 'non-existent-claude' });
79
- await errorClient.connect();
80
- await expect(errorClient.callTool('run', {
81
- prompt: 'Test prompt',
82
- workFolder: testDir,
83
- })).rejects.toThrow();
84
- await errorClient.disconnect();
85
- });
86
- it('should handle permission denied errors', async () => {
87
- const restrictedDir = '/root/restricted';
88
- // Non-existent directories now throw an error
89
- await expect(client.callTool('run', {
90
- prompt: 'Test prompt',
91
- workFolder: restrictedDir,
92
- })).rejects.toThrow(/does not exist/i);
93
- });
94
- });
95
- describe('Concurrent Requests', () => {
96
- it('should handle multiple simultaneous requests', async () => {
97
- const promises = Array(5).fill(null).map((_, i) => client.callTool('run', {
98
- prompt: `Create file test${i}.txt`,
99
- workFolder: testDir,
100
- }));
101
- const results = await Promise.allSettled(promises);
102
- const successful = results.filter(r => r.status === 'fulfilled');
103
- const failures = results
104
- .filter((r) => r.status === 'rejected')
105
- .map((r) => r.reason?.message ?? String(r.reason));
106
- expect(successful.length, `Concurrent run failures: ${failures.join(' | ')}`).toBeGreaterThan(0);
107
- });
108
- });
109
- describe('Large Prompts', () => {
110
- it('should handle very long prompts', async () => {
111
- const longPrompt = 'Create a file with content: ' + 'x'.repeat(10000);
112
- const response = await client.callTool('run', {
113
- prompt: longPrompt,
114
- workFolder: testDir,
115
- });
116
- expect(response).toBeTruthy();
117
- });
118
- });
119
- describe('Path Traversal', () => {
120
- it('should prevent path traversal attacks', async () => {
121
- const maliciousPath = join(testDir, '..', '..', 'etc', 'passwd');
122
- // Server resolves paths and checks existence
123
- // The path /etc/passwd may exist but be a file, not a directory
124
- await expect(client.callTool('run', {
125
- prompt: 'Read file',
126
- workFolder: maliciousPath,
127
- })).rejects.toThrow(/(does not exist|ENOTDIR)/i);
128
- });
129
- });
130
- });