Skip to content

fix(tests): remove broken sys.path.insert shadowing project packages - #101

Merged
github-actions[bot] merged 1 commit into
mainfrom
claude/hermes-errors-xh2x9x
Jul 18, 2026
Merged

fix(tests): remove broken sys.path.insert shadowing project packages#101
github-actions[bot] merged 1 commit into
mainfrom
claude/hermes-errors-xh2x9x

Conversation

@dizhaky

@dizhaky dizhaky commented Jul 18, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Fixes a real, 100%-reproducible test collection bug and cleans up six more files carrying the same latent defect, found while triaging a full test-suite run on main after PR #93 merged (69 failing tests across 26 files, 4 files that failed to collect at all).

tests/agent/test_model_metadata_ssl.py and tests/hermes_cli/test_auth_ssl_macos.py each had:

sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

This only ascends one level — to tests/, not the project root. Since tests/agent/ and tests/hermes_cli/ are real Python packages (each has __init__.py), inserting tests/ at sys.path[0] makes from agent.model_metadata import ... / from hermes_cli.auth import ... resolve to the test subpackage itself instead of the real top-level package. Neither has a model_metadata.py/auth.py, so collection fails with ModuleNotFoundError.

Six more files had the identical bug but it stayed dormant (likely because the correctly-resolved module was already cached in sys.modules by the time these files were collected, depending on collection order) — fixed for consistency since they're the same landmine waiting to trigger under a different collection order: test_model_metadata_local_ctx.py, test_voice_wrapper.py, test_tool_progress_scrollback.py, test_resume_display.py, test_cli_user_message_preview.py, test_cli_init.py.

The line was always redundant — tests/conftest.py:32-34 already inserts the real PROJECT_ROOT into sys.path unconditionally before any test file loads.

The remaining ~65 of the 69 originally-failing tests turned out to be a container-provisioning gap in this specific session's environment, not a code issue: psutil, fire, ruamel.yaml, and croniter are all declared as unconditional core dependencies in pyproject.toml (plus ptyprocess behind the pty extra) but were missing from this session's Python env. Installed locally to confirm — no repo change needed for those. One test remains failing in this sandbox only (test_auth_nous_provider.py::test_no_ca_bundle_returns_true) because this environment's outbound-proxy config sets REQUESTS_CA_BUNDLE system-wide, which _resolve_verify() correctly honors per its documented CA-bundle priority order — not reproducible in a normal CI/dev environment, left as-is.

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • tests/agent/test_model_metadata_ssl.py: removed the broken sys.path.insert line and the now-unused os/sys imports — fixes a 100%-reproducible collection failure.
  • tests/hermes_cli/test_auth_ssl_macos.py: same fix — fixes a 100%-reproducible collection failure. (sys import kept; still used elsewhere in the file for monkeypatch.setattr(sys, "platform", ...).)
  • tests/agent/test_model_metadata_local_ctx.py, tests/hermes_cli/test_voice_wrapper.py, tests/cli/test_resume_display.py: same fix, dormant bug (both os/sys imports removed — unused elsewhere).
  • tests/cli/test_tool_progress_scrollback.py, tests/cli/test_cli_user_message_preview.py: same fix, dormant bug (os import removed, sys kept — still used for sys.modules).
  • tests/cli/test_cli_init.py: same fix, dormant bug (both os/sys imports kept — both still used elsewhere in the file).

How to Test

  1. TZ=UTC LANG=C.UTF-8 PYTHONHASHSEED=0 python3 -m pytest tests/agent/test_model_metadata_ssl.py tests/hermes_cli/test_auth_ssl_macos.py tests/agent/test_model_metadata_local_ctx.py tests/hermes_cli/test_voice_wrapper.py tests/cli/test_tool_progress_scrollback.py tests/cli/test_resume_display.py tests/cli/test_cli_user_message_preview.py tests/cli/test_cli_init.py -q — 176 passed
  2. Full suite via scripts/run_tests_parallel.py (with psutil/fire/ruamel.yaml/croniter/ptyprocess installed to match this session's environment to pyproject.toml's declared dependencies): 25370/25371 passed — the 1 remaining failure is the sandbox-only REQUESTS_CA_BUNDLE artifact described above.
  3. ruff check on all 8 changed files — clean.

Checklist

Code

  • My commit messages follow Conventional Commits (fix(scope):)
  • My PR contains only changes related to this fix (no unrelated commits)
  • I've run the relevant test suites and all tests pass
  • I've added tests for my changes — N/A, this PR repairs test-collection correctness rather than adding new behavior

Documentation & Housekeeping

  • N/A — no user-facing behavior or config changed; test-only fix.

Generated by Claude Code

Eight test files under tests/<subdir>/ had:

    sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

which only ascends one level (to tests/), not to the project root. Since
tests/agent/, tests/hermes_cli/, and tests/cli/ are all real Python
packages (each has __init__.py), inserting tests/ at sys.path[0] causes
absolute imports like `from agent.model_metadata import ...` or `from
hermes_cli.auth import ...` to resolve to the test subpackage itself
instead of the real top-level package -- there's no such module in the
test subpackage, so it raises ModuleNotFoundError.

tests/agent/test_model_metadata_ssl.py and tests/hermes_cli/test_auth_ssl_macos.py
hit this every run (100% reproducible collection failure, not
environment-specific). The other six files (test_model_metadata_local_ctx.py,
test_voice_wrapper.py, test_tool_progress_scrollback.py, test_resume_display.py,
test_cli_user_message_preview.py, test_cli_init.py) have the identical bug but
it stayed dormant -- likely because the correctly-shadowed module was already
cached in sys.modules by the time these files were collected, depending on
collection order.

The line was always redundant: tests/conftest.py:32-34 already inserts the
real PROJECT_ROOT into sys.path unconditionally before any test file loads.
Deleted the line (and the now-unused os/sys imports where nothing else in
the file needed them) rather than fixing the ascent count, since conftest.py
already owns this responsibility.

Also installed psutil, ptyprocess, ruamel.yaml, croniter, and fire in this
environment -- all five are declared dependencies in pyproject.toml
(psutil/fire in the unconditional `dependencies` list, ruamel.yaml/croniter
also core, ptyprocess behind the `pty` extra) but were missing from this
session's Python environment, which was the root cause of ~65 of the 69
test failures seen in a fresh full-suite run on this branch. That's a
container-provisioning gap, not a code issue -- nothing to fix in the repo
for those. Full suite now passes 25370/25371; the one remaining failure
(test_auth_nous_provider.py::test_no_ca_bundle_returns_true) fails only
because this sandbox's outbound-proxy sets REQUESTS_CA_BUNDLE system-wide,
which _resolve_verify() correctly honors per its documented CA-bundle
priority order -- not reproducible in a normal CI/dev environment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PTSqxb1h9MRkvGvVJqSuQh
@github-actions

Copy link
Copy Markdown

🔎 Lint report: claude/hermes-errors-xh2x9x vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8636 on HEAD, 8636 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4604 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@dizhaky
dizhaky marked this pull request as ready for review July 18, 2026 01:45
@github-actions
github-actions Bot merged commit 8bb3cab into main Jul 18, 2026
31 checks passed
@github-actions
github-actions Bot deleted the claude/hermes-errors-xh2x9x branch July 18, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants