From 1483b22822137e7abd4b9c3b4c660c6b9ec2741e Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sun, 15 Nov 2026 19:57:56 -0700 Subject: [PATCH] Test that a blank InstallId file path means no installation ID InstallId::file documents "Blank means none", and the constructor skips installIdFromFile for a blank path, but nothing asserted it. Without that check a blank path would make up an in-memory ID and a whitespace-only path would write a file of that name into the working directory. Co-Authored-By: Claude Opus 5.5 --- test/test_trace_client.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_trace_client.cpp b/test/test_trace_client.cpp index 6707130..d0f3658 100644 --- a/test/test_trace_client.cpp +++ b/test/test_trace_client.cpp @@ -1614,6 +1614,29 @@ static void aBlankInstallIdMeansNoneAndAnOverlongOneIsRejected() { } } +static void aBlankInstallIdFileMeansNone() { + // A blank path is no file: no ID is made up, and nothing is written -- not + // even a file named by the whitespace, relative to the working directory. + StubServer server; + const char *const blanks[] = {"", " \t "}; + for (std::size_t i = 0; i < sizeof blanks / sizeof blanks[0]; ++i) { + trace_client::TraceClient client(server.baseUrl(), "MyGame", "1.2.3", "k", + trace_client::InstallId::fromFile(blanks[i])); + CHECK(client.isEnabled()); + CHECK(client.installId().empty()); + client.report("startup"); + CHECK(server.waitFor(i + 1, 10)); + client.close(); + } + CHECK(!exists(" \t ")); + std::vector got = server.received(); + CHECK_EQ(2u, got.size()); + for (std::size_t i = 0; i < got.size(); ++i) { + CHECK_EQ(std::string("{\"application\":\"MyGame\",\"name\":\"startup\",\"tags\":{\"version\":\"1.2.3\"}}"), + got[i].body); + } +} + static void anEventsOwnInstallTagWins() { StubServer server; trace_client::TraceClient client(server.baseUrl(), "MyGame", "1.2.3", "k", trace_client::InstallId::of("configured")); @@ -1906,6 +1929,7 @@ int main() { {"aDisabledClientNeverMakesUpOrWritesAnInstallId", aDisabledClientNeverMakesUpOrWritesAnInstallId}, {"anExplicitInstallIdIsTrimmedAndWinsOverTheFile", anExplicitInstallIdIsTrimmedAndWinsOverTheFile}, {"aBlankInstallIdMeansNoneAndAnOverlongOneIsRejected", aBlankInstallIdMeansNoneAndAnOverlongOneIsRejected}, + {"aBlankInstallIdFileMeansNone", aBlankInstallIdFileMeansNone}, {"anEventsOwnInstallTagWins", anEventsOwnInstallTagWins}, {"theInstallTagNeverPassesTheTagCap", theInstallTagNeverPassesTheTagCap}, {"onlyA201IsSuccess", onlyA201IsSuccess},