From f0acabaacbe35359885e90597f3c6e771fa6f514 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sat, 7 Nov 2026 19:43:38 -0700 Subject: [PATCH] Test which tags count as an event's own version or install An empty value is a tag and wins over the program's version or the configured installation ID, unlike a null one. Keys are matched exactly: "Version", "Install" or " version" are ordinary tags and do not displace either. Co-Authored-By: Claude Opus 5.5 --- tests/TraceClient.Tests/InstallIdTest.cs | 27 ++++++++++++++++++ tests/TraceClient.Tests/TraceClientTest.cs | 32 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/tests/TraceClient.Tests/InstallIdTest.cs b/tests/TraceClient.Tests/InstallIdTest.cs index f495474..69a4913 100644 --- a/tests/TraceClient.Tests/InstallIdTest.cs +++ b/tests/TraceClient.Tests/InstallIdTest.cs @@ -342,6 +342,33 @@ public void Report_ANullInstallTagDoesNotDisplaceTheConfiguredId() _server.Received.Single().Body); } + [Fact] + public void Report_AnEmptyInstallTagStillWinsOverTheConfiguredId() + { + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k", installId: "configured"); + + client.Report("startup", tags: new Dictionary { { "install", "" } }); + client.Close(); + + // Unlike a null value, an empty one is a tag: it is sent, and the configured ID is not added. + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"startup\",\"tags\":{\"install\":\"\",\"version\":\"1.2.3\"}}", + _server.Received.Single().Body); + } + + [Fact] + public void Report_OnlyTheExactLowercaseInstallKeyCountsAsTheEventsOwn() + { + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k", installId: "configured"); + + client.Report("startup", tags: new Dictionary { { "Install", "own" } }); + client.Close(); + + // Keys are compared ordinally, so "Install" is an ordinary tag and the configured ID is still added. + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"startup\"," + + "\"tags\":{\"Install\":\"own\",\"version\":\"1.2.3\",\"install\":\"configured\"}}", + _server.Received.Single().Body); + } + [Fact] public void Report_NeverAddsTheInstallTagPastTheTagLimit() { diff --git a/tests/TraceClient.Tests/TraceClientTest.cs b/tests/TraceClient.Tests/TraceClientTest.cs index 13b23e1..e186bfe 100644 --- a/tests/TraceClient.Tests/TraceClientTest.cs +++ b/tests/TraceClient.Tests/TraceClientTest.cs @@ -593,6 +593,38 @@ public void Report_ANullVersionTagDoesNotDisplaceTheProgramVersion() _server.Received.Single().Body); } + [Fact] + public void Report_AnEmptyVersionTagStillWinsOverTheProgramVersion() + { + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k"); + + client.Report("startup", tags: new Dictionary { { "version", "" } }); + client.Close(); + + // Unlike a null value, an empty one is a tag: it is sent, and the program's version is not added. + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"startup\",\"tags\":{\"version\":\"\"}}", + _server.Received.Single().Body); + } + + [Fact] + public void Report_OnlyTheExactLowercaseVersionKeyCountsAsTheEventsOwn() + { + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k"); + var tags = new List> + { + new KeyValuePair("Version", "9.9.9"), + new KeyValuePair(" version", "8.8.8"), + }; + + client.Report("startup", tags: tags); + client.Close(); + + // Keys are compared ordinally and untrimmed, so both are ordinary tags and the program's version is added. + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"startup\"," + + "\"tags\":{\"Version\":\"9.9.9\",\" version\":\"8.8.8\",\"version\":\"1.2.3\"}}", + _server.Received.Single().Body); + } + [Fact] public void Report_NeverModifiesTheCallersDictionary() {