[PR #536] removed serial testing library. #547

Closed
opened 2026-03-02 04:13:56 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/git-ai-project/git-ai/pull/536

State: closed
Merged: No


PR: Make tests parallel-safe and remove serial_test

Fixes #264

Summary

  • Add thread-local test environment overrides and HOME override to src/mdm/utils.rs.
  • Add per-TestRepo environment injection (env_vars, add_env, set_envs, clear_envs) to tests/repos/test_repo.rs so spawned child processes receive test-specific envs.
  • Update runtime code to consult test-aware helper (env_test_proxy) where tests previously mutated std::env (notably opencode + checkpoint presets and prompt utilities).
  • Replace in-test std::env::set_var usages in several tests with thread-local overrides (set_test_env_override) or per-repo env injection.
  • Remove the serial_test dev-dependency and #[serial] usage from tests.
  • Normalize blame output for --contents mode: map Not Committed YetExternal file (--contents) to stabilize tests.

Why

  • Many integration tests mutated the process-global environment which caused races and flakiness when tests ran in parallel. Thread-local overrides plus per-repo env injection let tests simulate environment variables without changing global std::env.

Files changed (high level)

  • src/mdm/utils.rs — added TEST_HOME_OVERRIDE, TEST_ENV_OVERRIDES, set_test_home_override, set_test_env_override, get_test_env_override, env_test_proxy.
  • src/git/test_utils/tmp_repo.rs — new file extracting TmpRepo and TmpFile structs from mod.rs with integrated unit tests for environment variable isolation.
  • src/git/test_utils/mod.rs — cleaned up to re-export TmpRepo and TmpFile from tmp_repo module; removed ~1300 lines of duplicated struct and method definitions.
  • Cargo.toml — removed serial_test dev-dependency.
  • src/commands/checkpoint_agent/opencode_preset.rs, src/commands/checkpoint_agent/agent_presets.rs, src/authorship/prompt_utils.rs — switched env reads to use env_test_proxy.
  • Tests updated: tests/github_copilot.rs, tests/opencode.rs, src/mdm/agents/codex.rs, and others to use test overrides instead of std::env::set_var.

Workflow Changes

  • .github/workflows/tests.yml - changed the testing tool to use 'cargo-nextest' for improved performance on integration tests. changed test workflow to perform unit and integration tests concurrently.

Notes & follow-ups

  • TmpRepo refactor: Extracted TmpRepo and TmpFile structs into their own file (src/git/test_utils/tmp_repo.rs) to improve code organization and added integrated unit tests (test_repo_specific_env_vars, test_env_vars_isolated_per_repo) that validate per-repo environment variable isolation. This matches the pattern of per-repo env injection used in TestRepo and supports parallel test execution.
  • These helpers are test-only; production behavior falls back to the real process environment when no override is set.

Open with Devin
**Original Pull Request:** https://github.com/git-ai-project/git-ai/pull/536 **State:** closed **Merged:** No --- # PR: Make tests parallel-safe and remove `serial_test` Fixes #264 Summary - Add thread-local test environment overrides and HOME override to `src/mdm/utils.rs`. - Add per-`TestRepo` environment injection (`env_vars`, `add_env`, `set_envs`, `clear_envs`) to `tests/repos/test_repo.rs` so spawned child processes receive test-specific envs. - Update runtime code to consult test-aware helper (`env_test_proxy`) where tests previously mutated `std::env` (notably opencode + checkpoint presets and prompt utilities). - Replace in-test `std::env::set_var` usages in several tests with thread-local overrides (`set_test_env_override`) or per-repo env injection. - Remove the `serial_test` dev-dependency and `#[serial]` usage from tests. - Normalize blame output for `--contents` mode: map `Not Committed Yet` → `External file (--contents)` to stabilize tests. Why - Many integration tests mutated the process-global environment which caused races and flakiness when tests ran in parallel. Thread-local overrides plus per-repo env injection let tests simulate environment variables without changing global `std::env`. Files changed (high level) - `src/mdm/utils.rs` — added `TEST_HOME_OVERRIDE`, `TEST_ENV_OVERRIDES`, `set_test_home_override`, `set_test_env_override`, `get_test_env_override`, `env_test_proxy`. - `src/git/test_utils/tmp_repo.rs` — new file extracting `TmpRepo` and `TmpFile` structs from mod.rs with integrated unit tests for environment variable isolation. - `src/git/test_utils/mod.rs` — cleaned up to re-export `TmpRepo` and `TmpFile` from tmp_repo module; removed ~1300 lines of duplicated struct and method definitions. - `Cargo.toml` — removed `serial_test` dev-dependency. - `src/commands/checkpoint_agent/opencode_preset.rs`, `src/commands/checkpoint_agent/agent_presets.rs`, `src/authorship/prompt_utils.rs` — switched env reads to use `env_test_proxy`. - Tests updated: `tests/github_copilot.rs`, `tests/opencode.rs`, `src/mdm/agents/codex.rs`, and others to use test overrides instead of `std::env::set_var`. Workflow Changes - `.github/workflows/tests.yml` - changed the testing tool to use 'cargo-nextest' for improved performance on integration tests. changed test workflow to perform unit and integration tests concurrently. Notes & follow-ups - **TmpRepo refactor**: Extracted `TmpRepo` and `TmpFile` structs into their own file (`src/git/test_utils/tmp_repo.rs`) to improve code organization and added integrated unit tests (`test_repo_specific_env_vars`, `test_env_vars_isolated_per_repo`) that validate per-repo environment variable isolation. This matches the pattern of per-repo env injection used in `TestRepo` and supports parallel test execution. - These helpers are test-only; production behavior falls back to the real process environment when no override is set. <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/git-ai-project/git-ai/pull/536" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
kerem 2026-03-02 04:13:56 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#547
No description provided.