(fix): Custom Commands follow symlinks (#4907)
This commit is contained in:
parent
771cb229ab
commit
3e81359c6b
|
@ -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 () => {
|
it('loads multiple commands', async () => {
|
||||||
const userCommandsDir = getUserCommandsDir();
|
const userCommandsDir = getUserCommandsDir();
|
||||||
mock({
|
mock({
|
||||||
|
|
|
@ -71,6 +71,7 @@ export class FileCommandLoader implements ICommandLoader {
|
||||||
nodir: true,
|
nodir: true,
|
||||||
dot: true,
|
dot: true,
|
||||||
signal,
|
signal,
|
||||||
|
follow: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue