Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

2.0 KB
Raw Blame
<!DOCTYPE html>
<html>
<head>
<title>Tool title is exposed correctly</title>
<meta name="timeout" content="long">
<link rel="author" href="mailto:[email protected]">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/helpers.js"></script>
</head>
<body>
<script>
promise_test(async () => {
  await document.modelContext.registerTool({
    name: 'with-title',
    title: 'My Custom Title',
    description: 'tool with title',
    execute: async () => 'empty'
  });

  const tools = await document.modelContext.getTools();
  const tool = tools.find(t => t.name === 'with-title');

  assert_equals(tool.title, 'My Custom Title', 'Title is preserved');
}, 'Tool title is preserved when provided');

promise_test(async () => {
  await document.modelContext.registerTool({
    name: 'without-title',
    description: 'tool without title',
    execute: async () => 'empty'
  });

  const tools = await document.modelContext.getTools();
  const tool = tools.find(t => t.name === 'without-title');

  // If not provided upon registration, `title` should be empty string in the
  // dictionary.
  assert_equals(tool.title, '', 'Title is empty string when not provided');
}, 'Missing tool title in registration is exposed as empty string');

promise_test(async () => {
  // \uD800 is an unpaired high surrogate.
  await document.modelContext.registerTool({
    name: 'with-unpaired-surrogate',
    title: 'Title with \uD800 unpaired surrogate',
    description: 'tool with unpaired surrogate in title',
    execute: async () => 'empty'
  });

  const tools = await document.modelContext.getTools();
  const tool = tools.find(t => t.name === 'with-unpaired-surrogate');

  // USVString replaces unpaired surrogates with U+FFFD.
  assert_equals(tool.title, 'Title with \uFFFD unpaired surrogate');
}, 'Tool title with unpaired surrogate is fixed up by USVString');
</script>
</body>
</html>