Automatic update from web-platform-tests WebMCP: Expose document.modelContext Per https://github.com/webmachinelearning/webmcp/issues/173 and https://github.com/w3ctag/design-reviews/issues/1231#issuecomment-4502765330, we're moving `modelContext` to `document` from `navigator`. This CL does that, but keeps `navigator` exposure around for a bit and dispatches a console warning when it is used. This CL also updates all web platform tests to use `document.modelContext`. There might be other lingering tests elsewhere, but we can update those when we fully remove the API. R=mfoltz Bug: 489045948 Change-Id: I2005719574b78367199c0a87f94f3577b8039f15 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7867800 Reviewed-by: Mark Foltz <mfoltz@chromium.org> Commit-Queue: Dominic Farolino <dom@chromium.org> Cr-Commit-Position: refs/heads/main@{#1636216} -- wpt-commits: 8fe4fa01ce521ea03e09d978e905af1d25b8d410 wpt-pr: 60158
50 lines
2.6 KiB
HTML
50 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>WebMCP: getTools() retrieves declarative schema at registration time</title>
|
|
<link rel="author" href="mailto:dom@chromium.org">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<body>
|
|
|
|
<form toolname="search_tool" tooldescription="Search the web">
|
|
<input type="text" name="query" required toolparamdescription="The search query">
|
|
<input type="number" name="limit" toolparamdescription="Max results count">
|
|
<input type="checkbox" name="safe_search" toolparamdescription="Enable safe search filtering">
|
|
</form>
|
|
|
|
<script>
|
|
promise_test(async t => {
|
|
// Wait for the form to get registered.
|
|
await new Promise(resolve => document.modelContext.ontoolchange = resolve);
|
|
|
|
const tools = await document.modelContext.getTools();
|
|
assert_equals(tools.length, 1, "Exactly one tool should be registered");
|
|
|
|
const tool = tools[0];
|
|
assert_equals(tool.name, "search_tool", "Tool name matches form attribute");
|
|
assert_equals(tool.description, "Search the web", "Tool description matches form attribute");
|
|
|
|
assert_true(!!tool.inputSchema, "inputSchema should be non-empty");
|
|
const schema = JSON.parse(tool.inputSchema);
|
|
|
|
assert_equals(schema.type, "object", "Schema should be an object");
|
|
|
|
// 'query' property validation (required string)
|
|
assert_true("query" in schema.properties, "Schema should contain 'query' property");
|
|
assert_equals(schema.properties.query.type, "string", "Query property type should be string");
|
|
assert_equals(schema.properties.query.description, "The search query", "Query property description is correct");
|
|
assert_array_equals(schema.required, ["query"], "Query should be a required property");
|
|
|
|
// 'limit' property validation (optional number)
|
|
assert_true("limit" in schema.properties, "Schema should contain 'limit' property");
|
|
assert_equals(schema.properties.limit.type, "number", "Limit property type should be number");
|
|
assert_equals(schema.properties.limit.description, "Max results count", "Limit property description is correct");
|
|
|
|
// 'safe_search' property validation (optional boolean)
|
|
assert_true("safe_search" in schema.properties, "Schema should contain 'safe_search' property");
|
|
assert_equals(schema.properties.safe_search.type, "boolean", "safe_search property type should be boolean");
|
|
assert_equals(schema.properties.safe_search.description, "Enable safe search filtering", "safe_search property description is correct");
|
|
}, "Test that getTools() returns the correct inputSchema for a declarative tool");
|
|
</script>
|
|
</body>
|