feat(platform): add executable permission validation to node-finder

- Add isExecutable() helper to verify files have execute permission
- On Unix: uses fs.constants.X_OK to check execute permission
- On Windows: only checks file existence (X_OK not meaningful)
- Replace fs.existsSync with isExecutable for all node path checks
- Add JSDoc comment documenting version sorting limitations
- Add test to verify found node binary is executable

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Kacper
2025-12-21 15:16:33 +01:00
parent b00568176c
commit 6e341c1c15
2 changed files with 52 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { findNodeExecutable, buildEnhancedPath } from '../src/node-finder.js';
import path from 'path';
import fs from 'fs';
describe('node-finder', () => {
describe('findNodeExecutable', () => {
@@ -51,6 +52,25 @@ describe('node-finder', () => {
];
expect(validSources).toContain(result.source);
});
it('should find an executable node binary', () => {
const result = findNodeExecutable();
// Skip this test if fallback is used (node not found via path search)
if (result.source === 'fallback') {
expect(result.nodePath).toBe('node');
return;
}
// Verify the found path is actually executable
if (process.platform === 'win32') {
// On Windows, just check file exists (X_OK is not meaningful)
expect(() => fs.accessSync(result.nodePath, fs.constants.F_OK)).not.toThrow();
} else {
// On Unix-like systems, verify execute permission
expect(() => fs.accessSync(result.nodePath, fs.constants.X_OK)).not.toThrow();
}
});
});
describe('buildEnhancedPath', () => {