Files
hermes-agent/tests/tools/test_approval_launchctl_performance.py
kshitijk4poor 61e730cc0b test(approval): pin the launchctl perf subprocess to the checkout under test
A bare `python -c` resolves `tools` through the venv's editable install (the
primary clone), not the worktree pytest runs in, so the regression guard could
silently test a different tree. Pass cwd + PYTHONPATH like
tests/tools/test_async_delegation.py does.
2026-09-17 20:38:43 +05:30

25 lines
973 B
Python

"""Long non-launchctl inputs must not starve other Gateway threads.
Subprocess timeout bounds regressions without hanging pytest on the GIL.
"""
import os
import subprocess
import sys
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_launchctl_guard_long_negative_input_is_bounded():
code = '''
from tools.approval_detection import DANGEROUS_PATTERNS_COMPILED
rules = [(rx, desc) for rx, desc in DANGEROUS_PATTERNS_COMPILED
if desc == "stop/restart hermes launchd service (kills running agents)"]
assert len(rules) == 1
rx = rules[0][0]
assert rx.search("x" * 100_000) is None
'''
# Pin the checkout under test: a bare `python -c` resolves `tools` through the venv's editable
# install (the primary clone), not through the worktree pytest is running in.
env = {**os.environ, "PYTHONPATH": REPO_ROOT}
subprocess.run([sys.executable, '-c', code], check=True, timeout=5, cwd=REPO_ROOT, env=env)