d10bb2ab6f
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.
Parallel directories for one source package, folded into the mirror:
tests/acp -> tests/acp_adapter (its __init__/conftest move with it)
tests/cli -> tests/hermes_cli (prompt_toolkit fixture merged into
hermes_cli/conftest.py)
tests/run_agent -> tests/agent (backoff fixture becomes
agent/conftest.py)
tests/relay -> tests/gateway/relay
tests/state -> tests/hermes_state
246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.
Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.
Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).
Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
"""Preflight lock-defer must not arm the insufficient-progress blocker.
|
|
|
|
Companion to ``tests/agent/test_compression_lock_defer.py`` — pins the
|
|
``build_turn_context`` preflight loop's handling of a lock-contended
|
|
compression no-op (#69870 lock-skip signal, consumer salvaged from #49874):
|
|
|
|
* the pass stops the preflight loop (the lock winner is already shrinking
|
|
the session) WITHOUT setting ``preflight_compression_blocked``, so the
|
|
loop's provider-proven error handlers keep their full retry budget;
|
|
* a genuine no-progress no-op (flag unset) still arms the blocker exactly
|
|
as before;
|
|
* a MagicMock-style truthy junk flag value does NOT take the defer branch
|
|
(type-pin rule).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import types
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from tests.agent.test_turn_context import _FakeAgent, _build
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _stub_runtime_main():
|
|
with patch("agent.auxiliary_client.set_runtime_main", lambda *a, **k: None):
|
|
yield
|
|
|
|
|
|
def _pressured_compressor():
|
|
"""Over-threshold compressor stub that opens the preflight threshold path."""
|
|
return types.SimpleNamespace(
|
|
protect_first_n=0,
|
|
protect_last_n=0,
|
|
threshold_tokens=1,
|
|
context_length=100_000,
|
|
last_prompt_tokens=0,
|
|
should_compress=lambda _tokens=None: True,
|
|
should_compress_info=lambda _tokens=None: (True, None),
|
|
should_defer_preflight_to_real_usage=lambda _t: False,
|
|
get_active_compression_failure_cooldown=lambda: None,
|
|
)
|
|
|
|
|
|
def _make_agent():
|
|
agent = _FakeAgent()
|
|
agent.compression_enabled = True
|
|
agent.context_compressor = _pressured_compressor()
|
|
agent._emit_status = MagicMock()
|
|
return agent
|
|
|
|
|
|
_HISTORY = [{"role": "user", "content": "old"}, {"role": "assistant", "content": "older"}]
|
|
|
|
|
|
def test_preflight_lock_skip_does_not_set_blocked_flag():
|
|
agent = _make_agent()
|
|
calls = []
|
|
|
|
def _lock_skip_compress(messages, _system_message, **_kwargs):
|
|
calls.append(1)
|
|
agent._compression_skipped_due_to_lock = "pid=1:tid=2:agent=aa:nonce=bb"
|
|
return messages, "SYSTEM"
|
|
|
|
agent._compress_context = _lock_skip_compress
|
|
|
|
ctx = _build(agent, conversation_history=list(_HISTORY))
|
|
|
|
# Exactly one pass: the defer stops the loop without arming the blocker.
|
|
assert calls == [1]
|
|
assert ctx.preflight_compression_blocked is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_preflight_magicmock_flag_value_is_not_a_defer():
|
|
"""Type-pin: truthy junk (MagicMock auto-attribute shape) must not be
|
|
treated as lock contention — the blocker arms as for a plain no-op."""
|
|
agent = _make_agent()
|
|
|
|
def _junk_flag_compress(messages, _system_message, **_kwargs):
|
|
agent._compression_skipped_due_to_lock = MagicMock()
|
|
return messages, "SYSTEM"
|
|
|
|
agent._compress_context = _junk_flag_compress
|
|
|
|
ctx = _build(agent, conversation_history=list(_HISTORY))
|
|
|
|
assert ctx.preflight_compression_blocked is True
|