You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(auth): make ADO error-context tests hermetic to ambient git credentials (#4762) - #4785
The CI leak detector on the failing shard named it: apm_cli.core.azure_cli.get_bearer_provider was left as a MagicMock. tests/utils/simulated_ado_chain.py patches that global inside try_with_fallback, and parallel downloads call that from several threads. Two overlapping patches restore each other's mock (enter A, enter B saves A's mock, exit A, exit B restores A's mock), so the rest of the xdist worker saw a foreign bearer provider. TestBuildErrorContextADO and test_ado_attempts_bearer_before_raising then failed. The ambient credential helper was not the cause: main's 8ea467f already routes git credential fills through a stand-in.
Change (tests only)
tests/utils/simulated_ado_chain.py: an RLock serializes the bearer patch.
tests/unit/core/test_simulated_ado_chain_threads.py: B calls in while A is inside the chain; the test counts concurrently active bearer patches (peak must be 1), checks both workers' results, and checks that the module global is the real function afterwards.
The issue's acceptance check (isolation from an ambient credential helper) is already met module-wide by main's autouse credential_children stand-in for git/gh children (8ea467f), so test_auth.py is unchanged. No product change, no changelog fragment.
Validation
Old vs new, host guard, pytest -p no:xdist tests/unit/core/test_simulated_ado_chain_threads.py: old helper 3/3 failed, fixed helper 5/5 passed.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The regression test checks only the mocked bearer failure, so it can pass despite restored credential leakage unless it also asserts that no credential-helper subprocess runs.
This test-only PR addresses #4762 by isolating Azure DevOps authentication tests from ambient Git credentials and resetting bearer-provider state across live module references. Product authentication behavior is unchanged.
Changes:
Stub Git credential resolution for the ADO error-context tests.
Reset bearer singletons on imported and live module objects.
Add a regression test configured with a hostile credential helper.
File
Description
tests/unit/test_auth.py
Adds credential-isolation fixtures, strengthens singleton cleanup, and introduces the hostile-helper regression test.
…#4762)
Parallel downloads call the simulated chain's try_with_fallback from
several threads. Each call patched azure_cli.get_bearer_provider; two
overlapping patches restore each other's MagicMock, leaving the module
global mocked for the rest of the xdist worker. TestBuildErrorContextADO
and the bearer regression trap then saw a foreign provider (CI leak
detector: apm_cli.core.azure_cli.get_bearer_provider). An RLock now
serializes the patch. Adds a thread-overlap regression test and a
hostile credential helper check for the ADO guidance.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The new test module lacks a required promise marker and fails the taxonomy gate, while concurrency and credential-fallback tests can pass without validating the intended behavior.
…mise (#4762)
The hostile-helper check now uses the real bearer provider with no az on
PATH, so it adds no AQ004 owner patch; the thread test carries its
P-OWN-host-credential-resolution promise (tm006).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… check (#4762)
Count concurrently active bearer patches instead of relying on timed
waits, surface worker results and exceptions in the main thread, and
drop the hostile-helper case: ADO build_error_context never reaches git
credential fill, and main's autouse credential_children fixture already
keeps every test_auth test off real git and gh children.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The regression tests can pass despite broken behavior because they do not reliably establish lock contention, verify worker outcomes and completion, or assert that credential-helper lookups never occur.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Synchronize workers to ensure the test detects missing locking
This timeout allows the regression test to pass without the lock. If thread B is scheduled more than one second after A enters, A exits its patch before B enters, so the final identity assertion succeeds even with the original unsafe implementation. A standard-library reproduction passes without serialization when B is delayed by 1.1 seconds. Please coordinate at the patch/lock-entry boundary so the test proves B is competing before A is released, rather than treating a missed handshake as successful serialization.
Propagate worker failures and verify both threads terminate
Thread.join() neither propagates worker assertions and exceptions nor verifies completion after a timeout. If both chain calls raise after restoring their patches, the final identity assertion can still pass. Check the call results on the pytest thread and assert that both workers have terminated.
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
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.
Fixes #4762
Root cause
The CI leak detector on the failing shard named it:
apm_cli.core.azure_cli.get_bearer_providerwas left as a MagicMock.tests/utils/simulated_ado_chain.pypatches that global insidetry_with_fallback, and parallel downloads call that from several threads. Two overlapping patches restore each other's mock (enter A, enter B saves A's mock, exit A, exit B restores A's mock), so the rest of the xdist worker saw a foreign bearer provider.TestBuildErrorContextADOandtest_ado_attempts_bearer_before_raisingthen failed. The ambient credential helper was not the cause: main's 8ea467f already routes git credential fills through a stand-in.Change (tests only)
tests/utils/simulated_ado_chain.py: an RLock serializes the bearer patch.tests/unit/core/test_simulated_ado_chain_threads.py: B calls in while A is inside the chain; the test counts concurrently active bearer patches (peak must be 1), checks both workers' results, and checks that the module global is the real function afterwards.The issue's acceptance check (isolation from an ambient credential helper) is already met module-wide by main's autouse
credential_childrenstand-in for git/gh children (8ea467f), so test_auth.py is unchanged. No product change, no changelog fragment.Validation
pytest -p no:xdist tests/unit/core/test_simulated_ado_chain_threads.py: old helper 3/3 failed, fixed helper 5/5 passed.scripts/check_test_assertions.py: ratchet clean.python -m tests.quality.taxonomy --changed: tm006 clean.