Repository navigation
Expand file tree
/
Copy pathtools.spec.ts
More file actions
1479 lines (1235 loc) · 53.4 KB
/
Copy pathtools.spec.ts
File metadata and controls
1479 lines (1235 loc) · 53.4 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { Locator, Page } from "@playwright/test";
import { test, expect, MOCK_CSRF_TOKEN } from "./fixtures/api-mock";
import { APP } from "./utils/paths";
import type { Tool } from "../src/types/tool";
/** Payload the create form POSTs to `/tools` (see useToolForm.getFormData). */
interface CreateToolPayload {
tool: Record<string, unknown>;
team_id?: string;
}
/** Flat payload the edit form PUTs to `/tools/{id}` (see useToolForm.handleSubmit). */
interface UpdateToolPayload {
name?: string;
url?: string;
customName?: string;
[key: string]: unknown;
}
interface JsonRpcRequest {
jsonrpc?: string;
id?: string | number | null;
method?: string;
params?: Record<string, unknown>;
}
/** Stub the tools list endpoint (`/tools?limit=0&include_inactive=true`). */
async function routeToolsList(page: Page, tools: Tool[]) {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(tools),
});
});
}
async function showDefinitionTab(panel: Locator) {
await panel.getByRole("tab", { name: "Definition" }).click();
}
async function openAddToolForm(page: Page) {
await page.getByText("Add tools").click();
await expect(page.getByRole("heading", { name: "Add tool" })).toBeVisible();
}
async function fillToolBasics(page: Page, name: string, url: string) {
await page.locator("#tool-name").fill(name);
await page.locator("#tool-url").fill(url);
}
async function openToolDetails(page: Page, gatewaySlug: string) {
await page.getByRole("button", { name: `More options for ${gatewaySlug}` }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: new RegExp(`Tools for ${gatewaySlug}`, "i") });
await expect(panel).toBeVisible();
return panel;
}
function makeTool(id: string, gatewaySlug: string, overrides: Partial<Tool> = {}): Tool {
return {
id,
name: id,
originalName: id,
description: `Description for ${id}`,
originalDescription: `Original description for ${id}`,
title: `${id} Title`,
gatewayId: `gw-${gatewaySlug}`,
gatewaySlug,
customName: id,
customNameSlug: id.toLowerCase(),
enabled: true,
reachable: true,
deprecated: false,
executionCount: 0,
tags: [],
integrationType: "mcp",
requestType: "http",
url: `https://example.com/${id}`,
headers: {},
inputSchema: { type: "object", properties: {} },
annotations: {},
jsonpathFilter: null,
auth: null,
createdAt: "2026-04-10T10:00:00Z",
updatedAt: "2026-04-10T10:00:00Z",
...overrides,
};
}
const TOOL_A1 = makeTool("get_issues", "github-server");
const TOOL_A2 = makeTool("create_issue", "github-server");
const TOOL_B1 = makeTool("send_message", "slack-server");
test.describe("Tools page", () => {
test.beforeEach(async ({ page, apiMock }) => {
await apiMock.mockSession();
await apiMock.mockPermissions();
await page.addInitScript(() => {
sessionStorage.setItem("mcpgateway_token", "mock-token-12345");
});
});
test("shows Add tools card when no tools exist", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await expect(page.getByText("Add tools")).toBeVisible();
await expect(
page.getByText(/Tools will appear automatically when you connect a MCP server/i),
).toBeVisible();
});
test("hides Add tools card when the caller lacks tools.create", async ({ page, apiMock }) => {
await apiMock.mockPermissions({ permissions: ["tools.read"] });
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await expect(page.getByRole("heading", { name: "Tools" })).toBeVisible();
await expect(page.getByText("Add tools")).not.toBeVisible();
});
test("Add tools card opens the tool form", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
// Click the Add tools card
await page.getByText("Add tools").click();
await expect(page.getByRole("heading", { name: "Add tool" })).toBeVisible();
});
test("shows tools grouped by gateway slug", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1, TOOL_A2, TOOL_B1]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await expect(page.getByRole("heading", { name: "Tools" })).toBeVisible();
await expect(page.getByText("github-server")).toBeVisible();
await expect(page.getByText("slack-server")).toBeVisible();
await expect(page.getByText("get_issues")).toBeVisible();
await expect(page.getByText("create_issue")).toBeVisible();
await expect(page.getByText("send_message")).toBeVisible();
await expect(page.getByText("2 tools")).toBeVisible();
await expect(page.getByText("1 tool")).toBeVisible();
});
test("shows error alert when tools API fails", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 500,
contentType: "application/json",
body: JSON.stringify({ detail: "Internal server error" }),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await expect(page.getByRole("alert")).toBeVisible();
await expect(page.getByText("Error loading tools")).toBeVisible();
});
test("caps badge display at 8 and shows +N overflow tag", async ({ page }) => {
const manyTools: Tool[] = Array.from({ length: 10 }, (_, i) =>
makeTool(`tool_${i + 1}`, "big-gateway"),
);
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(manyTools),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await expect(page.getByText("big-gateway")).toBeVisible();
await expect(page.getByText("10 tools")).toBeVisible();
await expect(page.getByText("tool_1")).toBeVisible();
await expect(page.getByText("tool_8")).toBeVisible();
await expect(page.getByText("tool_9")).not.toBeVisible();
await expect(page.getByText("tool_10")).not.toBeVisible();
await expect(page.getByText("+2")).toBeVisible();
});
test("truncates a long gateway name and keeps the overflow menu visible", async ({ page }) => {
// A gateway slug long enough to overflow the card at the default viewport.
const longSlug =
"openzeppelin-stylus-contracts-enterprise-edition-extended-long-server-name-instance";
const tools: Tool[] = [makeTool("stylus_erc20", longSlug), makeTool("stylus_erc721", longSlug)];
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(tools),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
// The kebab menu for the long-named group must stay visible.
const kebab = page.getByRole("button", { name: `More options for ${longSlug}` });
await expect(kebab).toBeVisible();
const card = page.locator('[data-slot="card"]').filter({ has: kebab });
const title = card.locator('[data-slot="card-header"] span.truncate').first();
// The title is actually clipped (its content is wider than the box) and
// carries a native tooltip so the full name stays discoverable on hover.
const isTruncated = await title.evaluate((el) => el.scrollWidth > el.clientWidth);
expect(isTruncated).toBe(true);
await expect(title).toHaveAttribute("title", longSlug);
// The kebab is not pushed past the card's right edge (it was clipped before).
const cardBox = await card.boundingBox();
const kebabBox = await kebab.boundingBox();
expect(cardBox).not.toBeNull();
expect(kebabBox).not.toBeNull();
expect(kebabBox!.x + kebabBox!.width).toBeLessThanOrEqual(cardBox!.x + cardBox!.width + 1);
// And it remains functional.
await kebab.click();
await expect(page.getByRole("menuitem", { name: "View details" })).toBeVisible();
});
test("opens more options dropdown and shows View Details item", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await expect(page.getByRole("menuitem", { name: "View details" })).toBeVisible();
});
test("opens details panel when View Details is clicked", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1, TOOL_A2]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await expect(panel).toBeVisible();
await expect(panel.getByText("get_issues").first()).toBeVisible();
await expect(panel.getByText("create_issue").first()).toBeVisible();
});
test("previews a tool with schema arguments and allowed passthrough headers", async ({
page,
}) => {
const previewTool = makeTool("search_issues", "github-server", {
description: "Search repository issues",
inputSchema: {
type: "object",
required: ["query"],
properties: {
query: { type: "string", description: "Search query" },
limit: { type: "integer" },
},
},
annotations: { readOnlyHint: true },
});
let previewBody: unknown = null;
let previewHeaders: Record<string, string> = {};
await routeToolsList(page, [previewTool]);
await page.route("**/v1/tools/preview/search_issues", async (route) => {
previewBody = route.request().postDataJSON();
previewHeaders = route.request().headers();
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
validated: true,
target: { kind: "local" },
resolvedArguments: { query: "cloudflare", limit: 5 },
annotations: { readOnlyHint: true },
preHooksRun: [],
warnings: [
{
code: "elicitation_skipped",
hook: "approval_hook",
message:
"Approval hook skipped during preview; live invocation may prompt for input.",
},
],
}),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await expect(panel.getByRole("heading", { name: "Tools", exact: true })).toBeVisible();
// Read-only/destructive annotation badges aren't part of the design here
// (they stay in use to gate live invocation, just not shown as badges).
await expect(panel.getByText("Read-only")).not.toBeVisible();
const previewButton = panel.getByRole("button", { name: "Preview" });
await expect(previewButton).toBeEnabled();
await previewButton.click();
await expect(panel.getByLabel("query")).toHaveAttribute("aria-invalid", "true");
await expect(panel.getByText("Required")).toBeVisible();
expect(previewBody).toBeNull();
await panel.getByLabel("query").fill("cloudflare");
await panel.getByLabel("limit").fill("5");
await panel.getByRole("button", { name: "Add header" }).click();
await panel.getByLabel("Header 1 name").fill("X-Tenant-Id");
await panel.getByLabel("Header 1 value").fill("team-a");
await expect(previewButton).toBeEnabled();
await previewButton.click();
await expect(panel.getByText("Preview 200")).toBeVisible();
await expect(panel.getByText("Warnings", { exact: true }).first()).toBeVisible();
await expect(
panel
.getByText("Approval hook skipped during preview; live invocation may prompt for input.")
.first(),
).toBeVisible();
await expect(panel.getByText("Resolved arguments")).toHaveCount(0);
await expect(panel.getByLabel("Copy raw preview response")).toBeVisible();
await expect(panel.locator("pre").filter({ hasText: "resolvedArguments" })).toContainText(
"cloudflare",
);
expect(previewBody).toEqual({ arguments: { query: "cloudflare", limit: 5 } });
expect(previewHeaders["x-tenant-id"]).toBe("team-a");
});
test("live invokes a read-only tool with JSON-RPC args and passthrough headers", async ({
page,
apiMock,
}) => {
const liveTool = makeTool("search_issues", "github-server", {
description: "Search repository issues",
inputSchema: {
type: "object",
required: ["query"],
properties: {
query: { type: "string", description: "Search query" },
limit: { type: "integer" },
},
},
annotations: { readOnlyHint: true },
});
let rpcBody: JsonRpcRequest | null = null;
let rpcHeaders: Record<string, string> = {};
await routeToolsList(page, [liveTool]);
await page.route("**/api/rpc", async (route) => {
rpcBody = route.request().postDataJSON() as JsonRpcRequest;
rpcHeaders = route.request().headers();
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
jsonrpc: "2.0",
id: rpcBody.id ?? "invoke-1",
result: {
content: [{ type: "text", text: "Live result from gateway", mimeType: "text/plain" }],
structured_output: { total: 1 },
},
}),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
const panel = await openToolDetails(page, "github-server");
await expect(panel.getByText("MCP version 2025-11-25")).toBeVisible();
await panel.getByRole("switch", { name: "Live invocation" }).click();
const invokeButton = panel.getByRole("button", { name: "Invoke tool" });
await expect(invokeButton).toBeEnabled();
await invokeButton.click();
await expect(panel.getByLabel("query")).toHaveAttribute("aria-invalid", "true");
await expect(panel.getByText("Required")).toBeVisible();
expect(rpcBody).toBeNull();
await panel.getByLabel("query").fill("cloudflare");
await panel.getByLabel("limit").fill("5");
await panel.getByRole("button", { name: "Add header" }).click();
await panel.getByLabel("Header 1 name").fill("X-Tenant-Id");
await panel.getByLabel("Header 1 value").fill("team-a");
await invokeButton.click();
await expect(panel.getByText("Live invoke 200")).toBeVisible();
await expect(panel.getByText("Live result from gateway").first()).toBeVisible();
await expect(panel.getByText("Structured output")).toBeVisible();
expect(rpcBody).toMatchObject({
jsonrpc: "2.0",
method: "tools/call",
params: {
name: "search_issues",
arguments: { query: "cloudflare", limit: 5 },
},
});
expect(rpcBody).not.toHaveProperty("params.server_id");
expect(rpcHeaders["x-tenant-id"]).toBe("team-a");
// Real mode gets a real, randomly-generated token from the real login.
expect(rpcHeaders["x-csrf-token"]).toBe((await apiMock.getRealCsrfToken()) ?? MOCK_CSRF_TOKEN);
});
test("confirms destructive local live invoke before calling /rpc", async ({ page }) => {
const destructiveTool = makeTool("delete_issue", "local-gateway", {
gatewayId: null,
annotations: { destructiveHint: true },
inputSchema: { type: "object", properties: {} },
});
let rpcRequestCount = 0;
await routeToolsList(page, [destructiveTool]);
await page.route("**/api/rpc", async (route) => {
rpcRequestCount += 1;
const body = route.request().postDataJSON() as JsonRpcRequest;
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
jsonrpc: "2.0",
id: body.id ?? "invoke-1",
result: { content: [{ type: "text", text: "Deleted", mimeType: "text/plain" }] },
}),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
const panel = await openToolDetails(page, "local-gateway");
await panel.getByRole("switch", { name: "Live invocation" }).click();
await panel.getByRole("button", { name: "Invoke tool" }).click();
const dialog = page.getByRole("alertdialog", { name: "Invoke destructive tool" });
await expect(dialog).toBeVisible();
await dialog.getByRole("button", { name: "Cancel" }).click();
await expect(dialog).not.toBeVisible();
expect(rpcRequestCount).toBe(0);
await panel.getByRole("button", { name: "Invoke tool" }).click();
await page
.getByRole("alertdialog", { name: "Invoke destructive tool" })
.getByRole("button", { name: "Invoke tool" })
.click();
await expect.poll(() => rpcRequestCount).toBe(1);
await expect(panel.getByText("Live invoke 200")).toBeVisible();
await expect(panel.getByText("Deleted").first()).toBeVisible();
});
test("sends MCP cancellation when cancelling live invoke", async ({ page }) => {
const slowTool = makeTool("slow_search", "github-server", {
annotations: { readOnlyHint: true },
inputSchema: { type: "object", properties: {} },
});
const rpcBodies: JsonRpcRequest[] = [];
let releaseInvoke: (() => void) | undefined;
const releaseInvokePromise = new Promise<void>((resolve) => {
releaseInvoke = resolve;
});
await routeToolsList(page, [slowTool]);
await page.route("**/api/rpc", async (route) => {
const body = route.request().postDataJSON() as JsonRpcRequest;
rpcBodies.push(body);
if (body.method === "notifications/cancelled") {
releaseInvoke?.();
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ jsonrpc: "2.0", id: body.id ?? "cancel-1", result: {} }),
});
return;
}
await releaseInvokePromise;
try {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
jsonrpc: "2.0",
id: body.id ?? "invoke-1",
result: { content: [{ type: "text", text: "Finished", mimeType: "text/plain" }] },
}),
});
} catch {
// The browser request is expected to be aborted after cancellation.
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
const panel = await openToolDetails(page, "github-server");
await panel.getByRole("switch", { name: "Live invocation" }).click();
await panel.getByRole("button", { name: "Invoke tool" }).click();
await expect(panel.getByRole("button", { name: "Cancel request" })).not.toBeVisible();
await expect(panel.getByRole("button", { name: "Cancel request" })).toBeVisible();
await panel.getByRole("button", { name: "Cancel request" }).click();
await expect
.poll(() => rpcBodies.some((body) => body.method === "notifications/cancelled"))
.toBe(true);
const invokeBody = rpcBodies.find((body) => body.method === "tools/call");
const cancelBody = rpcBodies.find((body) => body.method === "notifications/cancelled");
expect(invokeBody?.id).toEqual(expect.stringMatching(/^tool-live-/));
expect(cancelBody).toMatchObject({
jsonrpc: "2.0",
method: "notifications/cancelled",
params: {
requestId: String(invokeBody?.id),
reason: "user",
},
});
});
test("hides live invoke when tools.execute is missing", async ({ page, apiMock }) => {
await apiMock.mockPermissions({ permissions: ["tools.read", "servers.use"] });
const liveTool = makeTool("search_issues", "github-server", {
annotations: { readOnlyHint: true },
inputSchema: { type: "object", properties: {} },
});
await routeToolsList(page, [liveTool]);
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
const panel = await openToolDetails(page, "github-server");
await expect(panel.getByRole("button", { name: "Preview", exact: true })).toBeVisible();
await expect(panel.getByRole("switch", { name: "Live invocation" })).toHaveCount(0);
await expect(panel.getByText("Live invocation", { exact: true })).toHaveCount(0);
});
test("hides live invoke when servers.use is missing", async ({ page, apiMock }) => {
await apiMock.mockPermissions({ permissions: ["tools.read", "tools.execute"] });
const liveTool = makeTool("search_issues", "github-server", {
annotations: { readOnlyHint: true },
inputSchema: { type: "object", properties: {} },
});
await routeToolsList(page, [liveTool]);
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
const panel = await openToolDetails(page, "github-server");
await expect(panel.getByRole("button", { name: "Preview", exact: true })).toBeVisible();
await expect(panel.getByRole("switch", { name: "Live invocation" })).toHaveCount(0);
await expect(panel.getByText("Live invocation", { exact: true })).toHaveCount(0);
});
test("does not offer live invoke for federated tools without readOnlyHint", async ({ page }) => {
const federatedTool = makeTool("create_issue", "github-server", {
annotations: { destructiveHint: true },
inputSchema: { type: "object", properties: {} },
});
await routeToolsList(page, [federatedTool]);
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
const panel = await openToolDetails(page, "github-server");
await expect(
panel.getByText("Live invoke is not offered for federated tools without readOnlyHint."),
).toBeVisible();
await expect(panel.getByRole("switch", { name: "Live invocation" })).toBeDisabled();
await expect(panel.getByRole("button", { name: "Preview", exact: true })).toBeEnabled();
});
test("warns for denied passthrough headers and excludes them from preview", async ({ page }) => {
const previewTool = makeTool("search_issues", "github-server", {
inputSchema: {
type: "object",
required: ["query"],
properties: { query: { type: "string" } },
},
});
let previewHeaders: Record<string, string> = {};
await routeToolsList(page, [previewTool]);
await page.route("**/v1/tools/preview/search_issues", async (route) => {
previewHeaders = route.request().headers();
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
validated: true,
target: { kind: "local" },
resolvedArguments: { query: "cloudflare" },
annotations: {},
}),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await panel.getByLabel("query").fill("cloudflare");
await panel.getByRole("button", { name: "Add header" }).click();
await panel.getByLabel("Header 1 name").fill("Authorization");
await panel.getByLabel("Header 1 value").fill("Bearer typed-token");
await expect(panel.getByText("This header is not forwardable from the web UI.")).toBeVisible();
await expect(panel.getByRole("button", { name: "Preview", exact: true })).toBeDisabled();
await panel.getByLabel("Header 1 name").fill("X-Api-Key");
await panel.getByRole("button", { name: "Preview", exact: true }).click();
await expect(panel.getByText("Preview 200")).toBeVisible();
expect(previewHeaders.authorization).toBeUndefined();
expect(previewHeaders["x-api-key"]).toBe("Bearer typed-token");
});
test("closes details panel via close button", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await expect(panel).toBeVisible();
await page.getByLabel("Close tool details").click();
await expect(panel).not.toBeVisible();
});
test("optimistically removes tool on delete confirmation and shows success toast", async ({
page,
}) => {
let deleteRequestCount = 0;
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1, TOOL_A2]),
});
});
await page.route(`**/tools/${TOOL_A1.id}`, async (route) => {
if (route.request().method() === "DELETE") {
deleteRequestCount += 1;
await route.fulfill({ status: 204 });
} else {
await route.fallback();
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await expect(panel).toBeVisible();
await expect(panel.getByText("get_issues").first()).toBeVisible();
await showDefinitionTab(panel);
await panel.getByRole("button", { name: "More options" }).first().click();
await page.getByRole("menuitem", { name: "Delete" }).click();
const dialog = page.getByRole("dialog", { name: "Delete tool" });
await expect(dialog).toBeVisible();
await expect(dialog.getByText(/Are you sure you want to delete "get_issues"/i)).toBeVisible();
await dialog.getByRole("button", { name: "Delete" }).click();
await expect.poll(() => deleteRequestCount).toBe(1);
await expect(
page.locator("[data-sonner-toast]").filter({ hasText: /Tool.*get_issues.*deleted/i }),
).toBeVisible();
});
test("rolls back optimistic delete and shows error toast when delete API fails", async ({
page,
}) => {
let deleteRequestCount = 0;
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1, TOOL_A2]),
});
});
await page.route(`**/tools/${TOOL_A1.id}`, async (route) => {
if (route.request().method() === "DELETE") {
deleteRequestCount += 1;
await route.fulfill({
status: 403,
contentType: "application/json",
body: JSON.stringify({ detail: "Forbidden" }),
});
} else {
await route.fallback();
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await expect(panel).toBeVisible();
await showDefinitionTab(panel);
await panel.getByRole("button", { name: "More options" }).first().click();
await page.getByRole("menuitem", { name: "Delete" }).click();
const dialog = page.getByRole("dialog", { name: "Delete tool" });
await dialog.getByRole("button", { name: "Delete" }).click();
await expect.poll(() => deleteRequestCount).toBe(1);
await expect(
page.locator("[data-sonner-toast]").filter({ hasText: /Forbidden/i }),
).toBeVisible();
await expect(panel.getByText("get_issues").first()).toBeVisible();
});
test("cancels delete dialog and keeps tool in details panel", async ({ page }) => {
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_A1, TOOL_A2]),
});
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for github-server" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for github-server/i });
await showDefinitionTab(panel);
await panel.getByRole("button", { name: "More options" }).first().click();
await page.getByRole("menuitem", { name: "Delete" }).click();
const dialog = page.getByRole("dialog", { name: "Delete tool" });
await expect(dialog).toBeVisible();
await dialog.getByRole("button", { name: "Cancel" }).click();
await expect(dialog).not.toBeVisible();
await expect(panel.getByText("get_issues").first()).toBeVisible();
});
test("details panel closes immediately when the only tool in a group is deleted", async ({
page,
}) => {
const SOLO = makeTool("solo_tool", "solo-gateway");
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([SOLO]),
});
});
await page.route(`**/tools/${SOLO.id}`, async (route) => {
if (route.request().method() === "DELETE") {
await route.fulfill({ status: 204 });
} else {
await route.fallback();
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for solo-gateway" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for solo-gateway/i });
await expect(panel).toBeVisible();
await showDefinitionTab(panel);
await panel.getByRole("button", { name: "More options" }).first().click();
await page.getByRole("menuitem", { name: "Delete" }).click();
await page
.getByRole("dialog", { name: "Delete tool" })
.getByRole("button", { name: "Delete" })
.click();
await expect(panel).not.toBeVisible();
});
test("details panel stays open and deleted row is gone while remaining tool stays visible", async ({
page,
}) => {
const TOOL_1 = makeTool("alpha_tool", "multi-gw");
const TOOL_2 = makeTool("beta_tool", "multi-gw");
let resolveDelete!: () => void;
const deleteHeld = new Promise<void>((res) => {
resolveDelete = res;
});
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_1, TOOL_2]),
});
});
await page.route(`**/tools/${TOOL_1.id}`, async (route) => {
if (route.request().method() === "DELETE") {
await deleteHeld;
await route.fulfill({ status: 204 });
} else {
await route.fallback();
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for multi-gw" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for multi-gw/i });
await expect(panel).toBeVisible();
await showDefinitionTab(panel);
await expect(panel.getByText("alpha_tool").first()).toBeVisible();
await expect(panel.getByText("beta_tool").first()).toBeVisible();
await panel.getByRole("button", { name: "More options" }).first().click();
await page.getByRole("menuitem", { name: "Delete" }).click();
await page
.getByRole("dialog", { name: "Delete tool" })
.getByRole("button", { name: "Delete" })
.click();
await expect(panel.getByText("alpha_tool")).not.toBeVisible();
await expect(panel.getByText("beta_tool").first()).toBeVisible();
resolveDelete();
await expect(
page.locator("[data-sonner-toast]").filter({ hasText: /alpha_tool/i }),
).toBeVisible();
});
test("details panel re-opens with all tools restored after rollback", async ({ page }) => {
const TOOL_1 = makeTool("rollback_tool_1", "rb-gateway");
const TOOL_2 = makeTool("rollback_tool_2", "rb-gateway");
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([TOOL_1, TOOL_2]),
});
});
await page.route(`**/tools/${TOOL_1.id}`, async (route) => {
if (route.request().method() === "DELETE") {
await route.fulfill({
status: 403,
contentType: "application/json",
body: JSON.stringify({ detail: "Forbidden" }),
});
} else {
await route.fallback();
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "More options for rb-gateway" }).click();
await page.getByRole("menuitem", { name: "View details" }).click();
const panel = page.getByRole("region", { name: /Tools for rb-gateway/i });
await expect(panel).toBeVisible();
await showDefinitionTab(panel);
await panel.getByRole("button", { name: "More options" }).first().click();
await page.getByRole("menuitem", { name: "Delete" }).click();
await page
.getByRole("dialog", { name: "Delete tool" })
.getByRole("button", { name: "Delete" })
.click();
await expect(
page.locator("[data-sonner-toast]").filter({ hasText: /Forbidden/i }),
).toBeVisible();
await expect(panel).toBeVisible();
await expect(panel.getByText("rollback_tool_1").first()).toBeVisible();
await expect(panel.getByText("rollback_tool_2").first()).toBeVisible();
});
test("card group disappears from grid when its only tool is deleted", async ({ page }) => {
const SOLO = makeTool("lone_tool", "lone-gateway");
let toolDeleted = false;
await page.route("**/tools?*", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(toolDeleted ? [TOOL_A1] : [SOLO, TOOL_A1]),
});
});
await page.route(`**/tools/${SOLO.id}`, async (route) => {
if (route.request().method() === "DELETE") {
toolDeleted = true;
await route.fulfill({ status: 204 });
} else {
await route.fallback();
}
});
await page.goto(APP.TOOLS);
await page.waitForLoadState("networkidle");