Repository navigation
test: clear DTCTL_* variables in the cmd test binary - #872
Conversation
TestMain now unsets every DTCTL_* variable, so the cmd tests no longer depend on settings such as DTCTL_OUTPUT exported in the host shell. The re-exec guard asserts the child sees none, and its marker variable drops the DTCTL_ prefix so TestMain does not unset it.
There was a problem hiding this comment.
🟡 Changes recommended
The PR description contains unrelated pyfixest content and does not accurately document the DTCTL_* test-environment isolation change or its verification.
1 open issue
What changed in this PR
This PR isolates the cmd test binary from inherited DTCTL_* environment variables, preventing developer-specific settings from affecting test behavior.
Changes:
- Clears inherited
DTCTL_*variables before running the command test suite while preserving the test-only keyring setting. - Extends the subprocess regression test to verify that
DTCTL_*variables are removed. - Uses a non-
DTCTL_child-process marker so it survives environment cleanup.
| File | Description |
|---|---|
| cmd/main_test.go | Clears inherited DTCTL_* environment variables before command tests and validates the cleanup in a re-executed test process. |
Review effort: Lite
There was a problem hiding this comment.
❌ request changes
Request changes: clearing the config override can redirect mutating tests into a developer’s project config, and Windows environment variables are not fully scrubbed. The PR description also describes unrelated Python changes and should be corrected.
Review by DynaDev AI. Think this review is incorrect or incomplete? Report a DynaDev review issue, including this PR URL and the review-comment permalink.
Config-mutating tests now run from their own temp working directory as well as an isolated XDG config home, so a .dtctl.yaml in the repo or a parent directory is never discovered and rewritten. TestMain matches DTCTL_ case-insensitively, because Windows environment names are case-insensitive. The re-exec guard now also sets a mixed-case dtctl_ variable to cover that path.
There was a problem hiding this comment.
🔵 Needs a closer look
Windows-specific environment scrubbing remains insufficiently verified because testing was limited to Linux, leaving mixed-case handling, duplicate-name cleanup, and the child guard unvalidated.
No open issues 🎉
1 resolved since last review
Review effort: Lite
There was a problem hiding this comment.
💬 comment
Request changes: the config isolation fix is incomplete when the temporary directory is beneath a developer-owned .dtctl.yaml. The case-insensitive environment cleanup is fixed.
Follow-up Review — ✅ Fixed (1) ·
🔄 cmd/config_test.go:26 — partially addressed (Lines 23–26 change into t.TempDir(), but that directory can be under the repository when TMPDIR points there. Discovery still walks to the filesystem root, and TestConfigSetCmd can rewrite an ancestor .dtctl.yaml; pinning DTCTL_CONFIG to the temporary config would prevent discovery.)
✅ cmd/main_test.go:55 — fixed (Lines 55–56 use strings.EqualFold for the prefix, and lines 65–69 unset matches. The re-exec test supplies a mixed-case dtctl_context at line 144 and checks that it is absent.)
isolateConfigHome already chdirs into a temp directory and sets XDG_CONFIG_HOME, but discovery still walks from that directory to the filesystem root. When TMPDIR is inside the repository, that walk can find a developer-owned .dtctl.yaml and a config-mutating test can rewrite it. Pin DTCTL_CONFIG to the temporary global config file so Load and Save skip discovery entirely.
|
Follow-up from the last review: isolateConfigHome now also pins DTCTL_CONFIG to the temporary global config file (ae2a5ac). That skips discovery entirely, so a .dtctl.yaml above the temp directory cannot be loaded or rewritten even when TMPDIR sits inside the repo. |
There was a problem hiding this comment.
🔵 Needs a closer look
Approval is deferred because the change depends on Windows-specific case-insensitive environment and process-isolation behavior that was not validated beyond Linux, requiring Windows CI or a maintainer run.
No open issues 🎉
Review effort: Lite
There was a problem hiding this comment.
💬 comment
Request changes: the original config-mutation risk is only partially addressed. The named config and context tests are isolated, but the command probes can still rewrite an ancestor .dtctl.yaml, so the linked issue’s host-independence scope remains incomplete.
Follow-up Review — ✅ Fixed (0) ·
🔄 cmd/main_test.go:65 — partially addressed (The helper at cmd/config_test.go:27-31 pins the named tests to a temporary config, including when the temp directory is below the repository. However, isolateProbeHost clears DTCTL_CONFIG and changes into a temp directory (cmd/file_flags_probe_test.go:35-45); TestFileFlagsAreDeclared then runs config-mutating commands through runProbe without blocking them. If that temp directory is below a real .dtctl.yaml, their load and save paths can still discover and rewrite it.)
There was a problem hiding this comment.
💬 comment
Request changes: the original config-mutating tests are isolated, but the probe isolation still permits a destructive write to an ancestor config. The delta can replace that config's known fields with an empty test configuration.
Follow-up Review — ✅ Fixed (0) ·
🔄 cmd/file_flags_probe_test.go:47 — partially addressed (isolateConfigHome at cmd/config_test.go:27-31 pins the config and changes directory for the cited config and context tests. However, the probe helper at cmd/file_flags_probe_test.go:47 only sets the process environment; concurrent session probes scrub that value from their invocation overlay, allowing writes to discover an ancestor config. The new guard at lines 399-405 checks the environment value but does not exercise a write.)
Session-backed Concurrent probes scrub DTCTL_CONFIG from the invocation overlay, so saveConfig fell through to FindLocalConfig and could overwrite an ancestor .dtctl.yaml with an empty config. Re-grant the isolateProbeHost pin through RunOptions.Env and cover the write path with a regression test.
There was a problem hiding this comment.
💬 comment
Request changes: both previously identified config-write hazards are fixed, but the linked issue remains incomplete because some tests still load the developer’s config. The new ancestor-preservation test also has a non-blocking coverage gap.
Follow-up Review — ✅ Fixed (2) ·
✅ cmd/config_test.go:27 — fixed (Lines 27–31 set a temporary XDG config home, change to that directory, and pin DTCTL_CONFIG to its config file. The affected config and ctx tests use this helper; the explicit pin also prevents discovery above a temporary directory.)
✅ cmd/file_flags_probe_test.go:219 — fixed (Lines 219–230 pass the process’s temporary config pin through RunOptions.Env, which is applied after session scrubbing. The config-save path therefore uses that pin rather than ancestor discovery; lines 429–459 add the requested ancestor-config scenario.)
Clearing DTCTL_* left Run-level tests discovering a host .dtctl.yaml or global config. Pin a minimal config after the scrub, keep discovery tests able to clear the pin, and require the ancestor-preservation probe to succeed with the editor saved on the pinned path.
There was a problem hiding this comment.
💬 comment
Request changes: both previous findings are fixed, but the linked issue remains partially unresolved. A discovery test still reads the developer’s global config, including any inline credentials.
Follow-up Review — ✅ Fixed (2) ·
✅ cmd/file_flags_probe_test.go:453 — fixed (Lines 453–466 now require a zero exit code, load the pinned config, verify the editor is vim, and then compare the ancestor file.)
✅ cmd/main_test.go:88 — fixed (Lines 88–99 create a minimal test-owned config and pin DTCTL_CONFIG before the suite runs; config.Load prioritizes that path over discovery. Discovery-specific helpers clear the pin, although the alias discovery test has the separate global-config issue reported above.)
…dentials Clearing the DTCTL_CONFIG pin lets markLocal load the global config for host bindings. Point XDG_CONFIG_HOME at a test-owned directory in TestMain (and again before enabling discovery in TestResolveAlias_LocalConfigIgnored) so issue Dynatrace#826's no-host-credential-read requirement holds.
There was a problem hiding this comment.
🟢 Approval recommended
The changes isolate inherited environment, configuration, credentials, and working-directory state while adding regression coverage for concurrent writes and ancestor preservation, with no active issues identified.
No open issues 🎉
Review effort: Lite
There was a problem hiding this comment.
✅ approve
No critical code-review findings remain open. 2 warnings or nits are still open and don't block approval; their threads stay unresolved.
Approve: the previous host-config credential-read finding is fixed. Two non-blocking issues remain in the new test isolation and its coverage.
Follow-up Review — ✅ Fixed (1) ·
✅ cmd/alias_resolve_test.go:221 — fixed (TestMain sets XDG_CONFIG_HOME to its temporary config directory and reloads XDG at cmd/main_test.go:94-108. The alias test independently sets and reloads an isolated XDG home before clearing the pin and calling Load at lines 219-231, so markLocal resolves the global config under that temporary home.)
With a relative GOTMPDIR, TempDir after chdir can fail and a relative XDG_CONFIG_HOME stops resolving. Create temps first and use absolute paths. Assert ConfigDir in a decoy-host child without Reload so a missing xdg.Reload in TestMain is not masked. Signed-off-by: Beehtrix <walkin_danger@hotmail.com>
There was a problem hiding this comment.
✅ approve
Approve. Both previous findings are fixed, and no new regressions were identified in the delta.
Follow-up Review — ✅ Fixed (2) ·
✅ cmd/alias_resolve_test.go:214 — fixed (Lines 169–219 create all three temporary directories before changing directories and convert the paths used afterward to absolute paths; the chdir occurs at line 225.)
✅ cmd/main_test.go:185 — fixed (Lines 194–210 start a child with a decoy XDG_CONFIG_HOME. The child checks ConfigDir and DefaultConfigPath at lines 185–189 without reloading first, so it verifies the reload in TestMain.)
discostu105
left a comment
There was a problem hiding this comment.
LGTM. The iterations with the bots converged on the right design: scrub DTCTL_* case-insensitively, pin DTCTL_CONFIG to a file the test binary owns, isolate XDG_CONFIG_HOME and reload xdg, and make discovery tests opt out of the pin explicitly. I ran go test ./cmd/ on the head with DTCTL_OUTPUT=json and a lowercase dtctl_plain=1 exported, and it passes, which is the scenario from #826. Nothing in CI depends on DTCTL_* reaching cmd tests. No product code changes, so the risk is low.
One nit: in cmd/main_test.go the big TestMain doc comment (scrub, pin, XDG, data dir) now ends directly above isDTCTLVar, because the helpers were inserted between the comment and func TestMain. Godoc attaches all of it to isDTCTLVar. Move the two helpers above the comment, or below TestMain.


Summary
Makes the cmd test binary independent of the developer's shell and config.
TestMainunsets everyDTCTL_*variable, matching the prefix case-insensitively because Windows environment names are case-insensitive. The re-exec guard asserts the child sees none, and its environment includes a mixed-casedtctl_contextvariable to cover that path.config_test.goandctx_test.gorun from their own temp working directory as well as an isolated XDG config home. A.dtctl.yamlin the repo or a parent directory is therefore never discovered and rewritten.Fixes #826
Verification
go vet ./cmd/andgo test ./cmd/ -count=1pass locally on Linux.