fix(herdr): ensure unique agent name via sha1 truncation and align mock errors
- Replace legacy s[:16]-s[-15:] truncation with 8-char SHA-1 hash suffix in sanitize.py and lib.sh to prevent workspace name collisions - Align mock Herdr error messages in tests/conftest.py to real Herdr 0.8.0 output format - Add missing required/invalid_agent_name to early abort regex in lib.sh - Remove legacy heuristics in lib.sh has-session and unify mock agent lookups - Add unit tests in tests/test_sanitize_and_mock_errors.py (256/256 passed)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
# sanitize.py — Unified agent name sanitization contract for herdr 0.8.0 (E3 & E4)
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
def sanitize_herdr_agent_name(name: str) -> str:
|
||||
@@ -8,7 +7,7 @@ def sanitize_herdr_agent_name(name: str) -> str:
|
||||
1. Convert to lowercase.
|
||||
2. Replace invalid characters ([^a-z0-9_-]) with '-'.
|
||||
3. Ensure starts with a lowercase letter [a-z], prefixing with 'x-' if needed.
|
||||
4. Truncate to maximum 32 characters (16 + '-' + 15).
|
||||
4. Truncate to maximum 32 characters using 8-char SHA-1 hash suffix (s[:23] + '-' + sha1[:8]).
|
||||
"""
|
||||
if not name:
|
||||
return "agent"
|
||||
@@ -23,8 +22,10 @@ def sanitize_herdr_agent_name(name: str) -> str:
|
||||
if not s or not s[0].isalpha():
|
||||
s = "x-" + s
|
||||
|
||||
# 4. Truncate to 32 chars if needed
|
||||
# 4. Truncate to 32 chars if needed using collision-free SHA-1 hash suffix
|
||||
if len(s) > 32:
|
||||
s = s[:16] + '-' + s[-15:]
|
||||
h = hashlib.sha1(s.encode('utf-8')).hexdigest()[:8]
|
||||
s = f"{s[:23]}-{h}"
|
||||
|
||||
return s
|
||||
|
||||
|
||||
Reference in New Issue
Block a user