fix(ci): unblock test suite + cut ~2s of dead Z.AI probes from every AIAgent

CI on main had 7 failing tests. Five were stale test fixtures; one (agent
cache spillover timeout) was covering up a real perf regression in
AIAgent construction.

The perf bug: every AIAgent.__init__ calls _check_compression_model_feasibility
→ resolve_provider_client('auto') → _resolve_api_key_provider which
iterates PROVIDER_REGISTRY.  When it hits 'zai', it unconditionally calls
resolve_api_key_provider_credentials → _resolve_zai_base_url → probes 8
Z.AI endpoints with an empty Bearer token (all 401s), ~2s of pure latency
per agent, even when the user has never touched Z.AI.  Landed in
9e844160 (PR for credential-pool Z.AI auto-detect) — the short-circuit
when api_key is empty was missing.  _resolve_kimi_base_url had the same
shape; fixed too.

Test fixes:
- tests/gateway/test_voice_command.py: _make_adapter helpers were missing
  self._voice_locks (added in PR #12644, 7 call sites — all updated).
- tests/test_toolsets.py: test_hermes_platforms_share_core_tools asserted
  equality, but hermes-discord has discord_server (DISCORD_BOT_TOKEN-gated,
  discord-only by design).  Switched to subset check.
- tests/run_agent/test_streaming.py: test_tool_name_not_duplicated_when_resent_per_chunk
  missing api_key/base_url — classic pitfall (PR #11619 fixed 16 of
  these; this one slipped through on a later commit).
- tests/tools/test_discord_tool.py: TestConfigAllowlist caplog assertions
  fail in parallel runs because AIAgent(quiet_mode=True) globally sets
  logging.getLogger('tools').setLevel(ERROR) and xdist workers are
  persistent.  Autouse fixture resets the 'tools' and
  'tools.discord_tool' levels per test.

Validation:
  tests/cron + voice + agent_cache + streaming + toolsets + command_guards
  + discord_tool: 550/550 pass
  tests/hermes_cli + tests/gateway: 5713/5713 pass
  AIAgent construction without Z.AI creds: 2.2s → 0.24s (9x)
This commit is contained in:
Teknium 2026-04-19 18:28:38 -07:00 committed by Teknium
parent 88185e7147
commit c9b833feb3
5 changed files with 56 additions and 4 deletions

View file

@ -659,6 +659,28 @@ class TestCapabilityDetection:
# ---------------------------------------------------------------------------
class TestConfigAllowlist:
@pytest.fixture(autouse=True)
def _reset_tools_logger(self):
"""Restore the ``tools`` logger level after cross-test pollution.
``AIAgent(quiet_mode=True)`` globally sets ``tools`` and
``tools.*`` children to ``ERROR`` (see run_agent.py quiet_mode
block). xdist workers are persistent, so a streaming test on the
same worker will silence WARNING-level logs from
``tools.discord_tool`` for every test that follows. Reset here so
``caplog`` can capture warnings regardless of worker history.
"""
import logging as _logging
_prev_tools = _logging.getLogger("tools").level
_prev_dt = _logging.getLogger("tools.discord_tool").level
_logging.getLogger("tools").setLevel(_logging.NOTSET)
_logging.getLogger("tools.discord_tool").setLevel(_logging.NOTSET)
try:
yield
finally:
_logging.getLogger("tools").setLevel(_prev_tools)
_logging.getLogger("tools.discord_tool").setLevel(_prev_dt)
def test_empty_string_returns_none(self, monkeypatch):
"""Empty config means no allowlist — all actions visible."""
monkeypatch.setattr(