Skip to content

fix(smoke): force-override OMNIVOICE_DATA_DIR + purge cached backend modules - #95

Merged
debpalash merged 1 commit into
mainfrom
fix/smoke-test-pollution
May 20, 2026
Merged

fix(smoke): force-override OMNIVOICE_DATA_DIR + purge cached backend modules#95
debpalash merged 1 commit into
mainfrom
fix/smoke-test-pollution

Conversation

@debpalash

@debpalash debpalash commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

The smoke test used os.environ.setdefault() to point at the frozen fixture, which silently skipped when a prior test in the suite had already set the env var. Combined with core.config caching DB_PATH at module import time, this left smoke tests pointed at the wrong DB once Wave 1's services tests pre-imported main with their own temp state.

Test plan

  • pytest tests/smoke/ → 4 passed (no regression vs Phase 0 smoke matrix)
  • pytest tests/backend/services tests/smoke/ → 31 passed (used to fail at the smoke step)
  • pytest tests/ -q --ignore=tests/manual → 292 passed, 6 skipped, 12 xfailed, 1 xpassed, 0 failures
  • Cross-platform: change is OS-agnostic (no path / env-var conventions changed)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved smoke test reliability to ensure proper test isolation and prevent data contamination between test runs.

Review Change Stack

…modules

The smoke test used `os.environ.setdefault()` to point at the frozen
fixture, which silently skipped when a prior test in the suite had
already set the env var. Combined with `core.config` caching `DB_PATH`
at module import time, this left smoke tests pointed at the wrong DB
once Wave 1's services tests pre-imported `main` with their own temp
state.

Exposed by Wave 2's additional tests (PR #94) pushing collection order
past the tipping point, but the underlying pollution existed since Wave
1 merged — Wave 3 CI passed only by collection-order luck.

Fix mirrors the `sys.modules` purge pattern that
`tests/backend/services/conftest.py` already uses.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The smoke test fixture is hardened for isolation: OMNIVOICE_DATA_DIR is now force-set (not defaulted) to a per-session fixture copy, and previously imported backend modules are purged from sys.modules before app import, ensuring core.config re-reads the environment without cached state leakage.

Changes

Test Isolation Fixture

Layer / File(s) Summary
Test isolation fixture wiring
tests/smoke/test_boot_smoke.py
Smoke fixture force-sets OMNIVOICE_DATA_DIR to per-session copy and purges cached backend modules from sys.modules before importing FastAPI app, ensuring fresh config reads and preventing cross-test state leakage. Import of sys module added to support module-cache purge.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A fixture grows wise, clearing old dust,
Each test starts fresh—we trust, we trust!
Modules wiped clean, env vars speak true,
No state bleeds through from yesterday's brew.
Hippity-hop! The tests run anew. 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: forcing OMNIVOICE_DATA_DIR override and purging cached backend modules in smoke tests.
Description check ✅ Passed The description follows the template structure with all major sections (Summary, Changes, Testing via test plan, and Checklist items) substantially addressed, though the Type checkbox and formal Changes list could be slightly more explicit.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/smoke-test-pollution

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/smoke/test_boot_smoke.py`:
- Around line 47-50: The test currently sets os.environ["OMNIVOICE_DATA_DIR"] =
str(_FIXTURE_COPY) at import time and never restores it; change this to scope
the override to the fixture lifetime by moving the environment assignment into
the test fixture (or using pytest's monkeypatch.setenv) and restore the original
value on teardown; reference the same symbols OMNIVOICE_DATA_DIR, _FIXTURE_COPY
and os.environ when implementing the fix and, if the code under test reads
core.config at import time, ensure the env is set before importing (or reload
core.config after setting) so the temporary value is used only for that fixture
and not left as a process-global.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8584789f-d3cb-4aea-a2e5-51e557f10cfc

📥 Commits

Reviewing files that changed from the base of the PR and between c320412 and 50a6aea.

📒 Files selected for processing (1)
  • tests/smoke/test_boot_smoke.py

Comment on lines +47 to +50
# Point backend.core.config.get_app_data_dir() at the COPY. Force-override
# (not setdefault) — earlier tests in a full-suite run may have set it to
# their own temp dir, and core.config caches DB_PATH at first import.
os.environ["OMNIVOICE_DATA_DIR"] = str(_FIXTURE_COPY)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Scope OMNIVOICE_DATA_DIR override to fixture lifetime to avoid cross-test leakage.

Line 50 mutates process-global env at import time and never restores it. That can pollute later tests if collection/order changes, recreating the same class of flake in reverse.

Proposed fix
-# Point backend.core.config.get_app_data_dir() at the COPY. Force-override
-# (not setdefault) — earlier tests in a full-suite run may have set it to
-# their own temp dir, and core.config caches DB_PATH at first import.
-os.environ["OMNIVOICE_DATA_DIR"] = str(_FIXTURE_COPY)
-
-
 `@pytest.fixture`(scope="module")
 def client():
+    prev_data_dir = os.environ.get("OMNIVOICE_DATA_DIR")
+    os.environ["OMNIVOICE_DATA_DIR"] = str(_FIXTURE_COPY)
     # Purge any cached backend modules from earlier tests in the suite —
     # `core.config` reads OMNIVOICE_DATA_DIR at import time and caches DB_PATH,
     # so a prior import with a different value would survive the env-var
     # override above. Same pattern as tests/backend/services/conftest.py.
     for mod in list(sys.modules):
         if mod == "main" or mod == "core" or mod.startswith("core.") or mod.startswith("api.") or mod.startswith("services."):
             sys.modules.pop(mod, None)
     from fastapi.testclient import TestClient
     from main import app
-    return TestClient(app, client=("127.0.0.1", 50000))
+    try:
+        yield TestClient(app, client=("127.0.0.1", 50000))
+    finally:
+        if prev_data_dir is None:
+            os.environ.pop("OMNIVOICE_DATA_DIR", None)
+        else:
+            os.environ["OMNIVOICE_DATA_DIR"] = prev_data_dir
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/smoke/test_boot_smoke.py` around lines 47 - 50, The test currently sets
os.environ["OMNIVOICE_DATA_DIR"] = str(_FIXTURE_COPY) at import time and never
restores it; change this to scope the override to the fixture lifetime by moving
the environment assignment into the test fixture (or using pytest's
monkeypatch.setenv) and restore the original value on teardown; reference the
same symbols OMNIVOICE_DATA_DIR, _FIXTURE_COPY and os.environ when implementing
the fix and, if the code under test reads core.config at import time, ensure the
env is set before importing (or reload core.config after setting) so the
temporary value is used only for that fixture and not left as a process-global.

@debpalash
debpalash merged commit 7f49295 into main May 20, 2026
8 checks passed
@debpalash
debpalash deleted the fix/smoke-test-pollution branch May 20, 2026 00:44
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.

1 participant