From 427e48d8e9daadbff0fcbea7a87534ac0955a175 Mon Sep 17 00:00:00 2001 From: "zainnadeem(RedOpsCell)" Date: Mon, 3 Aug 2026 00:12:54 +0500 Subject: [PATCH 1/2] Fix Workspace Trust transition promise ordering --- .../workspaces/common/workspaceTrust.ts | 2 +- .../test/common/workspaceTrust.test.ts | 92 ++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts index cc10c260ddf150..1a7904c50fa2b5 100644 --- a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts +++ b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts @@ -625,7 +625,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork } async setUrisTrust(uris: URI[], trusted: boolean): Promise { - this.doSetUrisTrust(await Promise.all(uris.map(uri => this.getCanonicalUri(uri))), trusted); + await this.doSetUrisTrust(await Promise.all(uris.map(uri => this.getCanonicalUri(uri))), trusted); } getTrustedUris(): URI[] { diff --git a/src/vs/workbench/services/workspaces/test/common/workspaceTrust.test.ts b/src/vs/workbench/services/workspaces/test/common/workspaceTrust.test.ts index 8921cb040808a9..8ca3b973fec4c9 100644 --- a/src/vs/workbench/services/workspaces/test/common/workspaceTrust.test.ts +++ b/src/vs/workbench/services/workspaces/test/common/workspaceTrust.test.ts @@ -13,7 +13,7 @@ import { TestInstantiationService } from '../../../../../platform/instantiation/ import { NullLogService } from '../../../../../platform/log/common/log.js'; import { IRemoteAuthorityResolverService } from '../../../../../platform/remote/common/remoteAuthorityResolver.js'; import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js'; -import { IWorkspaceContextService } from '../../../../../platform/workspace/common/workspace.js'; +import { IWorkspaceContextService, toWorkspaceFolder } from '../../../../../platform/workspace/common/workspace.js'; import { IWorkspaceTrustEnablementService, IWorkspaceTrustInfo } from '../../../../../platform/workspace/common/workspaceTrust.js'; import { Workspace } from '../../../../../platform/workspace/test/common/testWorkspace.js'; import { Memento } from '../../../../common/memento.js'; @@ -159,6 +159,96 @@ suite('Workspace Trust', () => { assert.strictEqual(true, (await testObject.getUriTrustInfo(sameFolderDifferentMeta)).trusted); }); + test('setWorkspaceTrust waits for trust transition participants before resolving', async () => { + await configurationService.setUserConfiguration('security', getUserSettings(true, true)); + workspaceService.setWorkspace(new Workspace('folder-workspace', [toWorkspaceFolder(URI.parse('file:///Folder'))])); + const testObject = await initializeTestObject(); + + let releaseParticipant!: () => void; + const participantCanComplete = new Promise(resolve => releaseParticipant = resolve); + + let participantStartedResolve!: () => void; + const participantStarted = new Promise(resolve => participantStartedResolve = resolve); + + let participantStartedFlag = false; + let participantCompleted = false; + let trustChangeEventFired = false; + + const participantCompletedPromise = new Promise(resolve => { + store.add(testObject.addWorkspaceTrustTransitionParticipant({ + async participate(trusted: boolean): Promise { + if (trusted) { + participantStartedFlag = true; + participantStartedResolve(); + await participantCanComplete; + participantCompleted = true; + resolve(); + } + } + })); + }); + + store.add(testObject.onDidChangeTrust(trusted => { + if (trusted) { + trustChangeEventFired = true; + } + })); + + await testObject.setWorkspaceTrust(false); + assert.deepStrictEqual({ + trusted: testObject.isWorkspaceTrusted(), + participantStarted: participantStartedFlag, + participantCompleted, + trustChangeEventFired + }, { + trusted: false, + participantStarted: false, + participantCompleted: false, + trustChangeEventFired: false + }); + + const setWorkspaceTrustPromise = testObject.setWorkspaceTrust(true); + let setWorkspaceTrustResolved = false; + setWorkspaceTrustPromise.then(() => setWorkspaceTrustResolved = true); + + try { + await participantStarted; + await Promise.resolve(); + + assert.deepStrictEqual({ + setWorkspaceTrustResolved, + trusted: testObject.isWorkspaceTrusted(), + participantStarted: participantStartedFlag, + participantCompleted, + trustChangeEventFired + }, { + setWorkspaceTrustResolved: false, + trusted: true, + participantStarted: true, + participantCompleted: false, + trustChangeEventFired: false + }); + } finally { + releaseParticipant(); + await participantCompletedPromise; + } + + await setWorkspaceTrustPromise; + await Promise.resolve(); + + assert.deepStrictEqual({ + setWorkspaceTrustResolved, + trusted: testObject.isWorkspaceTrusted(), + participantCompleted, + trustChangeEventFired + }, { + setWorkspaceTrustResolved: true, + trusted: true, + participantCompleted: true, + trustChangeEventFired: true + }); + }); + async function initializeTestObject(): Promise { const workspaceTrustManagementService = store.add(instantiationService.createInstance(WorkspaceTrustManagementService)); await workspaceTrustManagementService.workspaceTrustInitialized; From 95116a83d06941adb9aaf6107b05e0269a471a42 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Tue, 18 Aug 2026 16:09:33 -0700 Subject: [PATCH 2/2] fix: improve focus handling after deleting trusted URI item if participant takes some time --- .../workspace/browser/workspaceTrustEditor.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts b/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts index 2c82bae817c3bd..aa8ea0539ae1c3 100644 --- a/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts +++ b/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts @@ -341,14 +341,18 @@ class WorkspaceTrustedUrisTable extends Disposable { } async delete(item: ITrustedUriItem) { - this.table.focusNext(); - await this.workspaceTrustManagementService.setUrisTrust([item.uri], false); - - if (this.table.getFocus().length === 0) { - this.table.focusLast(); + const index = this.table.indexOf(item); + if (index < this.table.length - 1) { + this.table.setFocus([index + 1]); + } else if (index > 0) { + this.table.setFocus([index - 1]); + } else { + this.table.setFocus([]); } - this._onDelete.fire(item); this.table.domFocus(); + + await this.workspaceTrustManagementService.setUrisTrust([item.uri], false); + this._onDelete.fire(item); } async edit(item: ITrustedUriItem, usePickerIfPossible?: boolean) {