Skip to content

chore: avoid creating temp files inside the source tree#2708

Open
ssbarnea wants to merge 1 commit intomainfrom
fix/pnpm
Open

chore: avoid creating temp files inside the source tree#2708
ssbarnea wants to merge 1 commit intomainfrom
fix/pnpm

Conversation

@ssbarnea
Copy link
Copy Markdown
Member

@ssbarnea ssbarnea commented Mar 31, 2026

Related: AAP-65204

The PR avoids creating temporary files inside the source tree during test execution by consolidating fixture path references and migrating tests to use system temporary directories. This ensures test artifacts don't pollute the repository, improving build hygiene and compatibility with different file system layouts.

  • Exported FIXTURES_BASE_PATH constant from test helper for shared fixture location reference
  • Removed __dirname derivations from eslint.config.mjs, simplifying parser configuration
  • Updated test files to import and use FIXTURES_BASE_PATH instead of deriving paths from __dirname
  • Migrated ansibleLint.test.ts and ansibleNavigator.test.ts to create isolated temporary directories using mkdtempSync instead of writing to source tree

related: AAP-65204

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates tests/config to avoid creating or relying on files inside the repository source tree, aligning with the goal of keeping the working tree clean during test runs (Related: AAP-65204).

Changes:

  • Move ansible-mcp-server tool tests to create playbook fixtures in a per-run OS temp directory and clean up the directory afterward.
  • Centralize ansible-language-server fixture base path resolution via an exported FIXTURES_BASE_PATH test helper constant.
  • Simplify eslint.config.mjs by removing manual __dirname derivation and dropping tsconfigRootDir.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/ansible-mcp-server/test/tools/ansibleNavigator.test.ts Writes playbooks into a temp directory instead of the test source directory; cleans up temp directory after tests.
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts Same temp-directory approach for ansible-lint tests; cleans up after tests.
packages/ansible-language-server/test/utils/pathUtils.test.ts Uses shared FIXTURES_BASE_PATH to locate fixtures.
packages/ansible-language-server/test/utils/getAnsibleMetaData.test.ts Uses shared FIXTURES_BASE_PATH for fixture paths instead of per-file __dirname resolution.
packages/ansible-language-server/test/helper.ts Exports FIXTURES_BASE_PATH for reuse across tests.
eslint.config.mjs Removes manual __dirname setup and tsconfigRootDir configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to 41
afterAll(() => {
rmSync(tempDir, { recursive: true, force: true });
});
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afterAll unconditionally calls rmSync(tempDir, ...). If beforeAll throws before tempDir is assigned (e.g., mkdtemp/writeFile failure), afterAll will run with tempDir undefined and throw, masking the original failure. Consider initializing tempDir as string | undefined and guarding in afterAll (or wrapping setup/teardown in try/finally).

Copilot uses AI. Check for mistakes.
Comment on lines +37 to 39
afterAll(() => {
rmSync(tempDir, { recursive: true, force: true });
});
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afterAll unconditionally calls rmSync(tempDir, ...). If beforeAll fails before assigning tempDir (mkdtemp/writeFile errors), cleanup will throw with an invalid path and can hide the real failure. Consider making tempDir optional and guarding the rmSync call.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

❌ 6 Tests Failed:

Tests completed Failed Passed Skipped
1537 6 1531 113
View the top 3 failed test(s) by shortest run time
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts > Ansible Lint Handler > Fix functionality > should handle clean playbook with no issues
Stack Traces | 1.56s run time
AssertionError: expected 'Error: ansible-lint failed with error…' to contain 'Linting'

- Expected
+ Received

