Skip to content

armgit / moli

Public Imported from GitHub
0

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

1.6 KB
Raw Blame
<!DOCTYPE html>
<html>
<head>
<title>WebMCP registerTool rejects on invalid name</title>
<link rel="author" href="mailto:[email protected]">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(async () => {
  // Valid names
  const validNames = [
    'a',
    'A',
    '0',
    'valid-name',
    'valid_name',
    'valid.name',
    'valid-name.with_extras-123',
    'a'.repeat(128)
  ];

  for (const name of validNames) {
    await document.modelContext.registerTool({
      name: name,
      description: 'valid name test',
      execute: async () => 'empty'
    });
  }
}, 'Valid tool names are accepted.');

promise_test(async t => {
  // Invalid names
  const invalidNames = [
    '', // Empty
    'a'.repeat(129), // Too long
    'name with space',
    'name@special',
    'name#special',
    'name$special',
    'name%',
    'name^',
    'name&',
    'name*',
    'name(',
    'name)',
    'name+',
    'name=',
    'name[',
    'name]',
    'name{',
    'name}',
    'name|',
    'name\\',
    'name:',
    'name;',
    'name"',
    'name\'',
    'name<',
    'name>',
    'name?',
    'name/',
    'name`',
    'name~',
  ];

  for (const name of invalidNames) {
    await promise_rejects_dom(t,
      'InvalidStateError',
      document.modelContext.registerTool({
        name: name,
        description: 'invalid name test',
        execute: async () => 'empty'
      }),
      `Tool name '${name}' is invalid.`
    );
  }
}, 'Invalid tool names throw InvalidStateError.');
</script>
</body>
</html>