Skip to content

fix(test): remove two process-global races causing flaky CI panics#61

Merged
jpage-godaddy merged 1 commit into
mainfrom
release-panic
Jul 23, 2026
Merged

fix(test): remove two process-global races causing flaky CI panics#61
jpage-godaddy merged 1 commit into
mainfrom
release-panic

Conversation

@jpage-godaddy

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes the flaky test panic seen in the release PR CI run: cli::user_agent_tests::install_debug_transport_logger_tracks_the_debug_pattern asserted on the process-wide default transport logger, but Cli::run republishes that same global on every call — including from the many unrelated tests that call cli.run(...) with no --debug flag. Any of those running concurrently could flip the global between this test's install and assert. Fixed by extracting the pure decision logic (debug_transport_logger_for) so the test no longer touches the shared global, and removing the now-dead TRANSPORT_LOGGER_TEST_LOCK/RestoreDefaultTransportLogger.
  • While stress-testing the fix, found a second instance of the same bug class: environments::tests::persist_active_without_app_id_errors_clearly resolves "prod" internally, reading the same PROD_* env vars its sibling tests mutate under ENV_LOCK — but it never took that lock itself. Fixed by taking ENV_LOCK there too.

Test plan

  • cargo test --features pkce-auth --lib x30 in a loop (previously failed within ~3 runs; now clean)
  • cargo test --all-targets and cargo test --all-targets --features pkce-auth
  • cargo test --doc and cargo test --doc --features pkce-auth
  • cargo clippy --all-targets -- -D warnings (default and pkce-auth)

🤖 Generated with Claude Code

`install_debug_transport_logger_tracks_the_debug_pattern` asserted on the
real process-wide transport debug logger, which `Cli::run` republishes on
every call (including from the many unrelated tests that call
`cli.run(...)` with no `--debug` flag). Any of those running concurrently
could flip the global between this test's install and assert, tripping the
panic seen in CI. Extract the pure decision logic into
`debug_transport_logger_for` so the test asserts on a locally-built logger
instead of the shared global, and drop the now-dead
`TRANSPORT_LOGGER_TEST_LOCK`/`RestoreDefaultTransportLogger`, which only ever
guarded this test against itself.

`persist_active_without_app_id_errors_clearly` resolves "prod" internally,
reading the same `PROD_*` env vars its sibling tests mutate under `ENV_LOCK`
— except this test never took that lock, so a concurrent sibling could
inject a value (e.g. an invalid `PROD_MIN_STAGE`) and fail resolution for an
unrelated reason. Take `ENV_LOCK` here too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces flaky CI panics by removing two process-global test races: one around the default transport logger being republished by Cli::run, and another around environment resolution reading PROD_* env vars while sibling tests mutate them.

Changes:

  • Extracted debug_transport_logger_for as pure decision logic and refactored transport logger installation to use it.
  • Updated the transport logger unit test to assert on the pure builder rather than the process-wide global.
  • Serialized the persist_active_without_app_id_errors_clearly environment test with ENV_LOCK, and removed now-unused transport-logger test locking/RAII cleanup helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/cli.rs Adds a pure transport-logger builder, refactors installation to use it, and updates the unit test to avoid touching a process-global.
src/transport/client.rs Removes unused test-only lock/RAII for restoring the default transport logger.
src/environments.rs Takes ENV_LOCK in a test that indirectly reads PROD_* env vars to prevent concurrent env mutation races.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jpage-godaddy
jpage-godaddy merged commit f4343a2 into main Jul 23, 2026
3 checks passed
@jpage-godaddy
jpage-godaddy deleted the release-panic branch July 23, 2026 16:36
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.

3 participants