From 83da05a60e057c01ace296637459d28f59ce2c46 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Thu, 12 Nov 2026 19:48:00 -0700 Subject: [PATCH] Test that Disabled() reports the environment when it opts out TraceClient.Disabled() goes through the same constructor as any other client, and the environment is checked before enabled: false. Under DO_NOT_TRACK=1 its DisabledReason is therefore "environment", not "config". The only existing assertion ran with a clean environment, so pin the other case and say so in the factory's XML doc. Co-Authored-By: Claude Opus 5.5 --- src/TraceClient/TraceClient.cs | 7 ++++++- tests/TraceClient.Tests/TraceClientTest.cs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/TraceClient/TraceClient.cs b/src/TraceClient/TraceClient.cs index 991299d..6394132 100644 --- a/src/TraceClient/TraceClient.cs +++ b/src/TraceClient/TraceClient.cs @@ -229,7 +229,12 @@ public TraceClient(string baseUrl, string application, string version, string ke _thread.Start(); } - /// A client that reports nothing. Useful as a default before settings are read. + /// + /// A client that reports nothing. Useful as a default before settings are read. + /// Its is , or + /// when the environment turns reporting off, since + /// the environment is checked first. + /// public static TraceClient Disabled() { return new TraceClient("http://disabled.invalid", "disabled", "disabled", enabled: false); diff --git a/tests/TraceClient.Tests/TraceClientTest.cs b/tests/TraceClient.Tests/TraceClientTest.cs index a71dbf0..377cf06 100644 --- a/tests/TraceClient.Tests/TraceClientTest.cs +++ b/tests/TraceClient.Tests/TraceClientTest.cs @@ -376,6 +376,20 @@ public void DisabledReason_NamesTheConfigFlagOrTheMissingKey() Assert.Equal("config", TraceClient.Disabled().DisabledReason); } + [Fact] + public void Disabled_SaysEnvironmentRatherThanConfigWhenTheEnvironmentOptsOut() + { + // Disabled() goes through the same constructor, and the environment + // is checked before enabled: false, so its reason is not always "config". + _environment[TraceClient.EnvDoNotTrack] = "1"; + + TraceClient client = TraceClient.Disabled(); + + Assert.False(client.IsEnabled); + Assert.Equal(TraceClient.ReasonEnvironment, client.DisabledReason); + Assert.Null(client.InstallId); + } + [Theory] [InlineData("")] [InlineData(" ")]