mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-27 21:05:34 +00:00
The uv-sync failure handling added in #398 was inline in the async `boot_backend` GUI path, so its logic — exit-code rendering and the stderr "tail" extraction — could only be verified by running the desktop app. This extracts the pure logic into three free functions and adds unit tests, so the message formatting is now covered by `cargo test` with no GUI / webview runtime needed. Extracted: - `uv_sync_stderr_tail(stderr, max_chars)` — last N chars of stderr, trimmed, on char boundaries. The original inline version used `.rev().take(N).collect().chars().rev().collect()`; the new version is `skip(count - N)` which is clearer and equally UTF-8-safe (matters because Windows consoles emit non-ASCII cp9xx bytes — a byte slice could split a codepoint). - `format_uv_sync_failure(root, exit_code, stderr)` — the non-zero-exit message. Now renders a missing exit code (signal-terminated process) as "unknown" instead of a misleading "-1". - `format_uv_sync_spawn_error(root, uv_bin, err)` — the can't-spawn message. `boot_backend` now calls these instead of formatting inline. Tests (7, in `#[cfg(test)] mod tests`): - tail returns whole string when shorter than the limit - tail keeps the END (the actionable line), not the spinner-noise start - tail trims surrounding whitespace - tail never splits a multi-byte codepoint (500×"é", limit 100 → exactly 100 chars, all "é") - failure message includes exit code + stderr tail + the actionable "run uv sync manually" hint - missing exit code renders as "exit unknown", never "exit -1" - spawn-error names the uv binary path and repo root Verified the logic standalone via `rustc --test` (7/7 pass). In CI they run via `cargo test` in desktop.yml's `validate` job, which already builds the Tauri crate with the webkit deps and runs on every PR that touches `frontend/**` — so this changes the existing `cargo check` step to `cargo test` (a superset: same build coverage, plus the tests). This doesn't verify the GUI *behavior* (that still needs a human running the app, or the windows-latest empirical path) — but the error-message logic that was previously untestable now has automated coverage. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>