You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add section on testing Workspace Trust behavior in extensions (#9784)
* docs: add section on testing Workspace Trust behavior in extensions
Adds a new section to the Testing Extensions guide explaining how
extension authors can write integration tests that cover both trusted
and untrusted workspace scenarios.
Covers:
- How Workspace Trust state works in the Extension Development Host
- Configuring separate test runs per trust state via @vscode/test-cli
- Using an isolated --user-data-dir to prevent trust from persisting
- Writing assertions using vscode.workspace.isTrusted
- Using onDidGrantWorkspaceTrust event in tests
- Configuring launch.json for trusted and untrusted test runs
Closes#9583
* Edit pass to make the section more concise
---------
Co-authored-by: Nick Trogh <ntrogh@hotmail.com>
Copy file name to clipboardExpand all lines: api/working-with-extensions/testing-extension.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -363,6 +363,67 @@ async function main() {
363
363
main();
364
364
```
365
365
366
+
## Testing Workspace Trust behavior
367
+
368
+
If your extension declares `capabilities.untrustedWorkspaces` in `package.json`, add integration tests for both trusted and untrusted workspaces. You can't programmatically grant or revoke Workspace Trust from an extension test. Use separate test runs for trusted and untrusted states.
369
+
370
+
When using `@vscode/test-cli`, define separate test configurations so you can run each trust state independently:
371
+
372
+
-**trustedWorkspaceTests**: Gives you a baseline run where trust restrictions are not applied. This helps verify your extension's full-feature behavior and catch regressions in the trusted path.
373
+
-**untrustedWorkspaceTests**: Verifies Restricted Mode behavior with Workspace Trust still enabled. Using a dedicated `--user-data-dir` prevents previously persisted trust decisions from making this run accidentally trusted.
374
+
375
+
Because each configuration has its own `label`, you can run them independently (for example, `vscode-test --label trustedWorkspaceTests` and `vscode-test --label untrustedWorkspaceTests`) or run both in sequence.
For more information on how to declare trust requirements in your extension manifest and how to use the `vscode.workspace.isTrusted` API, see the [Workspace Trust Extension Guide](/api/extension-guides/workspace-trust).
425
+
366
426
## Next steps
367
427
368
428
-[Continuous Integration](/api/working-with-extensions/continuous-integration) - Run your extension tests in a Continuous Integration service such as Azure DevOps.
429
+
-[Workspace Trust Extension Guide](/api/extension-guides/workspace-trust) - Learn how to declare and handle workspace trust in your extension.
0 commit comments