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
34 changes: 34 additions & 0 deletions inc/Cli/Commands/WorkspaceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3400,6 +3400,8 @@ private function render_worktree_abandoned_result( array $result, array $assoc_a
* @return array<string,mixed>
*/
private function compact_worktree_abandoned_result( array $result ): array {
$result['steps'] = $this->compact_worktree_abandoned_steps( (array) ( $result['steps'] ?? array() ) );

$blocked = (array) ( $result['blocked'] ?? array() );
if ( count($blocked) <= 25 ) {
return $result;
Expand Down Expand Up @@ -3435,6 +3437,38 @@ private function compact_worktree_abandoned_result( array $result ): array {
return $result;
}

/**
* Compact large nested step pagination handle lists.
*
* @param array<string,mixed> $steps Abandoned cleanup step summaries.
* @return array<string,mixed>
*/
private function compact_worktree_abandoned_steps( array $steps ): array {
foreach ( $steps as $step_key => $step ) {
if ( ! is_array($step) ) {
continue;
}

$pagination = (array) ( $step['pagination'] ?? array() );
foreach ( array( 'remaining_handles', 'handles' ) as $field ) {
$handles = (array) ( $pagination[ $field ] ?? array() );
if ( count($handles) <= 25 ) {
continue;
}

$pagination[ $field . '_examples' ] = array_slice(array_values($handles), 0, 25);
$pagination[ $field . '_truncated' ] = true;
$pagination[ $field . '_count' ] = count($handles);
unset($pagination[ $field ]);
}

$step['pagination'] = $pagination;
$steps[ $step_key ] = $step;
}

return $steps;
}

/**
* Render CLI output for worktree operations.
*
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 @@ -577,6 +577,7 @@ public function execute( array $input ): array
'reason' => 'large blocked output fixture',
);
}
$remaining_handles = array_map(fn( $row ) => (string) ( $row['handle'] ?? '' ), $skipped);

return array(
'success' => true,
Expand All @@ -590,6 +591,10 @@ public function execute( array $input ): array
'bytes_reclaimed' => empty($input['dry_run']) ? 4096 : 0,
),
'skipped' => $skipped,
'pagination' => array(
'remaining_total' => count($remaining_handles),
'remaining_handles' => $remaining_handles,
),
);
}
}
Expand Down Expand Up @@ -1168,13 +1173,17 @@ public function execute( array $input ): array
datamachine_code_cleanup_assert(array() === ( $abandoned_compact_json['blocked'] ?? null ), 'abandoned compact JSON omits full blocked rows');
datamachine_code_cleanup_assert(true === ( $abandoned_compact_json['evidence']['blocked_truncated'] ?? false ), 'abandoned compact JSON records blocked truncation evidence');
datamachine_code_cleanup_assert(isset($abandoned_compact_json['blocked_examples']['active_no_signal'][0]['handle']), 'abandoned compact JSON includes grouped blocked examples');
datamachine_code_cleanup_assert(! isset($abandoned_compact_json['steps']['bounded_apply_initial']['pagination']['remaining_handles']), 'abandoned compact JSON omits full nested remaining handles');
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');
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');

WP_CLI::$logs = array();
WP_CLI::$successes = array();
$command->worktree(array( 'abandoned' ), array( 'apply' => true, 'force' => true, 'stage' => 'bounded', 'limit' => 10, 'passes' => 1, 'verbose' => true, 'format' => 'json' ));
$abandoned_verbose_json = json_decode(WP_CLI::$logs[0] ?? '', true);
datamachine_code_cleanup_assert(JSON_ERROR_NONE === json_last_error(), 'abandoned verbose JSON output parses cleanly');
datamachine_code_cleanup_assert(32 === count($abandoned_verbose_json['blocked'] ?? array()), 'abandoned verbose JSON keeps full blocked rows');
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');
datamachine_code_cleanup_assert(! isset($abandoned_verbose_json['evidence']['blocked_truncated']), 'abandoned verbose JSON does not report truncation');
$bounded_apply_ability->extra_skipped = 0;

Expand Down
Loading