mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-17 23:35:54 +01:00
Add Approach 2: Service overrides for E2E mock testing
New files: - web.test.ts: TestSessionsBrowserMain with MockChatEntitlementService - web.test.factory.ts: Factory using TestSessionsBrowserMain - sessions.web.test.internal.ts: Test entry point Server uses test entry point when --mock, which injects a mock IChatEntitlementService returning ChatEntitlement.Free with installed=true, so Sessions thinks the user is signed in. Also adds ESLint import patterns for sessions web entry points. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1973,6 +1973,38 @@ export default tseslint.config(
|
|||||||
'vs/sessions/sessions.common.main.js'
|
'vs/sessions/sessions.common.main.js'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'target': 'src/vs/sessions/sessions.web.main.internal.ts',
|
||||||
|
'layer': 'browser',
|
||||||
|
'restrictions': [
|
||||||
|
'vs/base/~',
|
||||||
|
'vs/base/parts/*/~',
|
||||||
|
'vs/platform/*/~',
|
||||||
|
'vs/sessions/~',
|
||||||
|
'vs/sessions/contrib/*/~',
|
||||||
|
'vs/workbench/~',
|
||||||
|
'vs/workbench/browser/**',
|
||||||
|
'vs/workbench/services/*/~',
|
||||||
|
'vs/workbench/contrib/*/~',
|
||||||
|
'vs/sessions/sessions.web.main.js'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'target': 'src/vs/sessions/sessions.web.test.internal.ts',
|
||||||
|
'layer': 'browser',
|
||||||
|
'restrictions': [
|
||||||
|
'vs/base/~',
|
||||||
|
'vs/base/parts/*/~',
|
||||||
|
'vs/platform/*/~',
|
||||||
|
'vs/sessions/~',
|
||||||
|
'vs/sessions/contrib/*/~',
|
||||||
|
'vs/workbench/~',
|
||||||
|
'vs/workbench/browser/**',
|
||||||
|
'vs/workbench/services/*/~',
|
||||||
|
'vs/workbench/contrib/*/~',
|
||||||
|
'vs/sessions/sessions.web.main.js'
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'target': 'src/vs/sessions/~',
|
'target': 'src/vs/sessions/~',
|
||||||
'restrictions': [
|
'restrictions': [
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ ${importMapJson}
|
|||||||
</head>
|
</head>
|
||||||
<body aria-label="">
|
<body aria-label="">
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { create, URI } from '${fileRoot}/vs/sessions/sessions.web.main.internal.js';
|
import { create, URI } from '${fileRoot}/vs/sessions/${useMock ? 'sessions.web.test.internal' : 'sessions.web.main.internal'}.js';
|
||||||
create(document.body, {
|
create(document.body, {
|
||||||
productConfiguration: {
|
productConfiguration: {
|
||||||
nameShort: 'Sessions (Web)',
|
nameShort: 'Sessions (Web)',
|
||||||
|
|||||||
34
src/vs/sessions/browser/web.test.factory.ts
Normal file
34
src/vs/sessions/browser/web.test.factory.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import { IWorkbench, IWorkbenchConstructionOptions } from '../../workbench/browser/web.api.js';
|
||||||
|
import { TestSessionsBrowserMain } from './web.test.js';
|
||||||
|
import { IDisposable, toDisposable } from '../../base/common/lifecycle.js';
|
||||||
|
import { mark } from '../../base/common/performance.js';
|
||||||
|
import { DeferredPromise } from '../../base/common/async.js';
|
||||||
|
|
||||||
|
const workbenchPromise = new DeferredPromise<IWorkbench>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the Sessions workbench with mock services for E2E testing.
|
||||||
|
*/
|
||||||
|
export function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): IDisposable {
|
||||||
|
|
||||||
|
mark('code/didLoadWorkbenchMain');
|
||||||
|
|
||||||
|
let instantiatedWorkbench: IWorkbench | undefined = undefined;
|
||||||
|
new TestSessionsBrowserMain(domElement, options).open().then(workbench => {
|
||||||
|
instantiatedWorkbench = workbench;
|
||||||
|
workbenchPromise.complete(workbench);
|
||||||
|
});
|
||||||
|
|
||||||
|
return toDisposable(() => {
|
||||||
|
if (instantiatedWorkbench) {
|
||||||
|
instantiatedWorkbench.shutdown();
|
||||||
|
} else {
|
||||||
|
workbenchPromise.p.then(w => w.shutdown());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
66
src/vs/sessions/browser/web.test.ts
Normal file
66
src/vs/sessions/browser/web.test.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import { ServiceCollection } from '../../platform/instantiation/common/serviceCollection.js';
|
||||||
|
import { ILogService } from '../../platform/log/common/log.js';
|
||||||
|
import { IBrowserMainWorkbench } from '../../workbench/browser/web.main.js';
|
||||||
|
import { Workbench as SessionsWorkbench } from './workbench.js';
|
||||||
|
import { SessionsBrowserMain } from './web.main.js';
|
||||||
|
import { Emitter, Event } from '../../base/common/event.js';
|
||||||
|
import { CancellationToken } from '../../base/common/cancellation.js';
|
||||||
|
import { IObservable, observableValue } from '../../base/common/observable.js';
|
||||||
|
import { ChatEntitlement, IChatEntitlementService, IChatSentiment } from '../../workbench/services/chat/common/chatEntitlementService.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock implementation of IChatEntitlementService that makes the Sessions
|
||||||
|
* window think the user is signed in with a Free Copilot plan.
|
||||||
|
*/
|
||||||
|
class MockChatEntitlementService implements IChatEntitlementService {
|
||||||
|
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
|
||||||
|
readonly onDidChangeEntitlement = Event.None;
|
||||||
|
readonly onDidChangeQuotaExceeded = Event.None;
|
||||||
|
readonly onDidChangeQuotaRemaining = Event.None;
|
||||||
|
readonly onDidChangeSentiment = Event.None;
|
||||||
|
readonly onDidChangeAnonymous = Event.None;
|
||||||
|
|
||||||
|
readonly entitlement = ChatEntitlement.Free;
|
||||||
|
readonly entitlementObs: IObservable<ChatEntitlement> = observableValue('entitlement', ChatEntitlement.Free);
|
||||||
|
|
||||||
|
readonly previewFeaturesDisabled = false;
|
||||||
|
readonly organisations: string[] | undefined = undefined;
|
||||||
|
readonly isInternal = false;
|
||||||
|
readonly sku = 'free';
|
||||||
|
readonly copilotTrackingId = 'mock-tracking-id';
|
||||||
|
|
||||||
|
readonly quotas = {};
|
||||||
|
|
||||||
|
readonly sentiment: IChatSentiment = { installed: true, registered: true };
|
||||||
|
readonly sentimentObs: IObservable<IChatSentiment> = observableValue('sentiment', { installed: true, registered: true });
|
||||||
|
|
||||||
|
readonly anonymous = false;
|
||||||
|
readonly anonymousObs: IObservable<boolean> = observableValue('anonymous', false);
|
||||||
|
|
||||||
|
markAnonymousRateLimited(): void { }
|
||||||
|
async update(_token: CancellationToken): Promise<void> { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test variant of SessionsBrowserMain that injects mock services
|
||||||
|
* for E2E testing (auth, entitlements).
|
||||||
|
*/
|
||||||
|
export class TestSessionsBrowserMain extends SessionsBrowserMain {
|
||||||
|
|
||||||
|
protected override createWorkbench(domElement: HTMLElement, serviceCollection: ServiceCollection, logService: ILogService): IBrowserMainWorkbench {
|
||||||
|
console.log('[Sessions Web Test] Injecting mock services');
|
||||||
|
|
||||||
|
// Override entitlement service so Sessions thinks user is signed in
|
||||||
|
serviceCollection.set(IChatEntitlementService, new MockChatEntitlementService());
|
||||||
|
|
||||||
|
console.log('[Sessions Web Test] Creating Sessions workbench with mocks');
|
||||||
|
return new SessionsWorkbench(domElement, undefined, serviceCollection, logService);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/vs/sessions/sessions.web.test.internal.ts
Normal file
23
src/vs/sessions/sessions.web.test.internal.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// Test entry point for the Sessions workbench with mock services.
|
||||||
|
// Mirrors sessions.web.main.internal.ts but uses TestSessionsBrowserMain.
|
||||||
|
|
||||||
|
import './sessions.web.main.js';
|
||||||
|
import { create } from './browser/web.test.factory.js';
|
||||||
|
import { URI } from '../base/common/uri.js';
|
||||||
|
import { Event, Emitter } from '../base/common/event.js';
|
||||||
|
import { Disposable } from '../base/common/lifecycle.js';
|
||||||
|
import { LogLevel } from '../platform/log/common/log.js';
|
||||||
|
|
||||||
|
export {
|
||||||
|
create,
|
||||||
|
URI,
|
||||||
|
Event,
|
||||||
|
Emitter,
|
||||||
|
Disposable,
|
||||||
|
LogLevel,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user