Skip to content

Commit 3dbc886

Browse files
committed
fix: complete build isolation - no HOME pollution, no files outside out/
1 parent 0afba0f commit 3dbc886

20 files changed

Lines changed: 186 additions & 107 deletions

File tree

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# about not not using or creating files from user home directory directly (~).
44
!media/
55
.DS_Store
6-
.vite-dev-server-url
7-
.vite-dev.pid
6+
# Build tool caches (node-gyp, prek, etc.) - tests use out/*/tmp/home/.cache/
87
.cache
98
.eslintcache
109
.idea
@@ -14,6 +13,7 @@
1413
*.pyc
1514
*.pyo
1615
.task
16+
# VS Code test framework user data - created by @vscode/test-electron
1717
.vscode-test
1818
node_modules
1919
out
@@ -22,14 +22,8 @@ dist
2222
lib
2323

2424
# TODO: Seek to remove these from this file:
25-
.ansible
2625
CHANGELOG.html
2726
docs/als/settings.md
2827
examples/.vscode/
29-
packages/ansible-language-server/test/fixtures/diagnostics/invalid_yaml.yml
30-
resources/contentCreator/createDevcontainer/.devcontainer
31-
resources/contentCreator/createDevfile/devfile-template.txt
3228
test/testFixtures/.vscode/settings.json
33-
test/testFixtures/diagnostics/yaml/invalid_yaml.yml
34-
test/unit/lightspeed/utils/samples/collections/ansible_collections/community/broken_MANIFEST/MANIFEST.json
3529
xunit.xml

Taskfile.base.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ tasks:
3030
generates:
3131
- "{{ .VIRTUAL_ENV }}/pyvenv.cfg"
3232
- "{{ .VIRTUAL_ENV }}/CACHEDIR.TAG"
33-
- resources/contentCreator/createDevfile/devfile-template.txt
34-
- resources/contentCreator/createDevcontainer/
33+
- out/resources/contentCreator/createDevfile/devfile-template.txt
34+
- out/resources/contentCreator/createDevcontainer/
3535
dir: "{{ .TASKFILE_DIR }}"
3636
sources:
3737
- pyproject.toml

Taskfile.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ tasks:
203203
DONT_PROMPT_WSL_INSTALL: "1"
204204
# Possible workaround for: https://github.com/microsoft/vscode-test-cli/issues/555
205205
TMP: "{{ .TASKFILE_DIR }}/out/e2e/tmp"
206+
TMPDIR: "{{ .TASKFILE_DIR }}/out/e2e/tmp"
206207
generates:
207208
- out/junit/e2e-test-results.xml
208209
- out/coverage/e2e/cobertura-coverage.xml
@@ -211,10 +212,7 @@ tasks:
211212
sources:
212213
- "{src,test}/**/*"
213214
- .vscode-test.mjs
214-
- exclude: "**/.ansible/**/*"
215215
- exclude: test/testFixtures/.vscode/settings.json
216-
- exclude: test/testFixtures/diagnostics/yaml/invalid_yaml.yml
217-
- exclude: test/unit/lightspeed/utils/samples/collections/ansible_collections/community/broken_MANIFEST/MANIFEST.json
218216
cmds:
219217
- rimraf .vscode-test/user-data/logs/*
220218
- mkdir -p out/e2e/tmp
@@ -252,6 +250,9 @@ tasks:
252250
interactive: true
253251
unit:
254252
desc: Run unit tests with coverage report
253+
env:
254+
TMP: "{{ .TASKFILE_DIR }}/out/unit/tmp"
255+
TMPDIR: "{{ .TASKFILE_DIR }}/out/unit/tmp"
255256
deps:
256257
- build
257258
sources:
@@ -263,6 +264,7 @@ tasks:
263264
- out/coverage/unit/lcov.info
264265
- out/junit/unit-test-results.xml
265266
cmds:
267+
- mkdir -p out/unit/tmp
266268
- vitest run
267269
interactive: true
268270
package:
@@ -276,7 +278,6 @@ tasks:
276278
- .vscodeignore
277279
- CHANGELOG.md
278280
- README.md
279-
- exclude: "**/.ansible/**/*"
280281
- exclude: "test/ui/**/*"
281282
- package*.json
282283
- tools/helper

eslint.config.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import tsParser from "@typescript-eslint/parser";
66
import prettierRecommendedConfig from "eslint-plugin-prettier/recommended";
77
import globals from "globals";
88
import path from "path";
9-
import { fileURLToPath } from "url";
109
import { defineConfig } from "eslint/config";
1110
import { createRequire } from "module";
1211
import importPlugin from "eslint-plugin-import";
@@ -15,8 +14,6 @@ const require = createRequire(import.meta.url);
1514
/** @type {import('eslint').ESLint.Plugin} */
1615
const eslintPluginLocal = require("./test/eslint/eslint-plugin-local.cjs");
1716

18-
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
19-
const __dirname = path.dirname(__filename); // get the name of the directory
2017
const gitignorePath = path.resolve(import.meta.dirname, ".gitignore");
2118

