diff --git a/inc/Runtime/MountedRuntimeBootstrap.php b/inc/Runtime/MountedRuntimeBootstrap.php index 8e58e98..6f434bb 100644 --- a/inc/Runtime/MountedRuntimeBootstrap.php +++ b/inc/Runtime/MountedRuntimeBootstrap.php @@ -185,10 +185,11 @@ public static function adopt_workspace_mounts(): void { continue; } + $workspace_ref = (string) ( $mount['workspace_ref'] ?? '' ); WorkspaceAbilities::adoptRepo( array( 'path' => $path, - 'name' => basename($path), + 'name' => '' !== $workspace_ref ? $workspace_ref : basename($path), ) ); } @@ -207,7 +208,7 @@ private static function workspace_root_from_context( array $context ): string { /** * @param array $context - * @return array + * @return array */ private static function workspace_mounts( array $context, string $workspace_root ): array { $workspace = self::runtime_workspace_from_context($context); @@ -221,9 +222,14 @@ private static function workspace_mounts( array $context, string $workspace_root if ( '' === $target || 0 !== strpos($target . '/', $workspace_root . '/') ) { continue; } - $mounts[] = array( - 'path' => $target, - 'repo_backed' => 'repo-backed' === (string) ( $mount['sourceMode'] ?? '' ), + $workspace_ref = trim( (string) ( $mount['workspaceRef'] ?? '' ) ); + $mounts[] = array_filter( + array( + 'path' => $target, + 'repo_backed' => 'repo-backed' === (string) ( $mount['sourceMode'] ?? '' ), + 'workspace_ref' => $workspace_ref, + ), + static fn ( $value ): bool => '' !== $value ); } } diff --git a/tests/mounted-runtime-context.php b/tests/mounted-runtime-context.php index b5ccc50..54b6a7a 100644 --- a/tests/mounted-runtime-context.php +++ b/tests/mounted-runtime-context.php @@ -55,6 +55,29 @@ function mounted_runtime_context_assert_same( mixed $expected, mixed $actual, st mounted_runtime_context_assert_same('/tmp/legacy-mounted-workspace', $context['runtime_workspace']['root'] ?? '', 'Deprecated sandbox workspace input is normalized to runtime workspace.'); +$method = new ReflectionMethod(MountedRuntimeBootstrap::class, 'workspace_mounts'); + +$mounts = $method->invoke( + null, + array( + 'runtime_workspace' => array( + 'root' => '/tmp/mounted-workspace', + 'mounts' => array( + array( + 'target' => '/tmp/mounted-workspace/wp-site-generator', + 'sourceMode' => 'mounted', + 'workspaceRef' => 'wp-site-generator@wpsg-lab-proof-20260622-2102', + ), + ), + ), + ), + '/tmp/mounted-workspace' +); + +mounted_runtime_context_assert_same('wp-site-generator@wpsg-lab-proof-20260622-2102', $mounts[0]['workspace_ref'] ?? '', 'Mounted workspace adoption preserves the full worktree handle.'); + +$method = new ReflectionMethod(MountedRuntimeBootstrap::class, 'discover_context'); + $GLOBALS['wordpress_runtime_context'] = array( 'workspace_root' => '/tmp/generic-wordpress-workspace' ); $context = $method->invoke(null); unset($GLOBALS['wordpress_runtime_context']);