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.
88 lines
3.8 KiB
Python
88 lines
3.8 KiB
Python
"""Regression test for #48031 — /model switch lost after session auto-reset.
|
|
|
|
When `/model X` is the FIRST message after an idle/daily/suspended auto-reset,
|
|
it stores a session model override but the `was_auto_reset` flag is left True
|
|
(the slash-command path doesn't pass through the message handler that consumes
|
|
it). On the NEXT regular message, the auto-reset cleanup block in
|
|
`_handle_message_with_agent` pops the freshly-stored override BEFORE the flag
|
|
is consumed, so the switch is silently lost and resolution falls back to the
|
|
config default — while the session DB still shows the switched model (a
|
|
two-sources-of-truth divergence).
|
|
|
|
The fix consumes `was_auto_reset` at two sites:
|
|
1. the cleanup block in gateway/run.py captures it into a local and sets the
|
|
attribute False immediately (so it can't re-fire next message);
|
|
2. the slash-command model path in gateway/slash_commands.py consumes it
|
|
before storing the override (so a /model-first-after-reset isn't wiped).
|
|
|
|
These are AST invariants — load-bearing pins that fail if either consume is
|
|
removed (mirrors test_35809_auto_reset_clean_context.py's approach).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import ast
|
|
import inspect
|
|
|
|
from gateway import run_turn as gateway_run_turn
|
|
from gateway import slash_commands_model as gateway_slash
|
|
|
|
|
|
def _assigns_false(node: ast.AST, attr: str) -> bool:
|
|
"""True if `node` contains an assignment `<something>.<attr> = False`."""
|
|
for sub in ast.walk(node):
|
|
if isinstance(sub, ast.Assign):
|
|
for tgt in sub.targets:
|
|
if (
|
|
isinstance(tgt, ast.Attribute)
|
|
and tgt.attr == attr
|
|
and isinstance(sub.value, ast.Constant)
|
|
and sub.value.value is False
|
|
):
|
|
return True
|
|
return False
|
|
|
|
|
|
def test_run_consumes_was_auto_reset_in_cleanup_block():
|
|
"""The auto-reset cleanup block in gateway/run.py must set
|
|
`session_entry.was_auto_reset = False` so the cleanup (which pops the
|
|
session model/reasoning overrides) cannot re-fire on the next message and
|
|
wipe an override stored between turns (#48031)."""
|
|
tree = ast.parse(inspect.getsource(gateway_run_turn))
|
|
|
|
# Find the cleanup branch: an `if <flag>:` block that clears the
|
|
# conversation scope (post-funnel: one _clear_conversation_scope call
|
|
# replaced the inline override pops) AND clears the flag. We assert at
|
|
# least one such block sets was_auto_reset False.
|
|
found = False
|
|
for node in ast.walk(tree):
|
|
if not isinstance(node, ast.If):
|
|
continue
|
|
calls = {
|
|
n.func.attr
|
|
for n in ast.walk(node)
|
|
if isinstance(n, ast.Call) and isinstance(n.func, ast.Attribute)
|
|
}
|
|
# The cleanup block routes through the conversation-scope funnel —
|
|
# fingerprint of the transient-state cleanup.
|
|
if "_clear_conversation_scope" in calls and _assigns_false(node, "was_auto_reset"):
|
|
found = True
|
|
break
|
|
assert found, (
|
|
"gateway/run.py auto-reset cleanup block must consume "
|
|
"`was_auto_reset` (set it False) so it can't re-fire and wipe a "
|
|
"model override stored between turns (#48031)."
|
|
)
|
|
|
|
|
|
def test_slash_command_model_path_consumes_was_auto_reset():
|
|
"""The slash-command model path in gateway/slash_commands_model.py must consume
|
|
`was_auto_reset` before storing the new model override, so a
|
|
/model-first-after-auto-reset isn't wiped by the next message's cleanup
|
|
(#48031)."""
|
|
src = inspect.getsource(gateway_slash)
|
|
tree = ast.parse(src)
|
|
assert _assigns_false(tree, "was_auto_reset"), (
|
|
"gateway/slash_commands_model.py model path must set "
|
|
"`was_auto_reset = False` before storing the model override (#48031)."
|
|
)
|