Skip to content

Isolate secret-redaction tests from the shared SECRETS_REGEX global#14040

Open
fbartho wants to merge 1 commit into
warpdotdev:masterfrom
fbartho:fb/13973-secrets-regex-test-isolation
Open

Isolate secret-redaction tests from the shared SECRETS_REGEX global#14040
fbartho wants to merge 1 commit into
warpdotdev:masterfrom
fbartho:fb/13973-secrets-regex-test-isolation

Conversation

@fbartho

@fbartho fbartho commented Jul 20, 2026

Copy link
Copy Markdown

Closes #13973

Description

The secret-redaction tests install their own regexes into the single process-global SECRETS_REGEX (secrets.rs) with no isolation. Under plain cargo test, one test's regexes could overwrite another's before its assertion ran — the loser panics left: 0, right: 1, and which test loses rotates run to run, which is why this reported as a rotating flake rather than one consistent failure.

Fix: test_set_secrets_regex() returns a #[must_use] RAII guard (modeled on the existing FeatureFlag::override_enabledOverrideGuard pattern) that snapshots the global and restores it on drop. Since the global is process-wide (not thread-local), the guard prevents cross-test leakage but not mid-test interleaving — so the affected tests are also #[serial(secrets_regex)], a named group that avoids serializing against unrelated #[serial] tests. Converted all racing call sites in the three files from the issue: grid/secrets_tests.rs (9 tests), block/secret_redaction_tests.rs, and execute/grep_tests.rs.

Linked Issue

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).
    • Not applicable: test-only change, no user-visible behavior.

Testing

Repeated invocations of the affected modules under plain cargo test — the harness where the flake manifests (nextest's per-process isolation masks it):

  • Before: cargo test -p warp --lib terminal::model::grid::grid_handler::secretsFAILED. 3 passed; 7 failed (e.g. assertion left == right failed: left: 0, right: 1).

  • After: same command ×3 → ok. 10 passed every run. The other two modules: ai::blocklist::block::secret_redactionok. 19 passed ×3; …execute::grepok. 4 passed ×3.

  • Nextest (CI parity, was already green): cargo nextest run -p warp --lib -E 'test(secrets) + test(secret_redaction) + test(grep_tests)' → 72/72 passed.

  • cargo clippy -p warp --lib --tests and cargo check -p warp --lib --features test-util: zero warnings.

  • I have manually tested my changes locally with ./script/run

    • Not applicable: the issue only applies to test builds.

Screenshots / Videos

Not applicable: test-only change.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

SECRETS_REGEX is a single process-global Mutex<Arc<SecretsRegex>>, and
each secret-redaction test overwrote it directly via
set_user_and_enterprise_secret_regexes without any isolation. Under
plain `cargo test` (parallel by default, and even sequentially without
teardown), one test's regexes would leak into or get clobbered by
another's before its assertion ran, causing nondeterministic
`left: 0, right: 1` failures that rotated between runs.

Add test_set_secrets_regex, an RAII guard (modeled on
FeatureFlag::override_enabled) that snapshots the previous global
value and restores it on drop. Since SECRETS_REGEX is process-wide
rather than thread-local, the guard alone only prevents state from
leaking across tests - it does not stop concurrent tests from
interleaving mid-test. Pair it with #[serial(secrets_regex)] (a named
serial_test group, so these tests don't needlessly serialize against
unrelated #[serial] tests elsewhere in the crate) on every test that
reads or writes the global.

Closes warpdotdev#13973
@cla-bot cla-bot Bot added the cla-signed label Jul 20, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jul 20, 2026
@fbartho
fbartho marked this pull request as ready for review July 20, 2026 23:05
@oz-for-oss

oz-for-oss Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@fbartho

Every PR must be linked to a same-repo issue before Oz can review it.

This PR is linked to #13973, but no linked issue is marked ready-to-implement yet. Only repository maintainers apply that label, so please wait for a maintainer to mark the issue. Once it is marked, push a new commit or comment /oz-review to re-trigger review.

See the contribution guidelines for the full readiness model.

Powered by Oz

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fbartho

Every PR must be linked to a same-repo issue before Oz can review it.

This PR is linked to #13973, but no linked issue is marked ready-to-implement yet. Only repository maintainers apply that label, so please wait for a maintainer to mark the issue. Once it is marked, push a new commit or comment /oz-review to re-trigger review.

See the contribution guidelines for the full readiness model.

Powered by Oz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terminal secrets: redaction tests race on the shared process-global SECRETS_REGEX, failing nondeterministically in parallel runs

1 participant