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
Add async local override for build server detector (#678)
* Add async-local override for BuildServerDetector
Introduce an AsyncLocal-backed override for BuildServerDetector.Detected so tests (and other async-scoped code) can set the detected value without leaking to other threads. The static initialization now stores the computed detection in a private 'detected' field, and the Detected property reads from overrideDetected.Value ?? detected and sets overrideDetected.Value. Added unit tests to verify the override persists in the async context and doesn't leak, and updated readme/source docs with a snippet explaining how to override Detected in tests.
* Update Directory.Build.props
Copy file name to clipboardExpand all lines: readme.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,7 @@ DiffEngine manages launching and cleanup of diff tools. It is designed to be use
46
46
*[Closing a tool](#closing-a-tool)
47
47
*[File type detection](#file-type-detection)
48
48
*[BuildServerDetector](#buildserverdetector)
49
+
*[Override in tests](#override-in-tests)
49
50
*[AiCliDetector](#aiclidetector)
50
51
*[Disable for a machine/process](#disable-for-a-machineprocess)
51
52
*[Disable in code](#disable-in-code)
@@ -162,6 +163,50 @@ var isAppVeyor = BuildServerDetector.IsAppVeyor;
162
163
<!-- endSnippet -->
163
164
164
165
166
+
### Override in tests
167
+
168
+
`BuildServerDetector.Detected` can be set at test time. The value is stored in an `AsyncLocal`, so it is scoped to the current async context and does not leak to other threads or tests running in parallel.
Copy file name to clipboardExpand all lines: readme.source.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,13 @@ There are also individual properties to check for each specific build system
84
84
snippet: BuildServerDetectorProps
85
85
86
86
87
+
### Override in tests
88
+
89
+
`BuildServerDetector.Detected` can be set at test time. The value is stored in an `AsyncLocal`, so it is scoped to the current async context and does not leak to other threads or tests running in parallel.
90
+
91
+
snippet: BuildServerDetectorDetectedOverride
92
+
93
+
87
94
## AiCliDetector
88
95
89
96
`AiCliDetector.Detected` returns true if the current code is running in an AI-powered CLI environment.
0 commit comments