Skip to content

go test on a live Windows install deletes the production unit stubs (TestServiceUninstallWindows* missing XDG_STATE_HOME) #351

Closed

Description

@azrael-229

Running go test ./... — or even just go test ./internal/cli/ — on a machine with a live Berth install silently deletes the production stub files berthd.vbs, berth-gateway.vbs and berth-harbor.vbs from %USERPROFILE%\.local\state\berth\units\.

Mechanism: TestServiceUninstallWindows and TestServiceUninstallWindowsIgnoresEndFailure (internal/cli/service_windows_test.go) call serviceUninstall(..., dryRun=false) without setting XDG_STATE_HOME — every other test in the file does t.Setenv("XDG_STATE_HOME", t.TempDir()). With no XDG variable set, defaultStateDir() falls back to the real user state dir, and the non-dry uninstall path executes os.Remove(unitStubPath(u.Name)) for each unit (service_windows.go:332). The fake ops only fake the schtasks calls, so the real Task Scheduler is never touched — only the real files are deleted.

Repro: any machine with a live install (tasks + units\*.vbs present) → go test ./internal/cli -run TestServiceUninstallWindows → units\ loses its three production stubs.

Fix: add t.Setenv("XDG_STATE_HOME", t.TempDir()) to both tests, matching the rest of the file.

Verified on Windows 11 24H2, berth 0.6.2 (commit e451ba8).

Activity

  1. T-Crypt commented on Nov 16, 2026

    @T-Crypt
    Owner

    Thanks for the clear report. It's fixed in #352, which is on main and next. Both uninstall tests now set XDG_STATE_HOME to a temp dir. So does TestServiceInstallWindowsCommandFails, which had the same gap. I reproduced it under wine with stubs placed in the profile's state directory. The old tests deleted them. With the fix, the whole internal/cli package leaves them in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions