Skip to content

Restore EnvLock synchronisation unit tests (#321)#363

Draft
leynos wants to merge 1 commit into
mainfrom
issue-321-restore-envlock-tests
Draft

Restore EnvLock synchronisation unit tests (#321)#363
leynos wants to merge 1 commit into
mainfrom
issue-321-restore-envlock-tests

Conversation

@leynos

@leynos leynos commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #321

Restores the #[cfg(test)] mod tests block removed from tests/bdd/fixtures/mod.rs by PR #273, adapted to the current ensure_env_lock / restore_environment_locked semantics:

  • ensure_env_lock_acquires_lock_on_first_call
  • ensure_env_lock_is_idempotent
  • ensure_env_lock_captures_cwd
  • drop_restores_cwd_after_ensure_env_lock

The two CWD-asserting tests are hardened relative to the pre-#273 originals: they hold an outer EnvLock (re-entrant per thread) across the world's lifetime so a parallel test cannot move the process CWD between the world's drop and the assertion.

Validation

  • cargo test --test bdd_tests fixtures::tests — 4 passed
  • make check-fmt / make lint / make test — pass (37 suites)

🤖 Generated with Claude Code

Summary by Sourcery

Restore unit tests validating EnvLock environment synchronisation behavior in the BDD fixtures module.

Tests:

  • Reintroduce tests ensuring EnvLock is acquired on first use and remains held across repeated ensure_env_lock calls.
  • Add tests verifying ensure_env_lock captures the current working directory and that dropping the world restores the original CWD while guarding against parallel test interference.

PR #273 removed the `#[cfg(test)]` block in `tests/bdd/fixtures/mod.rs`
that validated `ensure_env_lock()` and the `Drop`-based working
directory restoration, leaving these synchronisation properties
untested at the unit level.

Restore the four tests (first-call acquisition, idempotency, CWD
capture, and Drop restoration), adapted to the current semantics. The
two CWD-asserting tests now hold an outer re-entrant `EnvLock` for
their full duration so parallel test threads cannot move the process
CWD between the world's drop and the assertion.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dcc0afee-f46c-4168-80d4-d3c02e97f8d6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-321-restore-envlock-tests

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

@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Restores and strengthens unit tests around EnvLock behavior in the BDD fixtures module, covering lock acquisition, idempotency, and CWD capture/restore semantics while making them robust against interference from parallel tests.

File-Level Changes

Change Details Files
Restore and harden EnvLock synchronization unit tests for TestWorld.
  • Reintroduce a #[cfg(test)] tests module in the fixtures file using current EnvLock/TestWorld semantics.
  • Add test to assert env_lock is initially None and becomes Some after ensure_env_lock is called.
  • Add idempotency test verifying repeated ensure_env_lock calls keep the lock held without reinitializing state.
  • Add test ensuring ensure_env_lock captures the current working directory when the lock is first acquired, using an outer EnvLock to prevent concurrent CWD changes.
  • Add test ensuring that dropping TestWorld restores the original working directory after a temporary CWD change, again guarded by an outer EnvLock to avoid interference from parallel tests.
tests/bdd/fixtures/mod.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#321 Restore a unit test that verifies ensure_env_lock() is idempotent when the lock is already held.
#321 Restore a unit test that verifies the EnvLock Drop implementation restores the original working directory after ensure_env_lock() is used.
#321 Adjust the restored EnvLock synchronisation tests to match the updated ensure_env_lock / restore_environment_locked semantics introduced in PR #273.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Restore EnvLock synchronisation unit tests removed in #273

1 participant