Skip to content

Test the constructor's trimming and report's tag cleaning - #17

Merged
dmccoystephenson merged 1 commit into
mainfrom
trace/test-constructor-trimming-and-tag-cleaning
Oct 18, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
trace/test-constructor-trimming-and-tag-cleaning

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Stage B (unit-test expansion) cycle: two characterization tests are added for constructor and report() branches that had no coverage. Production code is unchanged.

Summary

  • test_constructor_trims_the_base_url_application_and_key — a base URL, application and key padded with whitespace are shown to still yield POST /api/metrics, Authorization: Bearer k-123, "application":"MyGame" and a User-Agent ending (MyGame). Previously only a trailing slash and a blank key were exercised.
  • test_report_drops_none_tags_and_stringifies_the_rest_before_adding_the_version — through the real report() path (not just _json), a None tag key and value are shown to be dropped, a non-string value stringified, and a {"version": None} tag shown not to suppress the program's own version.

No tracking issue — gap found during triage. One behavior found while scanning, the version tag being added even past MAX_TAGS, was deliberately not characterized here and is filed as #16, because the fix would be Java-visible.

Test plan

  • python3 -m unittest -v locally — Ran 50 tests ... OK (48 before)
  • CI Build matrix green on 3.8 / 3.10 / 3.12

Java parity

No Java-visible behavior changed (tests only).

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

The constructor strips surrounding whitespace from base_url, application and
key, and report() drops None tag keys/values and stringifies the rest before
merging in the program version, but no test exercised either. Lock in that a
padded base URL, application and key still yield /api/metrics, "Bearer <key>"
and the bare application name, and that a None "version" tag does not
suppress the program's own version.

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

Copy link
Copy Markdown
Member Author

Self-review rubric (one intrinsic pass, anchored on CI run 39014267037):

  • Scope: PASS — git diff --stat origin/main shows only tests/test_trace_client.py, +19/-0; no production code, formatting or renames.
  • Tests-new: PASS (N/A) — no new public names; the two added tests cover existing, previously unexercised branches of __init__ (strip of base_url/application/key) and of _with_version reached through report().
  • Tests-fix: N/A — characterization cycle, no fix; production code is untouched. The distinguishing power of each assertion was checked by reading the code path: without .strip() the padded base URL would fail in urllib.request.Request (nothing arrives), the body would carry " MyGame ", and the header would be Bearer k-123, so each assertion would fail on an unstripped value.
  • Sibling structure: PASS — both tests follow the neighbours' pattern (_Capture loopback server, arrived.wait(5), close() at the end, assertion messages naming the promise).
  • Sibling renames: N/A — nothing renamed.
  • Docs: PASS — the README/docstrings already describe trimming and that tags are copied; nothing in the Phase 7 table changes for a tests-only diff.
  • Issue resolution: N/A — no Closes; the one behavior deliberately left uncharacterized (version tag past MAX_TAGS) is filed as The version tag is added even when it pushes an event past MAX_TAGS #16.
  • CI: PASS — test (3.8), test (3.10), test (3.12) all green on the PR head.
  • Stdlib-only: PASS — git diff origin/main | grep '^+.*import' is empty.
  • Py3.8 floor: PASS — test (3.8) green.
  • Never-raises / never-blocks, Log level, Version agreement, Exports: N/A — no production change; version string still 0.4.1 in all five places.
  • Java parity noted: PASS — the PR body states no Java-visible behavior changed.

Findings:

  • tests/test_trace_client.py:100 — the User-Agent check uses endswith("(MyGame)") rather than equality. This is weaker than the exact match in test_user_agent_names_the_client_version, but intentionally so: that test already pins the version prefix, and this one only asserts that the application name is trimmed. Left as-is; flagged as a judgment call.

Summary: tests-only, CI green across the matrix; ready for human review.

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 ba432b1 into main Oct 18, 2026
3 checks passed
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