Repository navigation
test(e2e): isolate test suites from host shell and git configs - #245
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DIFFM_FORMAT,DIFFM_IGNORE_COMMENTS,COLUMNS, andPAGERleak into test runners. If you have any of them exported in your terminal, unit and e2e tests fail on unexpected formatting or column widths.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 insidediffmtarget the wrong repository and break.What Changed
TestMainstartup incmd,internal/git, andinternal/pager. KeptDIFFM_TEST_*untouched so subprocess re-exec tests still work.isolatedEnv()intests/e2e/cli_test.goto filteros.Environ()in-place withslices.DeleteFunc, pointGIT_CONFIG_GLOBALto/dev/null, and setGIT_CONFIG_NOSYSTEM=1. Spawneddiffmcommands now completely ignore host Git configuration.TestCLI_SubprocessEnvironmentIsolationto verify thatisolatedEnv()strips repo pointer keys, and ran a realdiffmcommand under a brokenGIT_DIRto prove it doesn't fall over.