Skip to content

Commit cfa66a1

Browse files
authored
Add workspace remote backend hygiene diagnostics (#641)
1 parent 77ff744 commit cfa66a1

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

inc/Workspace/WorkspaceHygieneReport.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function workspace_hygiene_report( array $opts = array() ): array|\WP_Err
5959
$cleanup = null;
6060
$cleanup_error = null;
6161
$locks = WorkspaceMutationLock::status($this->workspace_path);
62+
$remote_backend = $this->build_remote_workspace_backend_report();
6263

6364
if ( $include_cleanup ) {
6465
$cleanup = $this->worktree_cleanup_merged(
@@ -92,6 +93,7 @@ public function workspace_hygiene_report( array $opts = array() ): array|\WP_Err
9293
),
9394
'worktrees' => $worktree_summary,
9495
'worktree_status_mode' => $worktree_status_mode,
96+
'remote_backend' => $remote_backend,
9597
'top_repos_by_worktrees' => $this->top_repos_by_worktree_count($worktrees, 10),
9698
'top_repos_by_size' => $this->top_repos_by_size( (array) ( $size_report['entries'] ?? array() ), 10),
9799
'locks' => $locks,
@@ -105,12 +107,40 @@ public function workspace_hygiene_report( array $opts = array() ): array|\WP_Err
105107
$include_cleanup ? 'Cleanup summary uses inventory-only dry-run detection (--inventory-only --skip-github); no per-worktree git probes or GitHub API lookups are required.' : 'Cleanup dry-run disabled by request.',
106108
! empty($worktree_summary['stale_primaries']) ? 'One or more primary checkouts are behind their configured upstream according to local remote refs; refresh before using a primary for verification.' : '',
107109
! empty($worktree_summary['base_branch_worktree_count']) ? 'One or more non-primary worktrees have a base branch checked out; gh pr merge --delete-branch can merge remotely but fail local cleanup.' : '',
110+
! empty($remote_backend['registered_state']) ? 'Remote workspace state is registered; local checkout commands should fall back to local workspace discovery when the remote backend misses a handle.' : '',
108111
)
109112
)
110113
),
111114
);
112115
}
113116

117+
/**
118+
* Summarize the GitHub API remote workspace backend state for diagnostics.
119+
*
120+
* @return array<string,mixed>
121+
*/
122+
private function build_remote_workspace_backend_report(): array {
123+
$available = class_exists(RemoteWorkspaceBackend::class);
124+
if ( ! $available ) {
125+
return array(
126+
'available' => false,
127+
'active' => false,
128+
'registered_state' => false,
129+
'mode' => 'local_git',
130+
);
131+
}
132+
133+
$registered_state = RemoteWorkspaceBackend::has_registered_state();
134+
$active = $registered_state ? true : RemoteWorkspaceBackend::should_handle();
135+
136+
return array(
137+
'available' => true,
138+
'active' => $active,
139+
'registered_state' => $registered_state,
140+
'mode' => $active ? 'remote_or_fallback' : 'local_git',
141+
);
142+
}
143+
114144
/**
115145
* Run age-gated workspace retention cleanup and return a compact report.
116146
*

tests/smoke-workspace-hygiene-report.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,31 @@ function is_wp_error( $value ): bool
6666
return $value instanceof \WP_Error;
6767
}
6868

69-
function get_option( string $name, $default = false ) // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
69+
function get_option( string $name, $default = false )
7070
{
71+
if ('datamachine_code_remote_workspace_state' === $name ) {
72+
return array(
73+
'repos' => array(
74+
'github-only' => array(
75+
'repo' => 'Extra-Chill/github-only',
76+
'url' => 'https://github.com/Extra-Chill/github-only.git',
77+
),
78+
),
79+
'worktrees' => array(),
80+
);
81+
}
82+
83+
if ('datamachine_worktree_metadata' !== $name ) {
84+
return $default;
85+
}
86+
7187
return $GLOBALS['__dmc_hygiene_metadata'];
7288
}
7389

7490
include __DIR__ . '/../inc/Workspace/WorkspaceLockStore.php';
7591
include __DIR__ . '/../inc/Workspace/WorkspaceMutationLock.php';
7692
include __DIR__ . '/../inc/Workspace/WorktreeContextInjector.php';
93+
include __DIR__ . '/../inc/Workspace/RemoteWorkspaceBackend.php';
7794
include __DIR__ . '/../inc/Workspace/Workspace.php';
7895

7996
function datamachine_code_hygiene_report_assert( bool $condition, string $message ): void
@@ -157,6 +174,9 @@ public function worktree_list( ?string $repo = null, ?string $state = null, arra
157174
datamachine_code_hygiene_report_assert(1 === (int) ( $minimal['worktrees']['missing_metadata'] ?? 0 ), 'inventory counts missing metadata from registry only');
158175
datamachine_code_hygiene_report_assert('alpha' === ( $minimal['top_repos_by_worktrees'][0]['repo'] ?? '' ), 'inventory builds repo count leaders');
159176
datamachine_code_hygiene_report_assert(1 === (int) ( $minimal['top_repos_by_worktrees'][0]['worktree_count'] ?? 0 ), 'repo count leaders ignore primaries and missing-metadata repo still sorts after alpha');
177+
datamachine_code_hygiene_report_assert(true === ( $minimal['remote_backend']['registered_state'] ?? false ), 'hygiene reports registered remote workspace state');
178+
datamachine_code_hygiene_report_assert('remote_or_fallback' === ( $minimal['remote_backend']['mode'] ?? '' ), 'hygiene reports remote backend fallback mode');
179+
datamachine_code_hygiene_report_assert(in_array('Remote workspace state is registered; local checkout commands should fall back to local workspace discovery when the remote backend misses a handle.', $minimal['notes'] ?? array(), true), 'hygiene notes remote backend local fallback expectation');
160180

161181
echo "\n[1a] Size report exposes top offenders and kind grouping\n";
162182
$with_sizes = $workspace->workspace_hygiene_report(

0 commit comments

Comments
 (0)