Skip to content

Commit 92724f7

Browse files
authored
Merge pull request #605 from Extra-Chill/fix/remote-backend-streaming
Fix remote workspace backend selection without streaming git
2 parents cbe9f2b + 44a933b commit 92724f7

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

inc/Workspace/RemoteWorkspaceBackend.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,25 @@ class RemoteWorkspaceBackend {
2222
* Whether the remote backend should handle workspace operations.
2323
*/
2424
public static function should_handle(): bool {
25+
$diagnostic = \DataMachineCode\Support\GitRunner::diagnose();
26+
$default = self::should_handle_for_local_capabilities(
27+
! empty($diagnostic['git_available']),
28+
! empty($diagnostic['git_available']) && ! empty($diagnostic['proc_open_available'])
29+
);
30+
2531
return (bool) apply_filters(
2632
'datamachine_code_remote_workspace_backend_should_handle',
27-
! \DataMachineCode\Support\GitRunner::is_available()
33+
$default
2834
);
2935
}
3036

37+
/**
38+
* Decide whether constrained runtimes need the GitHub-backed backend.
39+
*/
40+
public static function should_handle_for_local_capabilities( bool $git_available, bool $streaming_available ): bool {
41+
return ! ( $git_available && $streaming_available );
42+
}
43+
3144
/**
3245
* Clone/register a GitHub repository as a remote workspace primary.
3346
*

tests/smoke-remote-workspace-backend.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ function update_option( string $key, mixed $value, bool $autoload = true ): bool
163163
echo "Remote workspace backend - smoke\n";
164164

165165
$backend = new RemoteWorkspaceBackend();
166+
$assert('remote backend handles missing git runtime', RemoteWorkspaceBackend::should_handle_for_local_capabilities(false, false));
167+
$assert('remote backend handles non-streaming git runtime', RemoteWorkspaceBackend::should_handle_for_local_capabilities(true, false));
168+
$assert('remote backend leaves full local git runtime alone', ! RemoteWorkspaceBackend::should_handle_for_local_capabilities(true, true));
169+
166170
$clone = $backend->clone_repo('https://github.com/chubes4/example.git');
167171
$assert('clone registers remote repo', ! is_wp_error($clone) && 'example' === $clone['name'] && 'github_api' === $clone['backend']);
168172
$assert('clone backend result omits model-facing guidance', ! is_wp_error($clone) && ! array_key_exists('next_required_tool', $clone) && ! array_key_exists('next_required_args', $clone));

0 commit comments

Comments
 (0)