Skip to content

test(e2e): isolate test suites from host shell and git configs - #245

Merged
HarshK97 merged 1 commit into
mainfrom
test/isolate-user-config-options
Oct 10, 2026
Merged

HarshK97 merged 1 commit into
mainfrom
test/isolate-user-config-options

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. Local shell variables like DIFFM_FORMAT, DIFFM_IGNORE_COMMENTS, COLUMNS, and PAGER leak into test runners. If you have any of them exported in your terminal, unit and e2e tests fail on unexpected formatting or column widths.
  2. Host Git pointers (GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE) and global configs (~/.gitconfig) bleed into the CLI subprocesses that e2e tests spawn. So if tests run from inside a Git hook, worktree, or subshell, Git operations inside diffm target the wrong repository and break.

What Changed

  • Unset user config, pager, color, and Git pointer env vars at TestMain startup in cmd, internal/git, and internal/pager. Kept DIFFM_TEST_* untouched so subprocess re-exec tests still work.
  • Added isolatedEnv() in tests/e2e/cli_test.go to filter os.Environ() in-place with slices.DeleteFunc, point GIT_CONFIG_GLOBAL to /dev/null, and set GIT_CONFIG_NOSYSTEM=1. Spawned diffm commands now completely ignore host Git configuration.
  • Added TestCLI_SubprocessEnvironmentIsolation to verify that isolatedEnv() strips repo pointer keys, and ran a real diffm command under a broken GIT_DIR to prove it doesn't fall over.

Developer shell variables (DIFFM_*, PAGER, COLUMNS) and host Git
settings (GIT_DIR, ~/.gitconfig) leaked into test processes, causing
tests to fail or produce unexpected output depending on the local setup.

Sanitize user settings at TestMain entry across test packages, and
isolate e2e CLI subprocesses so host Git configurations cannot interfere.

- e2e: strip user config in TestMain and filter env in-place
- e2e: point GIT_CONFIG_GLOBAL to devnull and set GIT_CONFIG_NOSYSTEM
- e2e: add regression test verifying CLI runs with invalid host Git pointers
- cmd: clear user config and pager vars while keeping DIFFM_TEST_* flags
- git: clear GIT_DIR, GIT_WORK_TREE, and GIT_INDEX_FILE in TestMain
- pager: clear DIFFM_NO_PAGER, GIT_PAGER, and PAGER in TestMain
@HarshK97
HarshK97 merged commit c7e422b into main Oct 10, 2026
17 checks passed
@HarshK97
HarshK97 deleted the test/isolate-user-config-options branch October 10, 2026 09: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.

1 participant