Skip to content

Commit c8d6c19

Browse files
committed
Stabilize URL-encoded file paths in console test
1 parent a9dd9fd commit c8d6c19

3 files changed

Lines changed: 50 additions & 5 deletions

File tree

tests/tools/console.test.js.snapshot

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,40 @@ reqid=<reqid> data={"corsErrorStatus":{"corsError":"PreflightMissingAllowOriginH
119119
`;
120120

121121
exports[`console > get_console_message > when dialog is open 1`] = `
122-
{"content":[{"type":"text","text":"# Open dialog\\nalert: test dialog.\\nCall handle_dialog to handle it before continuing.\\nID: 1\\nMessage: error> This is an error\\n### Arguments\\nArg #0: This is an error\\n### Stack trace\\nat (VM7:1:9)\\nat (pptr:;CdpFrame.%3Canonymous%3E%20(file%3A%2F%2F%2FUsers%2Fsamiyac%2FDesktop%2Fchrome-devtools-mcp%2…:3:26)\\n--- PendingScript ----------------------\\nat (pptr:;CdpFrame.%3Canonymous%3E%20(file%3A%2F%2F%2FUsers%2Fsamiyac%2FDesktop%2Fchrome-devtools-mcp%2…:3:26)\\nNote: line and column numbers use 1-based indexing\\n## Console messages\\nShowing 1-1 of 1 (Page 1 of 1).\\nmsgid=1 [error] This is an error (1 args)"}],"structuredContent":{"dialog":{"type":"alert","message":"test dialog","defaultValue":""},"consoleMessage":{"id":1,"type":"error","text":"This is an error","argsCount":1,"args":["This is an error"],"stackTrace":"at (VM7:1:9)\\nat (pptr:;CdpFrame.%3Canonymous%3E%20(file%3A%2F%2F%2FUsers%2Fsamiyac%2FDesktop%2Fchrome-devtools-mcp%2…:3:26)\\n--- PendingScript ----------------------\\nat (pptr:;CdpFrame.%3Canonymous%3E%20(file%3A%2F%2F%2FUsers%2Fsamiyac%2FDesktop%2Fchrome-devtools-mcp%2…:3:26)\\nNote: line and column numbers use 1-based indexing"},"pagination":{"currentPage":0,"totalPages":1,"hasNextPage":false,"hasPreviousPage":false,"startIndex":0,"endIndex":1,"invalidPage":false},"consoleMessages":[{"type":"error","text":"This is an error","argsCount":1,"id":1}]}}
122+
{
123+
"dialog": {
124+
"type": "alert",
125+
"message": "test dialog",
126+
"defaultValue": ""
127+
},
128+
"consoleMessage": {
129+
"id": 1,
130+
"type": "error",
131+
"text": "This is an error",
132+
"argsCount": 1,
133+
"args": [
134+
"This is an error"
135+
],
136+
"stackTrace": "at (VM7:1:9)\\nat (pptr:;CdpFrame.%3Canonymous%3E%20(<file-path>)\\n--- PendingScript ----------------------\\nat (pptr:;CdpFrame.%3Canonymous%3E%20(<file-path>)\\nNote: line and column numbers use 1-based indexing"
137+
},
138+
"pagination": {
139+
"currentPage": 0,
140+
"totalPages": 1,
141+
"hasNextPage": false,
142+
"hasPreviousPage": false,
143+
"startIndex": 0,
144+
"endIndex": 1,
145+
"invalidPage": false
146+
},
147+
"consoleMessages": [
148+
{
149+
"type": "error",
150+
"text": "This is an error",
151+
"argsCount": 1,
152+
"id": 1
153+
}
154+
]
155+
}
123156
`;
124157

125158
exports[`console > list_console_messages > issues > when dialog is open 1`] = `

tests/tools/console.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import {
1919
listConsoleMessages,
2020
} from '../../src/tools/console.js';
2121
import {serverHooks} from '../server.js';
22-
import {getTextContent, withMcpContext} from '../utils.js';
22+
import {
23+
getTextContent,
24+
withMcpContext,
25+
stabilizeStructuredContent,
26+
} from '../utils.js';
2327

2428
describe('console', () => {
2529
before(async () => {
@@ -524,7 +528,6 @@ describe('console', () => {
524528
const dialogPromise = new Promise<Dialog>(resolve => {
525529
page.on('dialog', dialog => resolve(dialog));
526530
});
527-
528531
page.evaluate(() => {
529532
alert('test dialog');
530533
});
@@ -537,9 +540,14 @@ describe('console', () => {
537540
);
538541

539542
const result = await response.handle('get_console_message', context);
540-
t.assert.snapshot?.(JSON.stringify(result));
543+
t.assert.snapshot?.(
544+
JSON.stringify(
545+
stabilizeStructuredContent(result.structuredContent),
546+
null,
547+
2,
548+
),
549+
);
541550
await dialog.dismiss();
542-
context.getSelectedMcpPage().clearDialog();
543551
});
544552
});
545553
});

tests/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ export function stabilizeResponseOutput(text: unknown) {
287287
const acceptLanguageRegEx = /accept-language:.*\n/g;
288288
output = output.replaceAll(acceptLanguageRegEx, 'accept-language:<lang>\n');
289289

290+
// Stabilize URL-encoded file paths in stack traces starting with Users/
291+
const fileUriRegEx = /file%3A%2F%2F%2FUsers%2F[^)\n]+/g;
292+
output = output.replaceAll(fileUriRegEx, '<file-path>');
293+
290294
return output;
291295
}
292296

0 commit comments

Comments
 (0)