mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-29 01:31:41 +00:00
feat(tests): add live integration tests for file operations and shell noise filtering
- Introduce a new test suite in `test_file_tools_live.py` to validate file operations and ensure accurate command execution in a real environment. - Implement assertions to check for shell noise contamination in outputs, enhancing the reliability of command results. - Create fixtures for setting up a local environment and populating directories with known file contents for comprehensive testing. - Refactor shell noise handling in `process_registry.py` and `local.py` to support multiple noise patterns, improving output cleanliness.
This commit is contained in:
parent
23d0b7af6a
commit
1db5598294
3 changed files with 507 additions and 18 deletions
|
|
@ -11,20 +11,26 @@ from tools.environments.base import BaseEnvironment
|
|||
|
||||
# Noise lines emitted by interactive shells when stdin is not a terminal.
|
||||
# Filtered from output to keep tool results clean.
|
||||
_SHELL_NOISE = frozenset({
|
||||
_SHELL_NOISE_SUBSTRINGS = (
|
||||
"bash: cannot set terminal process group",
|
||||
"bash: no job control in this shell",
|
||||
"bash: no job control in this shell\n",
|
||||
"no job control in this shell",
|
||||
"no job control in this shell\n",
|
||||
})
|
||||
"cannot set terminal process group",
|
||||
"tcsetattr: Inappropriate ioctl for device",
|
||||
)
|
||||
|
||||
|
||||
def _clean_shell_noise(output: str) -> str:
|
||||
"""Strip shell startup warnings that leak when using -i without a TTY."""
|
||||
lines = output.split("\n", 2) # only check first two lines
|
||||
if lines and lines[0].strip() in _SHELL_NOISE:
|
||||
return "\n".join(lines[1:])
|
||||
return output
|
||||
"""Strip shell startup warnings that leak when using -i without a TTY.
|
||||
|
||||
Removes all leading lines that match known noise patterns, not just the first.
|
||||
Some environments emit multiple noise lines (e.g. Docker, non-TTY sessions).
|
||||
"""
|
||||
lines = output.split("\n")
|
||||
# Strip all leading noise lines
|
||||
while lines and any(noise in lines[0] for noise in _SHELL_NOISE_SUBSTRINGS):
|
||||
lines.pop(0)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
class LocalEnvironment(BaseEnvironment):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue