From 4669c0e48c97fe14b43e3c9dd9ba090e96b06d58 Mon Sep 17 00:00:00 2001 From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com> Date: Mon, 19 Jan 2026 04:46:23 +0000 Subject: [PATCH] fix(vscode-web): write settings to User path instead of Machine This changes the settings file location from: ~/.vscode-server/data/Machine/settings.json to: ~/.vscode-server/data/User/settings.json User Remote settings have higher precedence than User Local settings, ensuring module-provided settings properly override the users local machine settings. Previously, Machine settings could be overridden by User Remote settings, preventing the module from applying its configuration. VS Code settings precedence (lowest to highest): 1. Default 2. User Local 3. User Remote 4. Workspace 5. Workspace Folder --- .../coder/modules/vscode-web/main.test.ts | 57 ++++++++++++++++++- registry/coder/modules/vscode-web/run.sh | 6 +- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/registry/coder/modules/vscode-web/main.test.ts b/registry/coder/modules/vscode-web/main.test.ts index 860fc176..b04187cf 100644 --- a/registry/coder/modules/vscode-web/main.test.ts +++ b/registry/coder/modules/vscode-web/main.test.ts @@ -1,5 +1,13 @@ import { describe, expect, it } from "bun:test"; -import { runTerraformApply, runTerraformInit } from "~test"; +import { + execContainer, + findResourceInstance, + readFileContainer, + removeContainer, + runContainer, + runTerraformApply, + runTerraformInit, +} from "~test"; describe("vscode-web", async () => { await runTerraformInit(import.meta.dir); @@ -38,5 +46,50 @@ describe("vscode-web", async () => { expect(t).toThrow("Offline mode does not allow extensions to be installed"); }); - // More tests depend on shebang refactors + it("writes settings to User settings path not Machine", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + accept_license: "true", + offline: "true", + }); + const instance = findResourceInstance(state, "coder_script"); + // Verify the script uses User path, not Machine path + expect(instance.script).toContain(".vscode-server/data/User/settings.json"); + expect(instance.script).not.toContain(".vscode-server/data/Machine/settings.json"); + }); + + it("writes provided settings to ~/.vscode-server/data/User/settings.json", async () => { + const id = await runContainer("alpine"); + try { + const settings = { + "editor.fontSize": 16, + "workbench.colorTheme": "Default Dark+", + }; + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + accept_license: "true", + offline: "true", + settings: JSON.stringify(settings), + }); + const instance = findResourceInstance(state, "coder_script"); + // Extract and run only the settings portion of the script + const settingsScript = ` +SETTINGS='${JSON.stringify(settings).replace(/'/g, "'\\''")}' +if [ ! -f ~/.vscode-server/data/User/settings.json ]; then + mkdir -p ~/.vscode-server/data/User + echo "$SETTINGS" > ~/.vscode-server/data/User/settings.json +fi +`; + const resp = await execContainer(id, ["sh", "-c", settingsScript]); + expect(resp.exitCode).toBe(0); + const content = await readFileContainer( + id, + "/root/.vscode-server/data/User/settings.json", + ); + const actualSettings = JSON.parse(content.trim()); + expect(actualSettings).toEqual(settings); + } finally { + await removeContainer(id); + } + }); }); diff --git a/registry/coder/modules/vscode-web/run.sh b/registry/coder/modules/vscode-web/run.sh index 57bb760f..2aea275d 100644 --- a/registry/coder/modules/vscode-web/run.sh +++ b/registry/coder/modules/vscode-web/run.sh @@ -29,10 +29,10 @@ run_vscode_web() { } # Check if the settings file exists... -if [ ! -f ~/.vscode-server/data/Machine/settings.json ]; then +if [ ! -f ~/.vscode-server/data/User/settings.json ]; then echo "⚙️ Creating settings file..." - mkdir -p ~/.vscode-server/data/Machine - echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json + mkdir -p ~/.vscode-server/data/User + echo "${SETTINGS}" > ~/.vscode-server/data/User/settings.json fi # Check if vscode-server is already installed for offline or cached mode