Skip to content

Commit 2f20b96

Browse files
authored
Merge pull request #700 from Extra-Chill/fix/issue-697-bulk-cleanup
Fix bulk abandoned worktree cleanup limits
2 parents eb84901 + 30e538e commit 2f20b96

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

inc/Cli/Commands/WorkspaceCommand.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3519,7 +3519,7 @@ public function worktree( array $args, array $assoc_args ): void {
35193519
private function run_worktree_abandoned_orchestration( array $assoc_args ): array|\WP_Error {
35203520
$apply = ! empty($assoc_args['apply']);
35213521
$force = ! empty($assoc_args['force']);
3522-
$limit = isset($assoc_args['limit']) ? max(1, min(100, (int) $assoc_args['limit'])) : 100;
3522+
$limit = isset($assoc_args['limit']) ? max(1, min(1000, (int) $assoc_args['limit'])) : 100;
35233523
$passes = isset($assoc_args['passes']) ? max(1, min(25, (int) $assoc_args['passes'])) : 5;
35243524
$offset = isset($assoc_args['offset']) ? max(0, (int) $assoc_args['offset']) : 0;
35253525
$stage = isset($assoc_args['stage']) ? strtolower( (string) preg_replace('/[^a-zA-Z0-9_-]/', '', (string) $assoc_args['stage']) ) : 'reconcile';
@@ -3580,6 +3580,7 @@ private function run_worktree_abandoned_orchestration( array $assoc_args ): arra
35803580
'steps' => array(),
35813581
'blocked' => array(),
35823582
'summary' => array(
3583+
'scanned' => 0,
35833584
'reconciled' => 0,
35843585
'marked_cleanup_eligible' => 0,
35853586
'would_mark_cleanup_eligible' => 0,
@@ -3633,6 +3634,7 @@ private function run_worktree_abandoned_orchestration( array $assoc_args ): arra
36333634
return $reconcile;
36343635
}
36353636
$result['steps']['reconcile_metadata'] = $this->summarize_worktree_abandoned_step($reconcile);
3637+
$result['summary']['scanned'] += (int) ( $result['steps']['reconcile_metadata']['inspected'] ?? 0 );
36363638
$result['summary']['reconciled'] = (int) ( $reconcile['summary']['written'] ?? 0 );
36373639
$result['summary']['would_reconcile'] = (int) ( $reconcile['summary']['proposed'] ?? 0 );
36383640

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

36973699
$step_key = sprintf('%s_pass_%d', $key, $pass);
36983700
$result['steps'][ $step_key ] = $this->summarize_worktree_abandoned_step($step);
3701+
$result['summary']['scanned'] += (int) ( $result['steps'][ $step_key ]['inspected'] ?? 0 );
36993702
$written = (int) ( $step['summary']['written'] ?? 0 );
37003703
$planned = (int) ( $step['summary']['planned'] ?? 0 );
37013704
$pass_marked += $apply ? $written : $planned;
@@ -3837,6 +3840,7 @@ private function run_worktree_abandoned_bounded_apply( object $ability, array &$
38373840
$result['summary']['removed'] += (int) ( $bounded['summary']['removed'] ?? 0 );
38383841
$result['summary']['would_remove'] += (int) ( $bounded['summary']['would_remove'] ?? 0 );
38393842
$result['summary']['bytes_reclaimed'] += (int) ( $bounded['summary']['bytes_reclaimed'] ?? 0 );
3843+
$result['summary']['scanned'] += (int) ( $result['steps'][ sprintf('bounded_apply_%s', $step_label) ]['inspected'] ?? 0 );
38403844
$result['blocked'] = $this->merge_worktree_abandoned_blockers($result['blocked'], (array) ( $bounded['skipped'] ?? array() ));
38413845

38423846
return $bounded;
@@ -4089,6 +4093,10 @@ private function render_worktree_abandoned_result( array $result, array $assoc_a
40894093
'metric' => 'applied',
40904094
'value' => ! empty($result['applied']) ? 'yes' : 'no',
40914095
),
4096+
array(
4097+
'metric' => 'scanned',
4098+
'value' => (string) ( $summary['scanned'] ?? 0 ),
4099+
),
40924100
array(
40934101
'metric' => 'reconciled',
40944102
'value' => (string) ( $summary['reconciled'] ?? 0 ),

tests/smoke-worktree-cleanup-cli.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,15 @@ public function execute( array $input ): array
16441644
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_json['summary']['removed'] ?? 0 ), 'abandoned summary reports removed rows from initial and post-classifier drains');
16451645
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_json['summary']['blocked'] ?? 0 ), 'abandoned summary reports blocked rows');
16461646
datamachine_code_cleanup_assert(1 === (int) ( $abandoned_json['summary']['blocked_by_reason']['unpushed_commits'] ?? 0 ), 'abandoned preserves unpushed-commit blocker evidence');
1647+
datamachine_code_cleanup_assert(16 === (int) ( $abandoned_json['summary']['scanned'] ?? 0 ), 'abandoned summary reports aggregate scanned rows across classifier and bounded cleanup stages');
1648+
1649+
WP_CLI::$logs = array();
1650+
WP_CLI::$successes = array();
1651+
$command->worktree(array( 'abandoned' ), array( 'apply' => true, 'force' => true, 'stage' => 'bounded', 'limit' => 500, 'passes' => 1, 'format' => 'json' ));
1652+
$abandoned_bulk_limit_json = json_decode(WP_CLI::$logs[0] ?? '', true);
1653+
datamachine_code_cleanup_assert(JSON_ERROR_NONE === json_last_error(), 'abandoned bulk-limit JSON output parses cleanly');
1654+
datamachine_code_cleanup_assert(500 === (int) ( $abandoned_bulk_limit_json['limit'] ?? 0 ), 'abandoned honors operator bulk limit above the old 100-row cap');
1655+
datamachine_code_cleanup_assert(500 === (int) ( $bounded_apply_ability->last_input['limit'] ?? 0 ), 'abandoned forwards operator bulk limit to bounded cleanup apply');
16471656

16481657
$bounded_apply_ability->extra_skipped = 30;
16491658
WP_CLI::$logs = array();

0 commit comments

Comments
 (0)