console: piped lines run in order; cargo-valid: empty_world allows the first folder of the package path

The runner mounts the package at its host path, so / shows its first
folder: tmp locally, build in the Nix sandbox.
This commit is contained in:
2026-10-23 08:48:14 +01:00
parent c926f3bc72
commit e3935031ac
3 changed files with 70 additions and 56 deletions
+49 -46
View File
@@ -8,7 +8,7 @@ use std::{
time::Duration,
};
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
io::AsyncWriteExt,
process::{Child, Command},
};
@@ -307,51 +307,54 @@ async fn console_error_stops_host() {
assert!(stopped > 0);
}
/// Ps and kill remain available before a slow command returns.
/// Piped calls wait for activation, and EOF or quit preserves the last result.
#[tokio::test]
async fn piped_console_accepts_commands_during_a_call() {
let (_folder, world) = world();
install_probe(&world);
let mut child = binary()
.arg("run")
.arg(world)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
let mut input = child.stdin.take().unwrap();
let mut output = BufReader::new(child.stdout.take().unwrap()).lines();
input.write_all(b"probe.busy\n").await.unwrap();
let mut pid = None;
tokio::time::timeout(Duration::from_secs(15), async {
while pid.is_none() {
input.write_all(b"ps\n").await.unwrap();
while let Some(line) = output.next_line().await.unwrap() {
if line.contains("probe busy console") {
pid = line.split_whitespace().next().map(str::to_owned);
break;
}
if line.contains("PID PLUGIN METHOD") {
break;
}
}
async fn piped_console_runs_dependent_commands_in_order() {
for ending in ["", "quit\n"] {
let (_folder, world) = world();
std::fs::copy(probe(), world.join("candidate.wasm")).unwrap();
std::fs::create_dir_all(world.join("state/probe")).unwrap();
std::fs::write(world.join("state/probe/discover.json"), r#"{"methods":[]}"#).unwrap();
let activate = r#"core.activate {"plugin":"notes","wasm":"candidate.wasm","force":true}"#;
let call = r#"notes.echo {"ordered":true}"#;
let mut child = binary()
.arg("run")
.arg(&world)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
child
.stdin
.take()
.unwrap()
.write_all(format!("{activate}\n{call}\n{ending}").as_bytes())
.await
.unwrap();
let output = tokio::time::timeout(Duration::from_secs(20), child.wait_with_output())
.await
.unwrap()
.unwrap();
let stdout = String::from_utf8(output.stdout).unwrap();
assert_eq!(
output.status.code(),
Some(0),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(!stdout.contains("error:"), "{stdout}");
assert!(stdout.contains(r#""ordered": true"#), "{stdout}");
assert!(
stdout.find(&format!("> {activate}")).unwrap()
< stdout.find(&format!("> {call}")).unwrap(),
"{stdout}"
);
if !ending.is_empty() {
assert!(
stdout.find(r#""ordered": true"#).unwrap() < stdout.find("> quit").unwrap(),
"{stdout}"
);
}
})
.await
.unwrap();
input
.write_all(format!("kill {}\n", pid.unwrap()).as_bytes())
.await
.unwrap();
tokio::time::timeout(Duration::from_secs(15), async {
while let Some(line) = output.next_line().await.unwrap() {
if line.starts_with("> kill ") {
break;
}
}
})
.await
.unwrap();
input.write_all(b"quit\n").await.unwrap();
assert_eq!(status(&mut child).await.code(), Some(0));
}
}