@@ -7,7 +7,13 @@ import { mkdtemp, writeFile } from 'node:fs/promises';
7
7
import { tmpdir } from 'node:os' ;
8
8
import { promisify } from 'node:util' ;
9
9
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' ;
11
17
import { createHash } from 'node:crypto' ;
12
18
import { MinifiedWordPressVersionsList } from '@wp-playground/wordpress-builds' ;
13
19
@@ -235,5 +241,66 @@ describe('run-cli', () => {
235
241
*/
236
242
expect ( await getDirectoryChecksum ( tmpDir ) ) . toBe ( checksum ) ;
237
243
} ) ;
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
+ } ) ;
238
305
} ) ;
239
306
} ) ;
0 commit comments