Skip to main content

Module dispatch

Module dispatch 

Source
Expand description

Command dispatch: the Commands enum and the dispatch() function that routes a parsed subcommand to its executor.

This lives in the library crate (not main.rs) so its routing logic can be unit-tested under cargo llvm-cov’s --lib scope. The subcommands whose real execution performs I/O a unit test must never trigger - a real terminal takeover (dash), blocking stdin (setup interactive, foreground run), binding a real port (serve), spawning a detached worker or running a real inference loop (run background / __run-worker) - are routed through the RiskyExecutors trait rather than called directly. That way:

  • unit tests drive dispatch()’s full routing match against a #[cfg(test)] mock (MockRisky) that touches nothing real, and
  • the real implementations live in the (coverage-unmeasured) lev binary as main.rs’s RealExecutors, which simply wires real I/O into the library’s already-tested command cores.

Injection gives a “routing is tested, real I/O is never touched by a test” guarantee without any coverage escape hatch in library code.

Enums§

Commands

Traits§

RiskyExecutors
The subset of commands whose real execution performs I/O that a unit test must never trigger. dispatch() routes these through this trait so its routing logic stays unit-testable with a mock; the real implementations are supplied by the binary (main.rs’s RealExecutors).

Functions§

apply_region_flags
Inject argv-prescanned dynamic --<region> seed flags into a parsed run command. A no-op for every other subcommand. Kept here (a tested lib seam) so the bin entrypoint’s post-parse wiring stays branch-free.
dispatch
Route a parsed subcommand to its executor. Safe commands are called directly (and are exercised through dispatch() by the tests below); the I/O-risky ones go through ex (see RiskyExecutors).