- Linting
+ Error: ansible-lint failed with error:
+ WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
+ .........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py:242: UserWarning: Project directory /.ansible cannot be used for caching as it is not writable.
+   self.cache_dir = get_cache_dir(self.project_dir, isolated=self.isolated)
+ Traceback (most recent call last):
+   File ".........................../home/devtools/.local.../vsa/bin/ansible-lint", line 10, in <module>
+     sys.exit(_run_cli_entrypoint())
+              ~~~~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 447, in _run_cli_entrypoint
+     sys.exit(main(sys.argv))
+              ~~~~^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 376, in main
+     app = get_app(
+         offline=None,
+         cached=True,
+     )  # to be sure we use the offline value from settings
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13.../site-packages/ansiblelint/app.py", line 434, in get_app
+     app.runtime.prepare_environment(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+         install_local=(not offline),
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         offline=offline,
+         ^^^^^^^^^^^^^^^^
+         role_name_check=role_name_check,
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     )
+     ^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 743, in prepare_environment
+     for item in search_galaxy_paths(self.project_dir):
+                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 1077, in search_galaxy_paths
+     if file_path.exists():
+        ~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_abc.py", line 450, in exists
+     self.stat(follow_symlinks=follow_symlinks)
+     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_local.py", line 515, in stat
+     return os.stat(self, follow_symlinks=follow_symlinks)
+            ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ PermissionError: [Errno 13] Permission denied: '/root/galaxy.yml'
+
+

 ❯ test/tools/ansibleLint.test.ts:215:38
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts > Ansible Lint Handler > Fix functionality > should display fixed content when fix is applied and content is available
Stack Traces | 1.56s run time
AssertionError: expected 'Error: ansible-lint failed with exit …' to contain '📝 Fixed content:'

- Expected
+ Received

- 📝 Fixed content:
+ Error: ansible-lint failed with exit code 1 and error:
+ WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
+ .........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py:242: UserWarning: Project directory /.ansible cannot be used for caching as it is not writable.
+   self.cache_dir = get_cache_dir(self.project_dir, isolated=self.isolated)
+ Traceback (most recent call last):
+   File ".........................../home/devtools/.local.../vsa/bin/ansible-lint", line 10, in <module>
+     sys.exit(_run_cli_entrypoint())
+              ~~~~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 447, in _run_cli_entrypoint
+     sys.exit(main(sys.argv))
+              ~~~~^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 376, in main
+     app = get_app(
+         offline=None,
+         cached=True,
+     )  # to be sure we use the offline value from settings
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13.../site-packages/ansiblelint/app.py", line 434, in get_app
+     app.runtime.prepare_environment(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+         install_local=(not offline),
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         offline=offline,
+         ^^^^^^^^^^^^^^^^
+         role_name_check=role_name_check,
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     )
+     ^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 743, in prepare_environment
+     for item in search_galaxy_paths(self.project_dir):
+                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 1077, in search_galaxy_paths
+     if file_path.exists():
+        ~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_abc.py", line 450, in exists
+     self.stat(follow_symlinks=follow_symlinks)
+     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_local.py", line 515, in stat
+     return os.stat(self, follow_symlinks=follow_symlinks)
+            ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ PermissionError: [Errno 13] Permission denied: '/root/galaxy.yml'
+
+

 ❯ test/tools/ansibleLint.test.ts:200:38
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts > Ansible Lint Handler > Fix functionality > should apply fixes when fix: true is specified
Stack Traces | 1.93s run time
AssertionError: expected 'Error: ansible-lint failed with exit …' to contain '📝 Fixed content:'

- Expected
+ Received

