test: reduce unit test runtime by fixing slow polling and real HTTP calls

What does this MR do and why?

Addresses several root causes of slow unit tests identified through profiling and CI pipeline history analysis.

Changes

internal/commands/ci/ciutils/utils.go

  • Add PollInterval time.Duration to JobOptions. When zero, runTrace defaults to the existing 3-second interval. This lets tests pass time.Millisecond to avoid waiting for the first ticker tick on every test case.

internal/commands/ci/ciutils/utils_test.go

  • Add t.Parallel() to TestTraceJob and TestGetJobId (top-level and subtests) — these only use mock clients with no shared global state.
  • Pass PollInterval: time.Millisecond in TestTraceJob's JobOptions.

internal/commands/auth/login/helper_test.go

  • The "failed to refresh" test case had testOAuth2: true but no apiResponse, so the OAuth token refresh made a real TCP connection to gitlab.example.com. In CI (no external network), this blocked on the OS TCP timeout (1–3 minutes). Fix: provide a mock transport that immediately returns "connection refused".

internal/cmdutils/cmdutils_test.go

  • Add t.Parallel() to Test_PickMetadata (top-level and subtests) — no shared global state.

Why not more?

Stack and internal/git tests were considered but cannot be safely parallelized: they call InitGitRepo/InitGitRepoWithCommit which use t.Chdiros.Chdir, a process-global operation. Parallel subtests would race on the working directory.

Test_UsersPrompt and labels prompt tests reassign package-level function variables (listProjectMembers, listLabels) before running subtests; parallelizing them would create data races.

TestCiTrace (in ci/trace) still takes ~3s because NewCmdTrace's RunE constructs JobOptions internally with no injection point for PollInterval. Since those subtests already run in parallel the effective CI cost is ~3s, which is acceptable without a larger refactor.

MR acceptance checklist

  • This MR does not add new product functionality
  • Existing unit tests pass
  • No documentation changes needed

Merge request reports

Loading