feat(infra): temp IdeA généralisé à tous les agents + purge du store managed-tmp au shutdown d'IdeA — #200 (QA verte)

This commit is contained in:
2026-08-15 00:14:25 +02:00
parent e6f6eb5b1b
commit b5653b24b5
10 changed files with 271 additions and 14 deletions

View File

@ -238,4 +238,27 @@ impl ManagedTempStore for FsManagedTempStore {
}
Ok(ManagedTempGcReport { deleted })
}
async fn purge_all(&self) -> Result<ManagedTempGcReport, ManagedTempError> {
let mut deleted = 0usize;
let mut entries = match tokio::fs::read_dir(&self.root).await {
Ok(entries) => entries,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
return Ok(ManagedTempGcReport { deleted: 0 });
}
Err(err) => return Err(io_error(err)),
};
while let Some(entry) = entries.next_entry().await.map_err(io_error)? {
let path = entry.path();
let removed = match entry.file_type().await {
Ok(file_type) if file_type.is_dir() => tokio::fs::remove_dir_all(&path).await,
Ok(_) => tokio::fs::remove_file(&path).await,
Err(err) => Err(err),
};
if removed.is_ok() {
deleted += 1;
}
}
Ok(ManagedTempGcReport { deleted })
}
}

View File

@ -173,3 +173,43 @@ async fn handle_collision_does_not_reuse_existing_allocation() {
let _ = tokio::fs::remove_dir_all(app_data).await;
}
#[tokio::test]
async fn purge_all_deletes_active_allocations_eagerly() {
let app_data = temp_app_data("purge-all");
let store = FsManagedTempStore::new(&app_data);
store
.allocate(allocation(
handle("purge_dir"),
ManagedTempKind::Directory,
"dir",
1_000,
None,
))
.await
.unwrap();
store
.allocate(allocation(
handle("purge_file"),
ManagedTempKind::File,
"file",
1_000,
None,
))
.await
.unwrap();
let report = store.purge_all().await.unwrap();
assert_eq!(report.deleted, 2);
assert!(tokio::fs::metadata(store.root().join("purge_dir"))
.await
.is_err());
assert!(tokio::fs::metadata(store.root().join("purge_file"))
.await
.is_err());
assert_eq!(store.purge_all().await.unwrap().deleted, 0);
let _ = tokio::fs::remove_dir_all(app_data).await;
}