fix(test): isolate sysbin in install-preflight tests to prevent host $PATH leakage - #1706
Conversation
…PATH leakage The "node missing" / "npm missing" runtime preflight tests need a PATH where the host's real `node` and `npm` are NOT visible, so the error branches are actually exercised. The previous `TEST_SYSTEM_PATH = "/usr/bin:/bin"` literal leaks `/usr/bin/node` on any Linux distribution that installs Node via `apt install nodejs` (i.e. most of them). On those hosts the affected tests assert the wrong code path — they expect "node missing" but the preflight finds the system `/usr/bin/node` and reports a version mismatch instead. This replaces the literal with `buildIsolatedSystemPath()`, a small helper that creates a tmpdir under `os.tmpdir()` at module load and symlinks every entry from `/usr/bin` and `/bin` into it — except `node`, `npm`, and `npx`, which are deliberately excluded. Rebased onto the renamed .ts file from the TS migration stack. Closes #1621 (sub-item 2 of three). Co-Authored-By: TSavo <TSavo@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughReplaced the hardcoded test PATH in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
🦞 NemoClaw Functional Review — PR #1706Verdict: ✅ APPROVE Functional Testing
SecurityNo concerns. Single test file change. No new dependencies, no permission changes, no credential handling. The ArchitectureSingle file: 🦞 Auto-reviewed by Nemo. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/install-preflight.test.ts (1)
33-35: Optional: add one module-level cleanup for the temp sysbin directory.Not blocking, but this can leave many temp dirs during local watch/repeated runs.
♻️ Proposed cleanup
-import { describe, it, expect } from "vitest"; +import { describe, it, expect, afterAll } from "vitest"; ... const TEST_SYSTEM_PATH = buildIsolatedSystemPath(); +afterAll(() => { + fs.rmSync(TEST_SYSTEM_PATH, { recursive: true, force: true }); +});Also applies to: 60-60
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/install-preflight.test.ts` around lines 33 - 35, Add a module-level cleanup that removes the temporary sysbin directory created by the tests: within test/install-preflight.test.ts add an afterAll hook that deletes the temp sysbin directory (the variable holding it, e.g., sysbinDir or tempSysbinDir used when creating the dir in the file) using fs.rmSync or fs.promises.rm with recursive:true/force:true so repeated local runs/watch mode don't accumulate temp dirs; ensure the hook references the same variable used to create the directory and guard if it's undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/install-preflight.test.ts`:
- Around line 33-35: Add a module-level cleanup that removes the temporary
sysbin directory created by the tests: within test/install-preflight.test.ts add
an afterAll hook that deletes the temp sysbin directory (the variable holding
it, e.g., sysbinDir or tempSysbinDir used when creating the dir in the file)
using fs.rmSync or fs.promises.rm with recursive:true/force:true so repeated
local runs/watch mode don't accumulate temp dirs; ensure the hook references the
same variable used to create the directory and guard if it's undefined.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0857c876-38b1-4213-9ffa-53e71a644e48
📒 Files selected for processing (1)
test/install-preflight.test.ts
…$PATH leakage (NVIDIA#1706) The "node missing" / "npm missing" runtime preflight tests need a PATH where the host's real `node` and `npm` are NOT visible, so the error branches are actually exercised. The previous `TEST_SYSTEM_PATH = "/usr/bin:/bin"` literal leaks `/usr/bin/node` on any Linux distribution that installs Node via `apt install nodejs` (i.e. most of them). On those hosts the affected tests assert the wrong code path — they expect "node missing" but the preflight finds the system `/usr/bin/node` and reports a version mismatch instead. This replaces the literal with `buildIsolatedSystemPath()`, a small helper that creates a tmpdir under `os.tmpdir()` at module load and symlinks every entry from `/usr/bin` and `/bin` into it — except `node`, `npm`, and `npx`, which are deliberately excluded. Rebased onto the renamed .ts file from the TS migration stack. Closes NVIDIA#1621 (sub-item 2 of three). <!-- markdownlint-disable MD041 --> ## Summary <!-- 1-3 sentences: what this PR does and why. --> ## Related Issue <!-- Link to the issue: Fixes #NNN or Closes #NNN. Remove this section if none. --> ## Changes <!-- Bullet list of key changes. --> ## Type of Change <!-- Check the one that applies. --> - [ ] Code change for a new feature, bug fix, or refactor. - [ ] Code change with doc updates. - [ ] Doc only. Prose changes without code sample modifications. - [ ] Doc only. Includes code sample changes. ## Testing <!-- What testing was done? --> - [ ] `npx prek run --all-files` passes (or equivalently `make check`). - [ ] `npm test` passes. - [ ] `make docs` builds without warnings. (for doc-only changes) ## Checklist ### General - [ ] I have read and followed the [contributing guide](https://github.com/NVIDIA/NemoClaw/blob/main/CONTRIBUTING.md). - [ ] I have read and followed the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md). (for doc-only changes) ### Code Changes <!-- Skip if this is a doc-only PR. --> - [ ] Formatters applied — `npx prek run --all-files` auto-fixes formatting (or `make format` for targeted runs). - [ ] Tests added or updated for new or changed behavior. - [ ] No secrets, API keys, or credentials committed. - [ ] Doc pages updated for any user-facing behavior changes (new commands, changed defaults, new features, bug fixes that contradict existing docs). ### Doc Changes <!-- Skip if this PR has no doc changes. --> - [ ] Follows the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md). Try running the `nemoclaw-contributor-update-docs` agent skill to draft changes while complying with the style guide. For example, prompt your agent with "`/nemoclaw-contributor-update-docs` catch up the docs for the new changes I made in this PR." - [ ] New pages include SPDX license header and frontmatter, if creating a new page. - [ ] Cross-references and links verified. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test isolation for preflight/runtime checks by using an isolated system PATH to avoid interference from host-provided tools. * Made test setup more robust when preparing the isolated PATH by handling filesystem errors during population. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: TSavo <TSavo@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Brandon Pelfrey <bpelfrey@nvidia.com>
…$PATH leakage (NVIDIA#1706) The "node missing" / "npm missing" runtime preflight tests need a PATH where the host's real `node` and `npm` are NOT visible, so the error branches are actually exercised. The previous `TEST_SYSTEM_PATH = "/usr/bin:/bin"` literal leaks `/usr/bin/node` on any Linux distribution that installs Node via `apt install nodejs` (i.e. most of them). On those hosts the affected tests assert the wrong code path — they expect "node missing" but the preflight finds the system `/usr/bin/node` and reports a version mismatch instead. This replaces the literal with `buildIsolatedSystemPath()`, a small helper that creates a tmpdir under `os.tmpdir()` at module load and symlinks every entry from `/usr/bin` and `/bin` into it — except `node`, `npm`, and `npx`, which are deliberately excluded. Rebased onto the renamed .ts file from the TS migration stack. Closes NVIDIA#1621 (sub-item 2 of three). <!-- markdownlint-disable MD041 --> ## Summary <!-- 1-3 sentences: what this PR does and why. --> ## Related Issue <!-- Link to the issue: Fixes #NNN or Closes #NNN. Remove this section if none. --> ## Changes <!-- Bullet list of key changes. --> ## Type of Change <!-- Check the one that applies. --> - [ ] Code change for a new feature, bug fix, or refactor. - [ ] Code change with doc updates. - [ ] Doc only. Prose changes without code sample modifications. - [ ] Doc only. Includes code sample changes. ## Testing <!-- What testing was done? --> - [ ] `npx prek run --all-files` passes (or equivalently `make check`). - [ ] `npm test` passes. - [ ] `make docs` builds without warnings. (for doc-only changes) ## Checklist ### General - [ ] I have read and followed the [contributing guide](https://github.com/NVIDIA/NemoClaw/blob/main/CONTRIBUTING.md). - [ ] I have read and followed the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md). (for doc-only changes) ### Code Changes <!-- Skip if this is a doc-only PR. --> - [ ] Formatters applied — `npx prek run --all-files` auto-fixes formatting (or `make format` for targeted runs). - [ ] Tests added or updated for new or changed behavior. - [ ] No secrets, API keys, or credentials committed. - [ ] Doc pages updated for any user-facing behavior changes (new commands, changed defaults, new features, bug fixes that contradict existing docs). ### Doc Changes <!-- Skip if this PR has no doc changes. --> - [ ] Follows the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md). Try running the `nemoclaw-contributor-update-docs` agent skill to draft changes while complying with the style guide. For example, prompt your agent with "`/nemoclaw-contributor-update-docs` catch up the docs for the new changes I made in this PR." - [ ] New pages include SPDX license header and frontmatter, if creating a new page. - [ ] Cross-references and links verified. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test isolation for preflight/runtime checks by using an isolated system PATH to avoid interference from host-provided tools. * Made test setup more robust when preparing the isolated PATH by handling filesystem errors during population. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: TSavo <TSavo@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Brandon Pelfrey <bpelfrey@nvidia.com>
The "node missing" / "npm missing" runtime preflight tests need a PATH where the host's real
nodeandnpmare NOT visible, so the error branches are actually exercised. The previousTEST_SYSTEM_PATH = "/usr/bin:/bin"literal leaks/usr/bin/nodeon any Linux distribution that installs Node viaapt install nodejs(i.e. most of them). On those hosts the affected tests assert the wrong code path — they expect "node missing" but the preflight finds the system/usr/bin/nodeand reports a version mismatch instead.This replaces the literal with
buildIsolatedSystemPath(), a small helper that creates a tmpdir underos.tmpdir()at module load and symlinks every entry from/usr/binand/bininto it — exceptnode,npm, andnpx, which are deliberately excluded.Rebased onto the renamed .ts file from the TS migration stack.
Closes #1621 (sub-item 2 of three).
Summary
Related Issue
Changes
Type of Change
Testing
npx prek run --all-filespasses (or equivalentlymake check).npm testpasses.make docsbuilds without warnings. (for doc-only changes)Checklist
General
Code Changes
npx prek run --all-filesauto-fixes formatting (ormake formatfor targeted runs).Doc Changes
nemoclaw-contributor-update-docsagent skill to draft changes while complying with the style guide. For example, prompt your agent with "/nemoclaw-contributor-update-docscatch up the docs for the new changes I made in this PR."Summary by CodeRabbit