Skip to content

Conversation

@JacksonFergusonDev
Copy link
Owner

@JacksonFergusonDev JacksonFergusonDev commented Jan 29, 2026

Description

This PR fixes a critical issue where the test suite was leaking the Current Working Directory (CWD) state between tests and inadvertently modifying the user's actual ~/.local/state/git-pulsar/registry.

The Problem

Several tests in tests/test_cli.py were using os.chdir(tmp_path) to switch to a temporary test directory but were not resetting it.

  1. CWD Leak: Pytest runs in a single process. When os.chdir is used without cleanup, the process remains in the temp folder for all subsequent tests.
  2. Side Effects:
    • test_main_triggers_bootstrap was falling through to setup_repo(), which (because it wasn't mocked) registered the leaked temp directory into the user's real registry file.
    • This caused "ghost entries" in the registry and triggered "Repo missing" notifications from the actual background daemon.

The Fix

  1. Use monkeypatch.chdir: Replaced all instances of os.chdir(tmp_path) with monkeypatch.chdir(tmp_path) in tests/test_cli.py. This ensures the CWD is automatically restored to its original state after each test.
  2. Mock setup_repo: Added a mock for git_pulsar.cli.setup_repo in test_main_triggers_bootstrap to ensure it never attempts to run real setup logic during the test.

Changes

  • tests/test_cli.py:
    • Updated test_setup_repo_initializes_git
    • Updated test_main_triggers_bootstrap
    • Updated test_pause_command
    • Updated test_status_reports_pause_state
    • Updated test_diff_shows_untracked_files

Verification

  • Ran pytest.
  • Verified ~/.local/state/git-pulsar/registry is no longer modified during test runs.
  • Verified no "ghost entry" notifications are triggered.

Replaces the global `os.chdir` call in `test_setup_repo_initializes_git` with `monkeypatch.chdir`. This ensures proper teardown and restores the original CWD after the test completes, preventing subsequent tests from executing in a stale temporary directory.
Mocks `git_pulsar.cli.setup_repo` in `test_main_triggers_bootstrap`. Previously, `cli.main()` would fall through to the default `setup_repo` call, which—combined with the CWD leak—caused the test suite to register temporary test directories into the user's actual `~/.local/state/git-pulsar/registry` file.
@JacksonFergusonDev JacksonFergusonDev merged commit 0a65531 into main Jan 29, 2026
4 checks passed
@JacksonFergusonDev JacksonFergusonDev deleted the tests branch January 29, 2026 02:31
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.

2 participants