feat: Batch aus der Oberfläche starten

Tauri-Befehle start_batch, cancel_batch, batch_results. Fortschritt läuft
als Ereignis batch-event. Datenbank coding-bench.sqlite im Datenordner.
Oberfläche: Aufgaben wählen, Modelle und Wiederholungen angeben, starten,
abbrechen, Live-Log und Ergebnistabelle. Ollama-URL in config.toml.
40 Unit-Tests grün, svelte-check ohne Fehler. Im Fenster nicht geprüft.
lib.rs wurde vor meiner Änderung auf der Platte zurückgesetzt (ohne
runner/store); ich habe auf dem aktuellen Stand aufgebaut.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 19:46:04 +01:00
parent c8290aeb94
commit d49e4cfd05
5 changed files with 392 additions and 13 deletions

View File

@ -21,6 +21,8 @@ pub struct Config {
pub tasks_dir: Option<PathBuf>,
/// Container-Programm für die Sandbox (Podman-CLI).
pub container_runtime: String,
/// Ollama-Endpunkt für alle Modelle (Phase 1).
pub ollama_url: String,
/// Speicherlimit pro Lauf, Podman-Schreibweise.
pub sandbox_memory: String,
/// CPU-Anteil pro Lauf.
@ -34,6 +36,7 @@ impl Default for Config {
data_dir: None,
tasks_dir: None,
container_runtime: "podman".into(),
ollama_url: "http://127.0.0.1:11434".into(),
sandbox_memory: limits.memory,
sandbox_cpus: limits.cpus,
}
@ -130,6 +133,13 @@ mod tests {
assert_eq!(c.container_runtime, "podman");
}
#[test]
fn ollama_url_hat_standard_und_ist_ueberschreibbar() {
assert_eq!(Config::default().ollama_url, "http://127.0.0.1:11434");
let c = Config::parse("ollama_url = \"http://srv04:11434\"\n").unwrap();
assert_eq!(c.ollama_url, "http://srv04:11434");
}
#[test]
fn unbekannter_schluessel_ist_fehler() {
assert!(Config::parse("unbekannt = 1\n").is_err());

View File

@ -1,16 +1,31 @@
mod agent;
mod config;
mod runner;
mod store;
mod sandbox;
mod store;
mod tasks;
use config::Paths;
use tauri::{Manager, State};
use config::{Config, Paths};
use runner::{BatchSummary, Event, RunConfig};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use store::{RunRecord, Store};
use tauri::{Emitter, Manager, State};
pub const DB_FILE: &str = "coding-bench.sqlite";
pub const EVENT_NAME: &str = "batch-event";
/// Aufgelöste Pfade, einmal beim Start ermittelt.
pub struct AppPaths(pub Paths);
/// Steuerung für den laufenden Batch. Es läuft immer nur einer.
pub struct RunState {
/// Gesetzt, wenn der laufende Batch abbrechen soll.
pub cancel: Arc<AtomicBool>,
/// Gesetzt, solange ein Batch läuft.
pub running: Arc<AtomicBool>,
}
#[tauri::command]
fn get_paths(paths: State<'_, AppPaths>) -> Paths {
paths.0.clone()
@ -21,6 +36,88 @@ fn load_tasks(paths: State<'_, AppPaths>) -> tasks::LoadReport {
tasks::load_all(&paths.0.tasks_dir)
}
/// Startet einen Batch mit den angegebenen Modellen und Aufgaben-IDs.
/// Fortschritt kommt als Ereignis `batch-event`. Das Ergebnis ist die Zusammenfassung.
#[tauri::command]
async fn start_batch(
app: tauri::AppHandle,
paths: State<'_, AppPaths>,
cfg: State<'_, Config>,
run: State<'_, RunState>,
models: Vec<String>,
task_ids: Vec<String>,
repeats: u32,
note: String,
) -> Result<BatchSummary, String> {
if models.is_empty() || task_ids.is_empty() {
return Err("Mindestens ein Modell und eine Aufgabe wählen.".into());
}
if repeats == 0 {
return Err("Wiederholungen müssen mindestens 1 sein.".into());
}
if run.running.swap(true, Ordering::SeqCst) {
return Err("Ein Batch läuft bereits.".into());
}
run.cancel.store(false, Ordering::SeqCst);
let report = tasks::load_all(&paths.0.tasks_dir);
let selected: Vec<tasks::Task> = report
.tasks
.into_iter()
.filter(|t| task_ids.contains(&t.meta.id))
.collect();
if selected.len() != task_ids.len() {
run.running.store(false, Ordering::SeqCst);
return Err("Mindestens eine gewählte Aufgabe ist nicht gültig geladen.".into());
}
let jobs = runner::plan(&models, &selected, repeats);
let run_cfg = RunConfig {
runtime: cfg.container_runtime.clone(),
endpoint_url: cfg.ollama_url.clone(),
data_dir: paths.0.data_dir.clone(),
limits: cfg.sandbox_limits(),
};
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, &note, repeats, &jobs, &cancel, &on_event)
})();
running.store(false, Ordering::SeqCst);
outcome
})
.await
.map_err(|e| format!("Batch-Thread abgebrochen: {e}"))?;
run.running.store(false, Ordering::SeqCst);
result
}
/// Bricht den laufenden Batch ab. Der aktuelle Lauf wird verworfen.
/// Gibt `false` zurück, wenn gerade kein Batch läuft.
#[tauri::command]
fn cancel_batch(run: State<'_, RunState>) -> bool {
let running = run.running.load(Ordering::SeqCst);
if running {
run.cancel.store(true, Ordering::SeqCst);
}
running
}
/// Alle gespeicherten Läufe eines Batches.
#[tauri::command]
fn batch_results(paths: State<'_, AppPaths>, batch_id: i64) -> Result<Vec<RunRecord>, String> {
let store = Store::open(&paths.0.data_dir.join(DB_FILE))?;
store.runs_for_batch(batch_id)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
@ -35,11 +132,23 @@ pub fn run() {
.app_data_dir()
.map_err(|e| format!("Datenordner nicht ermittelbar: {e}"))?;
let (paths, cfg) = config::load_or_create(&config_dir, &default_data_dir)?;
// Datenbank einmal anlegen, damit Fehler früh sichtbar werden.
Store::open(&paths.data_dir.join(DB_FILE))?;
app.manage(AppPaths(paths));
app.manage(cfg);
app.manage(RunState {
cancel: Arc::new(AtomicBool::new(false)),
running: Arc::new(AtomicBool::new(false)),
});
Ok(())
})
.invoke_handler(tauri::generate_handler![get_paths, load_tasks])
.invoke_handler(tauri::generate_handler![
get_paths,
load_tasks,
start_batch,
cancel_batch,
batch_results
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -179,6 +179,44 @@ impl Store {
Ok(run_id)
}
/// Alle gespeicherten Läufe eines Batches, sortiert nach Modell, Aufgabe und Wiederholung.
pub fn runs_for_batch(&self, batch_id: i64) -> Result<Vec<RunRecord>, String> {
let mut stmt = self
.conn
.prepare(
"SELECT batch_id, model, task_id, repeat_idx, error_class, score, steps,
prompt_tokens, completion_tokens, duration_ms, tps, ttft_tool_ms,
artifact_path, summary, check_output
FROM run WHERE batch_id = ?1 ORDER BY model, task_id, repeat_idx",
)
.map_err(|e| e.to_string())?;
let rows = stmt
.query_map(params![batch_id], |r| {
let class: String = r.get(4)?;
let error_class = serde_json::from_value(serde_json::Value::String(class))
.unwrap_or(ErrorClass::EndpointError);
Ok(RunRecord {
batch_id: r.get(0)?,
model: r.get(1)?,
task_id: r.get(2)?,
repeat_idx: r.get(3)?,
error_class,
score: r.get(5)?,
steps: r.get(6)?,
prompt_tokens: r.get(7)?,
completion_tokens: r.get(8)?,
duration_ms: r.get::<_, i64>(9)? as u128,
tps: r.get(10)?,
ttft_tool_ms: r.get::<_, Option<i64>>(11)?.map(|v| v as u128),
artifact_path: r.get(12)?,
summary: r.get(13)?,
check_output: r.get(14)?,
})
})
.map_err(|e| e.to_string())?;
rows.collect::<Result<Vec<_>, _>>().map_err(|e| e.to_string())
}
pub fn run_count(&self, batch_id: i64) -> Result<i64, String> {
self.conn
.query_row("SELECT COUNT(*) FROM run WHERE batch_id = ?1", params![batch_id], |r| r.get(0))
@ -249,6 +287,20 @@ mod tests {
assert!(!keys.contains(&("m1".to_string(), "a-01".to_string(), 2)));
}
#[test]
fn laeufe_eines_batches_werden_zurueckgelesen() {
let mut s = Store::open_in_memory().unwrap();
let b = s.create_batch("", 2, "{}").unwrap();
s.insert_run(&rec(b, "m1", "a-01", 2), &[]).unwrap();
s.insert_run(&rec(b, "m1", "a-01", 1), &[]).unwrap();
let runs = s.runs_for_batch(b).unwrap();
assert_eq!(runs.len(), 2);
assert_eq!(runs[0].repeat_idx, 1);
assert_eq!(runs[0].error_class, ErrorClass::Ok);
assert_eq!(runs[0].ttft_tool_ms, Some(300));
assert!(s.runs_for_batch(99).unwrap().is_empty());
}
#[test]
fn unbekannter_batch_existiert_nicht() {
let s = Store::open_in_memory().unwrap();