Repository navigation
Description
Summary
On Windows, zero doctor saves a new entry in windows-cap-sids.json for the directory it runs in, although it is only validating the sandbox setup marker. The doctor tests in internal/cli run it from a fresh temp directory with the sandbox home resolved from the real environment, so every run of the suite appends to the developer's real %USERPROFILE%\.config\zero\windows-cap-sids.json.
Reproduction
main at 8288ae81, Windows 11, restricted-token backend with setup already done.
- Count the keys under
workspaceByRootin%USERPROFILE%\.config\zero\windows-cap-sids.json. go test ./internal/cli -run 'TestRunDoctorFormatsRedactedProviderDiagnostics$' -count=1- Count again.
Here it went from 4010 to 4011 and the file grew by 96 bytes. The new key is the test's temp directory.
That file on my machine now holds 4,011 workspace roots and is 710 KB. About 3,350 of them are temp directories from six doctor tests, 550 to 570 each: TestRunDoctorConnectivityProbesProvider, TestRunDoctorConnectivityReportsProviderHealthFailure, TestRunDoctorConnectivityDoesNotMaskConfigHealthFailure, TestRunDoctorFormatsRedactedProviderDiagnostics, TestRunDoctorJSONReturnsFailureForMissingProvider and TestRunDoctorReportsConfigValidationForMalformedFile.
Cause
windowsSandboxSetupCheckininternal/doctor/hardening.goresolves the sandbox home withsandbox.ResolveWindowsSandboxHome(nil), which reads the process environment, and then callssandbox.ValidateWindowsSandboxSetupMarker.- Validation builds the expected marker with
BuildWindowsSandboxSetupMarker. That derives the capability SIDs for the workspace throughWindowsWorkspaceCapabilitySID, which generates a SID for any root it has not seen and writes the whole file back. internal/doctor/hardening_test.gosetsZERO_WINDOWS_SANDBOX_HOMEto a temp directory for its own tests. Theinternal/clidoctor tests uset.TempDir()as the working directory and do not, so each run is a root the real file has never seen.
Why it matters
- Tests must not write the developer's real config directory. Test suite is not hermetic: config, cache and home dirs leak into tests #1103 closed that class in general; this path is still open on Windows.
- Outside tests, a diagnostic command changes persistent state: running
zero doctoronce in a directory leaves a capability entry for it. Nothing removes entries, and the file is loaded on every sandboxed launch.
Suggested direction
- Validation should look a root up, not create it. A root with no entry cannot match the recorded ACL plan anyway, so "setup is missing or out of date" is already the right answer for it.
- Redirect the sandbox home in the
internal/clidoctor tests, or pass the environment intowindowsSandboxSetupCheckso the test's own environment decides. A test that fails when the real sandbox home is touched would keep it closed. - Pruning entries whose root no longer exists is a separate question and could wait.
#808 and #901 both rework this part of the sandbox, so the fix is easiest after they land. I can take it then.
Activity
test(cli): isolate the doctor tests from the real per-user state (#1240)