Skip to content

Commit 7e7830d

Browse files
committed
Add a test to reproduce the error following external symlinks
1 parent 0b56e17 commit 7e7830d

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

packages/playground/cli/tests/run-cli.spec.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import { mkdtemp, writeFile } from 'node:fs/promises';
77
import { tmpdir } from 'node:os';
88
import { promisify } from 'node:util';
99
import { exec } from 'node:child_process';
10-
import { readdirSync } from 'node:fs';
10+
import {
11+
readdirSync,
12+
writeFileSync,
13+
symlinkSync,
14+
unlinkSync,
15+
existsSync,
16+
} from 'node:fs';
1117
import { createHash } from 'node:crypto';
1218
import { MinifiedWordPressVersionsList } from '@wp-playground/wordpress-builds';
1319

@@ -235,5 +241,66 @@ describe('run-cli', () => {
235241
*/
236242
expect(await getDirectoryChecksum(tmpDir)).toBe(checksum);
237243
});
244+
245+
test('should be able to follow external symlinks in primary and secondary PHP instances', async () => {
246+
// TODO: Make sure test always uses a single worker.
247+
// TODO: Is there a way to confirm we are testing use of a non-primary PHP instance?
248+
const tmpDir = await mkdtemp(
249+
path.join(tmpdir(), 'playground-test-')
250+
);
251+
writeFileSync(
252+
path.join(tmpDir, 'sleep.php'),
253+
'<?php sleep(1); echo "Slept"; '
254+
);
255+
const symlinkPath = path.join(
256+
import.meta.dirname,
257+
'mount-examples',
258+
'symlinking',
259+
'symlinked-script'
260+
);
261+
262+
try {
263+
if (existsSync(symlinkPath)) {
264+
unlinkSync(symlinkPath);
265+
}
266+
// TODO: Confirm that symlink target is outside of current working dir tree.
267+
symlinkSync(tmpDir, symlinkPath);
268+
cliServer = await runCLI({
269+
debug: true,
270+
command: 'server',
271+
followSymlinks: true,
272+
'mount-before-install': [
273+
{
274+
hostPath: symlinkPath,
275+
vfsPath: '/wordpress/wp-content/test-script',
276+
},
277+
],
278+
});
279+
expect(cliServer.workerThreadCount).toBe(1);
280+
// Make multiple simultaneous requests to force the use of a secondary PHP instance.
281+
// TODO: Find way to confirm this.
282+
const responses = await Promise.all([
283+
cliServer.playground.request({
284+
url: '/wp-content/test-script/sleep.php',
285+
method: 'GET',
286+
}),
287+
cliServer.playground.request({
288+
url: '/wp-content/test-script/sleep.php',
289+
method: 'GET',
290+
}),
291+
// Test a third request to hopefully test more than one secondary instance.
292+
cliServer.playground.request({
293+
url: '/wp-content/test-script/sleep.php',
294+
method: 'GET',
295+
}),
296+
]);
297+
responses.forEach((response) => {
298+
expect(response.httpStatusCode).toBe(200);
299+
expect(response.text).toContain('Slept');
300+
});
301+
} finally {
302+
unlinkSync(symlinkPath);
303+
}
304+
});
238305
});
239306
});

0 commit comments

Comments
 (0)