fix: eliminate shell noise from terminal output with fence markers

- Wrap commands with unique fence markers (printf FENCE; cmd; printf FENCE)
  to isolate real output from shell init/exit noise (oh-my-zsh, macOS
  session restore/save, docker plugin errors, etc.)
- Expand _clean_shell_noise to cover zsh/macOS patterns and strip from
  both beginning and end (fallback when fences are missing)
- Fix BSD find compatibility: fallback to simple find when -printf
  produces empty output (macOS)
- Fix test_terminal_disk_usage: use sys.modules to get the real module
  instead of the shadowed function from tools/__init__.py
- Add 13 new unit tests for fence extraction and zsh noise patterns
This commit is contained in:
0xbyt4 2026-03-02 22:53:21 +03:00
parent 3c13feed4c
commit 11615014a4
4 changed files with 168 additions and 21 deletions

View file

@ -5,6 +5,12 @@ from unittest.mock import patch, MagicMock
import pytest
# tools/__init__.py re-exports a *function* called ``terminal_tool`` which
# shadows the module of the same name. Use sys.modules to get the real module
# so patch.object works correctly.
import sys
import tools.terminal_tool # noqa: F401 -- ensure module is loaded
_tt_mod = sys.modules["tools.terminal_tool"]
from tools.terminal_tool import get_active_environments_info
# 1 MiB of data so the rounded MB value is clearly distinguishable
@ -34,10 +40,8 @@ class TestDiskUsageGlob:
"aaaaaaaa-1111-2222-3333-444444444444": MagicMock(),
}
with (
patch("tools.terminal_tool._active_environments", fake_envs),
patch("tools.terminal_tool._get_scratch_dir", return_value=fake_scratch),
):
with patch.object(_tt_mod, "_active_environments", fake_envs), \
patch.object(_tt_mod, "_get_scratch_dir", return_value=fake_scratch):
info = get_active_environments_info()
# Task A only: ~1.0 MB. With the bug (hardcoded hermes-*),
@ -51,10 +55,8 @@ class TestDiskUsageGlob:
"bbbbbbbb-5555-6666-7777-888888888888": MagicMock(),
}
with (
patch("tools.terminal_tool._active_environments", fake_envs),
patch("tools.terminal_tool._get_scratch_dir", return_value=fake_scratch),
):
with patch.object(_tt_mod, "_active_environments", fake_envs), \
patch.object(_tt_mod, "_get_scratch_dir", return_value=fake_scratch):
info = get_active_environments_info()
# Should be ~2.0 MB total (1 MB per task).