Auto-mount host directories referenced in wp-config.php#3099
Conversation
On a real WordPress server, PHP can access any path on the filesystem. Studio's WASM sandbox restricts PHP to the mounted site folder, causing plugins that reference external directories (via define() constants in wp-config.php) to silently fail. This parses wp-config.php for define() calls with absolute path values, filters to paths that exist on disk and are outside the site folder, and mounts them automatically at their real host location. Zero configuration required — developers write normal WordPress code and it works. Both mount sites are covered: - getBaseRunCLIArgs() in wordpress-server-child.ts (running server) - runWpCliCommand() in run-wp-cli-command.ts (standalone WP-CLI) Fixes #3082
9893353 to
ee1227d
Compare
📊 Performance Test ResultsComparing 6e6aa90 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
path.resolve('/etc/ssl') returns '\etc\ssl' on Windows, so the
literal '/etc/' prefix check never matched and the unit test
'should skip sensitive system paths' failed on the Windows CI agent.
Use the raw POSIX-style path captured from the regex (which is
guaranteed to start with '/') instead of the resolved path. The
sensitive-roots list is intentionally Unix-only — on a real Windows
host these paths will never exist anyway, and the existsSync() check
below is the actual safety net there.
Fixes the 'Unit Tests on windows' failure on PR #3099.
path.resolve('/etc/ssl') returns '\etc\ssl' on Windows, so the
literal '/etc/' prefix check never matched and the unit test
'should skip sensitive system paths' failed on the Windows CI agent.
Use the raw POSIX-style path captured from the regex (which is
guaranteed to start with '/') instead of the resolved path. The
sensitive-roots list is intentionally Unix-only — on a real Windows
host these paths will never exist anyway, and the existsSync() check
below is the actual safety net there.
Fixes the 'Unit Tests on windows' failure on PR #3099.
path.resolve('/etc/ssl') returns '\etc\ssl' on Windows, so the
literal '/etc/' prefix check never matched and the unit test
'should skip sensitive system paths' failed on the Windows CI agent.
Use the raw POSIX-style path captured from the regex (which is
guaranteed to start with '/') instead of the resolved path. The
sensitive-roots list is intentionally Unix-only — on a real Windows
host these paths will never exist anyway, and the existsSync() check
below is the actual safety net there.
Fixes the 'Unit Tests on windows' failure on PR #3099.
da95589 to
bd14cf8
Compare
…nfig-paths # Conflicts: # apps/cli/lib/run-wp-cli-command.ts
|
Closing this as superseded by the native PHP runtime rollout. I retested the original DMC workspace access failure with the Studio CLI using native PHP enabled and confirmed it succeeds without this PR:
The same no-PR command under the default Playground/WASM runtime still fails because
Given the native PHP launch plan says native PHP is expected to become the default runtime in Studio v1.11.0, this PR is no longer needed for the workflow it was carrying locally. Playground fallback parity would be the only remaining reason to keep it open. |
Summary
On a real WordPress server with MariaDB, if you
define( 'MY_PATH', '/some/dir' )in wp-config.php, PHP can just access that path. Studio's WASM sandbox only mounts the site folder at/wordpress, so any external path silently fails —file_exists()returns false,chmod()errors,scandir()breaks.This PR makes Studio behave like a real server by auto-detecting host directories from wp-config.php and mounting them transparently.
How it works
wp-config.phpfordefine()calls with absolute path string values/etc,/var,/proc,/sys,/dev)/Users/me/Developer→/Users/me/Developer)Zero configuration required. Developers write normal WordPress code and it works.
Use case
Plugins and developer tools that operate on files outside the WordPress site folder — git workspaces, shared asset directories, build output paths, data directories, AI agent memory stores. Example:
Before this PR: PHP gets
file_exists() = falsefor that path.After this PR: PHP can read/write/list that directory normally.
Changes
tools/common/lib/wp-config-mounts.ts—getWpConfigMountPaths()utilitytools/common/lib/tests/wp-config-mounts.test.ts— 11 tests covering edge casesapps/cli/wordpress-server-child.ts— auto-mounts ingetBaseRunCLIArgs()(running server path)apps/cli/lib/run-wp-cli-command.ts— auto-mounts inrunWpCliCommand()(standalone WP-CLI path)Testing
Manually verified with a real site that has
DATAMACHINE_WORKSPACE_PATHdefined in wp-config.php:file_exists('/Users/me/Developer')falsetrue✅scandir('/Users/me/Developer')falsetrue✅falsetrue✅Fixes #3082