Repository navigation
What a test changes for itself stays in its own task: no more shared statics in HeedCore - #279
Merged
Merged
Conversation
…statics in HeedCore Chats.localRoot, Paths.home, StartWorkForm.newSessionID and Clock.fixed were nonisolated(unsafe) statics. ChatStartTests swapped the chats root while other suites ran beside it and read it. They are now one value, HeedContext (home, chats root, pinned time, session id maker). Code reads HeedContext.current: the task's own when a test set one with HeedContext.with, else the process's. The old names stay as read-only properties, so the call sites (Clock.now has about 480) do not change. Why a task local and a process value, and not values passed in: the screenshot and tutor-check runs pin the fake world for the whole app, and SwiftUI draws from the run loop, outside any task, so their pin has to belong to the process (HeedContext.pinProcess, behind a Mutex, set once at the start of those runs as before). Tests need the opposite, a change only their own task tree sees, which is what @TaskLocal gives. Threading the values through every caller of Clock.now and Paths.split would not buy more isolation than that. The same for other process-wide state tests changed: - Remote.setTargets and setExtraOptions (the ssh integration tests) are gone; Remote.with(targets:extraOptions:) scopes them to the test's task. The app still sets the configured routes with setRoutes. - GitEnvironment.isolate() was a one-way switch the first git test turned on for the whole process, so a test that forgot it behaved differently depending on what ran before. The test bundle's constructor (HeedTestProcess.c) now sets the same variables before any test runs, and isolate() is gone. - GitEnvironmentTests set GIT_DIR and friends with setenv for the whole process; it now hands them to its own commands with GitEnvironment.$inheritedOverride. Looked at and left: PullTrustBook, WriteAccessBook, ToolLocator, TailscaleCLI (shared caches behind a Mutex or an actor, which no test changes), GitHub.$executable and the other task locals, AuditTap and CallLog install (only the app calls them), and HeedApp's statics (main-actor app state, not reached by the tests). .swiftlint.yml now rejects a nonisolated(unsafe) static var in Sources, and pinProcess, setenv, setRoutes and the AuditTap and CallLog installs in Tests. HeedContextTests reads while a neighbour's override is in effect; with `with` changed to set the process value, as the statics did, both of its tests fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and use Remote.with Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mpdreamz
force-pushed
the
fix/no-global-state
branch
from
November 16, 2026 17:40
c8df764 to
368196b
Compare
Mpdreamz
added a commit
that referenced
this pull request
Nov 16, 2026
) Main's lint fails: #279 added the `no_unsafe_static_var` rule and #273 (light theme) added two `nonisolated(unsafe) static var`s in GhosttyRuntime. The class is @mainactor and every use of `isDark` and `started` is on it, so the statics drop `nonisolated(unsafe)` and are main-actor isolated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 9 of the code-health plan (
fix/no-global-state).What was global, and what it is now
Chats.localRoot,Paths.home,StartWorkForm.newSessionID,Clock.fixed(nonisolated(unsafe) static var)HeedContextvalue. Code readsHeedContext.current: the task's own (HeedContext.with, used by tests), else the process's (HeedContext.pinProcess, behind a Mutex, called only by the shot runner and tutor check). The old names are read-only properties, soClock.now's ~480 call sites are unchanged.Remote.setTargets/setExtraOptions(ssh integration tests)Remote.with(targets:extraOptions:), a task local. The app keepssetRoutesfor the configured routes.GitEnvironment.isolate(), a one-way process switch the first git test turned onHeedTestProcess.c) before any test runs;isolate()is removed.GitEnvironmentTestsusedsetenv("GIT_DIR", …)on the whole processGitEnvironment.$inheritedOverridefor its own commands.Why a task local plus a process value, not values passed in: the screenshot and tutor-check runs pin the fake world for the whole app, and SwiftUI draws from the run loop, outside any task, so that pin has to belong to the process. Tests need a change that only their own task tree sees, and
@TaskLocalgives exactly that. Threading the values through every caller would not isolate anything further.Looked at and left:
PullTrustBook/WriteAccessBook/ToolLocator/TailscaleCLI(shared caches behind a Mutex or an actor, and no test changes them),GitHub.$executableand the other task locals,AuditTap/CallLog.install(only the app calls them), and HeedApp's main-actor statics.Lint
.swiftlint.ymlnow has two custom rules.no_unsafe_static_varrejects anonisolated(unsafe) static/class varin Sources, in either modifier order.tests_change_no_process_staterejectsHeedContext.pinProcess,setenv/unsetenv/putenv,Remote.setRoutes,AuditTap.installandCallLog.installin Tests. I checked both rules with a probe file containing violations: 5 of 5 were flagged.Verification
mise run fmt,mise run lintclean.mise run test: 2546 tests passed.HeedContextTestsreads a value while another task's override is in effect. I changedHeedContext.withto set the process value, as the statics did, and both of its expectations failed. I changedRemote.withto set the global routes, and that test failed too. Both changes are reverted.GitEnvironmentTestsstill expects the commit authorheed test, which only the constructor now sets.Not tested
RemoteIntegrationTests,RemoteSessionsIntegrationTests) needHEED_SSH_TEST. They compile but did not run.mise run shotsor the tutor check, which are thepinProcesscallers. The pinned values are the same as before.mise run live.🤖 Generated with Claude Code