Skip to content

Commit 878e6a3

Browse files
rwollCopilot
andcommitted
test: add parameterized policy plumbing smoke test
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cea11743-4d3d-48b7-9b6d-8028b722593d
1 parent 0fd2d7c commit 878e6a3

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

‎src/vs/code/electron-main/main.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ class CodeMain {
227227
policyServices.push(disposables.add(new NativePolicyService(logService, policyProductName)));
228228
} else if (isLinux) {
229229
policyServices.push(disposables.add(new FilePolicyService(URI.file(LINUX_SYSTEM_POLICY_FILE_PATH), fileService, logService)));
230-
} else if (environmentMainService.policyFile) {
230+
}
231+
if (environmentMainService.args['enable-smoke-test-driver'] && environmentMainService.policyFile) {
231232
policyServices.push(disposables.add(new FilePolicyService(environmentMainService.policyFile, fileService, logService)));
232233
}
233234

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as assert from 'assert';
7+
import * as fs from 'fs';
8+
import * as path from 'path';
9+
import { Application, ApplicationOptions, Logger } from '../../../../automation';
10+
import { installAllHandlers } from '../../utils';
11+
12+
const SETTING_KEY = 'extensions.autoUpdate';
13+
const SETTING_SELECTOR = `.settings-editor .setting-item-contents[data-key="${SETTING_KEY}"]`;
14+
15+
export function setup(logger: Logger) {
16+
for (const testCase of [
17+
{ name: 'without policy', policyValue: undefined, expectedValue: 'on' },
18+
{ name: 'with policy', policyValue: 'off', expectedValue: 'off' },
19+
]) {
20+
describe(`Policy Plumbing (${testCase.name})`, () => {
21+
installAllHandlers(logger, options => configurePolicyTest(options, testCase.policyValue));
22+
23+
it('applies the expected setting value', async function () {
24+
const app = this.app as Application;
25+
26+
await app.workbench.settingsEditor.searchSettingsUI(`@id:${SETTING_KEY}`);
27+
await app.code.waitForTextContent(
28+
`${SETTING_SELECTOR} .setting-item-control select option:checked`,
29+
testCase.expectedValue
30+
);
31+
await app.code.waitForElement(
32+
`${SETTING_SELECTOR} .setting-item-control select:${testCase.policyValue === undefined ? 'enabled' : 'disabled'}`
33+
);
34+
35+
const indicatorSelector = `${SETTING_SELECTOR} .setting-indicators-container .setting-indicator`;
36+
await app.code.waitForElements(
37+
indicatorSelector,
38+
false,
39+
elements => elements.some(element => element.textContent.includes('Managed by organization'))
40+
=== (testCase.policyValue !== undefined)
41+
);
42+
});
43+
});
44+
}
45+
}
46+
47+
function configurePolicyTest(options: ApplicationOptions, policyValue: string | undefined): ApplicationOptions {
48+
assert.ok(options.userDataDir);
49+
50+
const portablePath = `${options.userDataDir}-policy`;
51+
const userDataDir = path.join(portablePath, 'user-data');
52+
const userSettingsPath = path.join(userDataDir, 'User', 'settings.json');
53+
fs.mkdirSync(path.dirname(userSettingsPath), { recursive: true });
54+
fs.writeFileSync(userSettingsPath, JSON.stringify({ [SETTING_KEY]: 'on' }));
55+
56+
const extraArgs = [...(options.extraArgs ?? [])];
57+
if (policyValue !== undefined) {
58+
fs.writeFileSync(path.join(portablePath, 'policy.json'), JSON.stringify({ ExtensionsAutoUpdate: policyValue }));
59+
extraArgs.push('--__enable-file-policy');
60+
}
61+
62+
return {
63+
...options,
64+
userDataDir,
65+
extraArgs,
66+
extraEnv: {
67+
...options.extraEnv,
68+
VSCODE_PORTABLE: portablePath,
69+
},
70+
};
71+
}

‎test/smoke/src/main.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { setup as setupChatModelConfigTests } from './areas/chat/chatModelConfig
3535
import { setup as setupAccessibilityTests } from './areas/accessibility/accessibility.test';
3636
import { setup as setupAgentsWindowTests } from './areas/agentsWindow/agentsWindow.test';
3737
import { setup as setupBrowserViewTests } from './areas/browserView/browserView.test';
38+
import { setup as setupPolicyTests } from './areas/policy/policy.test';
3839

3940
const rootPath = path.join(__dirname, '..', '..', '..');
4041

@@ -445,5 +446,6 @@ describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => {
445446
if (!opts.web && !opts.remote) { setupChatModelConfigTests(logger); }
446447
if (!opts.web && !opts.remote) { setupAgentsWindowTests(logger); }
447448
if (!opts.web && !opts.remote) { setupBrowserViewTests(logger); }
449+
if (!opts.web && !opts.remote) { setupPolicyTests(logger); }
448450
setupAccessibilityTests(logger, opts, quality);
449451
});

0 commit comments

Comments
 (0)