Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions inc/Runtime/MountedRuntimeBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
);
}
Expand All @@ -207,7 +208,7 @@ private static function workspace_root_from_context( array $context ): string {

/**
* @param array<string,mixed> $context
* @return array<int,array{path:string,repo_backed:bool}>
* @return array<int,array{path:string,repo_backed:bool,workspace_ref?:string}>
*/
private static function workspace_mounts( array $context, string $workspace_root ): array {
$workspace = self::runtime_workspace_from_context($context);
Expand All @@ -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
);
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/mounted-runtime-context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Loading