Add mock web extension for E2E testing

New extension at extensions/sessions-e2e-mock/ provides:
- Mock GitHub auth provider (fake token, skips sign-in)
- Mock chat participant (canned responses based on input keywords)
- Mock file system for github-remote-file:// (in-memory files)

Server loads the extension when --mock flag is passed. The generate
and test runners both use --mock automatically.

New npm scripts:
- serve:mock — opens Sessions in browser with mocks loaded

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Osvaldo Ortega
2026-03-05 11:34:34 -08:00
parent c677691c87
commit fafc62f5ac
7 changed files with 349 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ const APP_ROOT = path.join(__dirname, '..');
async function main() {
const args = minimist(process.argv.slice(2), {
boolean: ['help', 'no-open', 'skip-welcome'],
boolean: ['help', 'no-open', 'skip-welcome', 'mock'],
string: ['host', 'port'],
});
@@ -24,7 +24,9 @@ async function main() {
'./scripts/code-sessions-web.sh [options]\n' +
' --host <host> Host to bind to (default: localhost)\n' +
' --port <port> Port to bind to (default: 8081)\n' +
' --no-open Do not open browser automatically\n'
' --no-open Do not open browser automatically\n' +
' --skip-welcome Skip the sessions welcome overlay\n' +
' --mock Load mock extension for E2E testing\n'
);
return;
}
@@ -50,7 +52,7 @@ async function main() {
// Serve the sessions workbench HTML at the root
if (url.pathname === '/' || url.pathname === '/index.html') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(getSessionsHTML(HOST, PORT, cssModules));
res.end(getSessionsHTML(HOST, PORT, cssModules, args['mock']));
return;
}
@@ -95,7 +97,7 @@ async function main() {
process.on('SIGTERM', () => { server.close(); process.exit(0); });
}
function getSessionsHTML(host, port, cssModules) {
function getSessionsHTML(host, port, cssModules, useMock) {
const baseUrl = `http://${host}:${port}`;
const fileRoot = `${baseUrl}/out`;
@@ -112,6 +114,11 @@ function getSessionsHTML(host, port, cssModules) {
}
const importMapJson = JSON.stringify({ imports }, null, 2);
// When --mock is passed, load the E2E mock extension
const additionalBuiltinExtensions = useMock
? `additionalBuiltinExtensions: [{ scheme: 'http', authority: '${host}:${port}', path: '/src/vs/sessions/test/e2e/extensions/sessions-e2e-mock' }],`
: '';
return `<!DOCTYPE html>
<html>
<head>
@@ -137,6 +144,7 @@ ${importMapJson}
nameLong: 'Sessions (Web)',
enableTelemetry: false,
},
${additionalBuiltinExtensions}
workspaceProvider: {
workspace: undefined,
open: async () => false,