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:
co-authored by
Serhii Dziupin
parent
8801d69c66
commit
ccb74d8366
@@ -0,0 +1,46 @@
|
||||
import { afterEach, describe, expect, mock, test } from 'bun:test';
|
||||
|
||||
type RuntimeApisStub = { runtime?: { isVSCode?: boolean } } | null;
|
||||
|
||||
let registeredRuntimeApis: RuntimeApisStub = null;
|
||||
|
||||
mock.module('@/contexts/runtimeAPIRegistry', () => ({
|
||||
getRegisteredRuntimeAPIs: (): RuntimeApisStub => registeredRuntimeApis,
|
||||
}));
|
||||
|
||||
const { isVSCodeRuntime } = await import('./desktop');
|
||||
|
||||
describe('desktop isVSCodeRuntime bootstrap detection', () => {
|
||||
afterEach(() => {
|
||||
registeredRuntimeApis = null;
|
||||
delete (globalThis as { window?: unknown }).window;
|
||||
});
|
||||
|
||||
test('detects VS Code from bootstrap config before RuntimeAPIs register', () => {
|
||||
registeredRuntimeApis = null;
|
||||
(globalThis as { window: unknown }).window = {
|
||||
__VSCODE_CONFIG__: {
|
||||
workspaceFolder: '/Users/me/project-a',
|
||||
workspaceFolders: [{ name: 'project-a', path: '/Users/me/project-a' }],
|
||||
},
|
||||
};
|
||||
|
||||
expect(isVSCodeRuntime()).toBe(true);
|
||||
});
|
||||
|
||||
test('falls back to registered RuntimeAPIs when bootstrap is absent', () => {
|
||||
registeredRuntimeApis = {
|
||||
runtime: { isVSCode: true },
|
||||
};
|
||||
(globalThis as { window: unknown }).window = {};
|
||||
|
||||
expect(isVSCodeRuntime()).toBe(true);
|
||||
});
|
||||
|
||||
test('does not classify an unregistered web runtime as VS Code', () => {
|
||||
registeredRuntimeApis = null;
|
||||
(globalThis as { window: unknown }).window = {};
|
||||
|
||||
expect(isVSCodeRuntime()).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user