Files
hermes-agent/tests/scripts/install/test_install_ps1_resolver_strictmode.py
T
teknium1 d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`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.
2026-09-13 09:18:02 -07:00

72 lines
3.2 KiB
Python

"""Regression: the ResolvedPathReport must not read an unset resolver.
Issue #93017: fresh Windows installs died at the ``$script:ResolvedPathReport``
block with ``The variable '$script:LastResolver' cannot be retrieved because
it has not been set`` — before any install stage ran. The mechanism:
``ConvertTo-LongPath`` short-circuits at the top for ordinary long paths
(``-notmatch '~\\d'`` returns early, per the comment "skip every resolver for
ordinary long paths, which is the overwhelmingly common case"), so
``$script:LastResolver`` is only ever assigned when a 8.3 short path actually
needs expansion. The report block read it unconditionally, which is fatal in
a ``Set-StrictMode`` session (the reporter hit it through three different
invocation styles, i.e. their host/session enables strict mode).
The fix initializes ``$script:LastResolver = 'none'`` at script scope before
``Set-LongProfileEnvVars`` can run any resolver — ``'none'`` being the
resolver's own value for "nothing ran".
install.ps1 only runs on Windows, so these tests lock the contract at the
source-text level (same style as test_install_ps1_uv_install_fallback.py).
"""
from __future__ import annotations
import re
from pathlib import Path
_INSTALL_PS1 = Path(__file__).resolve().parents[3] / "scripts" / "install.ps1"
def _ps1() -> str:
return _INSTALL_PS1.read_text(encoding="utf-8")
def test_last_resolver_initialized_at_script_scope():
source = _ps1()
match = re.search(r"^\$script:LastResolver = 'none'\s*$", source, re.MULTILINE)
assert match is not None, (
"$script:LastResolver must be initialized at script scope ('none') — "
"ConvertTo-LongPath only assigns it when a short path needs expanding, "
"so an ordinary long profile leaves it unset (#93017)"
)
def test_initialization_precedes_resolver_run_and_report_read():
source = _ps1()
init = re.search(r"^\$script:LastResolver = 'none'\s*$", source, re.MULTILINE)
run = re.search(r"^\$script:NormalizedProfilePaths = Set-LongProfileEnvVars", source, re.MULTILINE)
read = re.search(r"^\s+resolver\s+= \$script:LastResolver\s*$", source, re.MULTILINE)
assert init and run and read, "init / Set-LongProfileEnvVars / report read must all exist"
assert init.start() < run.start() < read.start(), (
"initialization must come before Set-LongProfileEnvVars can invoke a "
"resolver, and before the ResolvedPathReport reads the variable"
)
def test_convert_to_long_path_still_short_circuits_before_assigning():
"""Pin the mechanism that leaves the variable unset on normal paths.
The early return for paths without an 8.3 alias is what makes the
initialization load-bearing: if someone removes the short-circuit the
resolver always assigns, but the guard is a deliberate performance
choice (skip Add-Type for the overwhelmingly common case) and must
stay — so the init must stay too.
"""
source = _ps1()
start = source.index("function ConvertTo-LongPath")
body = source[start : start + 2000]
assert re.search(r"-notmatch '~\\d'", body), (
"ConvertTo-LongPath must keep its ordinary-long-path short-circuit "
"(the reason $script:LastResolver can be unset without an init)"
)