fix(ui): detect VS Code from bootstrap config in shared runtime helpers

d2efa707 fixed projects-store detection via __VSCODE_CONFIG__, but
lib/desktop.isVSCodeRuntime (used by useDirectoryStore) still required
RuntimeAPIs. At webview startup that left directory init on stale
localStorage paths from other windows (#2359).

Share bootstrap detection in lib/vscodeBootstrap and use it from both
desktop runtime checks and the projects-store helper.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-07-27 10:58:33 +00:00
co-authored by Serhii Dziupin
parent 8801d69c66
commit ccb74d8366
7 changed files with 121 additions and 14 deletions
@@ -0,0 +1,29 @@
import { afterEach, describe, expect, test } from 'bun:test';
import { getVSCodeBootstrapConfig, isVSCodeBootstrapPresent } from './vscodeBootstrap';
describe('VS Code bootstrap config', () => {
afterEach(() => {
delete (globalThis as { window?: unknown }).window;
});
test('reads extension-host __VSCODE_CONFIG__ before RuntimeAPIs exist', () => {
(globalThis as { window: unknown }).window = {
__VSCODE_CONFIG__: {
workspaceFolder: '/workspace/project-one',
workspaceFolders: [{ name: 'project-one', path: '/workspace/project-one' }],
},
};
expect(getVSCodeBootstrapConfig()).toEqual({
workspaceFolder: '/workspace/project-one',
workspaceFolders: [{ name: 'project-one', path: '/workspace/project-one' }],
});
expect(isVSCodeBootstrapPresent()).toBe(true);
});
test('treats missing window/bootstrap as not VS Code', () => {
expect(getVSCodeBootstrapConfig()).toBeNull();
expect(isVSCodeBootstrapPresent()).toBe(false);
expect(isVSCodeBootstrapPresent(null)).toBe(false);
});
});