fix: allow corrupted workdir removal

This commit is contained in:
2026-09-12 01:43:37 +09:00
parent ec5a403ec6
commit 4a89c04732
2 changed files with 50 additions and 2 deletions
@@ -3985,6 +3985,27 @@ mod tests {
} }
} }
#[test]
fn corrupted_working_directory_record_can_be_removed() {
let runtime_root = tempfile::tempdir().unwrap();
let materializer = RuntimeGitMaterializer::new(runtime_root.path());
let working_directory_id = "workdir-corrupted";
let root = materializer.working_directory_root(working_directory_id);
fs::create_dir_all(root.join(CHECKOUT_DIR)).unwrap();
fs::write(root.join(MATERIALIZATION_RECORD), b"not-json").unwrap();
let status = materializer
.working_directory_status(working_directory_id)
.unwrap();
assert_eq!(status.summary.status, WorkingDirectoryStatusKind::Corrupted);
let removed = materializer
.cleanup_working_directory(working_directory_id)
.unwrap();
assert_eq!(removed.summary.status, WorkingDirectoryStatusKind::NotFound);
assert!(!root.exists());
}
#[test] #[test]
fn cleanup_working_directory_removes_clone_and_record() { fn cleanup_working_directory_removes_clone_and_record() {
let repo = create_clean_repo(); let repo = create_clean_repo();
+29 -2
View File
@@ -11425,8 +11425,10 @@ fn execute_reserved_workdir_removal_with_provider(
true, true,
); );
}; };
if status.summary.cleanliness.as_deref() != Some("clean") let corrupted = status.summary.status == WorkingDirectoryStatusKind::Corrupted;
|| status.summary.status != WorkingDirectoryStatusKind::Active if !corrupted
&& (status.summary.cleanliness.as_deref() != Some("clean")
|| status.summary.status != WorkingDirectoryStatusKind::Active)
{ {
return api.config_store.complete_workdir_removal_retained( return api.config_store.complete_workdir_removal_retained(
&operation, &operation,
@@ -26684,6 +26686,31 @@ mod tests {
assert_eq!(dirty.disposition, Some(WorkdirRemovalDisposition::Retained)); assert_eq!(dirty.disposition, Some(WorkdirRemovalDisposition::Retained));
assert_eq!(dirty_provider.cleanup_calls(), 0); assert_eq!(dirty_provider.cleanup_calls(), 0);
let (corrupted_operation, mut corrupted_summary) =
reserve_removal_fixture(&api, "provider-corrupted");
corrupted_summary.status = WorkingDirectoryStatusKind::Corrupted;
corrupted_summary.cleanliness = Some("unknown".to_string());
let corrupted_provider = FakeWorkdirRemovalProvider::new(
workdir_removal_result(
WorkerOperationState::Accepted,
Some(corrupted_summary),
Vec::new(),
),
workdir_removal_result(WorkerOperationState::Accepted, None, Vec::new()),
);
let corrupted = execute_reserved_workdir_removal_with_provider(
&api,
corrupted_operation,
false,
&corrupted_provider,
)
.unwrap();
assert_eq!(
corrupted.disposition,
Some(WorkdirRemovalDisposition::Removed)
);
assert_eq!(corrupted_provider.cleanup_calls(), 1);
let (unsupported_operation, unsupported_summary) = let (unsupported_operation, unsupported_summary) =
reserve_removal_fixture(&api, "provider-unsupported"); reserve_removal_fixture(&api, "provider-unsupported");
let unsupported_provider = FakeWorkdirRemovalProvider::new( let unsupported_provider = FakeWorkdirRemovalProvider::new(