Choosing Between Environment‑Variable Placeholders and Secret Storage API for Credential Isolation in VSCode Integration Tests
0 reputation · 29 Aug 2024, 22:03 UTC
0 reputation · 29 Aug 2024, 22:03 UTC
The goal is to run VSCode integration tests without exposing production credentials, using a documented method for secret handling.
Constraints include limited support for the Secret Storage API in VSCode versions prior to 1.70, potential visibility of environment variables to other processes, and the lack of automatic secret clearing in the test harness, which makes manual cleanup error‑prone.
Which approach reliably isolates test secrets across VSCode restarts without exposing values to other processes? Can the Secret Storage API be cleared automatically within the test harness, or is manual intervention unavoidable? What is the minimal VSCode version required for a stable secret‑storage workflow in CI?
35775 reputation · 30 Aug 2024, 06:48 UTC
Use the VSCode Secret Storage API (`vscode.secrets`) for integration-test credentials. Environment variables are inherited by child processes and can be inspected by other processes or the CI runner, so they do not reliably isolate test secrets. Secret Storage is per-extension, API-only, and persists across VSCode restarts; however, the API does not clear secrets automatically. Your harness must call `vscode.secrets.delete` in teardown. For CI, use VSCode 1.70 or later; versions before 1.70 are flagged as potentially inconsistent for headless secret storage and should be verified with `code --version` before use.
Assumes tests run in the VSCode extension host with the `vscode` module available, and CI can run `code --version`. The API existed before 1.70, but stable headless behavior on Linux/macOS is treated as unverified below 1.70; mark that version check as required before merging.
await vscode.secrets.store('integration-test-cred', testSecret);assert.strictEqual(await vscode.secrets.get('integration-test-cred'), testSecret); assert.strictEqual(process.env['integration-test-cred'], undefined);await vscode.secrets.delete('integration-test-cred');Run `code --version` in CI and require at least 1.70. If the output is lower, do not rely on Secret Storage for CI until headless behavior is confirmed; pin the image to 1.70+ or rerun the compatibility test.
Missing diagnostic detail that can change the recommendation: what does `code --version` print on the CI image, and is VSCode launched headless? If below 1.70 or headless on Linux/macOS, pin to 1.70+ and retest before adopting Secret Storage in CI.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.