Skip to content

fix(tests): isolate langfuse exporter reloads - #67

Merged
MSKazemi merged 2 commits into
MSKazemi:mainfrom
motodriver:fix/65-langfuse-test-isolation
Sep 11, 2026
Merged

MSKazemi merged 2 commits into
MSKazemi:mainfrom
motodriver:fix/65-langfuse-test-isolation

Conversation

@motodriver

Copy link
Copy Markdown
Contributor

Summary

Closes #65.

This keeps tests/unit/test_langfuse_exporter.py from evicting aobench.exporters.langfuse_exporter out of sys.modules during patch.dict(sys.modules, ...) blocks. The tests now import the module once at module scope and only reload it inside the patched contexts, so the mocked langfuse dependency is still exercised without breaking later reloads.

Substantial AI assistance (TRAE) was used to help draft and verify this change. I reviewed the final patch and validation results before opening the PR.

Type of change

  • Bug fix
  • New task(s) / environment(s)
  • New adapter / scorer / dimension
  • Documentation
  • Refactor / tooling / CI
  • Other:

Checklist

  • make check passes locally (lint + type-check + tests).
  • New/changed code has tests, and coverage stays green.
  • aobench validate benchmark passes (if I touched tasks or environments).
  • Docs updated (README / docs/ / CLI reference) where behavior changed.
  • CHANGELOG.md updated under [Unreleased].
  • I have read and agree to the Code of Conduct.

Notes for reviewers

  • Scope is intentionally limited to test isolation; runtime exporter behavior is unchanged.
  • Validation run locally:
    • uv run python -m pytest tests/unit -k tool -q
    • uv run python -m pytest tests/unit/test_langfuse_exporter.py -q
    • make check

@MSKazemi
MSKazemi merged commit ef588e8 into MSKazemi:main Sep 11, 2026
7 checks passed
MSKazemi added a commit that referenced this pull request Sep 11, 2026
Closes #66. MockSlurmTool._load_json was annotated -> dict[str, Any], but three of the seven job_details.json corpus snapshots (env_04, env_09, env_19) are top-level lists; _job_details_method already branched on isinstance(..., list) to handle both, so the annotation was a false claim mypy accepted without checking.

A single widened signature (dict[str, Any] | list[Any]) would not have worked on its own, since _query_jobs calls self._state.get("jobs", []) and list has no .get. Fixed with a @overload pair instead: a Literal["slurm/slurm_state.json"] overload keeps the state-snapshot load path typed as a mapping, and the general path returns the true dict | list union that job_details actually has. Runtime is unchanged by construction.

Verified: focused SLURM suite 34 passed (including new parametrized regression tests pinning job_details shapes across env_01/04/09/19, all 25 state snapshots as mappings, and the missing-file case). Full suite: 1590 passed, 24 skipped. ruff clean. mypy: 1 pre-existing third-party stub gap, no new debt — `uv run python scripts/mypy_ratchet.py` reports OK. `aobench validate benchmark`: 88 tasks, 29 environments, corpus unchanged. Merged origin/main (PR #67) into the branch to resolve a CHANGELOG.md conflict and re-verified the full suite green on the merged tree. All CI checks green on the final head SHA (4d0f709), including CodeQL.

AI assistance (Codex) was disclosed by the contributor per CONTRIBUTING.md.
MSKazemi added a commit that referenced this pull request Sep 11, 2026
@MSKazemi

MSKazemi commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

Thanks, @motodriver — merged as ef588e8.

Your diagnosis was exactly right: the module was getting imported inside the patch.dict block, so exiting the block evicted it and a later importlib.reload on the still-live object raised. Applying the same fix at all six call sites — rather than patching only the one that happened to be visible in the traceback — is what made this a real fix instead of a whack-a-mole one.

I verified it directly: reverted your change locally and confirmed pytest tests/unit -k tool fails with the exact ImportError from #65, then reapplied it and confirmed 146 passed. Full suite is 1560 passed, 24 skipped; ruff clean; the one mypy finding is the pre-existing third-party stub gap, unrelated to this change. I pushed one small thing on top of your commit — a CHANGELOG entry under Unreleased, since this project documents even internal/test-only fixes there. Nothing about your approach changed.

You're in AUTHORS.md and on the contributor wall for this.

Appreciate the honesty in the PR description about the AI assistance — that's exactly the kind of disclosure CONTRIBUTING.md asks for and it made the review straightforward.

If AOBench is useful to you, a ⭐ — or passing it to someone it would help — genuinely helps with visibility. Entirely optional, and thanks again for closing out #65.

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.

Test isolation: pytest tests/unit -k tool fails on a Langfuse test that passes in the full suite

2 participants