Repository navigation
refactor(host): route app paths and version through an AppEnvironment port - #15918
Merged
nwparker merged 6 commits intoAug 22, 2026
Merged
Conversation
Contributor
Author
|
Post-review fix pushed: the shared vitest setup allocated a Readiness review of this stack returned no P0 and reported sections 03 (security) and 06 (backcompat / data loss) clean. |
nwparker
force-pushed
the
nwparker/app-environment-port
branch
from
August 22, 2026 10:22
b7e5155 to
e74e60c
Compare
nwparker
force-pushed
the
nwparker/app-environment-port
branch
2 times, most recently
from
August 22, 2026 23:11
a5c8f3d to
cd29acb
Compare
… port
`app.getPath('userData')` is the single largest Electron coupling in the main
process — 37 call sites — and it is one of the things stopping the Orca runtime
from booting on plain Node. Give it the same treatment as SecretStore.
- `src/shared/app-environment.ts` — the port plus a settable registry, covering
the members the runtime's module graph actually reads: paths, app path,
version, packaged flag, shutdown hook, exit, and Chromium process metrics.
`getAppEnvironment()` throws until installed, for the same reason the secret
store does: a silent default resolves `userData` to the wrong directory and the
caller writes real state there before anyone notices. No `node:` imports,
because `src/shared/**` is in the web build graph.
- `src/main/host/electron-app-environment.ts` — the desktop adapter, a
pass-through to `electron.app`.
- 9 modules migrated: telemetry, opencode/mimo/pi hook services,
terminal-history-paths, terminal-scrollback-snapshots, cli-installer,
clipboard-image-temp-file, memory/collector.
Deliberately NOT migrated: `src/main/browser/**`. That cluster is Chromium-
adjacent by nature — cookie jars, download destinations, offscreen pages — and a
Node backend does not ship it at all, so porting it buys nothing and churns
heavily-mocked suites. Also left alone for now: the call sites that additionally
touch `app.asar` path literals or `app.setName`, which need more than a
mechanical swap.
`getAppMetrics` stays on the port rather than being injected because
memory/collector.ts is its only caller and reads it from module scope; a Node
host returns [], having no Chromium processes to measure.
Test wiring: the secret-store setup file becomes `vitest-host-ports-setup.ts` and
installs both ports, exporting `fakeAppEnvironment`/`installFakeAppEnvironment`
so suites needing one specific member state only that instead of restating all
seven — which is boilerplate, and had pushed one suite past the max-lines budget.
Verified: 159 files / 1651 tests pass across every touched area; `tsc` clean on
both the node and web projects; `oxlint` clean.
Three suites import `installFakeAppEnvironment` from config/scripts, but that directory is outside tsconfig.node.json's include list, so composite typecheck failed with TS6307. Listing the one file matches how this config already pins individual files it needs. Local `tsc --composite false` does not reproduce this — only `pnpm typecheck` does, which is what CI runs.
hasAppEnvironment() and resetAppEnvironmentForTests() had zero callers. The secret-store equivalents are used, so these were mirror-symmetry rather than need; add them back when something actually needs them.
…cking electron These three suites mocked `electron.app.getPath` to point at a fixture dir. The production module now reads the port, so the mock was inert and the global test default's temp dir won — which broke the WSL path assertions and every deletion count. Found by a full-suite run, not by the targeted checks around the migrated modules, which is the argument for running the whole suite on a refactor this wide.
The setup allocated a mkdtemp directory at module scope, which vitest evaluates once per test *environment* — one per test file, not one per worker. Nothing removed them, so a full 6,000-file run left thousands behind. Proven: with an isolated TMPDIR, a three-file run previously added directories and now leaves zero.
Same reason as the SecretStore: vi.resetModules() rebuilds the module registry, and an environment installed before the reset read back as uninstalled.
nwparker
force-pushed
the
nwparker/app-environment-port
branch
from
August 22, 2026 23:24
cd29acb to
66c5ccc
Compare
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.
ELI5
Everywhere Orca needs to know "where do I keep my data?" it asks Electron directly:
app.getPath('userData'). That happens 37 times across 17 files. It is the single biggest reason the Orca runtime can only run inside Electron.This PR does the same thing #15916 did for secrets: put a small interface in the middle. Code now asks "the app environment" for the path. On the desktop that's a direct pass-through to
electron.app— same paths, same behaviour. A plain-Node server can answer differently.What changed
src/shared/app-environment.tsgetPath,getAppPath,getVersion,isPackaged,onWillQuit,exit,getAppMetrics.src/main/host/electron-app-environment.tselectron.app.src/main/index.tsconfig/scripts/vitest-host-ports-setup.tsvitest-secret-store-setup.ts; now installs both ports.What is deliberately not migrated
src/main/browser/**— left onelectron.appon purpose. That cluster is Chromium-adjacent by nature: cookie jars, download destinations, offscreen pages. A Node backend does not ship it at all, so porting it buys nothing and churns three heavily-mocked suites. I started that migration, measured the cost, and reverted it — the honest boundary is thatbrowser/is the desktop cluster.Also left for later: call sites that additionally touch
app.asarpath literals orapp.setName(ssh-relay-deploy,ssh-remote-cli-host-passthrough,persistence/loading-store/user-data-path,speech/stt-service,wsl-hook-relay-launch). Those need more than a mechanical swap.Two judgement calls worth reviewing
getAppMetricsstayed on the port rather than being injected. It is Chromium process metrics, so it looks like it does not belong — butmemory/collector.tsis its only caller and reads it from module scope. Adding an injection mechanism for one call site is more code than one extra port member. A Node host returns[], having no Chromium processes to measure.getAppEnvironment()throws when uninstalled. Same reasoning as the secret store: a silent default resolvesuserDatato the wrong directory and the caller writes real user state there before anyone notices.Proof of no regressions
window,browser,telemetry,cli,memory,pi,opencode,mimo, terminal paths, shared)tsc -p config/tsconfig.node.jsontsc -p config/tsconfig.tc.web.jsonoxlint(full repo)Why the desktop cannot behave differently: the adapter is a pass-through with no added logic. Paths still resolve at call time, not install time, so the existing
app.setName/initDataPathordering thatuserDatadepends on is unchanged — that ordering is called out in a comment at the install site.Elegance pass
The naive migration had every affected suite restate all seven port members — ~7 lines × N files of boilerplate, which pushed
clipboard-ipc-handlers.test.tspast the 800-linemax-linesbudget. Rather than add amax-linesdisable (forbidden byAGENTS.md, and the wrong fix), the setup file now exportsinstallFakeAppEnvironment(overrides)so a suite states only the member it cares about. Net: fewer lines than before, and the file is back under budget at 897→ within limit.User-facing trade-offs
None. No UI, wire-format, on-disk-format, or CLI change.
Review loops
AppEnvironmentwas sitting in the tree uninstalled. The second point was correct and is fixed here — it is installed. On the first: the split is deliberate and documented in the design doc.browser/**churn as not worth its cost; reverted. Caught the max-lines breach; fixed by removing boilerplate rather than suppressing.Verdict: ready to merge, after #15916.
Follow-ups
Commits added after this PR was opened
Review found three things after the initial push; all are fixed here rather than deferred.
fix(typecheck): list the vitest host-ports setup in the node projectinstallFakeAppEnvironmentfromconfig/scripts, which is outsidetsconfig.node.json's include list →TS6307. I had verified withtsc --composite false, which does not reproduce it; onlypnpm typecheck(what CI runs) does. Fixed by listing the one file, matching how that config already pins individual files.refactor(host): drop two unused AppEnvironment exportshasAppEnvironment()andresetAppEnvironmentForTests()had zero callers — mirror-symmetry with the secret store rather than need.test(terminal-history): install the AppEnvironment fake instead of mocking electronterminal-historysuites mockedelectron.app.getPathto a fixture dir; that mock is now inert, so the global default's temp dir won and broke the WSL path assertions and every deletion count. Found only by a full-suite run — which is the argument for running the whole suite on a refactor this wide.After the last of these, I computed the precise affected set rather than spot-checking: every test file that transitively imports one of the 9 migrated modules (81 files). All 81 pass — 849 tests, 0 failures.
Final regression evidence
mainpnpm typecheck(node + web + cli projects)oxlint(full repo)