(fix): Custom Commands follow symlinks (#4907)

This commit is contained in:
Abhi 2025-07-25 23:27:23 -04:00 committed by GitHub
parent 771cb229ab
commit 3e81359c6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 0 deletions

View File

@ -54,6 +54,63 @@ describe('FileCommandLoader', () => {
}
});
// Symlink creation on Windows requires special permissions that are not
// available in the standard CI environment. Therefore, we skip these tests
// on Windows to prevent CI failures. The core functionality is still
// validated on Linux and macOS.
const itif = (condition: boolean) => (condition ? it : it.skip);
itif(process.platform !== 'win32')(
'loads commands from a symlinked directory',
async () => {
const userCommandsDir = getUserCommandsDir();
const realCommandsDir = '/real/commands';
mock({
[realCommandsDir]: {
'test.toml': 'prompt = "This is a test prompt"',
},
// Symlink the user commands directory to the real one
[userCommandsDir]: mock.symlink({
path: realCommandsDir,
}),
});
const loader = new FileCommandLoader(null as unknown as Config);
const commands = await loader.loadCommands(signal);
expect(commands).toHaveLength(1);
const command = commands[0];
expect(command).toBeDefined();
expect(command.name).toBe('test');
},
);
itif(process.platform !== 'win32')(
'loads commands from a symlinked subdirectory',
async () => {
const userCommandsDir = getUserCommandsDir();
const realNamespacedDir = '/real/namespaced-commands';
mock({
[userCommandsDir]: {
namespaced: mock.symlink({
path: realNamespacedDir,
}),
},
[realNamespacedDir]: {
'my-test.toml': 'prompt = "This is a test prompt"',
},
});
const loader = new FileCommandLoader(null as unknown as Config);
const commands = await loader.loadCommands(signal);
expect(commands).toHaveLength(1);
const command = commands[0];
expect(command).toBeDefined();
expect(command.name).toBe('namespaced:my-test');
},
);
it('loads multiple commands', async () => {
const userCommandsDir = getUserCommandsDir();
mock({

View File

@ -71,6 +71,7 @@ export class FileCommandLoader implements ICommandLoader {
nodir: true,
dot: true,
signal,
follow: true,
};
try {