fix: Review-Befunde beheben (Image-Bau, Absturzsicherung, Image-Name, Ausgabelimit)
- App baut cb-python selbst: Containerfile eingebettet, Befehle image_status und build_image, Live-Ausgabe, Knopf in den Einstellungen. start_batch prüft vorher, ob die Images da sind. - running-Flag wird per Wächter zurückgesetzt, auch nach einem Absturz. - Ein Fehler in einem Lauf beendet nicht mehr den Batch: Lauf wird als sandbox_error gespeichert. endpoint_error und sandbox_error zählen nicht in die Bewertung und werden beim Fortsetzen wiederholt. - Image-Name wird geprüft (kein führendes -, nur erlaubte Zeichen), Podman bekommt -- vor dem Image. - Ausgabe von Befehlen wird auf 1 MiB je Strom begrenzt. - Abbruch wird auch vor dem Aufwärmen geprüft. - Fehlerklassen lesbar, Hinweis auf nicht gewertete Läufe. 65 Unit-Tests grün (6 ignorierte Integrationstests); echter Sandbox- und Image-Test grün. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
mod agent;
|
||||
mod config;
|
||||
mod images;
|
||||
mod ranking;
|
||||
mod runner;
|
||||
mod sandbox;
|
||||
@ -19,6 +20,7 @@ use tauri::{Emitter, Manager, State};
|
||||
|
||||
pub const DB_FILE: &str = "coding-bench.sqlite";
|
||||
pub const EVENT_NAME: &str = "batch-event";
|
||||
pub const IMAGE_EVENT: &str = "image-build";
|
||||
|
||||
/// Aufgelöste Pfade, einmal beim Start ermittelt.
|
||||
pub struct AppPaths(pub Paths);
|
||||
@ -35,6 +37,18 @@ pub struct RunState {
|
||||
pub cancel: Arc<AtomicBool>,
|
||||
/// Gesetzt, solange ein Batch läuft.
|
||||
pub running: Arc<AtomicBool>,
|
||||
/// Gesetzt, solange ein Image gebaut wird.
|
||||
pub building: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
/// Setzt ein Flag beim Verlassen des Gültigkeitsbereichs zurück, auch nach einem Fehler oder Panic.
|
||||
/// Ohne diesen Wächter bliebe `running` nach einem abgestürzten Batch-Thread dauerhaft gesetzt.
|
||||
struct FlagGuard(Arc<AtomicBool>);
|
||||
|
||||
impl Drop for FlagGuard {
|
||||
fn drop(&mut self) {
|
||||
self.0.store(false, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Modell für die Oberfläche, mit Hinweis, ob die Schlüssel-Variable gesetzt ist.
|
||||
@ -200,9 +214,24 @@ async fn start_batch(
|
||||
return Err("Mindestens eine gewählte Aufgabe ist nicht gültig geladen.".into());
|
||||
}
|
||||
|
||||
// Fehlt ein Image, scheitert sonst jeder Lauf einzeln. Besser sofort und mit klarer Anleitung.
|
||||
let mut missing: Vec<String> = Vec::new();
|
||||
for image in selected.iter().map(|t| t.meta.image.clone()).collect::<std::collections::BTreeSet<_>>() {
|
||||
if !images::exists(&runtime, &image)? {
|
||||
missing.push(image);
|
||||
}
|
||||
}
|
||||
if !missing.is_empty() {
|
||||
return Err(format!(
|
||||
"Container-Image fehlt: {}. Baue es in den Einstellungen unter „Container-Images“.",
|
||||
missing.join(", ")
|
||||
));
|
||||
}
|
||||
|
||||
if run.running.swap(true, Ordering::SeqCst) {
|
||||
return Err("Ein Batch läuft bereits.".into());
|
||||
}
|
||||
let _running_guard = FlagGuard(run.running.clone());
|
||||
run.cancel.store(false, Ordering::SeqCst);
|
||||
|
||||
let jobs = runner::plan(&models, &selected, repeats);
|
||||
@ -214,27 +243,83 @@ async fn start_batch(
|
||||
};
|
||||
let db_path = paths.0.data_dir.join(DB_FILE);
|
||||
let cancel = run.cancel.clone();
|
||||
let running = run.running.clone();
|
||||
let emitter = app.clone();
|
||||
|
||||
let result = tauri::async_runtime::spawn_blocking(move || {
|
||||
let outcome = (|| -> Result<BatchSummary, String> {
|
||||
let mut store = Store::open(&db_path)?;
|
||||
let on_event = |e: &Event| {
|
||||
let _ = emitter.emit(EVENT_NAME, e);
|
||||
};
|
||||
runner::run_batch(&mut store, &run_cfg, None, ¬e, repeats, &jobs, &cancel, &on_event)
|
||||
})();
|
||||
running.store(false, Ordering::SeqCst);
|
||||
outcome
|
||||
let mut store = Store::open(&db_path)?;
|
||||
let on_event = |e: &Event| {
|
||||
let _ = emitter.emit(EVENT_NAME, e);
|
||||
};
|
||||
runner::run_batch(&mut store, &run_cfg, None, ¬e, repeats, &jobs, &cancel, &on_event)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("Batch-Thread abgebrochen: {e}"))?;
|
||||
|
||||
run.running.store(false, Ordering::SeqCst);
|
||||
result
|
||||
}
|
||||
|
||||
/// Zustand eines Container-Images für die Einstellungen.
|
||||
#[derive(Serialize)]
|
||||
pub struct ImageStatus {
|
||||
pub image: String,
|
||||
pub available: bool,
|
||||
/// Die App kann es selbst bauen.
|
||||
pub buildable: bool,
|
||||
/// Fehlertext, falls die Prüfung selbst scheiterte (z. B. Podman fehlt).
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
/// Images, die die Aufgaben brauchen, und ihr Zustand.
|
||||
#[tauri::command]
|
||||
fn image_status(paths: State<'_, AppPaths>, cfg: State<'_, ConfigState>) -> Result<Vec<ImageStatus>, String> {
|
||||
let runtime = cfg.config.lock().map_err(|e| e.to_string())?.container_runtime.clone();
|
||||
let mut names: std::collections::BTreeSet<String> = tasks::load_all(&paths.0.tasks_dir)
|
||||
.tasks
|
||||
.into_iter()
|
||||
.map(|t| t.meta.image)
|
||||
.collect();
|
||||
// Das eingebaute Standard-Image zeigen wir auch ohne Aufgaben.
|
||||
names.insert("cb-python:latest".to_string());
|
||||
Ok(names
|
||||
.into_iter()
|
||||
.map(|image| {
|
||||
let buildable = images::embedded_containerfile(&image).is_some();
|
||||
match images::exists(&runtime, &image) {
|
||||
Ok(available) => ImageStatus { image, available, buildable, error: None },
|
||||
Err(e) => ImageStatus { image, available: false, buildable, error: Some(e) },
|
||||
}
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Baut ein eingebettetes Image. Die Ausgabe kommt zeilenweise als Ereignis `image-build`.
|
||||
#[tauri::command]
|
||||
async fn build_image(
|
||||
app: tauri::AppHandle,
|
||||
cfg: State<'_, ConfigState>,
|
||||
run: State<'_, RunState>,
|
||||
image: String,
|
||||
) -> Result<(), String> {
|
||||
tasks::validate_image(&image)?;
|
||||
if images::embedded_containerfile(&image).is_none() {
|
||||
return Err(format!("Für {image} gibt es kein eingebautes Containerfile."));
|
||||
}
|
||||
let runtime = cfg.config.lock().map_err(|e| e.to_string())?.container_runtime.clone();
|
||||
if run.building.swap(true, Ordering::SeqCst) {
|
||||
return Err("Es wird bereits ein Image gebaut.".into());
|
||||
}
|
||||
let _guard = FlagGuard(run.building.clone());
|
||||
let emitter = app.clone();
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
let name = image.clone();
|
||||
images::build(&runtime, &image, &mut |line| {
|
||||
let _ = emitter.emit(IMAGE_EVENT, serde_json::json!({ "image": name, "line": line }));
|
||||
})
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("Build-Thread abgebrochen: {e}"))?
|
||||
}
|
||||
|
||||
/// Bricht den laufenden Batch ab. Der aktuelle Lauf wird verworfen.
|
||||
/// Gibt `false` zurück, wenn gerade kein Batch läuft.
|
||||
#[tauri::command]
|
||||
@ -347,6 +432,7 @@ pub fn run() {
|
||||
app.manage(RunState {
|
||||
cancel: Arc::new(AtomicBool::new(false)),
|
||||
running: Arc::new(AtomicBool::new(false)),
|
||||
building: Arc::new(AtomicBool::new(false)),
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
@ -362,7 +448,9 @@ pub fn run() {
|
||||
batch_results,
|
||||
batch_ranking,
|
||||
run_steps,
|
||||
runtime_status
|
||||
runtime_status,
|
||||
image_status,
|
||||
build_image
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user