- 📝 Fixed content:
+ Error: ansible-lint failed with exit code 1 and error:
+ WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
+ .........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py:242: UserWarning: Project directory /.ansible cannot be used for caching as it is not writable.
+   self.cache_dir = get_cache_dir(self.project_dir, isolated=self.isolated)
+ Traceback (most recent call last):
+   File ".........................../home/devtools/.local.../vsa/bin/ansible-lint", line 10, in <module>
+     sys.exit(_run_cli_entrypoint())
+              ~~~~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 447, in _run_cli_entrypoint
+     sys.exit(main(sys.argv))
+              ~~~~^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 376, in main
+     app = get_app(
+         offline=None,
+         cached=True,
+     )  # to be sure we use the offline value from settings
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13.../site-packages/ansiblelint/app.py", line 434, in get_app
+     app.runtime.prepare_environment(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+         install_local=(not offline),
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         offline=offline,
+         ^^^^^^^^^^^^^^^^
+         role_name_check=role_name_check,
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     )
+     ^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 743, in prepare_environment
+     for item in search_galaxy_paths(self.project_dir):
+                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 1077, in search_galaxy_paths
+     if file_path.exists():
+        ~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_abc.py", line 450, in exists
+     self.stat(follow_symlinks=follow_symlinks)
+     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_local.py", line 515, in stat
+     return os.stat(self, follow_symlinks=follow_symlinks)
+            ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ PermissionError: [Errno 13] Permission denied: '/root/galaxy.yml'
+
+

 ❯ test/tools/ansibleLint.test.ts:173:38
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts > Ansible Lint Handler > Core linting functionality > should detect and report linting issues in playbooks
Stack Traces | 2.14s run time
AssertionError: expected 'Error: ansible-lint failed with error…' to contain 'Linting results'

- Expected
+ Received

- Linting results
+ Error: ansible-lint failed with error:
+ WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
+ .........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py:242: UserWarning: Project directory /.ansible cannot be used for caching as it is not writable.
+   self.cache_dir = get_cache_dir(self.project_dir, isolated=self.isolated)
+ Traceback (most recent call last):
+   File ".........................../home/devtools/.local.../vsa/bin/ansible-lint", line 10, in <module>
+     sys.exit(_run_cli_entrypoint())
+              ~~~~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 447, in _run_cli_entrypoint
+     sys.exit(main(sys.argv))
+              ~~~~^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 376, in main
+     app = get_app(
+         offline=None,
+         cached=True,
+     )  # to be sure we use the offline value from settings
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13.../site-packages/ansiblelint/app.py", line 434, in get_app
+     app.runtime.prepare_environment(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+         install_local=(not offline),
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         offline=offline,
+         ^^^^^^^^^^^^^^^^
+         role_name_check=role_name_check,
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     )
+     ^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 743, in prepare_environment
+     for item in search_galaxy_paths(self.project_dir):
+                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 1077, in search_galaxy_paths
+     if file_path.exists():
+        ~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_abc.py", line 450, in exists
+     self.stat(follow_symlinks=follow_symlinks)
+     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_local.py", line 515, in stat
+     return os.stat(self, follow_symlinks=follow_symlinks)
+            ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ PermissionError: [Errno 13] Permission denied: '/root/galaxy.yml'
+
+

 ❯ test/tools/ansibleLint.test.ts:51:38
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts > Ansible Lint Handler > Fix parameter handling > should run linting with automatic fixes when fix parameter is true
Stack Traces | 2.22s run time
AssertionError: expected 'Error: ansible-lint failed with exit …' to contain '📝 Fixed content:'

- Expected
+ Received

- 📝 Fixed content:
+ Error: ansible-lint failed with exit code 1 and error:
+ WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
+ .........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py:242: UserWarning: Project directory /.ansible cannot be used for caching as it is not writable.
+   self.cache_dir = get_cache_dir(self.project_dir, isolated=self.isolated)
+ Traceback (most recent call last):
+   File ".........................../home/devtools/.local.../vsa/bin/ansible-lint", line 10, in <module>
+     sys.exit(_run_cli_entrypoint())
+              ~~~~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 447, in _run_cli_entrypoint
+     sys.exit(main(sys.argv))
+              ~~~~^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 376, in main
+     app = get_app(
+         offline=None,
+         cached=True,
+     )  # to be sure we use the offline value from settings
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13.../site-packages/ansiblelint/app.py", line 434, in get_app
+     app.runtime.prepare_environment(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+         install_local=(not offline),
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         offline=offline,
+         ^^^^^^^^^^^^^^^^
+         role_name_check=role_name_check,
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     )
+     ^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 743, in prepare_environment
+     for item in search_galaxy_paths(self.project_dir):
+                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 1077, in search_galaxy_paths
+     if file_path.exists():
+        ~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_abc.py", line 450, in exists
+     self.stat(follow_symlinks=follow_symlinks)
+     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_local.py", line 515, in stat
+     return os.stat(self, follow_symlinks=follow_symlinks)
+            ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ PermissionError: [Errno 13] Permission denied: '/root/galaxy.yml'
+
+

 ❯ test/tools/ansibleLint.test.ts:157:38
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts > Ansible Lint Handler > Core linting functionality > should report no issues for clean playbooks
Stack Traces | 2.35s run time
AssertionError: expected 'Error: ansible-lint failed with error…' to contain 'Linting'

