Skip to content

test: prune low-value tests suite-wide — 58% fewer tests, half the wall time, zero flakes - #74383

Merged
teknium1 merged 7 commits into
mainfrom
tests/prune-low-value
Jul 29, 2026
Merged

test: prune low-value tests suite-wide — 58% fewer tests, half the wall time, zero flakes#74383
teknium1 merged 7 commits into
mainfrom
tests/prune-low-value

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Cuts the test suite from 46,820 to 19,757 test functions (−58%) while keeping every distinct behavioral contract, and halves full-suite wall time (583s → 294s). Stacked on #74330 (flake fixes) — merge that first.

Two systematic passes over every major test tree, applying the AGENTS.md test policy:

Deleted: near-duplicate parametrizations (boundaries + one representative kept), mock-echo tests (assert a mock returns what it was told), source-reading tests (banned outright), change-detector tests (exact catalog counts / name snapshots / version literals), async/sync twin duplicates, assertion-free trivials, per-platform copy-paste tests of shared base-adapter logic (one representative kept where the code under test is shared; per-platform kept where the adapter genuinely overrides).

Kept unconditionally: security/redaction/approval/command-guard behaviors, message-role alternation invariants, prompt-caching/deterministic-call-id invariants, issue-number regression tests (deduped), E2E tests, config-migration contracts.

Real test-quality bugs found by the sweep and fixed at the root:

  • ACP server tests fetched live models.dev/GitHub/Copilot/Anthropic catalogs on every session create — new autouse conftest stub: test_server.py 147s → 3.4s, now hermetic
  • Command-guard tests made real auxiliary-LLM HTTPS calls (smart-approval default leaked in) — 17.4s → 0.4s
  • Two model-switch files probed live provider catalogs (~2s/test) — stubbed
  • test_gateway_shutdown.py spun stop()'s 5s interrupt-deadline on MagicMock agents — 22s → 1.0s
  • test_telegram_noise_filter.py ran a 15-platform matrix over shared gateway logic — 3 representatives, 55s → 3.9s

Changes

  • 8 fan-out passes + 4 deeper passes across tests/gateway, hermes_cli, tools, agent, run_agent, plugins, cli, cron, tui_gateway, acp*, skills, docker, dashboard, and misc trees
  • 7 test files deleted outright; ~1,500 files trimmed; conftest.py/fakes/fixtures untouched; no production code touched in this PR
  • tests/acp/conftest.py added (offline model-inventory stub)
  • Sleep-based slowness shrunk where safe; wall-clock margins widened where thin (telegram_init_deadline 0.2s → 1.0s block margin with rationale)

Validation

Baseline (main) After
Test functions 46,820 19,757 (−57.8%)
Full suite result 50,530 passed / 4 failed / 1 flaky 21,718 passed / 0 failed / 0 flaky
Wall time (40 workers) 583.5s 293.9s
Slowest file 572s 65s

Every touched file verified green individually under the hermetic per-file runner (CI-parity); two full-suite scripts/run_tests.sh runs green end-to-end.

Infographic

Prune infographic

teknium1 added 3 commits July 29, 2026 12:18
…nmocked network in compressor tests, stale-SDK feishu pin guard, quadratic redact regexes

- Remove tests/-shadowing sys.path.insert(dirname/'..') from 11 test files:
  it prepended the tests/ dir itself to sys.path, so 'import agent' /
  'import hermes_cli' resolved to the test packages and collection died
  with ModuleNotFoundError depending on import order (2 files failed in
  every full-suite run; 9 more were latent).
- Patch call_llm in 5 context-compressor tests that called compress()
  unmocked: each burned ~50s attempting live LLM traffic through the
  relay before falling back (572s file — the slowest in the suite, and
  flaky under the 300s per-file timeout). File now runs in ~5s.
- agent/redact.py: fix two catastrophically-backtracking regexes hit by
  the compressor's redaction pass on large payloads —
  _STRICT_URL_USERINFO_RE anchors on the mandatory '//' (optional-scheme
  prefix backtracked O(n^2): ~55s on a 320KB payload, now sub-ms;
  output-equivalence fuzz-verified on 20k random strings), and the
  _CFG_DOTTED_RE/_CFG_ANCHORED_RE subs gain an exact linear keyword
  pre-gate so secret-free text skips the quadratic pattern entirely.
- tests/gateway/test_feishu.py: version-guard the extra_ua_tags SDK
  signature check; the repo pins lark-oapi==1.6.8 but stale local
  installs (1.5.3) fail the assertion — skip below the pin.
- tests/tools/test_managed_browserbase_and_modal.py: stub
  agent.redact + agent.credential_persistence in the fake agent package
  (empty __path__ blocks all real agent.* imports added since the fake
  was written).
- tests/gateway/test_startup_restart_race.py: raise wait_for timeouts
  2s -> 30s; 2s wall-clock on a loaded 40-worker box flaked in the
  baseline run (passes instantly when the box is quiet).
…t functions

