mirror of
https://github.com/samerfarida/mcp-ssh-orchestrator.git
synced 2026-11-20 20:33:16 +00:00
- Fix SSH client exception handling to catch only KeyError/AttributeError (Issue #1) - Fix DNS cache race condition with 1-second grace period (Issue #2) - Fix cleanup thread to support graceful shutdown and log exceptions (Issue #3) - Improve type hints for _ctx_log payload parameter (Issue #7) - Increase command hash length from 12 to 16 characters for better collision resistance (Issue #11) BREAKING CHANGE: Command hash length increased from 12 to 16 characters. External tools parsing command hashes may need updates. Added comprehensive unit tests for all fixes (11 new tests). All 280 tests pass.
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""Tests for utility functions."""
|
|
|
|
from mcp_ssh.tools.utilities import hash_command
|
|
|
|
|
|
def test_hash_command_length():
|
|
"""Test that hash_command returns 16-character hash."""
|
|
command = "test command"
|
|
hash_value = hash_command(command)
|
|
|
|
assert len(hash_value) == 16
|
|
assert isinstance(hash_value, str)
|
|
# Should be hexadecimal
|
|
assert all(c in "0123456789abcdef" for c in hash_value)
|
|
|
|
|
|
def test_hash_command_consistency():
|
|
"""Test that same command produces same hash."""
|
|
command = "uptime"
|
|
hash1 = hash_command(command)
|
|
hash2 = hash_command(command)
|
|
|
|
assert hash1 == hash2
|
|
assert len(hash1) == 16
|
|
|
|
|
|
def test_hash_command_uniqueness():
|
|
"""Test that different commands produce different hashes."""
|
|
command1 = "uptime"
|
|
command2 = "whoami"
|
|
hash1 = hash_command(command1)
|
|
hash2 = hash_command(command2)
|
|
|
|
assert hash1 != hash2
|
|
assert len(hash1) == 16
|
|
assert len(hash2) == 16
|
|
|
|
|
|
def test_hash_command_empty():
|
|
"""Test that empty command produces valid hash."""
|
|
hash_value = hash_command("")
|
|
assert len(hash_value) == 16
|
|
assert isinstance(hash_value, str)
|
|
|
|
|
|
def test_hash_command_none():
|
|
"""Test that None command produces valid hash."""
|
|
hash_value = hash_command(None) # type: ignore
|
|
assert len(hash_value) == 16
|
|
assert isinstance(hash_value, str)
|