Files
openidea/sdk/rust/openidea-plugin/tests/api15_process_streaming.rs
T
Ainul YaqinandAkin01 ed6f264875 fix(plugins): provide lossless bounded streaming and configurable capture for processes (#4812)
Plugins running compilers, linters or large diffs lost output: `start` kept only a 1 MiB tail and `run`/`run-command` truncated stderr. API 1.15 adds `process-options` (`max-output-bytes` up to 128 MiB, `buffer-bytes` up to 4 MiB), `run-captured`, which fails explicitly when either stream overflows, and `start-stream`, which streams losslessly with pipe backpressure: readers pause at the buffer limit, resume as `poll`/`chunk` consume, and `wait` drains up to the total limit so fast producers don't deadlock. Overflow stops the process tree and records its exit status before reaping it. `run`, `run-command` and `start` behave as before, and 1.14 components still load.

Closes #4763

Co-authored-by: Akin01 <16496278+Akin01@users.noreply.github.com>
2026-11-22 14:11:13 +08:00

29 lines
1005 B
Rust

use openidea_plugin::{
ProcessOutput,
host::{self, Command, ProcessOptions},
mock::MockHost,
};
#[test]
fn process_captured_and_stream_apis_are_available_in_sdk() {
let mock = MockHost::install().with_capabilities(&["process:git"]);
mock.on_process("git", |_args, _stdin| {
Ok(ProcessOutput { status: Some(0), stdout: "mock stdout".into(), stderr: String::new() })
});
let cmd = Command::new("git").arg("status");
let options = ProcessOptions { max_output_bytes: Some(8 << 20), buffer_bytes: Some(64 << 10) };
let out = host::run_captured(&cmd, None, None, Some(options)).unwrap();
assert_eq!(out.status, Some(0));
assert_eq!(out.stdout, "mock stdout");
let child = host::start_stream(&cmd, None, Some(options)).unwrap();
let chunk = child.poll(1024).unwrap();
assert_eq!(chunk.stdout, "started: git\n");
assert_eq!(chunk.status, None);
let final_chunk = child.wait(100).unwrap();
assert_eq!(final_chunk.status, Some(0));
}