Feat/cli editor cache#749
Closed
IvanMurzak wants to merge 4 commits into
Closed
Conversation
Two CLI quality-of-life improvements for `unity-mcp-cli open`:
1. Editor-path cache
- New `cli/src/utils/editor-cache.ts` persists the resolved Unity
Editor binary path to `~/.unity-mcp-cli-editor-cache.json`,
keyed by Unity version (with an `__auto__` slot for the
no-version case). Same convention as the existing
`~/.unity-mcp-cli-update.json`.
- `findEditorPath` (`utils/unity-editor.ts`) checks the cache
first and returns immediately on hit, skipping the Unity Hub
Electron probe entirely. Every successful resolution writes
back to the cache (fast path, hub-resolved, and the highest-
installed fallback).
- Stale entries auto-evict on read when the cached path no
longer exists on disk; corrupted-but-existing binaries are
cleared by an `onError` hook in `openProject` (`lib/open.ts`)
so the next invocation re-resolves from scratch.
- Measured impact on Windows with the editor installed at a
non-default location (`C:\UnityEditor\<version>\Editor\Unity.exe`):
cold run ~13.0s -> warm runs ~1.2s (~10x speedup; Unity Hub
CLI invocation eliminated on the warm path).
2. Quiet Unity Hub stderr
- `listInstalledEditors` and `listAvailableReleases`
(`utils/unity-hub.ts`) now pipe stderr via
`stdio: ['ignore', 'pipe', 'pipe']` instead of inheriting it.
Unity Hub is an Electron app and its embedded Chromium
routinely logs benign `quota_database.cc` errors to stderr
which previously leaked into the terminal during a successful
editor probe. Captured stderr is appended to the surfaced
error message in the catch path, so real Hub failures stay
diagnosable.
Full CLI test suite (`npm test` under `cli/`) passes: 370 passed,
1 skipped (pre-existing).
Review cleanup on top of the editor-cache + Hub-stderr commit: - `utils/unity-hub.ts`: hoist the duplicated stderr-extraction block from `listInstalledEditors` and `listAvailableReleases` catch handlers into a single `formatExecError(err)` helper. Both catch blocks now call it; behaviour unchanged. - `utils/editor-cache.ts`: trim the AUTO_KEY comment to just the why (collision-avoidance with the Unity-version namespace). - `utils/unity-editor.ts`: tighten the cache-lookup preamble in `findEditorPath` from 5 lines to 2. `npm run build` + `npm test` under `cli/`: 370 passed, 1 skipped.
Address PR #748 review comments: - `utils/editor-cache.ts`: switch the in-memory cache dict to a null-prototype object via `Object.create(null)`, and copy parsed JSON entries through that null-prototype shell. Defends against a `m_EditorVersion: __proto__` payload (or `--unity __proto__`) polluting the cache object's prototype chain. Public API unchanged. - `tests/editor-cache.test.ts` (NEW, 9 tests): cover read-missing → null, write/read round-trip, stale-entry auto-eviction, versioned-vs-`__auto__` key isolation, and `clearCachedEditorPath` precision. - `tests/unity-editor.test.ts` (+1 test): assert `findEditorPath` short-circuits via the cache without calling `ensureUnityHub` or `listInstalledEditors`. `npm test` under `cli/`: 380 passed, 1 skipped.
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.
This pull request introduces a persistent disk cache for resolved Unity Editor binary paths, significantly improving the performance of repeated editor launches by avoiding redundant and slow Unity Hub lookups. It also improves error reporting for Unity Hub CLI failures and adds comprehensive unit and integration tests for the new caching logic.
Key changes include:
Editor Path Caching
editor-cache.tsmodule that provides functions to read, write, and clear cached Unity Editor binary paths per version, using a JSON file in the user's home directory. The cache self-evicts stale entries if the binary no longer exists. (cli/src/utils/editor-cache.ts)findEditorPathinunity-editor.ts, so cache hits bypass slow Unity Hub lookups, and resolved paths are stored for future use. (cli/src/utils/unity-editor.ts) [1] [2] [3] [4] [5]cli/src/lib/open.ts) [1] [2]Error Handling and Diagnostics
stderroutput on failures, making troubleshooting easier. (cli/src/utils/unity-hub.ts) [1] [2] [3] [4]Testing
cli/tests/editor-cache.test.ts)findEditorPathreturns cached results without invoking Unity Hub helpers when the cache is warm. (cli/tests/unity-editor.test.ts) [1] [2]These changes collectively make repeated Unity Editor launches much faster, improve reliability, and provide better diagnostics for users.