Files
OpsLog/relaunch_test.go
T
rouggy f8d47cd3b5 fix(linux): the update relaunch is per-platform again
Restoring the PowerShell helper put it in update.go, which is shared —
so a Linux build would have tried to run `powershell` to relaunch
itself. It compiled and vetted cleanly for linux/amd64, which is exactly
why it needed catching before somebody built it: the fault only shows on
a real update, on a machine that has no PowerShell.

scheduleRelaunch now lives in the platform files. Windows keeps the
helper. Linux starts the new binary directly, which is right there and
not a compromise: nothing holds an executable open while it runs, so the
swap has already succeeded, and there is no mutex to race — the
single-instance guard is an flock the dying process releases as it
exits, and the new one waits for our pid first.

The two guards were looking at the old location and had to follow: the
Wait-Process/Start-Process check moves into relaunch_windows_test.go
where it belongs, and TestEveryRelaunchPassesItsPid now scans
updateswap_linux.go too — the direct spawn moved there, and without it
the test would have gone quiet again.

Checked from Windows, as BUILDING-LINUX.md says is done at every
release: GOOS=linux go build ./... and go vet ./... both clean.
2026-09-11 09:28:55 +02:00

32 lines
1.4 KiB
Go

package main
import (
"path/filepath"
"testing"
)
// A relaunch of OpsLog itself must not suppress the new process's window.
//
// SysProcAttr is where that damage was done: hideConsole sets HideWindow, which
// on Windows becomes SW_HIDE in the STARTUPINFO, and Windows applies it to the
// first top-level window the new process shows. The updated OpsLog started,
// took the single-instance mutex and connected the rig — invisibly. Two
// operators on 0.27.23 reported it as "it goes to reload and just fails to
// load": a process in the task manager, no window, and killing it then starting
// it by hand working every time.
//
// The window flags themselves are asserted in relaunch_windows_test.go, where
// SysProcAttr has the fields to look at.
func TestRelaunchCmdPassesItsArgumentsAndFolder(t *testing.T) {
cmd := relaunchCmd(filepath.Join("C:", "OpsLog", "OpsLog.exe"), "--post-update", "--wait-pid", "1234")
if len(cmd.Args) != 4 || cmd.Args[1] != "--post-update" || cmd.Args[3] != "1234" {
t.Errorf("args = %v, want the exe plus the three passed through", cmd.Args)
}
// The working directory matters: the new instance keeps its data folder
// beside the executable, and inheriting the old process's cwd would look for
// it somewhere else entirely.
if cmd.Dir != filepath.Join("C:", "OpsLog") {
t.Errorf("Dir = %q, want the executable's folder", cmd.Dir)
}
}