- Expected
+ Received

- Linting
+ Error: ansible-lint failed with error:
+ WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
+ .........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py:242: UserWarning: Project directory /.ansible cannot be used for caching as it is not writable.
+   self.cache_dir = get_cache_dir(self.project_dir, isolated=self.isolated)
+ Traceback (most recent call last):
+   File ".........................../home/devtools/.local.../vsa/bin/ansible-lint", line 10, in <module>
+     sys.exit(_run_cli_entrypoint())
+              ~~~~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 447, in _run_cli_entrypoint
+     sys.exit(main(sys.argv))
+              ~~~~^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13....../site-packages/ansiblelint/__main__.py", line 376, in main
+     app = get_app(
+         offline=None,
+         cached=True,
+     )  # to be sure we use the offline value from settings
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13.../site-packages/ansiblelint/app.py", line 434, in get_app
+     app.runtime.prepare_environment(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+         install_local=(not offline),
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         offline=offline,
+         ^^^^^^^^^^^^^^^^
+         role_name_check=role_name_check,
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     )
+     ^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 743, in prepare_environment
+     for item in search_galaxy_paths(self.project_dir):
+                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../vsa/lib/python3.13........./site-packages/ansible_compat/runtime.py", line 1077, in search_galaxy_paths
+     if file_path.exists():
+        ~~~~~~~~~~~~~~~~^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_abc.py", line 450, in exists
+     self.stat(follow_symlinks=follow_symlinks)
+     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File ".........................../home/devtools/.local.../uv/python/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/pathlib/_local.py", line 515, in stat
+     return os.stat(self, follow_symlinks=follow_symlinks)
+            ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ PermissionError: [Errno 13] Permission denied: '/root/galaxy.yml'
+
+

 ❯ test/tools/ansibleLint.test.ts:66:38

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

This pull request removes ESM module boilerplate (fileURLToPath, __dirname derivation) from configuration and test files. It centralizes fixture path management by exporting FIXTURES_BASE_PATH and refactors test files to use either this centralized constant or isolated temporary directories instead of static __dirname-relative paths.

Changes

Cohort / File(s) Summary
ESLint Configuration Cleanup
eslint.config.mjs
Removed fileURLToPath import and __dirname/__filename constants. Updated TypeScript parser options by removing tsconfigRootDir: __dirname, keeping only projectService: true.
Test Fixture Path Centralization
packages/ansible-language-server/test/helper.ts
Exported FIXTURES_BASE_PATH constant to make it publicly available for test file imports.
Tests Using Centralized Fixture Path
packages/ansible-language-server/test/utils/getAnsibleMetaData.test.ts, packages/ansible-language-server/test/utils/pathUtils.test.ts
Removed ESM boilerplate and migrated path construction to use the exported FIXTURES_BASE_PATH constant instead of __dirname-relative resolution.
Tests Using Temporary Directories
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts, packages/ansible-mcp-server/test/tools/ansibleNavigator.test.ts
Replaced static __dirname-based fixture paths with dynamically created temporary directories. Switched file operations from async (writeFile, unlink) to sync (writeFileSync, rmSync) for test data setup and teardown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The paths now flow where temp winds blow,
No __dirname chains to hold them so,
Through fixtures pooled and temps laid bare,
Our tests take flight on paths so fair! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the pull request: refactoring tests to use temporary directories instead of creating files in the source tree.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pnpm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/ansible-mcp-server/test/tools/ansibleNavigator.test.ts (1)

