@@ -22,16 +22,27 @@ class RemoteWorkspaceBackend
2222 {
2323 public static array $ show_input = array ();
2424 public static array $ worktree_input = array ();
25+ public static bool $ show_returns_remote_success = false ;
2526 public static bool $ worktree_returns_remote_success = false ;
2627
2728 public static function should_handle (): bool
2829 {
2930 return true ;
3031 }
3132
32- public function show ( string $ handle ): \WP_Error
33+ public function show ( string $ handle ): array | \WP_Error
3334 {
3435 self ::$ show_input = compact ('handle ' );
36+ if ( self ::$ show_returns_remote_success ) {
37+ return array (
38+ 'success ' => true ,
39+ 'name ' => $ handle ,
40+ 'repo ' => $ handle ,
41+ 'is_worktree ' => str_contains ($ handle , '@ ' ),
42+ 'path ' => 'github://Automattic/ ' . str_replace ('@ ' , '# ' , $ handle ),
43+ );
44+ }
45+
3546 return new \WP_Error (
3647 'remote_workspace_repo_not_found ' ,
3748 'Remote workspace repository "wpcom-codebox" is not registered. Call workspace_clone first. '
@@ -64,13 +75,17 @@ class Workspace
6475 public function show_repo ( string $ handle ): array
6576 {
6677 self ::$ show_input = compact ('handle ' );
78+ $ parsed = explode ('@ ' , $ handle , 2 );
79+ $ repo = $ parsed [0 ];
80+ $ slug = $ parsed [1 ] ?? '' ;
81+ $ path = '/Users/chubes/Developer/ ' . $ handle ;
6782 return array (
6883 'success ' => true ,
6984 'name ' => $ handle ,
70- 'repo ' => $ handle ,
71- 'is_worktree ' => false ,
72- 'path ' => ' /Users/chubes/Developer/ ' . $ handle ,
73- 'branch ' => 'main ' ,
85+ 'repo ' => $ repo ,
86+ 'is_worktree ' => '' !== $ slug ,
87+ 'path ' => $ path ,
88+ 'branch ' => '' !== $ slug ? str_replace ( ' - ' , ' / ' , $ slug ) : ' main ' ,
7489 'remote ' => 'git@github.a8c.com:Automattic/wpcom-codebox.git ' ,
7590 'commit ' => 'abc123 listed primary ' ,
7691 'dirty ' => 0 ,
@@ -161,10 +176,31 @@ function is_wp_error( $value ): bool
161176 )
162177 );
163178
164- $ assert ('remote show attempted first ' , ' wpcom-codebox ' === ( \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ show_input[ ' handle ' ] ?? '' ) );
165- $ assert ('local show fallback attempted ' , 'wpcom-codebox ' === ( \DataMachineCode \Workspace \Workspace::$ show_input ['handle ' ] ?? '' ));
179+ $ assert ('remote show is not consulted when local primary exists ' , array () === \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ show_input );
180+ $ assert ('local show attempted first ' , 'wpcom-codebox ' === ( \DataMachineCode \Workspace \Workspace::$ show_input ['handle ' ] ?? '' ));
166181 $ assert ('show returns local listed primary ' , is_array ($ show ) && '/Users/chubes/Developer/wpcom-codebox ' === ( $ show ['path ' ] ?? '' ));
167182
183+ \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ show_returns_remote_success = true ;
184+ \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ show_input = array ();
185+ \DataMachineCode \Workspace \Workspace::$ show_input = array ();
186+ $ duplicate_show = \DataMachineCode \Abilities \WorkspaceAbilities::showRepo (
187+ array (
188+ 'name ' => 'wpcom-codebox ' ,
189+ )
190+ );
191+
192+ $ assert ('duplicate remote show is not consulted when local primary exists ' , array () === \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ show_input );
193+ $ assert ('duplicate local primary wins show path ' , is_array ($ duplicate_show ) && '/Users/chubes/Developer/wpcom-codebox ' === ( $ duplicate_show ['path ' ] ?? '' ));
194+
195+ $ duplicate_path = \DataMachineCode \Abilities \WorkspaceAbilities::getPath (
196+ array (
197+ 'name ' => 'wpcom-codebox@fix-listed-primary-resolution ' ,
198+ )
199+ );
200+
201+ $ assert ('workspace path returns local worktree when duplicate remote exists ' , is_array ($ duplicate_path ) && '/Users/chubes/Developer/wpcom-codebox@fix-listed-primary-resolution ' === ( $ duplicate_path ['path ' ] ?? '' ));
202+ $ assert ('workspace path marks local worktree handle as existing ' , is_array ($ duplicate_path ) && true === ( $ duplicate_path ['exists ' ] ?? null ));
203+
168204 \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ worktree_returns_remote_success = true ;
169205 \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ worktree_input = array ();
170206 $ worktree = \DataMachineCode \Abilities \WorkspaceAbilities::worktreeAdd (
0 commit comments