MCPcopy
hub / github.com/HKUDS/OpenHarness / test_commands_registry

Function test_commands_registry

tests/test_untested_features.py:495–537  ·  view source on GitHub ↗

Test slash command registration and lookup.

()

Source from the content-addressed store, hash-verified

493# 9. Commands: register and lookup slash commands
494# ====================================================================
495async def test_commands_registry():
496 """Test slash command registration and lookup."""
497 from openharness.commands.registry import (
498 CommandRegistry, SlashCommand, CommandResult, CommandContext,
499 )
500
501 registry = CommandRegistry()
502
503 async def handle_test(args: str, ctx: CommandContext) -> CommandResult:
504 return CommandResult(message=f"Test executed with: {args}")
505
506 async def handle_clear(args: str, ctx: CommandContext) -> CommandResult:
507 return CommandResult(clear_screen=True)
508
509 registry.register(SlashCommand(name="test", description="Run a test", handler=handle_test))
510 registry.register(SlashCommand(name="clear", description="Clear screen", handler=handle_clear))
511
512 # Lookup
513 found = registry.lookup("/test hello world")
514 print(f" Lookup '/test hello world': {found[0].name if found else 'NOT FOUND'}, args='{found[1] if found else ''}'")
515
516 found2 = registry.lookup("/clear")
517 print(f" Lookup '/clear': {found2[0].name if found2 else 'NOT FOUND'}")
518
519 notfound = registry.lookup("/nonexistent")
520 print(f" Lookup '/nonexistent': {'NOT FOUND' if notfound is None else 'FOUND?!'}")
521
522 # Help text
523 help_text = registry.help_text()
524 print(f" Help text: {len(help_text)} chars, contains 'test': {'test' in help_text}")
525
526 # Default registry
527 from openharness.commands.registry import create_default_command_registry
528 default_reg = create_default_command_registry()
529 cmds = default_reg.list_commands()
530 print(f" Default registry: {len(cmds)} commands")
531
532 return (
533 found is not None and found[0].name == "test" and found[1] == "hello world"
534 and found2 is not None
535 and notfound is None
536 and len(cmds) > 0
537 )
538
539
540# ====================================================================

Callers 1

mainFunction · 0.85

Calls 7

registerMethod · 0.95
lookupMethod · 0.95
help_textMethod · 0.95
CommandRegistryClass · 0.90
SlashCommandClass · 0.90
list_commandsMethod · 0.80

Tested by

no test coverage detected