diff --git a/registry/coder/modules/vscode-web/main.test.ts b/registry/coder/modules/vscode-web/main.test.ts index 860fc176c..5a0052627 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,52 @@ 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 57bb760f9..2aea275d1 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