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
10 changes: 9 additions & 1 deletion inc/Cli/Commands/WorkspaceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ public function worktree( array $args, array $assoc_args ): void {
private function run_worktree_abandoned_orchestration( array $assoc_args ): array|\WP_Error {
$apply = ! empty($assoc_args['apply']);
$force = ! empty($assoc_args['force']);
$limit = isset($assoc_args['limit']) ? max(1, min(100, (int) $assoc_args['limit'])) : 100;
$limit = isset($assoc_args['limit']) ? max(1, min(1000, (int) $assoc_args['limit'])) : 100;
$passes = isset($assoc_args['passes']) ? max(1, min(25, (int) $assoc_args['passes'])) : 5;
$offset = isset($assoc_args['offset']) ? max(0, (int) $assoc_args['offset']) : 0;
$stage = isset($assoc_args['stage']) ? strtolower( (string) preg_replace('/[^a-zA-Z0-9_-]/', '', (string) $assoc_args['stage']) ) : 'reconcile';
Expand Down Expand Up @@ -3580,6 +3580,7 @@ private function run_worktree_abandoned_orchestration( array $assoc_args ): arra
'steps' => array(),
'blocked' => array(),
'summary' => array(
'scanned' => 0,
'reconciled' => 0,
'marked_cleanup_eligible' => 0,
'would_mark_cleanup_eligible' => 0,
Expand Down Expand Up @@ -3633,6 +3634,7 @@ private function run_worktree_abandoned_orchestration( array $assoc_args ): arra
return $reconcile;
}
$result['steps']['reconcile_metadata'] = $this->summarize_worktree_abandoned_step($reconcile);
$result['summary']['scanned'] += (int) ( $result['steps']['reconcile_metadata']['inspected'] ?? 0 );
$result['summary']['reconciled'] = (int) ( $reconcile['summary']['written'] ?? 0 );
$result['summary']['would_reconcile'] = (int) ( $reconcile['summary']['proposed'] ?? 0 );

Expand Down Expand Up @@ -3696,6 +3698,7 @@ private function run_worktree_abandoned_orchestration( array $assoc_args ): arra

$step_key = sprintf('%s_pass_%d', $key, $pass);
$result['steps'][ $step_key ] = $this->summarize_worktree_abandoned_step($step);
$result['summary']['scanned'] += (int) ( $result['steps'][ $step_key ]['inspected'] ?? 0 );
$written = (int) ( $step['summary']['written'] ?? 0 );
$planned = (int) ( $step['summary']['planned'] ?? 0 );
$pass_marked += $apply ? $written : $planned;
Expand Down Expand Up @@ -3837,6 +3840,7 @@ private function run_worktree_abandoned_bounded_apply( object $ability, array &$
$result['summary']['removed'] += (int) ( $bounded['summary']['removed'] ?? 0 );
$result['summary']['would_remove'] += (int) ( $bounded['summary']['would_remove'] ?? 0 );
$result['summary']['bytes_reclaimed'] += (int) ( $bounded['summary']['bytes_reclaimed'] ?? 0 );
$result['summary']['scanned'] += (int) ( $result['steps'][ sprintf('bounded_apply_%s', $step_label) ]['inspected'] ?? 0 );
$result['blocked'] = $this->merge_worktree_abandoned_blockers($result['blocked'], (array) ( $bounded['skipped'] ?? array() ));

return $bounded;
Expand Down Expand Up @@ -4089,6 +4093,10 @@ private function render_worktree_abandoned_result( array $result, array $assoc_a
'metric' => 'applied',
'value' => ! empty($result['applied']) ? 'yes' : 'no',
),
array(
'metric' => 'scanned',
'value' => (string) ( $summary['scanned'] ?? 0 ),
),
array(
'metric' => 'reconciled',
'value' => (string) ( $summary['reconciled'] ?? 0 ),
Expand Down
9 changes: 9 additions & 0 deletions tests/smoke-worktree-cleanup-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,15 @@ public function execute( array $input ): array
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_json['summary']['removed'] ?? 0 ), 'abandoned summary reports removed rows from initial and post-classifier drains');
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_json['summary']['blocked'] ?? 0 ), 'abandoned summary reports blocked rows');
datamachine_code_cleanup_assert(1 === (int) ( $abandoned_json['summary']['blocked_by_reason']['unpushed_commits'] ?? 0 ), 'abandoned preserves unpushed-commit blocker evidence');
datamachine_code_cleanup_assert(16 === (int) ( $abandoned_json['summary']['scanned'] ?? 0 ), 'abandoned summary reports aggregate scanned rows across classifier and bounded cleanup stages');

WP_CLI::$logs = array();
WP_CLI::$successes = array();
$command->worktree(array( 'abandoned' ), array( 'apply' => true, 'force' => true, 'stage' => 'bounded', 'limit' => 500, 'passes' => 1, 'format' => 'json' ));
$abandoned_bulk_limit_json = json_decode(WP_CLI::$logs[0] ?? '', true);
datamachine_code_cleanup_assert(JSON_ERROR_NONE === json_last_error(), 'abandoned bulk-limit JSON output parses cleanly');
datamachine_code_cleanup_assert(500 === (int) ( $abandoned_bulk_limit_json['limit'] ?? 0 ), 'abandoned honors operator bulk limit above the old 100-row cap');
datamachine_code_cleanup_assert(500 === (int) ( $bounded_apply_ability->last_input['limit'] ?? 0 ), 'abandoned forwards operator bulk limit to bounded cleanup apply');

$bounded_apply_ability->extra_skipped = 30;
WP_CLI::$logs = array();
Expand Down
Loading