Files
magpie/internal
TryWorldandTryWorld c31dcb8824 fix(autostart): turning Open at login off says so when the Run key refuses it (#1081)
* autostart: the Run key is reached through one variable

disable and enabled open HKCU\...\CurrentVersion\Run themselves, so a test can
only reach whatever the real user's key answers — and this machine's own Run key
opens with SET_VALUE, which is exactly the case that hides the bug. One variable
holds the open, so a test can hand back a key the user's ACL refuses, as the
probe key this change was checked against did.

No behaviour changes: the variable is registry.OpenKey, and the two call sites
answer as they did.

* fix(autostart): turning Open at login off says so when the Run key refuses it

magpie autostart off returned success for every error from opening
HKCU\...\CurrentVersion\Run, and the Settings switch did the same, when the
Run key's ACL denies the user SET_VALUE: the magpie value was left where it
was, Windows started it again at the next sign-in, and the switch showed
off. Confirmed on this machine with a probe key under HKCU whose ACL denies
SET_VALUE but allows QUERY_VALUE: OpenKey with QUERY_VALUE reads the value
fine while OpenKey with SET_VALUE returns Access is denied, which is not
registry.ErrNotExist, so the old disable() read it as "nothing to turn off".
The probe key was removed afterwards; the real magpie Run value was never
opened for writing.

disable() now returns an error that isn't a missing key, as the three
file-backed platforms already do: they ignore only "the record isn't there"
and report the rest. The other OpenKey calls in the file are classified the
same way, each through its own variable so a test can refuse it:
enabled() told the two apart already; switchedOff() now returns errors.Is(err,
registry.ErrNotExist), because a marker that cannot be read is not "switched
off" either — the Run value is what starts magpie, and reporting off would
hide that; and what enable() did to the marker unchecked is now
clearApprovedMarker(), which returns every error that isn't a missing marker,
so Set(true) no longer answers success while Task Manager's Startup apps
marker still tells Windows to leave magpie switched off. The Run value is
written before the marker is cleared either way, so that is the one step
left that can leave the switch on and Windows starting nothing.

TestDisableReportsAKeyItCannotReach checks that Set(false) returns an error
for Access is denied and none for ErrNotExist.
TestEnabledUnreadableKeyIsNotOff checks that a Run key that cannot be read is
not read as off while a missing one is.
TestClearApprovedMarkerReportsOneItCannotReach checks the same pair for
clearApprovedMarker, and TestSwitchedOffUnreadableMarkerIsNotOff that a
marker which cannot be read is not read as switched off while a missing one
is. Run here against disable() as it answers every error with nil,
TestDisableReportsAKeyItCannotReach fails with "a Run key that refuses
SET_VALUE was reported as turned off"; against clearApprovedMarker() as it
returns nil for an OpenKey error and drops DeleteValue's, it fails with "a
Startup apps marker that cannot be cleared was reported as on"; and with
switchedOff() still folding its OpenKey error into false,
TestSwitchedOffUnreadableMarkerIsNotOff fails with "no marker reads as not
switched off". All four pass with the change. TestSet still skips on Windows,
where the Run key is the real user's; none of the new tests opens it.

go vet, gofmt (on LF-normalized copies, since the worktree is CRLF), the
windows, darwin and linux builds and test compiles, and
go test -race ./internal/autostart pass. The real Run key on this machine
still opens with SET_VALUE, so the ordinary path is unchanged; only a key the
ACL does refuse is reported. The StartupApproved\Run key itself was not
probed — this machine has no marker for Task Manager to have switched off —
so that half rests on the four tests and on OpenKey answering a key with the
refusing ACL the way it answered the Run key above.

* fix(autostart): no Startup apps marker at all is not switched off

switchedOff answered errors.Is(err, registry.ErrNotExist) for a Startup
Approved\Run key it could not open, so a machine with no such key at all
read as switched off. Windows writes that key the first time Startup apps
lists an entry: a user who never opened Task Manager's Startup apps has no
key, while every Run value the machine has is on. enabled() ends in
!switchedOff(), so Settings showed "login: off" and the tray said magpie
doesn't open at login for a magpie that does start at every sign-in.

Only a marker that says so is switched off now: one that is missing, or
that cannot be read, is not. The comment above the function said as much
already, which is what gave the wrong answer away.

TestSwitchedOffUnreadableMarkerIsNotOff had pinned the wrong half of this:
its last pair asserted that no marker reads as switched off. It is now
TestSwitchedOffUnreadableOrAbsentMarkerIsNotOff, asserting neither case
is. TestEnabledWithNoMarkerIsOn covers the real machine the first one could
not: the Run value there, the marker key not, which is what a user who has
never opened Startup apps has.

The Run value's read goes through readRunValue beside openRunKey and
openApprovedKey, so a test can hand back a value with no Run key of its
own: the package's other tests skip on Windows because the Run key is the
real user's, and these read it.

---------

Co-authored-by: TryWorld <TryWorld2026@users.noreply.github.com>
2026-10-13 12:27:31 +08:00
..
…
…