Systematic prune per AGENTS.md test policy, one pass over every major
test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli,
cron, tui_gateway, honcho/openviking, root-level):

- DELETE: source-reading tests (read_text/getsource on prod files),
  change-detector tests (exact catalog counts, model-name snapshots,
  config version literals), mock-echo tests (assert a mock returns what
  it was told), assertion-free/trivial tests, near-duplicate
  parametrizations (boundaries + one representative kept), async/sync
  twin duplicates, cosmetic within-file variations.
- KEEP (mandatory): security/redaction/approval guards, message-role
  alternation invariants, prompt-caching/deterministic-call-id
  invariants, issue-number regression tests (deduped), E2E tests.
- 6 test files deleted outright (script-style/no-assert or fully
  redundant); conftest.py, fakes/, fixtures/ untouched.
- tests/acp/conftest.py added: autouse fixture stubs the live
  models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server
  tests performed on every session create — test_server.py 147s → 3.4s,
  and the tests are now genuinely hermetic.
- Sleep-based slowness shrunk where safe (codex_ttfb_watchdog,
  compression_concurrent_fork, etc.); no wall-clock assertion tightened.

Verification: full hermetic suite via scripts/run_tests.sh —
2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall
(baseline: 583s wall, 13,564s subprocess CPU).
…ite wall 315s → 294s

Second, deeper pass over tools/gateway/hermes_cli plus first pass over
the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker,
dashboard, conformance, monitoring, secret_sources, hermes_state,
providers). Same rubric as wave 1 (AGENTS.md test policy); security,
alternation/caching invariants, issue-number regressions, and E2E kept.

Real test-quality fixes found and rooted out along the way:
- tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls
  (DEFAULT_CONFIG smart-approval leaked in) — pinned approval
  mode=manual via autouse fixture: 17.4s → 0.4s.
- test_model_switch_custom_providers.py / test_user_providers_model_switch.py
  silently probed live provider catalogs (~2s/test) — stubbed
  cached_provider_model_ids/provider_model_ids/fetch_api_models.
- test_telegram_noise_filter.py: 15-platform copy-paste matrix over
  shared gateway.run logic → 3 representative platforms (55s → 3.9s).
- test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on
  MagicMock agents — interrupt.side_effect now clears _running_agents
  (22s → 1.0s).
- test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x
  (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps
  patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait
  5s → 0.5s.
- test_telegram_init_deadline.py: loop-block margin restored to 1.0s
  with rationale comment — the watchdog-dump assertion needs the loop
  blocked well past deadline+grace under parallel load (flaked once in
  the 40-worker verification run at a 0.2s margin).

Verification: full hermetic suite via scripts/run_tests.sh —
2,438 files, 21,718 tests passed, 0 failed, 293.9s wall.
Suite totals vs original baseline: 46,820 → 19,757 test functions
(−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Jul 29, 2026
# Conflicts:
#	tests/hermes_cli/test_install_cua_driver.py
#	tests/run_agent/test_codex_app_server_integration.py
#	tests/test_tui_gateway_server.py
#	tests/tools/test_computer_use_delivery_ladder.py
#	tests/tools/test_zombie_process_cleanup.py
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 3913ac2

ℹ️ Info

Desktop E2E visual evidence · View test artifacts · View job

1 visual diff.

inline evidence upload failed.

Failed to upload diff-665a0833239e-onboarding-overlay-diff.png with gh image (exit code 1): Error uploading /home/runner/work/_temp/e2e-evidence/diff-665a0833239e-onboarding-overlay-diff.png: step 0 (get upload token): uploadToken not found on repo page — do you have write access to NousResearch/hermes-agent? (or, if NousResearch enforces SAML SSO, authorize at https://github.com/orgs/NousResearch/sso)

teknium1 added 3 commits July 29, 2026 15:13
# Conflicts:
#	tests/agent/test_context_compressor.py
#	tests/gateway/test_startup_restart_race.py
#	tests/hermes_cli/test_voice_wrapper.py
# Conflicts:
#	tests/run_agent/test_conversation_fallback_state.py
…e with main's readonly sweep)

Main's 243c918/a16fd675df/7142dc4580 added load_config_readonly
sibling stubs across 38 files; our pruned versions of 11 of those files
kept only the load_config stubs. Re-applied the pairing at every
surviving site (26 patch()/setattr sites) — same return_value/
side_effect as the adjacent load_config stub. 494 tests green across
the 11 files.
@teknium1
teknium1 merged commit 92856bc into main Jul 29, 2026
38 checks passed
@teknium1
teknium1 deleted the tests/prune-low-value branch July 29, 2026 22:46
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
…ow-value

test: prune low-value tests suite-wide — 58% fewer tests, half the wall time, zero flakes
33hodl pushed a commit to 33hodl/hermes-agent that referenced this pull request Aug 12, 2026
…ow-value

test: prune low-value tests suite-wide — 58% fewer tests, half the wall time, zero flakes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants