From c8434987d967d8a81ba84095340c339ff2af3392 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sat, 3 Oct 2026 01:42:26 -0600 Subject: [PATCH] Test that unsent reports are not logged and non-number values are omitted The README promises that a report which was never going to be sent -- a disabled or closed client, or a blank or non-string name -- is not passed to debug, but no test supplied a debug callback on those paths, and a non-string name was never exercised. Nor was the rule that a value which is not a number is left out of the body. Two characterization tests now pin both; trace-client.ts is unchanged. Co-Authored-By: Claude Opus 5.5 --- tests/trace-client.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/trace-client.test.ts b/tests/trace-client.test.ts index 99a5b40..dee5b7b 100644 --- a/tests/trace-client.test.ts +++ b/tests/trace-client.test.ts @@ -262,6 +262,35 @@ describe("TraceClient", () => { assert.deepEqual(capture.requests, []); }); + it("logs nothing for a report that was never going to be sent", async () => { + // Only drops of a report an enabled client meant to send reach debug. + const off = new TraceClient(baseUrl, "MyGame", { version: "1.2.3", key: "k", enabled: false, debug }); + await off.report("startup"); + const keyless = new TraceClient(baseUrl, "MyGame", { version: "1.2.3", debug }); + await keyless.report("startup"); + const on = new TraceClient(baseUrl, "MyGame", { version: "1.2.3", key: "k", debug }); + for (const name of ["", " ", 42, undefined, null]) { + await on.report(name as unknown as string); + } + await on.close(); + await on.report("after-close"); + await sleep(100); + assert.deepEqual(capture.requests, []); + assert.deepEqual(log, [], "a disabled or closed client, or a blank or non-string name, is not a drop"); + }); + + it("omits a value that is not a number", async () => { + const client = new TraceClient(baseUrl, "MyGame", { version: "1.2.3", key: "k" }); + for (const value of ["5", null, true]) { + await client.report("loose", { value: value as unknown as number }); + } + assert.equal(capture.requests.length, 3); + for (const request of capture.requests) { + assert.deepEqual(JSON.parse(request.body), { application: "MyGame", name: "loose", tags: { version: "1.2.3" } }); + } + await client.close(); + }); + it("rejects a missing baseUrl or application at construction", () => { assert.throws(() => new TraceClient("", "MyGame", { version: "1.2.3" })); assert.throws(() => new TraceClient(" ", "MyGame", { version: "1.2.3" }));