Skip to content

test(discover): isolate fallback tests from RENDERDOC_PYTHON_PATH env leak#243

Merged
BANANASJIM merged 3 commits into
masterfrom
fix/discover-test-isolation
Jun 10, 2026
Merged

test(discover): isolate fallback tests from RENDERDOC_PYTHON_PATH env leak#243
BANANASJIM merged 3 commits into
masterfrom
fix/discover-test-isolation

Conversation

@BANANASJIM

@BANANASJIM BANANASJIM commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

TestFindRenderdocFallback::test_import_failed_without_module_leaves_no_diagnostic failed whenever the test environment had a real renderdoc module reachable through RENDERDOC_PYTHON_PATH (which pixi.toml injects as .local/renderdoc). After pixi run sync populates that directory, find_renderdoc() legitimately picks it up as a candidate, _has_renderdoc_module() returns true for it, and a diagnostic is set — breaking the test's "no diagnostic" assertion. The product code is correct; the test lacked environment isolation.

This explains the intermittent failures observed across CI-adjacent and dev environments: the test passed in checkouts that had never run pixi run sync and failed in ones that had.

Fix (test-side only, discover.py untouched)

  • All four TestFindRenderdocFallback tests now clear RENDERDOC_PYTHON_PATH via monkeypatch.delenv, pinning their candidate lists to exactly what they mock.
  • New regression-guard test test_import_failed_with_env_module_sets_diagnostic covers the inverse: with RENDERDOC_PYTHON_PATH pointing at a directory that does contain a renderdoc.so whose import fails, the diagnostic must be populated with that path. Deterministic in both environment states.

Verification

  • Poisoned state (real renderdoc.so under .local/renderdoc): base test file reproduces the failure; with this change, all 18 tests pass.
  • Clean env (RENDERDOC_PYTHON_PATH unset): 18 passed.
  • Full suite: 2971 passed, coverage 92.89%.

Summary by CodeRabbit

Release Notes

  • Documentation

    • Added comprehensive proposal and plan documentation for test isolation improvements
  • Tests

    • Enhanced test isolation by clearing environment variables between test cases to prevent cross-test contamination
    • Added regression test case to verify correct behavior when environment variables are configured

… leak

The four TestFindRenderdocFallback tests did not neutralise the ambient
RENDERDOC_PYTHON_PATH variable, which pixi activation sets to a real
renderdoc module directory after sync. The env-path candidate was probed
with the mocked outcome but _has_renderdoc_module evaluated the real path,
populating the diagnostic and failing
test_import_failed_without_module_leaves_no_diagnostic.

Add monkeypatch.delenv to all four tests and a regression guard
(test_import_failed_with_env_module_sets_diagnostic) that pins the
product behaviour: an env-path candidate holding a module artifact that
fails to import records a diagnostic. No production code changes.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR fixes environment-dependent test failures by documenting and implementing test isolation for RENDERDOC_PYTHON_PATH contamination. Four existing TestFindRenderdocFallback tests now clear the environment variable, and a new regression test verifies correct diagnostic behavior when an env-path candidate contains a stub module artifact.

Changes

Discover test isolation

Layer / File(s) Summary
Problem definition and isolation strategy
openspec/changes/2026-06-09-discover-test-isolation/proposal.md
Root-cause analysis explaining how RENDERDOC_PYTHON_PATH set by pixi run leaks into find_renderdoc() candidate probing, causing false-positive diagnostics. Proposes minimal monkeypatch.delenv() fix.
Test plan and verification approach
openspec/changes/2026-06-09-discover-test-isolation/test-plan.md, tasks.md
Specifies three groups of unit test cases (TC-1 through TC-5) covering "no module" and "env-path with import-failed" scenarios, with explicit monkeypatch.delenv() requirements. Includes tasks checklist and verification commands for pixi-harness and clean environments.
Test isolation and regression test implementation
tests/unit/test_discover.py
Four TestFindRenderdocFallback tests now call monkeypatch.delenv("RENDERDOC_PYTHON_PATH", raising=False) to prevent cross-test contamination. New test test_import_failed_with_env_module_sets_diagnostic sets up a temp dir with a fake renderdoc.so, stubs probing to return IMPORT_FAILED, and verifies correct diagnostic recording with candidate path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • BANANASJIM/rdc-cli#234: Adds underlying diagnostic handling and ProbeResult.IMPORT_FAILED tests that this PR's env-path regression test depends on.
  • BANANASJIM/rdc-cli#140: Introduces the diagnostic probe machinery and fallback test infrastructure that this PR extends with environment isolation.

Poem

🐰 A rabbit hops through tests so clear,
Scrubbing paths that shouldn't be here—
RENDERDOC_PYTHON_PATH, be gone!*
Isolation keeps the tests marching on! 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: isolating fallback tests from environment variable contamination.
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/discover-test-isolation

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.

@BANANASJIM

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
openspec/changes/2026-06-09-discover-test-isolation/test-plan.md (1)

15-17: ⚡ Quick win

Add language identifier to fenced code block.

The shell command block should specify shell or bash as the language identifier for proper syntax highlighting and tooling support.

📝 Proposed fix
-```
+```shell
 pixi run uv run pytest tests/unit/test_discover.py::TestFindRenderdocFallback::test_import_failed_without_module_leaves_no_diagnostic -v
</details>

As per coding guidelines, the markdown linter flags fenced code blocks without language specifications.

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @openspec/changes/2026-06-09-discover-test-isolation/test-plan.md around
lines 15 - 17, The fenced code block containing the shell command "pixi run uv
run pytest
tests/unit/test_discover.py::TestFindRenderdocFallback::test_import_failed_without_module_leaves_no_diagnostic
-v" needs a language identifier; update the opening fence to use "shell" (or "bash") so the block is marked as shell script for linting and syntax
highlighting, leaving the command text unchanged.


</details>

<!-- cr-comment:v1:101495a44d6611e18ac9d6f7 -->

_Source: Linters/SAST tools_

</blockquote></details>

</blockquote></details>

<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @openspec/changes/2026-06-09-discover-test-isolation/test-plan.md:

  • Around line 15-17: The fenced code block containing the shell command "pixi
    run uv run pytest
    tests/unit/test_discover.py::TestFindRenderdocFallback::test_import_failed_without_module_leaves_no_diagnostic
    -v" needs a language identifier; update the opening fence to use "shell" (or "bash") so the block is marked as shell script for linting and syntax
    highlighting, leaving the command text unchanged.

</details>

---

<details>
<summary>ℹ️ Review info</summary>

<details>
<summary>⚙️ Run configuration</summary>

**Configuration used**: defaults

**Review profile**: CHILL

**Plan**: Pro

**Run ID**: `c91fa532-6073-4949-9a07-43db00345ad9`

</details>

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 8923bc62381a5b7681919dbc7b33f08edfdad687 and cd9c9825b562848d2a79c097c39cb3c234f47668.

</details>

<details>
<summary>📒 Files selected for processing (4)</summary>

* `openspec/changes/2026-06-09-discover-test-isolation/proposal.md`
* `openspec/changes/2026-06-09-discover-test-isolation/tasks.md`
* `openspec/changes/2026-06-09-discover-test-isolation/test-plan.md`
* `tests/unit/test_discover.py`

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@BANANASJIM BANANASJIM merged commit 074951d into master Jun 10, 2026
17 checks passed
@BANANASJIM BANANASJIM deleted the fix/discover-test-isolation branch June 10, 2026 07:05
BANANASJIM added a commit that referenced this pull request Jun 10, 2026
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