Skip to content

Test that the environment fails closed per variable and is read once - #41

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/test-environment-read-once
Nov 20, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/test-environment-read-once

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) for the opt-out contract made fail-closed in 0.4.0 (#40). Tests only; no production code is changed.

  • EnvironmentDisables_IsTrueWhenEitherVariableAloneCannotBeRead — the existing sandbox test makes every environment read throw. This theory makes only one variable unreadable while the other reads as clearly "on" (TRACE_USAGE_REPORTING=on or DO_NOT_TRACK=0), and pins that the client still fails closed with reason environment and sends nothing.
  • Environment_IsReadOnceInTheConstructorSoALaterOptOutDoesNotStopAClient — DisabledReason is documented as "decided once, in the constructor". Setting DO_NOT_TRACK=1 after construction is shown to leave an enabled client reporting, while EnvironmentDisables() already answers true.
  • Environment_IsReadOnceInTheConstructorSoALaterOptInDoesNotStartAClient — the reverse: clearing TRACE_USAGE_REPORTING=off after construction does not turn a disabled client back on ("nothing in this client ever turns a switch back on").

These are characterization tests of current, documented behaviour. The second test pins a property a maintainer may later choose to change (re-checking the environment per report); if so, it is the test to update.

No tracking issue — the gap was found during triage by reading the constructor and EnvironmentDisables against TraceClientTest.cs.

Skipped issues

All three open issues are behaviour-contract decisions reserved for the maintainer, so none was picked:

Test plan

  • Build workflow green on ubuntu-latest (net8.0)
  • Build workflow green on windows-latest (net8.0 + net48)
  • New tests appear in the run's test count

dotnet is not installed in the sandbox this PR was prepared in, so the tests were not run locally; the CI matrix on the PR head is the verification.

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

Pins two parts of the 0.4.0 opt-out contract that had no test: one
unreadable variable disables reporting even when the other says "on",
and the environment is consulted only in the constructor, so a later
change neither stops an enabled client nor starts a disabled one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (anchored on CI run 44688680905 on the PR head):

  • Scope: PASS — only tests/TraceClient.Tests/TraceClientTest.cs is modified (+65 lines). All of it serves the Stage B target (the opt-out environment checks).
  • Tests-new: PASS (not applicable) — no new public member was added.
  • Tests-fix: PASS (not applicable) — no production code changed; these are characterization tests of current behaviour.
  • Sibling structure: PASS — the new tests use the existing _environment / EnvironmentSource seam, the _server fixture, Subject_BehaviourInPlainWords naming and why-comments, the same as the neighbouring EnvironmentDisables_IsTrueWhenTheEnvironmentCannotBeRead.
  • Sibling renames: PASS (not applicable) — nothing was renamed.
  • Docs: PASS — no behaviour changed. The tests pin what the DisabledReason XML doc ("Decided once, in the constructor"), the class remarks and the README "Turning it off" section already say.
  • Issue resolution: PASS (not applicable) — no Closes; the PR body says there is no tracking issue.
  • CI: PASS — ubuntu-latest net8.0 and windows-latest net8.0 + net48 are all green with 166 tests each. That is up from 162 on main run 44466066340, so all 4 new cases (2 theory rows and 2 facts) ran on every target.
  • No dependencies / single file / vendoring floor / environment seam / version agreement / opt-out contract: PASS — src/ is untouched.

Findings for a human to weigh:

  • tests/TraceClient.Tests/TraceClientTest.cs (EnvironmentDisables_IsTrueWhenEitherVariableAloneCannotBeRead, Environment_IsReadOnceInTheConstructorSoALaterOptInDoesNotStartAClient) — Thread.Sleep(100) before Assert.Empty. For a disabled client it is redundant rather than load-bearing, because a disabled client has no queue or thread and cannot send. It mirrors TraceUsageReporting_DisablesReportingForAnythingButAClearOn, so it cannot flake in the passing direction.
  • Environment_IsReadOnceInTheConstructorSoALaterOptOutDoesNotStopAClient pins a property that a maintainer may later choose to change: honouring a DO_NOT_TRACK set mid-run. That would be a contract change, and this test is the one to update.

Summary: a tests-only Stage B PR that is green on every CI leg and touches no do-not-auto-merge path.

This 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 ec77794 into main Nov 20, 2026
2 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/test-environment-read-once branch November 20, 2026 06:36
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