Files
sousa-gecko/testing/web-platform/tests/webmcp/imperative/executeTool-invalid-dictionary.https.html
T
Dominic Farolino 11893e0338 Bug 2053430 [wpt PR 61137] - WebMCP: Remove the ModelContextTesting API, a=testonly
Automatic update from web-platform-tests
WebMCP: Remove the ModelContextTesting API

This CL removes the ModelContextTesting API. It's a reland of https://crrev.com/c/7895790, which was reverted in
https://crrev.com/c/7959699. The CL was reverted due to the
`virtual/webmcp/inspector-protocol/webmcp/log-tool-calls.js` timing out
on overloaded bots.

That test originally asserted that the modelContextTesting API could
abort a long-running (10 second!) tool. Since aborting a tool call for
the production modelContext API is still in progress (see
https://crbug.com/481899636), any CL replacing usages of
modelContextTesting with modelContext has to accept that the
long-running tool will run to completion, instead of being aborted
correctly. On particularly busy bots, the 10-second tool could exceed
the bot's timeout window, and fail with a timeout.

This CL adjusts the 10-second tool to a 50-ms tool, so that it runs
quickly. This is kind of fudging that particular inspector test, but the
timeout will be reverted back to its long 10-second timeout once
https://crrev.com/c/8025300 lands, implementing tool abort support for
the production modelContext API.

R=beaufort.francois@gmail.com, nasko

Bug: 515272366
Change-Id: I695ad7479d1b90de3d1edb705e71532e4b160957
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8062045
Reviewed-by: Fr <beaufort.francois@gmail.com>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1658818}

--

wpt-commits: ed76dd926b0ca18aafb188452f9ccf746be8bff4
wpt-pr: 61137
2026-07-12 11:57:32 +00:00

76 lines
2.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>WebMCP: executeTool dictionary member validation checks</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(async t => {
// Register a legitimate tool first to retrieve a valid template.
await document.modelContext.registerTool({
name: "legit_tool",
description: "Legitimate tool description",
execute: async (args) => "success"
});
const tools = await document.modelContext.getTools();
const legit = tools.find(t => t.name === "legit_tool");
assert_true(!!legit, "Legitimate tool must be successfully discovered");
// Construct a dictionary containing all required members except the required 'origin' member.
const invalidTool = {
name: legit.name,
description: legit.description,
window: legit.window
// 'origin' is intentionally omitted!
};
// Invoking executeTool() must return a Promise rejected with TypeError.
await promise_rejects_js(
t,
TypeError,
document.modelContext.executeTool(invalidTool, '{}'),
"executeTool() must reject with TypeError if 'origin' member is omitted"
);
}, "executeTool() rejects with TypeError when the required 'origin' dictionary member is omitted");
promise_test(async t => {
await document.modelContext.registerTool({
name: "json-test-tool",
description: "Tool for JSON tests",
execute: async (args) => "success"
});
const tools = await document.modelContext.getTools();
const tool = tools.find(t => t.name === "json-test-tool");
assert_true(!!tool, "Legitimate tool must be successfully discovered");
await promise_rejects_dom(
t,
"UnknownError",
document.modelContext.executeTool(tool, "invalid-json"),
"executeTool() must reject with UnknownError for invalid JSON input"
);
}, "executeTool() rejects with UnknownError for invalid JSON arguments");
promise_test(async t => {
const dummyTool = {
name: "non-existent-tool",
description: "dummy description",
window: window,
origin: self.origin
};
await promise_rejects_dom(
t,
"UnknownError",
document.modelContext.executeTool(dummyTool, "{}"),
"executeTool() must reject with UnknownError for non-existent tool object"
);
}, "executeTool() rejects with UnknownError when a non-existent tool object is supplied");
</script>
</body>
</html>