fix(cli): run the bundled generated-ui server in Node mode under Electron (#16064)

* fix(cli): run the bundled generated-ui server in Node mode under Electron

When the CLI is launched by an IDE companion, process.execPath is the
Electron binary, and the ACP launch scrubs ELECTRON_RUN_AS_NODE from the
inherited environment. Spawning the bundled generated-ui MCP server then
started the VS Code GUI, which opened the entry file in an editor.
Pin ELECTRON_RUN_AS_NODE=1 in the server config when running on
Electron; an explicit server env wins over the inherited one.

Fixes #16063

* fix(cli): access process.versions with bracket notation

The repository tsconfig enables noPropertyAccessFromIndexSignature, so
process.versions.electron fails typecheck with TS4111; the generated-ui
server config and its test must read the Electron version as
process.versions['electron'].

Fixes #16063

Co-authored-by: Qwen-Coder <[email protected]>

---------

Co-authored-by: Qwen-Coder <[email protected]>
Co-authored-by: 易良 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-11-03 19:38:10 +08:00
1 parent 76ab3ad4d6
commit 6fe83a8245
2 files changed
+27

No files matched your search

@@ -87,6 +87,26 @@ describe('bundled Generated UI candidate', () => {
});
});
it('forces Node mode when the CLI runs as the Electron binary', () => {
const assets = join(fixture, 'generated-ui');
populate(assets);
const originalElectron = process.versions['electron'];
Object.defineProperty(process.versions, 'electron', {
value: '43.8.3',
configurable: true,
});
try {
expect(prepareBundledGeneratedUi(true, true).server?.env).toEqual({
ELECTRON_RUN_AS_NODE: '1',
});
} finally {
Object.defineProperty(process.versions, 'electron', {
value: originalElectron,
configurable: true,
});
}
});
it.each(files)(
'withholds an incomplete installation missing %s',
(missing) => {
@@ -75,6 +75,13 @@ export function prepareBundledGeneratedUi(
// Declared up front: the model should see the view as an option when it
// decides how to answer, not only after searching for deferred tools.
alwaysLoadTools: true,
// When the CLI itself is the Electron binary launched by an IDE
// companion, the ACP launch scrubs ELECTRON_RUN_AS_NODE from the
// inherited environment (#16063): without it this child starts the
// VS Code GUI, which opens the entry file in an editor.
...(process.versions['electron']
? { env: { ELECTRON_RUN_AS_NODE: '1' } }
: {}),
},
};
}