fix: hide the background updater console window on Windows (#1336)

A detached Windows child gets its own console window. With the shell: true introduced for the CVE-2024-27980 fix, a passive background auto-update could flash a command window even though stdio is ignored. Set windowsHide on the detached background child so the silent updater stays silent. The foreground `kimi upgrade` path is interactive (stdio: inherit, non-detached) and reuses the parent console, so it is left unchanged.
This commit is contained in:
liruifengv 2026-07-03 11:32:31 +08:00 committed by GitHub
parent 93f16c32d7
commit 4c1d0a1633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---
Keep automatic background updates from flashing a console window on Windows.

View file

@ -607,6 +607,10 @@ async function startBackgroundInstall(
detached: true,
stdio: 'ignore',
shell: platform === 'win32' ? true : undefined,
// On Windows a detached child gets its own console window; with shell:true
// that window would flash during a passive background update. Hide it so
// the silent updater stays silent.
windowsHide: platform === 'win32' ? true : undefined,
});
child.once('error', () => { finish(false); });
child.once('exit', (code) => { finish(code === 0); });

View file

@ -600,6 +600,27 @@ describe('runUpdatePreflight', () => {
}));
});
it('win32 background auto-update hides the console window', async () => {
mocks.readUpdateCache.mockResolvedValue(cacheWith('0.5.0'));
mocks.readUpdateInstallState.mockResolvedValue(installState());
mocks.refreshUpdateCache.mockResolvedValue(cacheWith('0.5.0'));
mocks.detectInstallSource.mockResolvedValue('npm-global');
mockSpawnExit(0);
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', { value: 'win32' });
try {
const { options } = captureOutput();
await expect(runUpdatePreflight('0.4.0', options)).resolves.toBe('continue');
expect(mocks.spawn).toHaveBeenCalledWith(
'npm.cmd',
['install', '-g', '@moonshot-ai/kimi-code@0.5.0'],
{ detached: true, stdio: 'ignore', shell: true, windowsHide: true },
);
} finally {
Object.defineProperty(process, 'platform', { value: originalPlatform });
}
});
it('tracks and logs successful background update installs', async () => {
mocks.readUpdateCache.mockResolvedValue(cacheWith('0.5.0'));
mocks.readUpdateInstallState.mockResolvedValue(installState());