fix(cli): detect symlinked entrypoints (#652)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import path from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
|
||||
import { isModuleCliExecution, normalizeCliEntryPath } from './cli-entry.js';
|
||||
|
||||
describe('cli entry detection', () => {
|
||||
const modulePath = '/tmp/openchamber/bin/cli.js';
|
||||
const moduleUrl = pathToFileURL(modulePath).href;
|
||||
|
||||
it('resolves symlinked entry paths before comparing', () => {
|
||||
const symlinkPath = '/usr/local/bin/openchamber';
|
||||
const realpath = (filePath) => {
|
||||
if (filePath === path.resolve(symlinkPath)) {
|
||||
return modulePath;
|
||||
}
|
||||
return filePath;
|
||||
};
|
||||
|
||||
expect(isModuleCliExecution(symlinkPath, moduleUrl, realpath)).toBe(true);
|
||||
});
|
||||
|
||||
it('falls back to resolved paths when realpath fails', () => {
|
||||
const realpath = () => {
|
||||
throw new Error('realpath unavailable');
|
||||
};
|
||||
|
||||
expect(isModuleCliExecution(modulePath, moduleUrl, realpath)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for non-matching entry path', () => {
|
||||
expect(isModuleCliExecution('/tmp/other-cli.js', moduleUrl)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for empty entry path', () => {
|
||||
expect(isModuleCliExecution('', moduleUrl)).toBe(false);
|
||||
});
|
||||
|
||||
it('normalizes direct paths when realpath fails', () => {
|
||||
const unresolvedPath = './packages/web/bin/cli.js';
|
||||
const realpath = () => {
|
||||
throw new Error('no symlink resolution');
|
||||
};
|
||||
|
||||
expect(normalizeCliEntryPath(unresolvedPath, realpath)).toBe(path.resolve(unresolvedPath));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user