From b10c45ed027c85bc748551d37d8aea312055b401 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sun, 15 Nov 2026 00:02:32 -0700 Subject: [PATCH] Test that an event's own overlong version or install tag drops it An event's own version and install tags win over the configured ones, but no test covered what happens when that tag is past MaxLength. Pin the current behaviour: the event is dropped and logged as "tag version longer than 255 characters" (or "tag install ...") rather than sent with the program's version or configured ID in its place, while a tag exactly at the limit is still sent. Co-Authored-By: Claude Opus 5.5 --- tests/TraceClient.Tests/InstallIdTest.cs | 20 ++++++++++++++++++++ tests/TraceClient.Tests/TraceClientTest.cs | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/TraceClient.Tests/InstallIdTest.cs b/tests/TraceClient.Tests/InstallIdTest.cs index 4880c9a..56c0b01 100644 --- a/tests/TraceClient.Tests/InstallIdTest.cs +++ b/tests/TraceClient.Tests/InstallIdTest.cs @@ -347,6 +347,26 @@ public void Report_AnEventsOwnInstallTagWins() _server.Received.Single().Body); } + [Fact] + public void Report_AnEventsOwnInstallTagPastTheLimitDropsTheEventRatherThanFallingBack() + { + var log = new ConcurrentQueue(); + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k", log: log.Enqueue, + installId: "configured"); + + client.Report("startup", tags: new Dictionary { { "install", new string('i', TraceClient.MaxLength + 1) } }); + client.Report("command", tags: new Dictionary { { "install", new string('i', TraceClient.MaxLength) } }); + client.Close(); + + // The event's own tag wins even when the server would reject it, so the + // configured ID is not sent in its place: the whole event is dropped. + Assert.Equal("[trace] dropped startup: tag install longer than " + TraceClient.MaxLength + " characters", + Assert.Single(log)); + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"command\"," + + "\"tags\":{\"install\":\"" + new string('i', TraceClient.MaxLength) + "\",\"version\":\"1.2.3\"}}", + _server.Received.Single().Body); + } + [Fact] public void Report_ANullInstallTagDoesNotDisplaceTheConfiguredId() { diff --git a/tests/TraceClient.Tests/TraceClientTest.cs b/tests/TraceClient.Tests/TraceClientTest.cs index c1dd52c..d1e7668 100644 --- a/tests/TraceClient.Tests/TraceClientTest.cs +++ b/tests/TraceClient.Tests/TraceClientTest.cs @@ -632,6 +632,25 @@ public void Report_AnEmptyVersionTagStillWinsOverTheProgramVersion() _server.Received.Single().Body); } + [Fact] + public void Report_AnEventsOwnVersionTagPastTheLimitDropsTheEventRatherThanFallingBack() + { + var log = new ConcurrentQueue(); + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k", log: log.Enqueue); + + client.Report("startup", tags: new Dictionary { { "version", new string('9', TraceClient.MaxLength + 1) } }); + client.Report("command", tags: new Dictionary { { "version", new string('9', TraceClient.MaxLength) } }); + client.Close(); + + // The event's own tag wins even when the server would reject it, so the + // program's version is not sent in its place: the whole event is dropped. + Assert.Equal("[trace] dropped startup: tag version longer than " + TraceClient.MaxLength + " characters", + Assert.Single(log)); + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"command\"," + + "\"tags\":{\"version\":\"" + new string('9', TraceClient.MaxLength) + "\"}}", + _server.Received.Single().Body); + } + [Fact] public void Report_OnlyTheExactLowercaseVersionKeyCountsAsTheEventsOwn() {