-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathclient.test.ts
More file actions
116 lines (100 loc) · 3.3 KB
/
client.test.ts
File metadata and controls
116 lines (100 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it, afterEach, beforeEach} from 'node:test';
import {
handleResponse,
startDaemon,
stopDaemon,
} from '../../src/daemon/client.js';
import {isDaemonRunning} from '../../src/daemon/utils.js';
describe('daemon client', () => {
describe('start/stop', () => {
beforeEach(async () => {
await stopDaemon();
});
afterEach(async () => {
await stopDaemon();
});
it('should start and stop daemon', async () => {
assert.ok(!isDaemonRunning(), 'Daemon should not be running initially');
await startDaemon();
assert.ok(isDaemonRunning(), 'Daemon should be running after start');
await stopDaemon();
assert.ok(!isDaemonRunning(), 'Daemon should not be running after stop');
});
it('should handle starting daemon when already running', async () => {
await startDaemon();
assert.ok(isDaemonRunning(), 'Daemon should be running');
// Starting again should be a no-op
await startDaemon();
assert.ok(isDaemonRunning(), 'Daemon should still be running');
});
it('should handle stopping daemon when not running', async () => {
assert.ok(!isDaemonRunning(), 'Daemon should not be running initially');
// Stopping when not running should be a no-op
await stopDaemon();
assert.ok(!isDaemonRunning(), 'Daemon should still not be running');
});
});
describe('parsing', () => {
it('handles MCP response with text format', async () => {
const textResponse = {content: [{type: 'text' as const, text: 'test'}]};
assert.strictEqual(handleResponse(textResponse, 'md'), 'test');
});
it('handles JSON response', async () => {
const jsonResponse = {
content: [],
structuredContent: {
test: 'data',
number: 123,
},
};
assert.strictEqual(
handleResponse(jsonResponse, 'json'),
JSON.stringify(jsonResponse.structuredContent),
);
});
it('handles error response when isError is true', async () => {
const errorResponse = {
isError: true,
content: [{type: 'text' as const, text: 'Something went wrong'}],
};
assert.strictEqual(
handleResponse(errorResponse, 'md'),
JSON.stringify(errorResponse.content),
);
});
it('handles text response when json format is requested but no structured content', async () => {
const textResponse = {
content: [{type: 'text' as const, text: 'Fall through text'}],
};
assert.deepStrictEqual(
handleResponse(textResponse, 'json'),
JSON.stringify(['Fall through text']),
);
});
it('throws error for unsupported content type', async () => {
const unsupportedContentResponse = {
content: [
{
type: 'resource' as const,
resource: {
uri: 'data:image/png;base64,base64data',
blob: 'base64data',
mimeType: 'image/png',
},
},
],
structuredContent: {},
};
assert.throws(
() => handleResponse(unsupportedContentResponse, 'md'),
new Error('Not supported response content type'),
);
});
});
});