Skip to content

Pin that a report's body goes out as UTF-8 with its length in bytes - #50

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/pin-utf8-wire-body
Nov 16, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/pin-utf8-wire-body

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Stage B unit-test expansion: how a report's body is encoded on the wire is now pinned. Only tests are added, and no production code is changed.

Summary

  • report_sendsNonAsciiTextAsUtf8WithALengthCountedInBytes: an event whose name and tag hold a two-byte (é), a three-byte (€) and a four-byte (surrogate pair) character arrives as exactly the expected JSON in UTF-8. The Content-Length header equals the byte count, which is larger than the char count, and Content-Type is exactly application/json; charset=utf-8. Until now no test sent non-ASCII text over HTTP (only quote() was tested directly), and the existing Content-Type assertion checked only the application/json prefix.
  • report_aLoneSurrogateIsSentAsAQuestionMarkRatherThanDroppingTheReport: half a surrogate pair in a tag value is passed through by quote() and replaced with ? by String.getBytes(UTF_8). The report still goes out, with a matching length. This is recorded as current behaviour, not as a bug: the report is neither dropped nor turned into an exception.
  • A small RawRequest fixture and a reportAndCaptureRawRequest helper capture the raw body bytes and the two headers on a loopback server of their own. The shared fixture decodes the body before storing it, so it cannot show the byte count.

Regression evidence

send() streams the body with setFixedLengthStreamingMode(bytes.length). As a check, that line was temporarily changed to body.length() (chars instead of bytes). With that change the first new test failed (the report should reach the server ==> expected: <true> but was: <false>), because the connection rejected the body as longer than the declared length. With the line restored the test passed. The source change was reverted before committing, and git status showed only the test file modified.

Test plan

  • mvn -B verify locally on Java 21: Tests run: 120, Failures: 0, Errors: 0, Skipped: 0, and both new tests appear in the surefire report
  • CI matrix build (8), build (17), build (21) green

Work selection

Every open issue (#13, #15, #27, #31, #39, #40, #42) is deferred, as in the previous cycles: each asks for a maintainer decision on the opt-out contract, the wire format, or the "Opting out" README wording, which is on the do-not-auto-merge list. A read of TraceClient.java against TraceClientTest.java found the server-wide parser, opt-outs, install ID, coalescing and JSON helpers already covered branch by branch. The body encoding on the wire was the remaining untested behaviour.

Observation, not acted on: the README section "The wire format" does not say that the body is UTF-8. That could be added in a later documentation cycle. It is left out here so this PR stays test-only.

No tracking issue: this gap was found during triage.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (scored against the diff and CI on head c1a01cd):

  • Scope: PASS — gh pr diff 50 --name-only lists only src/test/java/software/stephenson/trace/TraceClientTest.java; no production, docs or build file is touched.
  • Tests-new: PASS (not applicable) — no public method is added; the two new tests drive existing report()/send() behaviour.
  • Tests-fix: PASS (not applicable as a fix; guard checked empirically) — no bug fix is claimed. As a characterization guard, setFixedLengthStreamingMode(bytes.length) was temporarily changed to body.length(), and report_sendsNonAsciiTextAsUtf8WithALengthCountedInBytes failed (the report should reach the server); restored, it passed.
  • Sibling structure: PASS — the new tests follow the methodUnderTest_behaviourInPlainWords naming and the Arrange/Act/Assert layout. The local loopback HttpServer is stopped in a finally, matching report_returnsBeforeTheServerAnswers.
  • Sibling renames: PASS (not applicable) — nothing is renamed.
  • Docs: PASS — no behaviour changes, so no README/Javadoc row is affected. One observation is recorded in the PR body: the README "The wire format" section does not state that the body is UTF-8.
  • Issue resolution: PASS (not applicable) — no Closes #N; the gap was found during triage.
  • CI: PASS — build (8), build (17) and build (21) are green on the head.

Repo-specific:

  • No dependencies / Single file / Java 8: PASS — pom.xml and src/main are untouched; the test uses only Java 8 APIs (CopyOnWriteArrayList, assertArrayEquals), and build (8) is green.
  • Never throws / Non-blocking & bounded / Environment seam / Version agreement / Opt-out contract: PASS (not applicable) — no production code changed.

Finding, judgment only, not blocking: src/test/java/software/stephenson/trace/TraceClientTest.java (reportAndCaptureRawRequest) — if the delivery assertion fails, client.close() is skipped and the client's daemon sender thread is left to time out. Other tests in the file follow the same pattern, so this is left as it is.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit c9902db into main Nov 16, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/pin-utf8-wire-body branch November 16, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant