MMnode/bench/tauri/README.md
Z User eefca88d35 feat: Moxie bench - standalone python/web harness for the fixed pipeline
- bench/ FastAPI server: fixed 9-stage pipeline parsed from the base
  workflow, serial render jobs, WS progress mirroring ComfyUI's push
  events, /api/view + ComfyUI-compatible /view, /upload/image,
  /easy-media/* aliases for the ported editor
- dual backend: self-contained mock renderer (numpy+ffmpeg, deterministic
  per prompt/seed, native + RTX-upscaled mp4 branches) and a ComfyUI
  bridge (substitutes the plan into base_workflow.json, converts to the
  /prompt API format, polls history, downloads outputs)
- timeline port: frontend/src/bench mounts the unmodified MultiTrack
  editor against a comfyAPI shim (fetchApi/toast/dialog/custom events);
  build.bench.ts emits bench/ui-dist served by the server
- packaging: PyInstaller onedir spec + Tauri2 sidecar docs
- tests: bench/tests contract suite + scripts/test_bench_pipeline.py
  e2e (API+WS+render); prebuilt bench UI committed
2026-09-28 01:42:58 +00:00

3.3 KiB

Using the bench as a Tauri 2 sidecar

The bench is a self-contained Python HTTP server (FastAPI + uvicorn). Packaged with PyInstaller it becomes an moxie-bench binary your Tauri 2 app spawns at startup and talks to over http://127.0.0.1:<port>.

1. Build the sidecar

# in the MMnode repo
pip install -r bench/requirements.txt pyinstaller
cd frontend && bun install && bun run build:bench:release && cd ..
pyinstaller bench/moxie_bench.spec
# -> dist/moxie-bench/moxie-bench(.exe) + _internal/

Ship the whole dist/moxie-bench/ folder (onedir layout: the binary needs _internal/ beside it).

2. Bundle it with the Tauri app

tauri.conf.json (resources approach — simplest and cross-platform):

{
  "bundle": {
    "resources": {
      "../MMnode/dist/moxie-bench/": "moxie-bench/"
    }
  }
}

The folder lands in the app resource dir; resolve it at runtime with @tauri-apps/api/path → resourceDir().

3. Spawn and wait for health

Rust side (tauri plugin-shell or std::process):

use std::process::{Command, Stdio};
use std::time::Duration;

let sidecar = app.path().resource_dir()?.join("moxie-bench/moxie-bench");
let port: u16 = 8787; // pick a free port, pass it through
let mut child = Command::new(sidecar)
    .arg("--port").arg(port.to_string())
    .arg("--host").arg("127.0.0.1")
    .arg("--backend").arg("auto")   // mock when no ComfyUI is reachable
    .stdout(Stdio::null())
    .stderr(Stdio::null())
    .spawn()?;

// poll until ready before loading the webview UI
async fn wait_healthy(port: u16) -> bool {
    let url = format!("http://127.0.0.1:{port}/api/health");
    for _ in 0..60 {
        if let Ok(resp) = reqwest::get(&url).await {
            if resp.status().is_success() { return true; }
        }
        tokio::time::sleep(Duration::from_millis(500)).await;
    }
    false
}

4. Drive it from the webview

Everything the bench UI does is plain HTTP/WS on the same origin — the Tauri webview can call the same endpoints:

Action Call
health/backend GET /api/health, GET /api/config
base workflow + timeline GET /api/workflow
render plan preview GET /api/plan
queue a render POST /api/render {track_data, overrides}
live progress WebSocket ws://127.0.0.1:<port>/api/ws
job list / detail GET /api/jobs, GET /api/jobs/{id}
play/save outputs GET /api/view?filename=...&type=output&job=<job_id>

POST /api/render body:

{
  "track_data": { "tracks": [ ... editor JSON ... ] },
  "overrides": {
    "width": 1920, "height": 1080, "frame_rate": 24,
    "steps": 4, "seed": 12345, "project_name": "MM-myproject",
    "backend": "auto"
  }
}

5. Backends

  • mock — self-contained synthetic renderer (numpy + ffmpeg). Deterministic per (prompt, seed); real mp4 + audio on both output branches. Use it to develop the Tauri integration with zero model downloads.
  • comfy — drives a running ComfyUI (--comfyui-url, default http://127.0.0.1:8188) with the exact base workflow. Real generation, same API surface. Start ComfyUI headless: python main.py --listen 127.0.0.1.
  • auto (default) — comfy when reachable, else mock.

6. Shutdown

Kill the spawned process on app exit (Rust child.kill() / Drop), or send SIGTERM. The server has no state beyond work/ on disk; job history lives in memory.