39-40: Guard teardown to avoid masking setup failures.

Line 40 assumes tempDir is always initialized. If beforeAll fails early, teardown can throw and hide the original failure.

Suggested hardening
-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
...
-  let tempDir: string;
+  let tempDir = "";
...
   afterAll(() => {
-    rmSync(tempDir, { recursive: true, force: true });
+    if (tempDir && existsSync(tempDir)) {
+      rmSync(tempDir, { recursive: true, force: true });
+    }
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ansible-mcp-server/test/tools/ansibleNavigator.test.ts` around lines
39 - 40, The afterAll teardown calls rmSync(tempDir, { recursive: true, force:
true }) unguarded which can throw if beforeAll failed to set tempDir; update the
afterAll handler to first verify tempDir is defined and optionally that it
exists (e.g., using fs.existsSync) and only then call rmSync, or wrap the rmSync
call in a try/catch to swallow cleanup errors so setup failures aren't masked;
reference the afterAll block, tempDir variable and rmSync call when making this
change.
packages/ansible-mcp-server/test/tools/ansibleLint.test.ts (1)

37-38: Make cleanup resilient to partial setup failures.

Line 38 can throw if beforeAll fails before tempDir is assigned. Guarding teardown prevents secondary failures from obscuring the primary error.

Suggested hardening
-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
...
-  let tempDir: string;
+  let tempDir = "";
...
   afterAll(() => {
-    rmSync(tempDir, { recursive: true, force: true });
+    if (tempDir && existsSync(tempDir)) {
+      rmSync(tempDir, { recursive: true, force: true });
+    }
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ansible-mcp-server/test/tools/ansibleLint.test.ts` around lines 37 -
38, The teardown in afterAll currently calls rmSync(tempDir, { recursive: true,
force: true }) which can throw if tempDir was never set (due to beforeAll
failing); update afterAll to guard the cleanup by checking that tempDir is
defined and non-empty (and/or exists) before calling rmSync, and wrap the rmSync
call in a try/catch to swallow/ log any cleanup errors so they don't mask the
original failure — locate the afterAll block and the tempDir variable referenced
there and add the guard and error handling around rmSync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/ansible-mcp-server/test/tools/ansibleLint.test.ts`:
- Around line 37-38: The teardown in afterAll currently calls rmSync(tempDir, {
recursive: true, force: true }) which can throw if tempDir was never set (due to
beforeAll failing); update afterAll to guard the cleanup by checking that
tempDir is defined and non-empty (and/or exists) before calling rmSync, and wrap
the rmSync call in a try/catch to swallow/ log any cleanup errors so they don't
mask the original failure — locate the afterAll block and the tempDir variable
referenced there and add the guard and error handling around rmSync.

In `@packages/ansible-mcp-server/test/tools/ansibleNavigator.test.ts`:
- Around line 39-40: The afterAll teardown calls rmSync(tempDir, { recursive:
true, force: true }) unguarded which can throw if beforeAll failed to set
tempDir; update the afterAll handler to first verify tempDir is defined and
optionally that it exists (e.g., using fs.existsSync) and only then call rmSync,
or wrap the rmSync call in a try/catch to swallow cleanup errors so setup
failures aren't masked; reference the afterAll block, tempDir variable and
rmSync call when making this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 32e813e0-7f47-4216-b119-e459ac330778

📥 Commits

Reviewing files that changed from the base of the PR and between 608422f and 2bc2790.

📒 Files selected for processing (6)
  • eslint.config.mjs
  • packages/ansible-language-server/test/helper.ts
  • packages/ansible-language-server/test/utils/getAnsibleMetaData.test.ts
  • packages/ansible-language-server/test/utils/pathUtils.test.ts
  • packages/ansible-mcp-server/test/tools/ansibleLint.test.ts
  • packages/ansible-mcp-server/test/tools/ansibleNavigator.test.ts
💤 Files with no reviewable changes (1)
  • eslint.config.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants