Skip to content

Keep the tests off the machine's launchd - #2

Open
MaxFreedomPollard wants to merge 1 commit into
mainfrom
claude/hopeful-tharp-bbc2ee
Open

Keep the tests off the machine's launchd#2
MaxFreedomPollard wants to merge 1 commit into
mainfrom
claude/hopeful-tharp-bbc2ee

Conversation

@MaxFreedomPollard

@MaxFreedomPollard MaxFreedomPollard commented Aug 1, 2026

Copy link
Copy Markdown
Owner

The suite deregistered the real login agent. Two macOS tests redirected HOME and called set_login for real. That moves the plist but not the launchd domain: _gui_domain() asks the real uid and LAUNCH_AGENT_LABEL is a module constant, so running the tests booted the developer's own agent out of launchd, left ~/Library/LaunchAgents/io.github.maxfreedompollard.compartment.menubar.plist on disk unloaded, and bootstrapped a job under the real label that RunAtLoad then started. They also wrote and codesigned a bundle in the real ~/Applications, because USER_APP_BUNDLE is bound at import while HOME is still real.

menubar._launchctl now joins _systemctl and _schtasks in the autouse no_real_supervisors guard, so no test in any file reaches the real launchd by forgetting to stub it. The round trip keeps a recorder of its own and the recorded verbs are the assertion: bootout, bootstrap, print, print, bootout, unload, each naming our own job and nothing else. The plist round trip still asserts, and RunAtLoad plus KeepAlive/SuccessfulExit are both checked where only RunAtLoad was before.

Coverage against the live launchd is kept as one test behind pytest -m real_launchctl, deselected by default, which registers a per-pid label running /usr/bin/true and boots it out in a finally. It writes its plist with a vault, so launchd reading the file back is a real check that the EnvironmentVariables block is well formed.

Rebased onto main. This started as two commits; the second carried the start-at-login vault passthrough, which v4.4 shipped independently in d6af2e9, with XML escaping this branch did not have. tests/test_menu_bar_persistence.py already covers every case those tests covered, so that commit is dropped and nothing from it is re-applied.

Full suite green on macOS.

@MaxFreedomPollard
MaxFreedomPollard force-pushed the claude/hopeful-tharp-bbc2ee branch from 2851de5 to 52fa259 Compare August 1, 2026 02:04
@MaxFreedomPollard MaxFreedomPollard changed the title Keep the tests off the machine's launchd, and carry the vault into every login item Keep the tests off the machine's launchd Aug 1, 2026
A fake HOME moves the plist and nothing else. _gui_domain asks the real
uid and LAUNCH_AGENT_LABEL is a module constant, so a macOS run of
tests/test_status_bar_install.py deregistered the developer's own
Compartment agent, left the real plist on disk unloaded, and started a
second menu bar app from RunAtLoad. Confirmed by rerunning the old tests
with a launchctl of our own first on PATH, which recorded bootout of
gui/<real uid>/<real label> followed by a bootstrap of a plist in a
temporary directory.

menubar._launchctl now joins _systemctl and _schtasks in the autouse
no_real_supervisors guard, so no test in any file reaches the real
launchd by forgetting to stub it. The round trip keeps a recorder of its
own and asserts the verbs: booted out before it is bootstrapped,
confirmed by asking launchd rather than by the exit status of a verb,
and deregistered before the plist is deleted. KeepAlive is asserted
where it was not before, and the fixture also stops the login bundle
being written into the real ~/Applications, since USER_APP_BUNDLE is
bound at import, before HOME is faked.

Coverage against the live launchd is kept as one test behind
-m real_launchctl, deselected by default, which registers a per-pid
label of its own running /usr/bin/true and boots it out in a finally.
@MaxFreedomPollard
MaxFreedomPollard force-pushed the claude/hopeful-tharp-bbc2ee branch from 52fa259 to 997752d Compare August 1, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant