Skip to content

Commit 1bf3720

Browse files
committed
Fix: Adding MCPFailure tracking mock
1 parent 819fe6d commit 1bf3720

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

src/tools/applive.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ export async function startAppLiveSession(args: {
3737

3838
// check if the app path exists && is readable
3939
if (!fs.existsSync(args.appPath)) {
40-
throw new Error("The app path does not exist.");
40+
throw new Error("The app path does not exist");
41+
}
42+
43+
try {
44+
fs.accessSync(args.appPath, fs.constants.R_OK);
45+
} catch (error) {
46+
throw new Error("The app path does not exist or is not readable");
4147
}
42-
fs.accessSync(args.appPath, fs.constants.R_OK);
4348

4449
const launchUrl = await startSession({
4550
appPath: args.appPath,

tests/tools/applive.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jest.mock('../../src/logger', () => ({
1616
error: jest.fn()
1717
}));
1818
jest.mock('../../src/lib/instrumentation', () => ({
19-
trackMCPEvent: jest.fn()
19+
trackMCPEvent: jest.fn(),
20+
trackMCPFailure: jest.fn()
2021
}));
2122

2223
describe('startAppLiveSession', () => {

tests/tools/automate.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { getNetworkFailures } from '../../src/tools/automate';
22
import { retrieveNetworkFailures } from '../../src/lib/api';
3+
import addAutomateTools from '../../src/tools/automate';
34

45
jest.mock('../../src/lib/api', () => ({
56
retrieveNetworkFailures: jest.fn()
67
}));
78
jest.mock('../../src/lib/instrumentation', () => ({
8-
trackMCPEvent: jest.fn()
9+
trackMCPEvent: jest.fn(),
10+
trackMCPFailure: jest.fn()
911
}));
1012
jest.mock('../../src/logger', () => ({
1113
error: jest.fn(),
@@ -26,10 +28,23 @@ describe('getNetworkFailures', () => {
2628
],
2729
totalFailures: 1
2830
};
31+
32+
let serverMock: any;
2933

3034
beforeEach(() => {
3135
jest.clearAllMocks();
3236
(retrieveNetworkFailures as jest.Mock).mockResolvedValue(mockFailures);
37+
38+
serverMock = {
39+
tool: jest.fn((name, desc, schema, handler) => {
40+
serverMock.handler = handler;
41+
}),
42+
server: {
43+
getClientVersion: jest.fn().mockReturnValue({ name: 'test-client', version: '1.0.0' })
44+
}
45+
};
46+
47+
addAutomateTools(serverMock);
3348
});
3449

3550
it('should return failure logs when present', async () => {
@@ -44,13 +59,13 @@ describe('getNetworkFailures', () => {
4459
(retrieveNetworkFailures as jest.Mock).mockResolvedValue({ failures: [], totalFailures: 0 });
4560
const result = await getNetworkFailures({ sessionId: validSessionId });
4661
expect(retrieveNetworkFailures).toHaveBeenCalledWith(validSessionId);
47-
expect(result.content[0].text).toContain('No network failures found for sessio');
62+
expect(result.content[0].text).toContain('No network failures found for session');
4863
expect(result.isError).toBeFalsy();
4964
});
5065

5166
it('should handle errors from the API', async () => {
5267
(retrieveNetworkFailures as jest.Mock).mockRejectedValue(new Error('Invalid session ID'));
53-
const result = await getNetworkFailures({ sessionId: 'invalid-id' });
68+
const result = await serverMock.handler({ sessionId: 'invalid-id' });
5469
expect(retrieveNetworkFailures).toHaveBeenCalledWith('invalid-id');
5570
expect(result.content[0].text).toBe('Failed to fetch network logs: Invalid session ID');
5671
expect(result.content[0].isError).toBe(true);
@@ -59,7 +74,7 @@ describe('getNetworkFailures', () => {
5974

6075
it('should handle empty session ID', async () => {
6176
(retrieveNetworkFailures as jest.Mock).mockRejectedValue(new Error('Session ID is required'));
62-
const result = await getNetworkFailures({ sessionId: '' });
77+
const result = await serverMock.handler({ sessionId: '' });
6378
expect(retrieveNetworkFailures).toHaveBeenCalledWith('');
6479
expect(result.content[0].text).toBe('Failed to fetch network logs: Session ID is required');
6580
expect(result.content[0].isError).toBe(true);

tests/tools/live.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ jest.mock('../../src/logger', () => ({
1414
error: jest.fn()
1515
}));
1616
jest.mock('../../src/lib/instrumentation', () => ({
17-
trackMCPEvent: jest.fn()
17+
trackMCPEvent: jest.fn(),
18+
trackMCPFailure: jest.fn()
1819
}));
1920

2021
describe('startBrowserLiveSession', () => {
@@ -73,7 +74,7 @@ describe('startBrowserLiveSession', () => {
7374
(startBrowserSession as jest.Mock).mockRejectedValue(new Error('Session start failed'));
7475
const result = await serverMock.handler(validDesktopArgs);
7576
expect(logger.error).toHaveBeenCalled();
76-
expect(result.content[0].text).toContain('Failed to start session');
77+
expect(result.content[0].text).toContain('Failed to start a browser live session');
7778
});
7879

7980
it('should fail on schema validation error (missing desiredBrowser)', async () => {

tests/tools/observability.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ jest.mock('../../src/lib/api', () => ({
77
}));
88

99
jest.mock('../../src/lib/instrumentation', () => ({
10-
trackMCPEvent: jest.fn()
10+
trackMCPEvent: jest.fn(),
11+
trackMCPFailure: jest.fn()
1112
}));
1213

1314
describe('getFailuresInLastRun', () => {

tests/tools/testmanagement.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jest.mock('../../src/config', () => ({
2929
}));
3030
jest.mock('../../src/lib/instrumentation', () => ({
3131
trackMCPEvent: jest.fn(),
32+
trackMCPFailure: jest.fn()
3233
}));
3334

3435
const mockServer = {

0 commit comments

Comments
 (0)