Skip to content

test: add e2e test suite for CLI binary-level testing#24

Merged
alexandreafj merged 4 commits into
masterfrom
feature/e2e-tests
May 1, 2026
Merged

test: add e2e test suite for CLI binary-level testing#24
alexandreafj merged 4 commits into
masterfrom
feature/e2e-tests

Conversation

@alexandreafj
Copy link
Copy Markdown
Owner

Summary

  • Adds 77 automated e2e tests that build the gitm binary and exercise all commands as a real user would
  • Each test runs in an isolated environment (separate HOME dir → separate DB)
  • Uses real git repos in t.TempDir() (no mocks, per AGENTS.md)
  • Runs with race detection in ~30s

Test Coverage

Command Tests Notes
repo add/list/remove/rename 20 All variations + edge cases
status 8 Clean, dirty, ahead/behind, --fetch
branch create/rename 11 --repo, --all, --from, --no-remote
checkout 8 Default branch, existing, remote-only, dirty, untracked
update 6 Up-to-date, remote ahead, dirty, diverged
track/untrack 3 Edge cases (TUI-dependent for file selection)
commit/discard 3 Edge cases (TUI-dependent for interaction)
stash 2 list empty/with stashes
help/version/upgrade 5 All commands help, unknown cmd

Key Findings (documented via t.Log in tests)

  1. checkout fails for remote-only branches that haven't been fetched — ls-remote confirms existence but no git fetch runs before git checkout
  2. status DIRTY column counts untracked files in "N modified" count — misleading label
  3. repo add with duplicate --alias silently ignored (exit 0, no error message)

How to run

go test ./internal/e2e/ -v -race -timeout 120s

Copilot AI review requested due to automatic review settings May 1, 2026 09:43
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

❌ CI Failed - Lint check failed (Go 1.26)

Coverage: unavailable

Previous checks passed: Format ✓ Lint ✗ Tests ✗

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Go e2e test suite under internal/e2e/ that builds the gitm binary once and exercises CLI commands end-to-end using real temporary git repositories and isolated HOME directories (separate DB per test).

Changes:

  • Introduces an e2e harness (TestMain, env isolation, git helpers, assertion helpers) to run the compiled gitm binary.
  • Adds command-level e2e coverage for repo/status/branch/checkout/update plus limited coverage for TUI-heavy commands and help/version/upgrade.
  • Documents several observed behavioral “findings” via logs in tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
internal/e2e/helpers_test.go Builds gitm once and provides isolated env + git/assert helpers for the e2e suite.
internal/e2e/repo_test.go E2E coverage for gitm repo add/list/remove/rename (incl. auto-detect).
internal/e2e/status_test.go E2E coverage for gitm status across common repo states and --fetch.
internal/e2e/branch_test.go E2E coverage for gitm branch create/rename across --repo/--all/--from/--no-remote.
internal/e2e/checkout_test.go E2E coverage for gitm checkout scenarios (dirty, untracked-only, remote-only, pull-after-switch).
internal/e2e/update_test.go E2E coverage for gitm update scenarios (up-to-date, remote-ahead, dirty, diverged).
internal/e2e/track_test.go Edge-case coverage for gitm track/untrack in non-interactive contexts.
internal/e2e/interactive_test.go Edge-case coverage/logging for TUI-heavy commands (commit/discard/stash/reset).
internal/e2e/help_test.go E2E coverage for --help/--version, unknown command behavior, and upgrade smoke check.

Comment thread internal/e2e/track_test.go Outdated
Comment thread internal/e2e/interactive_test.go Outdated
Comment thread internal/e2e/repo_test.go Outdated
Comment thread internal/e2e/repo_test.go Outdated
Comment thread internal/e2e/update_test.go Outdated
Comment thread internal/e2e/track_test.go Outdated
Comment thread internal/e2e/branch_test.go
Comment thread internal/e2e/update_test.go
Comment thread internal/e2e/helpers_test.go
Comment thread internal/e2e/helpers_test.go Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

✅ All checks passed (Go 1.26)

Coverage: 67.5%

Adds 77 automated e2e tests that build the gitm binary and exercise it
as a real user would, using isolated HOME directories and real git repos.

Covers: repo add/list/remove/rename, status, branch create/rename,
checkout, update, track/untrack, commit, discard, stash, reset,
upgrade, help/version.

Key findings documented in test output via t.Log:
- checkout fails for unfetched remote-only branches
- status DIRTY column counts untracked files as 'modified'
- duplicate alias on repo add silently ignored
- Check os.MkdirAll return values (errcheck)
- Remove unused gitLog and isDirty helper methods (unused)
- Use errors.As instead of type assertion on *exec.ExitError (errorlint)
- Add missing errors import
- Cross-platform: replace /dev/null with os.DevNull, add Windows HOME
  env vars (USERPROFILE/HOMEDRIVE/HOMEPATH), clean up TestMain temp dir
- Stronger assertions: replace t.Log-only tests with real assertions
  for remote-only checkout, diverged update, dirty branch create,
  non-existent branch rename, and stash list empty state
- Broader match fixes: 'No' -> specific messages like 'No dirty
  repositories found', 'No untracked files found'
- Skip TUI-dependent tests that cannot run in non-TTY environments
  (commit protection, reset, track file picker)
- Remove custom contains/findSubstring reimplementing strings.Contains
- Use filepath.Join instead of string concatenation with '/'
- Remove unused dataDir struct field
- Use upgrade --help instead of real network call in TestUpgrade
Copilot AI review requested due to automatic review settings May 1, 2026 10:23
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

✅ All checks passed (Go 1.26)

Coverage: 68.1%

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.

Comment thread internal/e2e/repo_test.go Outdated
Comment thread internal/e2e/repo_test.go
Comment thread internal/e2e/status_test.go Outdated
Comment thread internal/e2e/track_test.go Outdated
Comment thread internal/e2e/update_test.go Outdated
Comment thread internal/e2e/repo_test.go Outdated
Comment thread internal/e2e/repo_test.go Outdated
Comment thread internal/e2e/repo_test.go
Comment thread internal/e2e/status_test.go
Comment thread internal/e2e/helpers_test.go
- Use filepath.Join for non-existent path test (cross-platform)
- Assert exit codes in AutoDetectWithDepth, remove _ = r1/r2 workaround
- Replace generic "1" with "changed" in DirtyModified check
- Use specific "No files matching" assertion in untrack test
- Assert deterministic non-zero exit for unknown --repo alias
- Assert idempotent behavior for duplicate path add (exit 0 + warning)
- Assert non-zero exit for conflicting alias (fixed in PR #25)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

✅ All checks passed (Go 1.26)

Coverage: 68.1%

@alexandreafj alexandreafj merged commit 977abf6 into master May 1, 2026
1 check passed
@alexandreafj alexandreafj deleted the feature/e2e-tests branch May 1, 2026 19:28
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