豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit cb0079e

Browse files
authored
refactor: simplify the response texts (#1095)
- removed redundant headers in Markdown - updates more tests to use snapshots
1 parent dfa9b79 commit cb0079e

File tree

7 files changed

+46
-86
lines changed

7 files changed

+46
-86
lines changed

src/McpResponse.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ export class McpResponse implements Response {
503503
extensionServiceWorkers?: object[];
504504
} = {};
505505

506-
const response = [`# ${toolName} response`];
506+
const response = [];
507507
if (this.#textResponseLines.length) {
508508
structuredContent.message = this.#textResponseLines.join('\n');
509509
response.push(...this.#textResponseLines);
@@ -512,38 +512,33 @@ export class McpResponse implements Response {
512512
const networkConditions = this.#page?.networkConditions;
513513
if (networkConditions) {
514514
const timeout = this.#page!.pptrPage.getDefaultNavigationTimeout();
515-
response.push(`## Network emulation`);
516-
response.push(`Emulating: ${networkConditions}`);
515+
response.push(`Emulating network conditions: ${networkConditions}`);
517516
response.push(`Default navigation timeout set to ${timeout} ms`);
518517
structuredContent.networkConditions = networkConditions;
519518
structuredContent.navigationTimeout = timeout;
520519
}
521520

522521
const viewport = this.#page?.viewport;
523522
if (viewport) {
524-
response.push(`## Viewport emulation`);
525523
response.push(`Emulating viewport: ${JSON.stringify(viewport)}`);
526524
structuredContent.viewport = viewport;
527525
}
528526

529527
const userAgent = this.#page?.userAgent;
530528
if (userAgent) {
531-
response.push(`## UserAgent emulation`);
532-
response.push(`Emulating userAgent: ${userAgent}`);
529+
response.push(`Emulating user agent: ${userAgent}`);
533530
structuredContent.userAgent = userAgent;
534531
}
535532

536533
const cpuThrottlingRate = this.#page?.cpuThrottlingRate ?? 1;
537534
if (cpuThrottlingRate > 1) {
538-
response.push(`## CPU emulation`);
539-
response.push(`Emulating: ${cpuThrottlingRate}x slowdown`);
535+
response.push(`Emulating CPU throttling: ${cpuThrottlingRate}x slowdown`);
540536
structuredContent.cpuThrottlingRate = cpuThrottlingRate;
541537
}
542538

543539
const colorScheme = this.#page?.colorScheme;
544540
if (colorScheme) {
545-
response.push(`## Color Scheme emulation`);
546-
response.push(`Emulating: ${colorScheme}`);
541+
response.push(`Emulating color scheme: ${colorScheme}`);
547542
structuredContent.colorScheme = colorScheme;
548543
}
549544

tests/McpResponse.test.js.snapshot

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
exports[`McpResponse > add network request when attached 1`] = `
2-
# test response
32
## Request http://example.com
43
Status: pending
54
### Request Headers
@@ -42,7 +41,6 @@ exports[`McpResponse > add network request when attached 2`] = `
4241
`;
4342

4443
exports[`McpResponse > add network request when attached with POST data 1`] = `
45-
# test response
4644
## Request http://example.com
4745
Status: 200
4846
### Request Headers
@@ -96,7 +94,6 @@ exports[`McpResponse > add network request when attached with POST data 2`] = `
9694
`;
9795

9896
exports[`McpResponse > add network requests when setting is true 1`] = `
99-
# test response
10097
## Network requests
10198
Showing 1-2 of 2 (Page 1 of 1).
10299
reqid=1 GET http://example.com [pending]
@@ -134,7 +131,6 @@ exports[`McpResponse > add network requests when setting is true 2`] = `
134131
`;
135132

136133
exports[`McpResponse > adds a message when no console messages exist 1`] = `
137-
# test response
138134
## Console messages
139135
<no console messages found>
140136
`;
@@ -144,7 +140,6 @@ exports[`McpResponse > adds a message when no console messages exist 2`] = `
144140
`;
145141

146142
exports[`McpResponse > adds a prompt dialog 1`] = `
147-
# test response
148143
# Open dialog
149144
prompt: message (default value: "default").
150145
Call handle_dialog to handle it before continuing.
@@ -161,7 +156,6 @@ exports[`McpResponse > adds a prompt dialog 2`] = `
161156
`;
162157

163158
exports[`McpResponse > adds an alert dialog 1`] = `
164-
# test response
165159
# Open dialog
166160
alert: message.
167161
Call handle_dialog to handle it before continuing.
@@ -178,9 +172,7 @@ exports[`McpResponse > adds an alert dialog 2`] = `
178172
`;
179173

180174
exports[`McpResponse > adds color scheme emulation setting when it is set 1`] = `
181-
# test response
182-
## Color Scheme emulation
183-
Emulating: dark
175+
Emulating color scheme: dark
184176
`;
185177

186178
exports[`McpResponse > adds color scheme emulation setting when it is set 2`] = `
@@ -190,7 +182,6 @@ exports[`McpResponse > adds color scheme emulation setting when it is set 2`] =
190182
`;
191183

192184
exports[`McpResponse > adds console messages when the setting is true 1`] = `
193-
# test response
194185
## Console messages
195186
Showing 1-1 of 1 (Page 1 of 1).
196187
msgid=1 [log] Hello from the test (1 args)
@@ -219,9 +210,7 @@ exports[`McpResponse > adds console messages when the setting is true 2`] = `
219210
`;
220211

221212
exports[`McpResponse > adds cpu throttling setting when it is over 1 1`] = `
222-
# test response
223-
## CPU emulation
224-
Emulating: 4x slowdown
213+
Emulating CPU throttling: 4x slowdown
225214
`;
226215

227216
exports[`McpResponse > adds cpu throttling setting when it is over 1 2`] = `
@@ -231,13 +220,15 @@ exports[`McpResponse > adds cpu throttling setting when it is over 1 2`] = `
231220
`;
232221

233222
exports[`McpResponse > adds image when image is attached 1`] = `
223+
224+
`;
225+
226+
exports[`McpResponse > adds image when image is attached 2`] = `
234227
{}
235228
`;
236229

237230
exports[`McpResponse > adds throttling setting when it is not null 1`] = `
238-
# test response
239-
## Network emulation
240-
Emulating: Slow 3G
231+
Emulating network conditions: Slow 3G
241232
Default navigation timeout set to 100000 ms
242233
`;
243234

@@ -249,9 +240,7 @@ exports[`McpResponse > adds throttling setting when it is not null 2`] = `
249240
`;
250241

251242
exports[`McpResponse > adds userAgent emulation setting when it is set 1`] = `
252-
# test response
253-
## UserAgent emulation
254-
Emulating userAgent: MyUA
243+
Emulating user agent: MyUA
255244
`;
256245

257246
exports[`McpResponse > adds userAgent emulation setting when it is set 2`] = `
@@ -261,8 +250,6 @@ exports[`McpResponse > adds userAgent emulation setting when it is set 2`] = `
261250
`;
262251

263252
exports[`McpResponse > adds viewport emulation setting when it is set 1`] = `
264-
# test response
265-
## Viewport emulation
266253
Emulating viewport: {"deviceScaleFactor":1,"isMobile":false,"hasTouch":false,"isLandscape":false,"width":400,"height":400}
267254
`;
268255

@@ -280,7 +267,6 @@ exports[`McpResponse > adds viewport emulation setting when it is set 2`] = `
280267
`;
281268

282269
exports[`McpResponse > allows response text lines to be added 1`] = `
283-
# test response
284270
Testing 1
285271
Testing 2
286272
`;
@@ -292,18 +278,34 @@ exports[`McpResponse > allows response text lines to be added 2`] = `
292278
`;
293279

294280
exports[`McpResponse > does not include anything in response if snapshot is null 1`] = `
281+
282+
`;
283+
284+
exports[`McpResponse > does not include anything in response if snapshot is null 2`] = `
295285
{}
296286
`;
297287

298288
exports[`McpResponse > does not include cpu throttling setting when it is 1 1`] = `
289+
290+
`;
291+
292+
exports[`McpResponse > does not include cpu throttling setting when it is 1 2`] = `
299293
{}
300294
`;
301295

302296
exports[`McpResponse > does not include network requests when setting is false 1`] = `
297+
298+
`;
299+
300+
exports[`McpResponse > does not include network requests when setting is false 2`] = `
303301
{}
304302
`;
305303

306304
exports[`McpResponse > does not include throttling setting when it is null 1`] = `
305+
306+
`;
307+
308+
exports[`McpResponse > does not include throttling setting when it is null 2`] = `
307309
{}
308310
`;
309311

@@ -312,7 +314,6 @@ exports[`McpResponse > doesn't list the issue message if mapping returns null 1`
312314
`;
313315

314316
exports[`McpResponse > list pages 1`] = `
315-
# test response
316317
## Pages
317318
1: about:blank [selected]
318319
`;
@@ -330,7 +331,6 @@ exports[`McpResponse > list pages 2`] = `
330331
`;
331332

332333
exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = `
333-
# test response
334334
## Latest page snapshot
335335
uid=1_0 RootWebArea "My test page" url="about:blank"
336336
uid=1_1 button "Click me" focusable focused
@@ -364,7 +364,6 @@ exports[`McpResponse > returns correctly formatted snapshot for a simple tree 2`
364364
`;
365365

366366
exports[`McpResponse > returns values for textboxes 1`] = `
367-
# test response
368367
## Latest page snapshot
369368
uid=1_0 RootWebArea "My test page" url="about:blank"
370369
uid=1_1 StaticText "username"
@@ -399,7 +398,6 @@ exports[`McpResponse > returns values for textboxes 2`] = `
399398
`;
400399

401400
exports[`McpResponse > returns verbose snapshot and structured content 1`] = `
402-
# test response
403401
## Latest page snapshot
404402
uid=1_0 RootWebArea "My test page" url="about:blank"
405403
uid=1_1 ignored
@@ -454,7 +452,6 @@ exports[`McpResponse > returns verbose snapshot and structured content 2`] = `
454452
`;
455453

456454
exports[`McpResponse > saves snapshot to file and returns structured content 1`] = `
457-
# test response
458455
Saved snapshot to <file>
459456
`;
460457

@@ -728,7 +725,6 @@ exports[`McpResponse network pagination > returns subsequent page when pageIdx p
728725
`;
729726

730727
exports[`McpResponse network pagination > trace insights > includes error if insight not found 1`] = `
731-
# test response
732728
No Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.
733729
`;
734730

@@ -737,7 +733,6 @@ exports[`McpResponse network pagination > trace insights > includes error if ins
737733
`;
738734

739735
exports[`McpResponse network pagination > trace insights > includes the trace insight output 1`] = `
740-
# test response
741736
## Insight Title: LCP breakdown
742737

743738
## Insight Summary:
@@ -787,7 +782,6 @@ exports[`McpResponse network pagination > trace insights > includes the trace in
787782
`;
788783

789784
exports[`McpResponse network pagination > trace summaries > includes the trace summary text and structured data 1`] = `
790-
# test response
791785
## Summary of Performance trace findings:
792786
URL: https://web.dev/
793787
Trace bounds: {min: 122410994891, max: 122416385853}
@@ -982,7 +976,6 @@ exports[`McpResponse network pagination > trace summaries > includes the trace s
982976
`;
983977

984978
exports[`McpResponse network request filtering > filters network requests by resource type 1`] = `
985-
# test response
986979
## Network requests
987980
Showing 1-2 of 2 (Page 1 of 1).
988981
reqid=1 GET http://example.com [pending]
@@ -1020,7 +1013,6 @@ exports[`McpResponse network request filtering > filters network requests by res
10201013
`;
10211014

10221015
exports[`McpResponse network request filtering > filters network requests by single resource type 1`] = `
1023-
# test response
10241016
## Network requests
10251017
Showing 1-1 of 1 (Page 1 of 1).
10261018
reqid=1 GET http://example.com [pending]
@@ -1050,7 +1042,6 @@ exports[`McpResponse network request filtering > filters network requests by sin
10501042
`;
10511043

10521044
exports[`McpResponse network request filtering > shows all requests when empty resourceTypes array is provided 1`] = `
1053-
# test response
10541045
## Network requests
10551046
Showing 1-5 of 5 (Page 1 of 1).
10561047
reqid=1 GET http://example.com [pending]
@@ -1112,7 +1103,6 @@ exports[`McpResponse network request filtering > shows all requests when empty r
11121103
`;
11131104

11141105
exports[`McpResponse network request filtering > shows all requests when no filters are provided 1`] = `
1115-
# test response
11161106
## Network requests
11171107
Showing 1-5 of 5 (Page 1 of 1).
11181108
reqid=1 GET http://example.com [pending]
@@ -1174,15 +1164,14 @@ exports[`McpResponse network request filtering > shows all requests when no filt
11741164
`;
11751165

11761166
exports[`McpResponse network request filtering > shows no requests when filter matches nothing 1`] = `
1177-
# test response
1167+
11781168
`;
11791169

11801170
exports[`McpResponse network request filtering > shows no requests when filter matches nothing 2`] = `
11811171
{}
11821172
`;
11831173

11841174
exports[`extensions > lists extensions 1`] = `
1185-
# test response
11861175
## Extensions
11871176
id=id1 "Extension 1" v1.0 Enabled
11881177
id=id2 "Extension 2" v2.0 Disabled
@@ -1210,7 +1199,6 @@ exports[`extensions > lists extensions 2`] = `
12101199
`;
12111200

12121201
exports[`lighthouse > includes lighthouse report paths 1`] = `
1213-
# test response
12141202
## Lighthouse Audit Results
12151203
Mode: navigation
12161204
Device: desktop

tests/McpResponse.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ describe('McpResponse', () => {
7070
'test',
7171
context,
7272
);
73-
assert.equal(content[0].type, 'text');
74-
assert.deepStrictEqual(getTextContent(content[0]), `# test response`);
73+
t.assert.snapshot?.(getTextContent(content[0]));
7574
t.assert.snapshot?.(
7675
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
7776
);
@@ -94,7 +93,6 @@ describe('McpResponse', () => {
9493
'test',
9594
context,
9695
);
97-
assert.equal(content[0].type, 'text');
9896
t.assert.snapshot?.(getTextContent(content[0]));
9997
t.assert.snapshot?.(
10098
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
@@ -303,8 +301,7 @@ describe('McpResponse', () => {
303301
context,
304302
);
305303
await context.emulate({});
306-
assert.equal(content[0].type, 'text');
307-
assert.strictEqual(getTextContent(content[0]), `# test response`);
304+
t.assert.snapshot?.(getTextContent(content[0]));
308305
t.assert.snapshot?.(
309306
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
310307
);
@@ -317,7 +314,7 @@ describe('McpResponse', () => {
317314
'test',
318315
context,
319316
);
320-
assert.strictEqual(getTextContent(content[0]), `# test response`);
317+
t.assert.snapshot?.(getTextContent(content[0]));
321318
assert.equal(content[1].type, 'image');
322319
assert.strictEqual(getImageContent(content[1]).data, 'imageBase64');
323320
assert.strictEqual(getImageContent(content[1]).mimeType, 'image/png');
@@ -348,7 +345,7 @@ describe('McpResponse', () => {
348345
'test',
349346
context,
350347
);
351-
assert.strictEqual(getTextContent(content[0]), `# test response`);
348+
t.assert.snapshot?.(getTextContent(content[0]));
352349
t.assert.snapshot?.(
353350
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
354351
);
@@ -474,7 +471,7 @@ describe('McpResponse', () => {
474471
'test',
475472
context,
476473
);
477-
assert.strictEqual(getTextContent(content[0]), `# test response`);
474+
t.assert.snapshot?.(getTextContent(content[0]));
478475
t.assert.snapshot?.(
479476
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
480477
);

tests/index.test.js.snapshot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exports[`e2e > calls a tool 1`] = `
2+
[{"type":"text","text":"## Pages\\n1: about:blank [selected]"}]
3+
`;
4+
5+
exports[`e2e > calls a tool multiple times 1`] = `
6+
[{"type":"text","text":"## Pages\\n1: about:blank [selected]"}]
7+
`;

0 commit comments

Comments
 (0)