2026-07-27 10:58:33 +00:00
|
|
|
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,
|
|
|
|
|
}));
|
|
|
|
|
|
2026-08-29 01:06:36 +03:00
|
|
|
interface TestWindow {
|
|
|
|
|
__VSCODE_CONFIG__?: { workspaceFolder: string; workspaceFolders: { name: string; path: string }[] };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* bun test runs without a DOM, so `globalThis` has no `window` binding to
|
|
|
|
|
* assign through. Defining the property directly installs the stub without
|
|
|
|
|
* asserting that it is a real `Window`.
|
|
|
|
|
*/
|
|
|
|
|
const setTestWindow = (value: TestWindow | undefined): void => {
|
|
|
|
|
if (value === undefined) {
|
|
|
|
|
Reflect.deleteProperty(globalThis, 'window');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Object.defineProperty(globalThis, 'window', { value, configurable: true, writable: true });
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-27 10:58:33 +00:00
|
|
|
const { isVSCodeRuntime } = await import('./desktop');
|
|
|
|
|
|
|
|
|
|
describe('desktop isVSCodeRuntime bootstrap detection', () => {
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
registeredRuntimeApis = null;
|
2026-08-29 01:06:36 +03:00
|
|
|
setTestWindow(undefined);
|
2026-07-27 10:58:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('detects VS Code from bootstrap config before RuntimeAPIs register', () => {
|
|
|
|
|
registeredRuntimeApis = null;
|
2026-08-29 01:06:36 +03:00
|
|
|
setTestWindow({
|
2026-07-27 10:58:33 +00:00
|
|
|
__VSCODE_CONFIG__: {
|
|
|
|
|
workspaceFolder: '/Users/me/project-a',
|
|
|
|
|
workspaceFolders: [{ name: 'project-a', path: '/Users/me/project-a' }],
|
|
|
|
|
},
|
2026-08-29 01:06:36 +03:00
|
|
|
});
|
2026-07-27 10:58:33 +00:00
|
|
|
|
|
|
|
|
expect(isVSCodeRuntime()).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('falls back to registered RuntimeAPIs when bootstrap is absent', () => {
|
|
|
|
|
registeredRuntimeApis = {
|
|
|
|
|
runtime: { isVSCode: true },
|
|
|
|
|
};
|
2026-08-29 01:06:36 +03:00
|
|
|
setTestWindow({});
|
2026-07-27 10:58:33 +00:00
|
|
|
|
|
|
|
|
expect(isVSCodeRuntime()).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('does not classify an unregistered web runtime as VS Code', () => {
|
|
|
|
|
registeredRuntimeApis = null;
|
2026-08-29 01:06:36 +03:00
|
|
|
setTestWindow({});
|
2026-07-27 10:58:33 +00:00
|
|
|
|
|
|
|
|
expect(isVSCodeRuntime()).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
});
|