Skip to content

Commit e0cd26c

Browse files
committed
fix: keep remote workspace backend after preload
1 parent a7ea69d commit e0cd26c

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

inc/Workspace/RemoteWorkspaceBackend.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class RemoteWorkspaceBackend {
2222
* Whether the remote backend should handle workspace operations.
2323
*/
2424
public static function should_handle(): bool {
25+
if ( self::has_registered_state() ) {
26+
return true;
27+
}
28+
2529
$diagnostic = \DataMachineCode\Support\GitRunner::diagnose();
2630
$default = self::should_handle_for_local_capabilities(
2731
! empty($diagnostic['git_available']),
@@ -41,6 +45,18 @@ public static function should_handle_for_local_capabilities( bool $git_available
4145
return ! ( $git_available && $streaming_available );
4246
}
4347

48+
/**
49+
* Whether remote workspace state already exists for this runtime.
50+
*/
51+
public static function has_registered_state(): bool {
52+
$state = function_exists('get_option') ? get_option(self::OPTION, array()) : array();
53+
if ( ! is_array($state) ) {
54+
return false;
55+
}
56+
57+
return ! empty($state['repos']) || ! empty($state['worktrees']);
58+
}
59+
4460
/**
4561
* Clone/register a GitHub repository as a remote workspace primary.
4662
*

tests/smoke-workspace-preload-artifact.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ static function (): WP_Error {
201201
)
202202
);
203203
$assert('falls back to remote backend when local git clone is unavailable', ! is_wp_error($remote_fallback) && 'github_api' === ( $remote_fallback['repositories'][0]['result']['backend'] ?? '' ));
204+
$assert(
205+
'remote preload state keeps remote backend active for later tools',
206+
\DataMachineCode\Workspace\RemoteWorkspaceBackend::has_registered_state()
207+
&& false === \DataMachineCode\Workspace\RemoteWorkspaceBackend::should_handle_for_local_capabilities(true, true)
208+
&& \DataMachineCode\Workspace\RemoteWorkspaceBackend::should_handle()
209+
);
204210

205211
if (array() !== $failures ) {
206212
echo "\nFailures:\n";

0 commit comments

Comments
 (0)