Skip to main content

Module process

Module process 

Source
Expand description

Subprocess invocation seam shared by the ecosystem crawlers.

Several crawlers ask an external CLI for a path that’s hard to infer otherwise — npm root -g, gem env gemdir, python3 -c "import site; ...", etc. The historical pattern was to embed std::process::Command::new(bin).args([...]).output() directly inside each helper, which leaves two arms untestable without installing the binary: the success arm (binary present, stdout parsed) and the spawn-Err arm (binary missing or unspawnable).

This module provides a CommandRunner trait whose default impl, SystemCommandRunner, performs the real spawn, and whose test double (MockCommandRunner in tests/common/mod.rs) maps (bin, args) to canned stdout. Each shell-out helper accepts a &dyn CommandRunner argument so tests can inject the mock; production callers either build the helper with the default runner or thread a singleton.

Structs§

SystemCommandRunner
Default runner: spawns the real binary via std::process::Command.

Traits§

CommandRunner
Run an external binary with the given args and return its stdout, trimmed, when the spawn succeeded AND the process exited with a success status AND stdout is non-empty after trimming.