Skip to content

fix(tests): resolve 20 remaining unit test failures post-#589 #660

Description

@vybe

Summary

After the #589 Redis auth migration, 20 unit test failures remain across 7 test files. These fall into two categories: (a) missing/renamed code in the main codebase that tests reference, and (b) unit tests that don't inherit the main conftest's REDIS_URL credential patch.

Context

Discovered during post-#589 test suite run on 2026-05-05. The 1,766 crash-loop errors from #589 are cleared. These are pre-existing or recent regressions unrelated to the Redis migration itself.

Failures by Group

Group A — Missing/renamed code (9 failures, 5 errors)

test_agent_readiness_probe.py (5 errors — collection failure)

  • ImportError: cannot import name 'get_agent_default_resources' from 'services.settings_service'
  • services/agent_service/lifecycle.py:26 imports this function but it doesn't exist in settings_service.py

test_telegram_webhook_backfill.py (4 failures)

  • ImportError: cannot import name 'AgentDefaultResourcesUpdate' from 'models'
  • routers/settings.py:18 imports this model but it's been removed/renamed from models.py

test_fleet_sync_audit.py (2 failures)

  • sqlite3.IntegrityError: UNIQUE constraint failed: agent_git_config.github_repo, agent_git_config.working_branch
  • Test seeds duplicate (github_repo, working_branch) rows to test detection logic, but the schema UNIQUE constraint blocks this. Constraint likely needs to be partial (only for source_mode=0).

test_git_status_dual_ahead_behind.py (2 failures)

  • compute_ahead_behind() returns (0, 0) when (0, 1) / (1, 0) expected
  • Ahead/behind calculation for the working branch is broken

test_schedule_status_observability.py (1 failure)

  • Expected #378 residual-race log message not emitted — log statement missing or changed

Group B — REDIS_URL not patched in unit test isolation (10 failures)

test_file_upload.py (6), test_voice_auth.py (3), test_chat_sync_backlog.py (1) all fail with:

  • RuntimeError: REDIS_URL must include credentials
  • These tests import modules whose import chain reaches config.py before the main conftest's setdefault patch applies
  • Fix: Add tests/unit/conftest.py that sets os.environ.setdefault("REDIS_URL", "redis://test:test@redis:6379") before any imports

Group C — Collection errors (2 files excluded entirely)

unit/test_skill_service_user_agent.py

  • ModuleNotFoundError: No module named 'utils.url_validation'
  • skill_service.py imports validate_skills_library_url from a module not yet created

unit/test_voice_tools.py

  • ImportError: cannot import name 'GeminiVoiceService' from 'services.gemini_voice'
  • Class renamed or not yet added

Group D — Contract mismatch (1 failure)

test_subscription_auto_switch.py::test_get_auto_switch_default_on

  • assert False is True — auto-switch setting defaults to False but test expects True

Acceptance Criteria

  • get_agent_default_resources added to services/settings_service.py or import in lifecycle.py updated
  • AgentDefaultResourcesUpdate model restored in models.py or routers/settings.py import updated
  • test_fleet_sync_audit.py fixtures updated to work with UNIQUE constraint (or constraint made partial)
  • compute_ahead_behind() correctly returns ahead/behind counts for working branch
  • tests/unit/conftest.py created with REDIS_URL credential patch (fixes 10 failures in one shot)
  • #378 residual-race log re-added to task_execution_service.py
  • utils/url_validation.py created with validate_skills_library_url
  • GeminiVoiceService added/corrected in services/gemini_voice.py
  • Auto-switch default aligned between backend and test expectation
  • All 25 failures resolved, test suite passes cleanly

Technical Notes

Quickest wins in order:

  1. tests/unit/conftest.py with REDIS_URL patch → fixes 10 failures instantly
  2. AgentDefaultResourcesUpdate restore → fixes 4 failures + unblocks settings.py
  3. get_agent_default_resources in settings_service.py → fixes 5 collection errors

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions