Files
sousa-gecko/testing/web-platform/tests/webmcp/imperative/getTools.https.html
T
François Beaufort 0ff2d99fbc Bug 2048468 [wpt PR 60693] - [WebMCP] Tool retrieval getTools() should be sorted alphabetically., a=testonly
Automatic update from web-platform-tests
[WebMCP] Tool retrieval getTools() should be sorted alphabetically.

Spec issue: https://github.com/webmachinelearning/webmcp/issues/206

Bug: 489045948
Change-Id: Iaab334c00480279abb518b4255c443432b16583e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7921035
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Reviewed-by: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1648385}

--

wpt-commits: 2379fdee0976c8359dfbb18f7b22c9946fa25024
wpt-pr: 60693
2026-06-19 20:55:15 +00:00

40 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>WebMCP getTools()</title>
<link rel="author" href="mailto:dom@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(async (t) => {
const tool_c = { name: 'c', description: 'tool registered first', execute: () => {} };
const tool_b = { name: 'b', description: 'tool registered second', execute: () => {} };
const tool_a = { name: 'a', description: 'tool registered last', execute: () => {} };
const controller_b = new AbortController();
// Register tool_c, tool_b, and tool_a tools in this specific order.
await document.modelContext.registerTool(tool_c);
await document.modelContext.registerTool(tool_b, { signal: controller_b.signal });
await document.modelContext.registerTool(tool_a);
let tools = await document.modelContext.getTools();
assert_equals(tools.length, 3, 'Should find exactly the 3 registered tools');
assert_equals(tools[0].name, 'a', 'First tool should be "a"');
assert_equals(tools[1].name, 'b', 'Second tool should be "b"');
assert_equals(tools[2].name, 'c', 'Third tool should be "c"');
// Unregistering tool_b should still preserve lexicographical order.
controller_b.abort();
tools = await document.modelContext.getTools();
assert_equals(tools.length, 2, 'Should find exactly the 3 registered tools');
assert_equals(tools[0].name, 'a', 'First tool should be "a"');
assert_equals(tools[1].name, 'c', 'Second tool should be "c"');
}, 'getTools should return all tools sorted in lexicographical order');
</script>
</body>
</html>