Skip to content

Commit 006445a

Browse files
authored
Merge pull request #586 from Extra-Chill/fix-abandoned-cleanup-compact-pagination
Compact abandoned cleanup pagination handles
2 parents d6cadbe + 77ca8f3 commit 006445a

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

inc/Cli/Commands/WorkspaceCommand.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,6 +3400,8 @@ private function render_worktree_abandoned_result( array $result, array $assoc_a
34003400
* @return array<string,mixed>
34013401
*/
34023402
private function compact_worktree_abandoned_result( array $result ): array {
3403+
$result['steps'] = $this->compact_worktree_abandoned_steps( (array) ( $result['steps'] ?? array() ) );
3404+
34033405
$blocked = (array) ( $result['blocked'] ?? array() );
34043406
if ( count($blocked) <= 25 ) {
34053407
return $result;
@@ -3435,6 +3437,38 @@ private function compact_worktree_abandoned_result( array $result ): array {
34353437
return $result;
34363438
}
34373439

3440+
/**
3441+
* Compact large nested step pagination handle lists.
3442+
*
3443+
* @param array<string,mixed> $steps Abandoned cleanup step summaries.
3444+
* @return array<string,mixed>
3445+
*/
3446+
private function compact_worktree_abandoned_steps( array $steps ): array {
3447+
foreach ( $steps as $step_key => $step ) {
3448+
if ( ! is_array($step) ) {
3449+
continue;
3450+
}
3451+
3452+
$pagination = (array) ( $step['pagination'] ?? array() );
3453+
foreach ( array( 'remaining_handles', 'handles' ) as $field ) {
3454+
$handles = (array) ( $pagination[ $field ] ?? array() );
3455+
if ( count($handles) <= 25 ) {
3456+
continue;
3457+
}
3458+
3459+
$pagination[ $field . '_examples' ] = array_slice(array_values($handles), 0, 25);
3460+
$pagination[ $field . '_truncated' ] = true;
3461+
$pagination[ $field . '_count' ] = count($handles);
3462+
unset($pagination[ $field ]);
3463+
}
3464+
3465+
$step['pagination'] = $pagination;
3466+
$steps[ $step_key ] = $step;
3467+
}
3468+
3469+
return $steps;
3470+
}
3471+
34383472
/**
34393473
* Render CLI output for worktree operations.
34403474
*

tests/smoke-worktree-cleanup-cli.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ public function execute( array $input ): array
577577
'reason' => 'large blocked output fixture',
578578
);
579579
}
580+
$remaining_handles = array_map(fn( $row ) => (string) ( $row['handle'] ?? '' ), $skipped);
580581

581582
return array(
582583
'success' => true,
@@ -590,6 +591,10 @@ public function execute( array $input ): array
590591
'bytes_reclaimed' => empty($input['dry_run']) ? 4096 : 0,
591592
),
592593
'skipped' => $skipped,
594+
'pagination' => array(
595+
'remaining_total' => count($remaining_handles),
596+
'remaining_handles' => $remaining_handles,
597+
),
593598
);
594599
}
595600
}
@@ -1168,13 +1173,17 @@ public function execute( array $input ): array
11681173
datamachine_code_cleanup_assert(array() === ( $abandoned_compact_json['blocked'] ?? null ), 'abandoned compact JSON omits full blocked rows');
11691174
datamachine_code_cleanup_assert(true === ( $abandoned_compact_json['evidence']['blocked_truncated'] ?? false ), 'abandoned compact JSON records blocked truncation evidence');
11701175
datamachine_code_cleanup_assert(isset($abandoned_compact_json['blocked_examples']['active_no_signal'][0]['handle']), 'abandoned compact JSON includes grouped blocked examples');
1176+
datamachine_code_cleanup_assert(! isset($abandoned_compact_json['steps']['bounded_apply_initial']['pagination']['remaining_handles']), 'abandoned compact JSON omits full nested remaining handles');
1177+
datamachine_code_cleanup_assert(32 === (int) ( $abandoned_compact_json['steps']['bounded_apply_initial']['pagination']['remaining_handles_count'] ?? 0 ), 'abandoned compact JSON keeps nested remaining handle count');
1178+
datamachine_code_cleanup_assert(25 === count($abandoned_compact_json['steps']['bounded_apply_initial']['pagination']['remaining_handles_examples'] ?? array()), 'abandoned compact JSON keeps bounded nested handle examples');
11711179

11721180
WP_CLI::$logs = array();
11731181
WP_CLI::$successes = array();
11741182
$command->worktree(array( 'abandoned' ), array( 'apply' => true, 'force' => true, 'stage' => 'bounded', 'limit' => 10, 'passes' => 1, 'verbose' => true, 'format' => 'json' ));
11751183
$abandoned_verbose_json = json_decode(WP_CLI::$logs[0] ?? '', true);
11761184
datamachine_code_cleanup_assert(JSON_ERROR_NONE === json_last_error(), 'abandoned verbose JSON output parses cleanly');
11771185
datamachine_code_cleanup_assert(32 === count($abandoned_verbose_json['blocked'] ?? array()), 'abandoned verbose JSON keeps full blocked rows');
1186+
datamachine_code_cleanup_assert(32 === count($abandoned_verbose_json['steps']['bounded_apply_initial']['pagination']['remaining_handles'] ?? array()), 'abandoned verbose JSON keeps full nested remaining handles');
11781187
datamachine_code_cleanup_assert(! isset($abandoned_verbose_json['evidence']['blocked_truncated']), 'abandoned verbose JSON does not report truncation');
11791188
$bounded_apply_ability->extra_skipped = 0;
11801189

0 commit comments

Comments
 (0)