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
15 changes: 14 additions & 1 deletion inc/Workspace/RemoteWorkspaceBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ class RemoteWorkspaceBackend {
* Whether the remote backend should handle workspace operations.
*/
public static function should_handle(): bool {
$diagnostic = \DataMachineCode\Support\GitRunner::diagnose();
$default = self::should_handle_for_local_capabilities(
! empty($diagnostic['git_available']),
! empty($diagnostic['git_available']) && ! empty($diagnostic['proc_open_available'])
);

return (bool) apply_filters(
'datamachine_code_remote_workspace_backend_should_handle',
! \DataMachineCode\Support\GitRunner::is_available()
$default
);
}

/**
* Decide whether constrained runtimes need the GitHub-backed backend.
*/
public static function should_handle_for_local_capabilities( bool $git_available, bool $streaming_available ): bool {
return ! ( $git_available && $streaming_available );
}

/**
* Clone/register a GitHub repository as a remote workspace primary.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/smoke-remote-workspace-backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ function update_option( string $key, mixed $value, bool $autoload = true ): bool
echo "Remote workspace backend - smoke\n";

$backend = new RemoteWorkspaceBackend();
$assert('remote backend handles missing git runtime', RemoteWorkspaceBackend::should_handle_for_local_capabilities(false, false));
$assert('remote backend handles non-streaming git runtime', RemoteWorkspaceBackend::should_handle_for_local_capabilities(true, false));
$assert('remote backend leaves full local git runtime alone', ! RemoteWorkspaceBackend::should_handle_for_local_capabilities(true, true));

$clone = $backend->clone_repo('https://github.com/chubes4/example.git');
$assert('clone registers remote repo', ! is_wp_error($clone) && 'example' === $clone['name'] && 'github_api' === $clone['backend']);
$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));
Expand Down
Loading