P-043 Phase 1: background_term-Hook fix

- on_post_tool_call dekrementiert NICHT mehr background_term (war im selben Turn)
- Neuer Hook on_background_process_stop dekrementiert bei echtem Prozess-Ende
- background_term bleibt > 0 solange Hintergrundprozess laeuft
- Hook-Registrierung in __init__.py: 10 -> 11 Hooks (background_process_stop)
- Alten Test auf P-043-Verhalten aktualisiert (test_post_tool_call_terminal_bg_noop)
- Neuer Test test_background_process_stop_decrements
This commit is contained in:
Bernd (Hermes)
2026-08-09 19:49:26 +02:00
parent aefe61fd61
commit 61f8d69423
3 changed files with 180 additions and 15 deletions
+20 -1
View File
@@ -558,7 +558,8 @@ class TestHookBackgroundTerminal:
counters = engine.get_counters()
assert counters["background_term"] == 0
def test_post_tool_call_terminal_bg_decrements(self):
def test_post_tool_call_terminal_bg_noop(self):
"""P-043: post_tool_call dekrementiert NICHT mehr background_term."""
engine = _make_engine()
engine.on_pre_tool_call(
tool_name="terminal",
@@ -570,6 +571,24 @@ class TestHookBackgroundTerminal:
)
time.sleep(engine._away_grace_s + 0.05)
counters = engine.get_counters()
# P-043: background_term bleibt > 0 — Dekrement erfolgt via
# on_background_process_stop (echtes Prozess-Ende)
assert counters["background_term"] == 1
# Phase ist GREEN_PULSE (Subagent aktiv)
assert engine.get_status() == "ONLINE" # P3 → ONLINE (visible toggled)
def test_background_process_stop_decrements(self):
"""P-043: on_background_process_stop dekrementiert background_term."""
engine = _make_engine()
engine.on_pre_tool_call(
tool_name="terminal",
args={"background": True, "command": "sleep 10"},
)
assert engine.get_counters()["background_term"] == 1
engine.on_background_process_stop()
time.sleep(engine._away_grace_s + 0.05)
counters = engine.get_counters()
assert counters["background_term"] == 0
assert engine.get_status() == "ONLINE"