Skip to content

Test the install ID file's length limit, its failure logs and an explicit ID's character set - #23

Merged
dmccoystephenson merged 1 commit into
mainfrom
trace/install-id-file-edge-tests
Oct 23, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
trace/install-id-file-edge-tests

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) of the per-installation ID code in TraceClient.install_id_from_file and the constructor's install_id= handling. These are characterization tests only. No production code is changed.

  • test_install_id_from_file_takes_an_id_of_exactly_the_tag_length_limit: a line of exactly MAX_TAG_LENGTH characters is accepted as the ID. Until now only the over-limit side (256) was tested. Lines with characters outside [A-Za-z0-9_.-] (a slash, an inner space) are skipped, and a file that already holds an ID is not rewritten.
  • test_install_id_file_failures_are_logged_at_debug_only: both failure branches (could not read, could not write) log one [trace]-prefixed record each, and nothing above DEBUG. To reach the write branch, os.makedirs is made to fail with a mock for a file that does not exist.
  • test_explicit_install_id_is_sent_as_given_without_the_files_character_rule: an ID passed as install_id= is only trimmed and length-checked. It is not held to the file's character rule, which matches the constructor docstring and the README.

Observation (not changed here)

test_unwritable_install_id_file_yields_an_in_memory_id_and_never_raises puts the ID path under a regular file. That path fails on the read (NotADirectoryError), not the write, so the "could not write" branch is not what it exercises. The outcome it asserts (an in-memory ID, nothing created) holds either way, and the new log test now covers the write branch directly. The test's name could be tightened in a later cycle.

Deferred

Java parity

No Java-visible behavior changed (tests only).

Test plan

  • python3 -m unittest -v on Python 3.8.10 locally: Ran 67 tests, OK
  • CI Build: test (3.8), test (3.10), test (3.12)

No tracking issue. The 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

…icit ID's character set

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

Copy link
Copy Markdown
Member Author

Self-review rubric (Phase 4), scored against the diff and CI on head bdc37c1:

  • Scope: PASS. git diff origin/main --name-only lists only tests/test_trace_client.py (+30 lines, all test code).
  • Tests-new: PASS (N/A). No new public names; three tests were added for existing behavior.
  • Tests-fix: N/A. Characterization only, no production fix to revert.
  • Sibling structure: PASS. The tests sit in the existing per-installation-ID section of TraceClientTest, reuse _tmpdir/_sent_tags/self.log, and use long plain-words names.
  • Sibling renames: N/A. Nothing was renamed.
  • Docs: PASS. No behavior changed. The new tests assert what the install_id_from_file docstring and the README "Where it lives" section already say (first valid line, at most 255 characters, never overwrites, never raises).
  • Issue resolution: N/A. No Closes. The gap was found during triage, and The version tag is added even when it pushes an event past MAX_TAGS #16's deferral is recorded in the PR body.
  • CI: PASS. test (3.8), test (3.10) and test (3.12) are green on the PR head.
  • Stdlib-only: PASS. git diff origin/main | grep -c '^+.*import' gives 0, and pyproject.toml is untouched.
  • Py3.8 floor: PASS. test (3.8) is green, and the local run on 3.8.10 also passed (Ran 67 tests, OK).
  • Never-raises / never-blocks: N/A. No production code changed.
  • Log level: PASS. No _LOG. lines were added. The new test asserts that both install-ID failure paths log only at DEBUG.
  • Version agreement: PASS. No version string was touched.
  • Exports: N/A. No new public names.
  • Java parity noted: PASS. The PR body says no Java-visible behavior changed.

Judgment calls:

  • tests/test_trace_client.py:719 — mock.patch("trace_client.trace_client.os.makedirs", ...) patches the shared os module's attribute, so the patch applies process-wide while the with block runs. Nothing else calls os.makedirs during that window (no sender thread is alive in this test), so it is safe as written. A future test that runs work concurrently inside such a block would need to scope it more narrowly.
  • The existing test_unwritable_install_id_file_yields_an_in_memory_id_and_never_raises exercises the read-failure branch, not the write-failure branch (this is described in the PR body). Its assertions still hold. A rename is left for a later cycle so that this PR stays additive.

Summary: tests-only, additive, CI green on all three interpreters, and no do-not-auto-merge path is touched.

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 7be2622 into main Oct 23, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the trace/install-id-file-edge-tests branch October 23, 2026 13:17
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