Skip to content

Commit 6a1948b

Browse files
committed
fix: delete marked worktrees before classification
1 parent 5f4cfbc commit 6a1948b

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

inc/Cli/Commands/WorkspaceCommand.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,6 +2850,23 @@ private function run_worktree_abandoned_orchestration( array $assoc_args ): arra
28502850
'source' => self::CLEANUP_CLI_SOURCE,
28512851
);
28522852

2853+
if ( $apply ) {
2854+
$bounded = $this->run_worktree_abandoned_bounded_apply($abilities['bounded_apply'], $result, true, $force, $limit, 'initial');
2855+
if ( is_wp_error($bounded) ) {
2856+
return $bounded;
2857+
}
2858+
2859+
if ( 'bounded' === $stage ) {
2860+
$prune = $abilities['prune']->execute(array());
2861+
if ( is_wp_error($prune) ) {
2862+
return $prune;
2863+
}
2864+
$result['steps']['prune'] = $this->summarize_worktree_abandoned_step($prune);
2865+
2866+
return $this->finalize_worktree_abandoned_result($result, $apply, $force, $limit, $passes, $until_budget, $started_at);
2867+
}
2868+
}
2869+
28532870
if ( $stage_order[ $stage ] <= $stage_order['reconcile'] ) {
28542871
$reconcile_input = array_merge(
28552872
$common_page,

tests/smoke-worktree-cleanup-cli.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ public function execute( array $input ): array
11301130
datamachine_code_cleanup_assert(JSON_ERROR_NONE === json_last_error(), 'abandoned JSON output parses cleanly');
11311131
datamachine_code_cleanup_assert(true === ( $abandoned_json['applied'] ?? null ), 'abandoned apply mode is explicit in JSON');
11321132
datamachine_code_cleanup_assert(true === ( $abandoned_json['force'] ?? null ), 'abandoned force mode is explicit in JSON');
1133+
datamachine_code_cleanup_assert('bounded_apply_initial' === array_key_first($abandoned_json['steps'] ?? array()), 'abandoned apply drains already-marked rows before slow classifiers');
11331134
datamachine_code_cleanup_assert(1 === (int) ( $reconcile_metadata_ability->last_input['limit'] ?? 0 ), 'abandoned forwards limit to metadata reconciliation');
11341135
datamachine_code_cleanup_assert(false === ( $reconcile_metadata_ability->last_input['dry_run'] ?? null ), 'abandoned --apply applies metadata reconciliation');
11351136
datamachine_code_cleanup_assert(array( 0, 1 ) === array_map(fn( $input ) => (int) ( $input['offset'] ?? 0 ), array_slice($reconcile_metadata_ability->inputs, -2)), 'abandoned drains metadata reconciliation pages in apply mode');
@@ -1140,7 +1141,7 @@ public function execute( array $input ): array
11401141
datamachine_code_cleanup_assert(true === ( $bounded_apply_ability->last_input['force'] ?? null ), 'abandoned forwards force only to bounded cleanup removal');
11411142
datamachine_code_cleanup_assert(false === ( $bounded_apply_ability->last_input['dry_run'] ?? null ), 'abandoned --apply removes eligible rows');
11421143
datamachine_code_cleanup_assert(1 === $prune_ability->calls, 'abandoned prunes stale git metadata after cleanup pass');
1143-
datamachine_code_cleanup_assert(1 === (int) ( $abandoned_json['summary']['removed'] ?? 0 ), 'abandoned summary reports removed rows');
1144+
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_json['summary']['removed'] ?? 0 ), 'abandoned summary reports removed rows from initial and post-classifier drains');
11441145
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_json['summary']['blocked'] ?? 0 ), 'abandoned summary reports blocked rows');
11451146
datamachine_code_cleanup_assert(1 === (int) ( $abandoned_json['summary']['blocked_by_reason']['unpushed_commits'] ?? 0 ), 'abandoned preserves unpushed-commit blocker evidence');
11461147

@@ -1172,9 +1173,10 @@ public function execute( array $input ): array
11721173
datamachine_code_cleanup_assert(JSON_ERROR_NONE === json_last_error(), 'abandoned stalled remote-clean JSON output parses cleanly');
11731174
datamachine_code_cleanup_assert('remote-clean' === ( $abandoned_remote_clean_stalled_json['continuation']['stage'] ?? '' ), 'abandoned stalled remote-clean emits remote-clean continuation');
11741175
datamachine_code_cleanup_assert(42 === (int) ( $abandoned_remote_clean_stalled_json['continuation']['offset'] ?? -1 ), 'abandoned stalled remote-clean keeps current offset continuation');
1175-
datamachine_code_cleanup_assert(count($bounded_apply_ability->inputs) === $bounded_call_count_before_stalled_classifier + 1, 'abandoned drains bounded cleanup before returning stalled classifier continuation');
1176+
datamachine_code_cleanup_assert(count($bounded_apply_ability->inputs) === $bounded_call_count_before_stalled_classifier + 2, 'abandoned drains bounded cleanup before and after stalled classifier continuation');
1177+
datamachine_code_cleanup_assert('bounded_apply_initial' === array_key_first($abandoned_remote_clean_stalled_json['steps'] ?? array()), 'abandoned stalled classifier run starts with bounded cleanup');
11761178
datamachine_code_cleanup_assert(isset($abandoned_remote_clean_stalled_json['steps']['bounded_apply_remote-clean']), 'abandoned stalled classifier output includes bounded cleanup step');
1177-
datamachine_code_cleanup_assert(1 === (int) ( $abandoned_remote_clean_stalled_json['summary']['removed'] ?? 0 ), 'abandoned stalled classifier summary includes bounded removals');
1179+
datamachine_code_cleanup_assert(2 === (int) ( $abandoned_remote_clean_stalled_json['summary']['removed'] ?? 0 ), 'abandoned stalled classifier summary includes bounded removals');
11781180
$active_remote_clean_ability->stall_at_offset = null;
11791181

11801182
$reconcile_metadata_ability->stall_at_offset = 90;

0 commit comments

Comments
 (0)