Skip to content

Stabilize more backend unit tests in lightweight Windows env#7791

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/windows-backend-unit-next
Jun 11, 2026
Merged

Stabilize more backend unit tests in lightweight Windows env#7791
kodjima33 merged 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/windows-backend-unit-next

Conversation

@tianmind-studio

Copy link
Copy Markdown
Contributor

Summary

  • Make test_action_item_reminder_cancel_on_complete.py install explicit firebase_admin.messaging/auth stubs before importing the real utils.notifications helper.
  • Stub storage-test-only heavy imports (opuslib, DB modules, pinecone/database.vector_db) so test_batch_upload_storage.py can run without native Opus or Pinecone SDK setup.

Why

In a minimal Windows backend venv, these tests failed during collection/import before reaching their own assertions:

  • utils.notifications import failed because from firebase_admin import messaging, auth could not resolve submodules from the test meta-path stub.
  • utils.other.storage import failed when opuslib could not find the native Opus library, even though the batch upload tests do not exercise Opus encode/decode paths.
  • The merge-copy tests in the same storage file imported database.vector_db, which required pinecone although those tests only patch and exercise copy path naming.

Testing

  • python -m pytest tests\unit\test_action_item_reminder_cancel_on_complete.py -q -> 7 passed
  • python -m pytest tests\unit\test_batch_upload_storage.py -q -> 27 passed, 1 warning
  • python -m pytest tests\unit\test_action_item_reminder_cancel_on_complete.py tests\unit\test_batch_upload_storage.py -q -> 34 passed, 1 warning
  • python -m black --line-length 120 --skip-string-normalization tests\unit\test_action_item_reminder_cancel_on_complete.py tests\unit\test_batch_upload_storage.py --check
  • python -m py_compile tests\unit\test_action_item_reminder_cancel_on_complete.py tests\unit\test_batch_upload_storage.py
  • git diff --check -- backend/tests/unit/test_action_item_reminder_cancel_on_complete.py backend/tests/unit/test_batch_upload_storage.py

Note: after excluding files already covered by open Windows test-stability PRs, collection now progresses through these files and reaches a later independent test_daily_summary_race_condition.py sys.modules issue; this PR intentionally stays scoped to the two fixed files.

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two test files that failed during pytest collection on a minimal Windows backend environment due to unresolvable native/cloud imports (opuslib, firebase_admin submodules, pinecone). Both fixes are surgical: stubs are injected into sys.modules at the earliest safe point before the module under test is imported.

  • test_action_item_reminder_cancel_on_complete.py: Introduces _install_stub_module to pre-populate firebase_admin, firebase_admin.messaging, and firebase_admin.auth in sys.modules before utils.notifications is loaded. The new stubs are wired as parent attributes so from firebase_admin import messaging, auth resolves correctly, and the existing finally cleanup already removes them.
  • test_batch_upload_storage.py: Adds opuslib, database.redis_db, and database.users to the module-level sys.modules.setdefault block, and extends TestCopyAudioChunksForMergeBatchAware.setup_class to also stub database.vector_db and pinecone.

Confidence Score: 5/5

Safe to merge — the changes are confined to test infrastructure and do not touch any production code path.

Both changes are minimal, targeted stub injections that have no effect on production logic. The new firebase_admin stubs are correctly ordered and cleaned up by the existing finally block. The opuslib/database/pinecone stubs use setdefault so they cannot overwrite a previously-installed real module.

No files require special attention.

Important Files Changed

Filename Overview
backend/tests/unit/test_action_item_reminder_cancel_on_complete.py Adds _install_stub_module helper to pre-populate firebase_admin submodules in sys.modules before importing utils.notifications, fixing submodule resolution on Windows
backend/tests/unit/test_batch_upload_storage.py Adds module-level sys.modules stubs for opuslib, database.redis_db, database.users, and extends setup_class to stub database.vector_db and pinecone

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph test_action_item[test_action_item_reminder_cancel_on_complete.py]
        A[_load_real_notifications] --> B[sys.meta_path.insert finder]
        B --> C[_install_stub_module firebase_admin]
        C --> D[_install_stub_module firebase_admin.messaging]
        D --> E[_install_stub_module firebase_admin.auth]
        E --> F[import utils.notifications]
        F --> G[return notif]
        G --> H[finally: remove finder and clean sys.modules]
    end
    subgraph test_batch_upload[test_batch_upload_storage.py]
        I[module level] --> J[sys.modules.setdefault stubs including opuslib NEW]
        J --> K[import utils.other.storage]
        K --> L[TestCopyAudioChunksForMergeBatchAware.setup_class]
        L --> M[stubs including database.vector_db NEW and pinecone NEW]
        M --> N[import merge_conversations per test]
    end
Loading

Reviews (1): Last reviewed commit: "test(backend): stub heavy imports for Wi..." | Re-trigger Greptile

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only stabilization (backend/tests/unit), CI green

@kodjima33 kodjima33 merged commit 82ed9cc into BasedHardware:main Jun 11, 2026
2 checks passed
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