2219
export default defineConfig(
@@ -43,7 +40,7 @@ export default defineConfig(
4340
parser: tsParser,
4441
parserOptions: {
4542
projectService: true,
46-
tsconfigRootDir: __dirname,
43+
tsconfigRootDir: import.meta.dirname,
4744
},
4845
},
4946
plugins: {

packages/ansible-language-server/Taskfile.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ tasks:
4646
desc: Run all tests using node (same version as vscode), will skip @ee tests if both SKIP_PODMAN=1 and SKIP_DOCKER=1.
4747
dir: "{{ .TASKFILE_DIR }}"
4848
interactive: true
49+
env:
50+
TMP: "{{ .TASKFILE_DIR }}/../../out/als/tmp"
51+
TMPDIR: "{{ .TASKFILE_DIR }}/../../out/als/tmp"
4952
deps:
5053
- build
5154
sources:
@@ -62,6 +65,7 @@ tasks:
6265
- ../../out/coverage/unit/lcov.info # sonar
6366
- ../../out/junit/unit-test-results.xml
6467
cmds:
68+
- mkdir -p ../../out/als/tmp
6569
- bash -c ". {{.VIRTUAL_ENV}}/bin/activate && command -v ansible-lint && pnpm run test"
6670
test-with-ee:
6771
dir: '{{ .TASKFILE_DIR }}'

packages/ansible-language-server/test/fixtures/diagnostics/invalid_yaml.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
hosts: localhost
44
tasks:
55
# This following line is invalid and has been kept this way to test the YAML diagnostics features of extension.
6-
# The file is ignored while running yammlint pre-commit hook.
6+
# The file is ignored while running yamllint pre-commit hook.
77
- debug: msg="foo: bar"
88
become: true

packages/ansible-language-server/test/globalSetup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { isWindows, console } from "@test/helper.js";
33
import { spawn, spawnSync, SpawnSyncOptions } from "child_process";
44
import path from "path";
5+
import fs from "fs";
56
import { createRequire } from "module";
67
import { quote } from "shell-quote";
78

@@ -66,6 +67,12 @@ function execWithTimeout(
6667
}
6768

6869
export async function setup() {
70+
// Isolate HOME for language server tests to prevent writing to user's home directory
71+
const testHome = path.resolve(__dirname, "../../../out/als/tmp/home");
72+
fs.mkdirSync(testHome, { recursive: true });
73+
process.env.HOME = testHome;
74+
process.env.USERPROFILE = testHome; // Windows uses USERPROFILE instead of HOME
75+
6976
// Only run prerequisite checks when actually running tests, not when listing
7077
// Check if we're in list mode by checking command line arguments
7178
const isListing =

packages/ansible-language-server/test/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { ExtensionSettings } from "@src/interfaces/extensionSettings.js";
1515

1616
import Fuse from "fuse.js";
1717

18-
const FIXTURES_BASE_PATH = path.join(__dirname, "fixtures");
18+
export const FIXTURES_BASE_PATH = path.join(__dirname, "fixtures");
1919
const ANSIBLE_COLLECTIONS_FIXTURES_BASE_PATH = path.resolve(
2020
FIXTURES_BASE_PATH,
2121
"common",

packages/ansible-language-server/test/utils/getAnsibleMetaData.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { expect, beforeAll, afterAll } from "vitest";
22
import * as path from "path";
3-
import { fileURLToPath } from "url";
4-
import { dirname } from "path";
53
import {
64
ansibleMetaDataEntryType,
75
ansibleMetaDataType,
86
getAnsibleMetaData,
97
getResultsThroughCommandRunner,
108
} from "@src/utils/getAnsibleMetaData.js";
119
import {
10+
FIXTURES_BASE_PATH,
1211
createTestWorkspaceManager,
1312
disableExecutionEnvironmentSettings,
1413
enableExecutionEnvironmentSettings,
@@ -17,30 +16,23 @@ import {
1716
setFixtureAnsibleCollectionPathEnv,
1817
} from "@test/helper.js";
1918

20-
const __filename = fileURLToPath(import.meta.url);
21-
const __dirname = dirname(__filename);
22-
2319
function getAnsibleTestInfo() {
2420
const ansibleInfo: ansibleMetaDataEntryType = {};
2521
ansibleInfo["core version"] = ".";
2622
ansibleInfo["location"] = "/ansible";
2723
ansibleInfo["config file path"] = path.resolve(
28-
__dirname,
29-
"..",
30-
"fixtures",
24+
FIXTURES_BASE_PATH,
3125
"utils",
3226
"getAnsibleMetaData",
3327
"ansible.cfg",
3428
);
3529
ansibleInfo["collections location"] = [
36-
path.resolve(__dirname, "..", "fixtures", "common", "collections"),
30+
path.resolve(FIXTURES_BASE_PATH, "common", "collections"),
3731
];
3832
ansibleInfo["module location"] = ["/modules"];
3933
ansibleInfo["default host list path"] = [
4034
path.resolve(
41-
__dirname,
42-
"..",
43-
"fixtures",
35+
FIXTURES_BASE_PATH,
4436
"utils",
4537
"getAnsibleMetaData",
4638
"inventory",

packages/ansible-language-server/test/utils/pathUtils.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { expect } from "vitest";
22
import * as path from "path";
3-
import { fileURLToPath } from "url";
4-
import { dirname } from "path";
53
import { globArray } from "@src/utils/pathUtils.js";
6-
7-
const __filename = fileURLToPath(import.meta.url);
8-
const __dirname = dirname(__filename);
4+
import { FIXTURES_BASE_PATH } from "@test/helper.js";
95

106
describe("docsFinder", function () {
11-
const dir = path.resolve(__dirname, "..", "fixtures", "utils", "docsFinder");
7+
const dir = path.resolve(FIXTURES_BASE_PATH, "utils", "docsFinder");
128

139
describe("globArray()", function () {
1410
const tests = [

0 commit comments

Comments
 (0)